Pare down rawinsonde parser a bit (for now)

This commit is contained in:
XANTRONIX 2025-02-28 18:51:56 -05:00
parent 0ca324b9b5
commit 44f55167f7

View file

@ -1,5 +1,6 @@
import io
import re
import enum
import datetime
from xmet.util import each_chunk
@ -12,17 +13,52 @@ CHUNK_STRIP_CHARS = "\x01\x03\x0a\x20"
class RawinsReaderException(Exception):
...
class RawinsSample():
def __init__(self):
self.surface: bool = False
self.height: float = None
self.pressure: float = None
self.temp: float = None
self.dewpoint: float = None
class RawinsObs():
def __init__(self, kind: str):
self.kind = str
self.values: list[str] = list()
def read(self, value: str):
self.values.append(value)
class RawinsChunk():
def __init__(self,
wfo: str,
product: str,
station: str,
values: list[str]):
self.wfo = wfo
self.product = product
self.station = station
self.values = values
def is_obs_start(self, value: str) -> bool:
return value == 'TTAA' or value == 'TTBB' \
or value == 'TTCC' or value == 'TTDD' \
or value == 'PPAA' or value == 'PPBB' \
or value == 'PPCC' or value == 'PPDD'
def each_obs(self):
obs = None
for value in self.values:
if self.is_obs_start(value):
if obs is not None:
yield obs
obs = RawinsObs(value)
elif obs is not None:
obs.read(value)
if obs is not None:
yield obs
class RawinsReader():
"""
A reader for the global `Current.rawins` file provided by UCAR:
@ -37,8 +73,7 @@ class RawinsReader():
def parse_chunk(self, text: str) -> RawinsChunk:
meta = {
'wfo': None, # NWS forecast office
'product': None, # NWS product code
'station': None # WMO rawinsonde station ID
'product': None # NWS product code
}
line_index = 0
@ -96,7 +131,6 @@ class RawinsReader():
return RawinsChunk(meta['wfo'],
meta['product'],
meta['station'],
values)
def each_chunk(self) -> list[Sounding]: