From 17df1e1dba6bdfc5a3fc244cc7d6f3ceebfcef34 Mon Sep 17 00:00:00 2001 From: XANTRONIX Industrial Date: Mon, 14 Apr 2025 11:04:33 -0400 Subject: [PATCH] Split BUFRSounding.latest() into separate methods --- lib/xmet/bufr.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/xmet/bufr.py b/lib/xmet/bufr.py index 2cf6d58..e3d598d 100644 --- a/lib/xmet/bufr.py +++ b/lib/xmet/bufr.py @@ -82,8 +82,9 @@ class BUFRSounding(Sounding): DataAccessLayer.changeEDEXHost(BUFRSounding.EDEX_HOST) @staticmethod - def latest(station: str) -> Self: + def create_request(station: str): request = DataAccessLayer.newDataRequest() + request.setLocationNames(station) request.setDatatype(BUFRSounding.BUFR_TYPE) request.setParameters('staElev', 'staName') @@ -91,21 +92,20 @@ class BUFRSounding(Sounding): request.getParameters().extend(BUFRSounding.BUFR_PARAMS_SIGT) request.getParameters().extend(BUFRSounding.BUFR_PARAMS_SIGW) - request.setLocationNames(station) - - datatimes = DataAccessLayer.getAvailableTimes(request) - - response = DataAccessLayer.getGeometryData(request, - times=datatimes[-1].validPeriod) + return request + @staticmethod + def request_sounding(request, period) -> Self: sounding = BUFRSounding() + response = DataAccessLayer.getGeometryData(request, times=period) + geom = response[0].getGeometry() dt = response[0].getDataTime() epoch = dt.getRefTime().time / 1000.0 timestamp = datetime.datetime.fromtimestamp(epoch, datetime.UTC) - sounding.station = station + sounding.station = response[0].getLocationName() sounding.data_source_pressure = 'UCAR' sounding.data_source_other = 'UCAR' sounding.location = shapely.Point(geom.x, geom.y) @@ -147,3 +147,11 @@ class BUFRSounding(Sounding): sounding.samples.append(sounding.samples_by_height[height]) return sounding + + @staticmethod + def latest(station: str) -> Self: + request = BUFRSounding.create_request(station) + datatimes = DataAccessLayer.getAvailableTimes(request) + + return BUFRSounding.request_sounding(request, + datatimes[-1].validPeriod)