Pare down rawinsonde parser a bit (for now)
This commit is contained in:
parent
0ca324b9b5
commit
44f55167f7
1 changed files with 39 additions and 5 deletions
|
@ -1,5 +1,6 @@
|
||||||
import io
|
import io
|
||||||
import re
|
import re
|
||||||
|
import enum
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from xmet.util import each_chunk
|
from xmet.util import each_chunk
|
||||||
|
@ -12,17 +13,52 @@ CHUNK_STRIP_CHARS = "\x01\x03\x0a\x20"
|
||||||
class RawinsReaderException(Exception):
|
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():
|
class RawinsChunk():
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
wfo: str,
|
wfo: str,
|
||||||
product: str,
|
product: str,
|
||||||
station: str,
|
|
||||||
values: list[str]):
|
values: list[str]):
|
||||||
self.wfo = wfo
|
self.wfo = wfo
|
||||||
self.product = product
|
self.product = product
|
||||||
self.station = station
|
|
||||||
self.values = values
|
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():
|
class RawinsReader():
|
||||||
"""
|
"""
|
||||||
A reader for the global `Current.rawins` file provided by UCAR:
|
A reader for the global `Current.rawins` file provided by UCAR:
|
||||||
|
@ -37,8 +73,7 @@ class RawinsReader():
|
||||||
def parse_chunk(self, text: str) -> RawinsChunk:
|
def parse_chunk(self, text: str) -> RawinsChunk:
|
||||||
meta = {
|
meta = {
|
||||||
'wfo': None, # NWS forecast office
|
'wfo': None, # NWS forecast office
|
||||||
'product': None, # NWS product code
|
'product': None # NWS product code
|
||||||
'station': None # WMO rawinsonde station ID
|
|
||||||
}
|
}
|
||||||
|
|
||||||
line_index = 0
|
line_index = 0
|
||||||
|
@ -96,7 +131,6 @@ class RawinsReader():
|
||||||
|
|
||||||
return RawinsChunk(meta['wfo'],
|
return RawinsChunk(meta['wfo'],
|
||||||
meta['product'],
|
meta['product'],
|
||||||
meta['station'],
|
|
||||||
values)
|
values)
|
||||||
|
|
||||||
def each_chunk(self) -> list[Sounding]:
|
def each_chunk(self) -> list[Sounding]:
|
||||||
|
|
Loading…
Add table
Reference in a new issue