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
|
||||
|
||||
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
|
||||
def init():
|
||||
DataAccessLayer.changeEDEXHost(BUFRSounding.EDEX_HOST)
|
||||
|
@ -84,45 +117,28 @@ class BUFRSounding(Sounding):
|
|||
params = item.getParameters()
|
||||
|
||||
if set(params) & BUFRSounding.BUFR_PARAMS_MAN:
|
||||
pressure = item.getNumber('prMan') / 100.0
|
||||
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
|
||||
|
||||
pressure = item.getNumber('prMan') / 100.0
|
||||
height = item.getNumber('htMan')
|
||||
wind_dir = item.getNumber('wsMan')
|
||||
wind_speed = item.getNumber('wdMan')
|
||||
|
||||
if wind_dir != -9999.0 and wind_speed != -9999.0:
|
||||
sample.wind_speed = wind_dir
|
||||
sample.wind_dir = wind_speed
|
||||
sounding.record_wind(pressure, height, wind_dir, wind_speed)
|
||||
|
||||
if set(params) & BUFRSounding.BUFR_PARAMS_SIGT:
|
||||
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'))
|
||||
sample.dewpoint = celsius(item.getNumber('tdSigT'))
|
||||
sounding.record_temp_dewpoint(pressure, height, temp, dewpoint)
|
||||
|
||||
if set(params) & BUFRSounding.BUFR_PARAMS_SIGW:
|
||||
pressure = item.getNumber('prSigW') / 100.0
|
||||
height = item.getNumber('htSigW')
|
||||
pressure = item.getNumber('prSigW') / 100.0
|
||||
height = item.getNumber('htSigW')
|
||||
wind_speed = item.getNumber('wsSigW')
|
||||
wind_dir = item.getNumber('wdSigW')
|
||||
|
||||
if pressure == -99.99:
|
||||
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')
|
||||
sounding.record_wind(pressure, height, wind_speed, wind_dir)
|
||||
|
||||
for pressure in sorted(sounding.samples_by_pressure.keys(), reverse=True):
|
||||
sounding.samples.append(sounding.samples_by_pressure[pressure])
|
||||
|
|
Loading…
Add table
Reference in a new issue