Skip to content

Commit

Permalink
Updated get_bufr to support static GPS heights.
Browse files Browse the repository at this point in the history
* Bedrock stations shouldn’t depend on the noisy GPS signal for elevation.
* Added station dimension values for WEG_B
* Added corresponding unittest
  • Loading branch information
ladsmund committed Jul 3, 2024
1 parent 1558759 commit 2f3cd35
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/pypromice/postprocess/get_bufr.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ class StationConfiguration:
temperature_from_sonic_ranger: Optional[float] = None
height_of_gps_from_station_ground: Optional[float] = None
sonic_ranger_from_gps: Optional[float] = None
static_height_of_gps_from_mean_sea_level: Optional[float] = None

# The station data will be exported to BUFR if True. Otherwise, it will only export latest position
export_bufr: bool = False
Expand Down Expand Up @@ -558,14 +559,22 @@ def get_bufr_variables(
if station_configuration.barometer_from_gps is None:
raise AttributeError("barometer_from_gps is required for BUFR export")

if station_configuration.static_height_of_gps_from_mean_sea_level is None:
height_of_gps_above_mean_sea_level = data["gps_alt_fit"]
else:
height_of_gps_above_mean_sea_level = (
station_configuration.static_height_of_gps_from_mean_sea_level
)

heightOfStationGroundAboveMeanSeaLevel = (
data["gps_alt_fit"] - station_configuration.height_of_gps_from_station_ground
height_of_gps_above_mean_sea_level - station_configuration.height_of_gps_from_station_ground
)

heightOfBarometerAboveMeanSeaLevel = (
data["gps_alt_fit"] + station_configuration.barometer_from_gps
height_of_gps_above_mean_sea_level + station_configuration.barometer_from_gps
)


heightOfSensorAboveLocalGroundOrDeckOfMarinePlatformTempRH = (
station_configuration.temperature_from_station_ground
)
Expand Down
6 changes: 6 additions & 0 deletions src/pypromice/postprocess/station_configurations.toml
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,12 @@ station_site = "NUK_U"
project = "Wegener"
station_type = "land"
wmo_id = "460"
barometer_from_gps = 1.3
anemometer_from_sonic_ranger = 0.4
temperature_from_sonic_ranger = 0.0
height_of_gps_from_station_ground = 0.9
sonic_ranger_from_gps = 1.3
static_height_of_gps_from_mean_sea_level = 17.5
export_bufr = true
skipped_variables = []
positions_update_timestamp_only = false
Expand Down
62 changes: 62 additions & 0 deletions tests/unit/bufr_export/test_get_bufr.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,68 @@ def test_bufr_variables_promice_v3(self):
heightOfBarometerAboveMeanSeaLevel=2126,
)

def test_bufr_variables_static_gps_elevation(self):
timestamp = datetime.datetime.now()
data = pd.Series(
data=dict(
rh_i=0.93,
t_i=-21,
name="",
p_i=993,
wdir_i=32.1,
wspd_i=5.3,
gps_lon_fit=-46.0,
gps_lat_fit=66.0,
# This is a erroneous value that should be overridden by the static value
gps_alt_fit=142.1,
z_boom_u_smooth=2.1,
),
name=timestamp,
)
station_config = StationConfiguration(
stid="A_STID",
station_type="land",
wmo_id="4201",
export_bufr=True,
barometer_from_gps=1.3,
height_of_gps_from_station_ground=0.9,
static_height_of_gps_from_mean_sea_level=17.5,
anemometer_from_sonic_ranger=None,
temperature_from_sonic_ranger=None,
sonic_ranger_from_gps=None,
)
# The elevations should be determined from the static variable
expected_station_ground_elevation = 17.5 - 0.9
expected_barometer_elevation = 17.5 + 1.3

expected_bufr_variables = BUFRVariables(
wmo_id=station_config.wmo_id,
station_type=station_config.station_type,
timestamp=timestamp,
relativeHumidity=1.0,
airTemperature=252.2, # Converted to kelvin
pressure=199300.0,
windDirection=32.0,
windSpeed=5.3,
latitude=66.0,
longitude=-46.0,
heightOfStationGroundAboveMeanSeaLevel=expected_station_ground_elevation,
heightOfBarometerAboveMeanSeaLevel=expected_barometer_elevation,
# The sensor heights are ignored since the necessary dimension values are missing
heightOfSensorAboveLocalGroundOrDeckOfMarinePlatformTempRH=np.nan,
heightOfSensorAboveLocalGroundOrDeckOfMarinePlatformWSPD=np.nan,
)

output = get_bufr_variables(
data,
station_configuration=station_config,
)

self.assertEqual(
expected_bufr_variables,
output,
)

def test_fails_on_missing_dimension_values(self):
"""
Test that get_bufr_variables raises an AttributeError if the data is missing
Expand Down

0 comments on commit 2f3cd35

Please sign in to comment.