Rename rawins.py to raob.py

This commit is contained in:
XANTRONIX 2025-03-02 01:02:37 -05:00
parent af6d2809b5
commit 368846cb60

View file

@ -10,10 +10,10 @@ from xmet.sounding import Sounding, SoundingSample
CHUNK_SEP = "\x01" CHUNK_SEP = "\x01"
CHUNK_STRIP_CHARS = "\x01\x03\x0a\x20" CHUNK_STRIP_CHARS = "\x01\x03\x0a\x20"
class RawinsReaderException(Exception): class RAOBReaderException(Exception):
... ...
class RawinsSample(): class RAOBSample():
def __init__(self): def __init__(self):
self.surface: bool = False self.surface: bool = False
self.height: float = None self.height: float = None
@ -23,14 +23,14 @@ class RawinsSample():
self.wind_dir: float = None self.wind_dir: float = None
self.wind_speed: float = None self.wind_speed: float = None
class RawinsSounding(): class RAOBSounding():
def __init__(self): def __init__(self):
self.timestamp: datetime.datetime = None self.timestamp: datetime.datetime = None
self.station: int = None self.station: int = None
self.cur: RawinsSample = None self.cur: RAOBSample = None
self.samples: list[RawinsSample] = list() self.samples: list[RAOBSample] = list()
class RawinsObs(): class RAOBObs():
def __init__(self, kind: str): def __init__(self, kind: str):
self.kind: str = kind self.kind: str = kind
self.values: list[str] = list() self.values: list[str] = list()
@ -197,8 +197,8 @@ class RawinsObs():
'pressure': float(pressure) 'pressure': float(pressure)
} }
def parse_sample_values(self, values: list[str]) -> RawinsSample: def parse_sample_values(self, values: list[str]) -> RAOBSample:
sample = RawinsSample() sample = RAOBSample()
if values[0][0:2] == '99': if values[0][0:2] == '99':
sample.surface = True sample.surface = True
@ -221,7 +221,7 @@ class RawinsObs():
return sample return sample
def parse_ttaa(self) -> RawinsSounding: def parse_ttaa(self) -> RAOBSounding:
# #
# Return None if there is no height data up to 100mb. # Return None if there is no height data up to 100mb.
# #
@ -239,7 +239,7 @@ class RawinsObs():
if sample is None: if sample is None:
return return
sounding = RawinsSounding() sounding = RAOBSounding()
sounding.timestamp = self.parse_timestamp(self.values[0]) sounding.timestamp = self.parse_timestamp(self.values[0])
sounding.station = int(self.values[1]) sounding.station = int(self.values[1])
sounding.samples.append(sample) sounding.samples.append(sample)
@ -257,7 +257,7 @@ class RawinsObs():
return sounding return sounding
class RawinsChunk(): class RAOBChunk():
def __init__(self, def __init__(self,
wfo: str, wfo: str,
product: str, product: str,
@ -280,7 +280,7 @@ class RawinsChunk():
if obs is not None: if obs is not None:
yield obs yield obs
obs = RawinsObs(value) obs = RAOBObs(value)
elif obs is not None: elif obs is not None:
obs.read(value) obs.read(value)
@ -297,7 +297,7 @@ class RawinsChunk():
yield sounding yield sounding
class RawinsReader(): class RAOBReader():
""" """
A reader for the global `Current.rawins` file provided by UCAR: A reader for the global `Current.rawins` file provided by UCAR:
@ -308,7 +308,7 @@ class RawinsReader():
self.soundings = dict() self.soundings = dict()
self.current = Sounding() self.current = Sounding()
def parse_chunk(self, text: str) -> RawinsChunk: def parse_chunk(self, text: str) -> RAOBChunk:
meta = { meta = {
'wfo': None, # NWS forecast office 'wfo': None, # NWS forecast office
'product': None # NWS product code 'product': None # NWS product code
@ -330,7 +330,7 @@ class RawinsReader():
match = RE_ID.match(lines[0]) match = RE_ID.match(lines[0])
if match is None: if match is None:
raise RawinsReaderException(f"First chunk line not 3-digit identifier ({lines[0]})") raise RAOBReaderException(f"First chunk line not 3-digit identifier ({lines[0]})")
else: else:
line_index += 1 line_index += 1
@ -342,7 +342,7 @@ class RawinsReader():
match = RE_ISSUANCE.match(lines[1]) match = RE_ISSUANCE.match(lines[1])
if match is None: if match is None:
raise RawinsReaderException('Second chunk line not product issuance') raise RAOBReaderException('Second chunk line not product issuance')
else: else:
meta['wfo'] = match['wfo'] meta['wfo'] = match['wfo']
line_index += 1 line_index += 1
@ -367,7 +367,7 @@ class RawinsReader():
for line in lines[line_index:]: for line in lines[line_index:]:
values.extend(re.split(r'\s+', line)) values.extend(re.split(r'\s+', line))
return RawinsChunk(meta['wfo'], return RAOBChunk(meta['wfo'],
meta['product'], meta['product'],
values) values)