Fix BUFRSounding
This commit is contained in:
parent
d55c83f54c
commit
86444caee6
1 changed files with 28 additions and 6 deletions
|
@ -1,9 +1,11 @@
|
||||||
|
from typing import Self
|
||||||
|
|
||||||
from awips.dataaccess import DataAccessLayer
|
from awips.dataaccess import DataAccessLayer
|
||||||
|
|
||||||
from xmet.sounding import Sounding, SoundingSample
|
from xmet.sounding import Sounding, SoundingSample
|
||||||
from xmet.units import celsius
|
from xmet.units import celsius
|
||||||
|
|
||||||
class BUFRSounding():
|
class BUFRSounding(Sounding):
|
||||||
EDEX_HOST = 'edex-cloud.unidata.ucar.edu'
|
EDEX_HOST = 'edex-cloud.unidata.ucar.edu'
|
||||||
|
|
||||||
BUFR_TYPE = 'bufrua'
|
BUFR_TYPE = 'bufrua'
|
||||||
|
@ -11,12 +13,25 @@ class BUFRSounding():
|
||||||
BUFR_PARAMS_SIGT = set(['prSigT', 'htSigT', 'tpSigT', 'tdSigT'])
|
BUFR_PARAMS_SIGT = set(['prSigT', 'htSigT', 'tpSigT', 'tdSigT'])
|
||||||
BUFR_PARAMS_SIGW = set(['prSigW', 'htSigW', 'wdSigW', 'wsSigW'])
|
BUFR_PARAMS_SIGW = set(['prSigW', 'htSigW', 'wdSigW', 'wsSigW'])
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
|
||||||
|
self.samples_by_pressure = dict()
|
||||||
|
|
||||||
|
def sample(self, pressure: float) -> SoundingSample:
|
||||||
|
sample = self.samples_by_pressure.get(pressure)
|
||||||
|
|
||||||
|
if sample is None:
|
||||||
|
self.samples_by_pressure[pressure] = SoundingSample()
|
||||||
|
|
||||||
|
return self.samples_by_pressure[pressure]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def init():
|
def init():
|
||||||
DataAccessLayer.changeEDEXHost(BUFRSounding.EDEX_HOST)
|
DataAccessLayer.changeEDEXHost(BUFRSounding.EDEX_HOST)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def latest(station: str) -> Sounding:
|
def latest(station: str) -> Self:
|
||||||
request = DataAccessLayer.newDataRequest()
|
request = DataAccessLayer.newDataRequest()
|
||||||
request.setDatatype(BUFRSounding.BUFR_TYPE)
|
request.setDatatype(BUFRSounding.BUFR_TYPE)
|
||||||
request.setParameters('staElev', 'staName')
|
request.setParameters('staElev', 'staName')
|
||||||
|
@ -32,24 +47,31 @@ class BUFRSounding():
|
||||||
response = DataAccessLayer.getGeometryData(request,
|
response = DataAccessLayer.getGeometryData(request,
|
||||||
times=datatimes[-1].validPeriod)
|
times=datatimes[-1].validPeriod)
|
||||||
|
|
||||||
sounding = Sounding()
|
sounding = BUFRSounding()
|
||||||
|
|
||||||
for item in response:
|
for item in response:
|
||||||
params = item.getParameters()
|
params = item.getParameters()
|
||||||
|
|
||||||
if set(params) & BUFRSounding.BUFR_PARAMS_MAN:
|
if set(params) & BUFRSounding.BUFR_PARAMS_MAN:
|
||||||
sample = sounding.sample(item.getNumber('prMan') / 100.0)
|
pressure = item.getNumber('prMan') / 100.0
|
||||||
|
sample = sounding.sample(pressure)
|
||||||
|
|
||||||
|
sample.pressure = pressure
|
||||||
sample.height = item.getNumber('htMan')
|
sample.height = item.getNumber('htMan')
|
||||||
sample.wind_speed = item.getNumber('wsMan')
|
sample.wind_speed = item.getNumber('wsMan')
|
||||||
sample.wind_dir = item.getNumber('wdMan')
|
sample.wind_dir = item.getNumber('wdMan')
|
||||||
|
|
||||||
if set(params) & BUFRSounding.BUFR_PARAMS_SIGT:
|
if set(params) & BUFRSounding.BUFR_PARAMS_SIGT:
|
||||||
sample = sounding.sample(item.getNumber('prSigT') / 100.0)
|
pressure = item.getNumber('prSigT') / 100.0
|
||||||
|
sample = sounding.sample(pressure)
|
||||||
|
|
||||||
sample.temp = celsius(item.getNumber('tpSigT'))
|
sample.temp = celsius(item.getNumber('tpSigT'))
|
||||||
sample.dewpoint = celsius(item.getNumber('tdSigT'))
|
sample.dewpoint = celsius(item.getNumber('tdSigT'))
|
||||||
|
|
||||||
if set(params) & BUFRSounding.BUFR_PARAMS_SIGW:
|
if set(params) & BUFRSounding.BUFR_PARAMS_SIGW:
|
||||||
sample = sounding.sample(item.getNumber('prSigW') / 100.0)
|
pressure = item.getNumber('prSigW') / 100.0
|
||||||
|
sample = sounding.sample(pressure)
|
||||||
|
|
||||||
sample.height = item.getNumber('htSigW')
|
sample.height = item.getNumber('htSigW')
|
||||||
sample.wind_speed = item.getNumber('wsSigW')
|
sample.wind_speed = item.getNumber('wsSigW')
|
||||||
sample.wind_dir = item.getNumber('wdSigW')
|
sample.wind_dir = item.getNumber('wdSigW')
|
||||||
|
|
Loading…
Add table
Reference in a new issue