diff --git a/lib/xmet/bufr.py b/lib/xmet/bufr.py index 35af234..c5f33a3 100644 --- a/lib/xmet/bufr.py +++ b/lib/xmet/bufr.py @@ -20,8 +20,9 @@ class BUFRSounding(Sounding): super().__init__() self.samples_by_pressure = dict() + self.samples_by_height = dict() - def sample(self, pressure: float) -> SoundingSample: + def sample_by_pressure(self, pressure: float) -> SoundingSample: sample = self.samples_by_pressure.get(pressure) if sample is None: @@ -32,6 +33,17 @@ class BUFRSounding(Sounding): return sample + def sample_by_height(self, height: float) -> SoundingSample: + sample = self.samples_by_height.get(height) + + if sample is None: + sample = SoundingSample() + sample.height = height + + self.samples_by_height[height] = sample + + return sample + @staticmethod def init(): DataAccessLayer.changeEDEXHost(BUFRSounding.EDEX_HOST) @@ -73,25 +85,32 @@ class BUFRSounding(Sounding): if set(params) & BUFRSounding.BUFR_PARAMS_MAN: pressure = item.getNumber('prMan') / 100.0 - sample = sounding.sample(pressure) + height = item.getNumber('htMan') + + if pressure == -99.99: + sample = sounding.sample_by_height(height) + else: + sample = sounding.sample_by_pressure(pressure) - sample.pressure = pressure - sample.height = item.getNumber('htMan') sample.wind_speed = item.getNumber('wsMan') sample.wind_dir = item.getNumber('wdMan') if set(params) & BUFRSounding.BUFR_PARAMS_SIGT: pressure = item.getNumber('prSigT') / 100.0 - sample = sounding.sample(pressure) + sample = sounding.sample_by_pressure(pressure) sample.temp = celsius(item.getNumber('tpSigT')) sample.dewpoint = celsius(item.getNumber('tdSigT')) if set(params) & BUFRSounding.BUFR_PARAMS_SIGW: pressure = item.getNumber('prSigW') / 100.0 - sample = sounding.sample(pressure) + height = item.getNumber('htSigW') + + if pressure == -99.99: + sample = sounding.sample_by_height(height) + else: + sample = sounding.sample_by_pressure(pressure) - sample.height = item.getNumber('htSigW') sample.wind_speed = item.getNumber('wsSigW') sample.wind_dir = item.getNumber('wdSigW')