Simplify code a bit
This commit is contained in:
parent
b8903a69f8
commit
854cfa65e4
1 changed files with 45 additions and 29 deletions
|
@ -44,6 +44,39 @@ class BUFRSounding(Sounding):
|
||||||
|
|
||||||
return sample
|
return sample
|
||||||
|
|
||||||
|
def sample(self, pressure: float, height: float) -> SoundingSample:
|
||||||
|
if pressure == -99.99:
|
||||||
|
sample = self.sample_by_height(height)
|
||||||
|
else:
|
||||||
|
sample = self.sample_by_pressure(pressure)
|
||||||
|
|
||||||
|
if height != -9999.0:
|
||||||
|
sample.height = height
|
||||||
|
|
||||||
|
return sample
|
||||||
|
|
||||||
|
def record_wind(self,
|
||||||
|
pressure: float,
|
||||||
|
height: float,
|
||||||
|
wind_speed: float,
|
||||||
|
wind_dir: float):
|
||||||
|
sample = self.sample(pressure, height)
|
||||||
|
|
||||||
|
if wind_speed != -9999.0 and wind_dir != -9999.0:
|
||||||
|
sample.wind_speed = wind_speed
|
||||||
|
sample.wind_dir = wind_dir
|
||||||
|
|
||||||
|
def record_temp_dewpoint(self,
|
||||||
|
pressure: float,
|
||||||
|
height: float,
|
||||||
|
temp: float,
|
||||||
|
dewpoint: float):
|
||||||
|
sample = self.sample(pressure, height)
|
||||||
|
|
||||||
|
if temp != -9999.0 and dewpoint != -9999.0:
|
||||||
|
sample.temp = temp
|
||||||
|
sample.dewpoint = dewpoint
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def init():
|
def init():
|
||||||
DataAccessLayer.changeEDEXHost(BUFRSounding.EDEX_HOST)
|
DataAccessLayer.changeEDEXHost(BUFRSounding.EDEX_HOST)
|
||||||
|
@ -86,43 +119,26 @@ class BUFRSounding(Sounding):
|
||||||
if set(params) & BUFRSounding.BUFR_PARAMS_MAN:
|
if set(params) & BUFRSounding.BUFR_PARAMS_MAN:
|
||||||
pressure = item.getNumber('prMan') / 100.0
|
pressure = item.getNumber('prMan') / 100.0
|
||||||
height = item.getNumber('htMan')
|
height = item.getNumber('htMan')
|
||||||
|
|
||||||
if pressure == -99.99:
|
|
||||||
sample = sounding.sample_by_height(height)
|
|
||||||
else:
|
|
||||||
sample = sounding.sample_by_pressure(pressure)
|
|
||||||
|
|
||||||
if height != -9999.0:
|
|
||||||
sample.height = height
|
|
||||||
|
|
||||||
wind_dir = item.getNumber('wsMan')
|
wind_dir = item.getNumber('wsMan')
|
||||||
wind_speed = item.getNumber('wdMan')
|
wind_speed = item.getNumber('wdMan')
|
||||||
|
|
||||||
if wind_dir != -9999.0 and wind_speed != -9999.0:
|
sounding.record_wind(pressure, height, wind_dir, wind_speed)
|
||||||
sample.wind_speed = wind_dir
|
|
||||||
sample.wind_dir = wind_speed
|
|
||||||
|
|
||||||
if set(params) & BUFRSounding.BUFR_PARAMS_SIGT:
|
if set(params) & BUFRSounding.BUFR_PARAMS_SIGT:
|
||||||
pressure = item.getNumber('prSigT') / 100.0
|
pressure = item.getNumber('prSigT') / 100.0
|
||||||
sample = sounding.sample_by_pressure(pressure)
|
height = -9999.0
|
||||||
|
temp = celsius(item.getNumber('tpSigT'))
|
||||||
|
dewpoint = celsius(item.getNumber('tdSigT'))
|
||||||
|
|
||||||
sample.temp = celsius(item.getNumber('tpSigT'))
|
sounding.record_temp_dewpoint(pressure, height, temp, dewpoint)
|
||||||
sample.dewpoint = celsius(item.getNumber('tdSigT'))
|
|
||||||
|
|
||||||
if set(params) & BUFRSounding.BUFR_PARAMS_SIGW:
|
if set(params) & BUFRSounding.BUFR_PARAMS_SIGW:
|
||||||
pressure = item.getNumber('prSigW') / 100.0
|
pressure = item.getNumber('prSigW') / 100.0
|
||||||
height = item.getNumber('htSigW')
|
height = item.getNumber('htSigW')
|
||||||
|
wind_speed = item.getNumber('wsSigW')
|
||||||
|
wind_dir = item.getNumber('wdSigW')
|
||||||
|
|
||||||
if pressure == -99.99:
|
sounding.record_wind(pressure, height, wind_speed, wind_dir)
|
||||||
sample = sounding.sample_by_height(height)
|
|
||||||
else:
|
|
||||||
sample = sounding.sample_by_pressure(pressure)
|
|
||||||
|
|
||||||
if height != -9999.0:
|
|
||||||
sample.height = height
|
|
||||||
|
|
||||||
sample.wind_speed = item.getNumber('wsSigW')
|
|
||||||
sample.wind_dir = item.getNumber('wdSigW')
|
|
||||||
|
|
||||||
for pressure in sorted(sounding.samples_by_pressure.keys(), reverse=True):
|
for pressure in sorted(sounding.samples_by_pressure.keys(), reverse=True):
|
||||||
sounding.samples.append(sounding.samples_by_pressure[pressure])
|
sounding.samples.append(sounding.samples_by_pressure[pressure])
|
||||||
|
|
Loading…
Add table
Reference in a new issue