Skip to content

Commit

Permalink
Tightened mapping ranges and added pytests
Browse files Browse the repository at this point in the history
  • Loading branch information
RoryPTB committed Sep 13, 2023
1 parent b3c9aa3 commit 732602b
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 52 deletions.
23 changes: 21 additions & 2 deletions synop2bufr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,23 @@ def parse_synop(message: str, year: int, month: int) -> dict:
except Exception:
output['dewpoint_temperature'] = None

# Verify that the dewpoint temperature is less than or equal to
# the air temperature
if ((output.get('air_temperature') is not None) and
(output.get('dewpoint_temperature') is not None)):

A = output['air_temperature']
D = output['dewpoint_temperature']

# If the dewpoint temperature is higher than the air temperature,
# log a warning and set both values to None
if A < D:
LOGGER.warning(f"Reported dewpoint temperature {D} is greater than the reported air temperature {A}. Elements set to missing") # noqa
warning_msgs.append(f"Reported dewpoint temperature {D} is greater than the reported air temperature {A}. Elements set to missing") # noqa

output['air_temperature'] = None
output['dewpoint_temperature'] = None

# RH is already given in %
if decoded.get('relative_humidity') is not None:
try:
Expand Down Expand Up @@ -1420,7 +1437,8 @@ def transform(data: str, metadata: str, year: int,
),
"value": f"data:vs_s3_{idx+1}"},
{"eccodes_key": f"#{idx+3}#cloudAmount",
"value": f"data:cloud_amount_s3_{idx+1}"},
"value": f"data:cloud_amount_s3_{idx+1}",
"valid_min": "const:0", "valid_max": "const:8"},
{"eccodes_key": f"#{idx+5}#cloudType",
"value": f"data:cloud_genus_s3_{idx+1}"},
{"eccodes_key": f"#{idx+2}#heightOfBaseOfCloud",
Expand Down Expand Up @@ -1453,7 +1471,8 @@ def transform(data: str, metadata: str, year: int,
),
"value": f"const:{vs_s4}"},
{"eccodes_key": f"#{idx+num_s3_clouds+3}#cloudAmount",
"value": f"data:cloud_amount_s4_{idx+1}"},
"value": f"data:cloud_amount_s4_{idx+1}",
"valid_min": "const:0", "valid_max": "const:8"},
{"eccodes_key": f"#{idx+num_s3_clouds+5}#cloudType",
"value": f"data:cloud_genus_s4_{idx+1}"},
{"eccodes_key": f"#{idx+1}#heightOfTopOfCloud",
Expand Down
48 changes: 24 additions & 24 deletions synop2bufr/resources/synop-mappings-307080.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,49 +42,49 @@
{"eccodes_key": "#1#day", "value": "data:day", "valid_min": "const:0", "valid_max": "const:63"},
{"eccodes_key": "#1#hour", "value": "data:hour", "valid_min": "const:0", "valid_max": "const:31"},
{"eccodes_key": "#1#minute", "value": "data:minute", "valid_min": "const:0", "valid_max": "const:63"},
{"eccodes_key": "#1#nonCoordinatePressure", "value": "data:station_pressure", "valid_min": "const:0", "valid_max": "const:163830"},
{"eccodes_key": "#1#pressureReducedToMeanSeaLevel", "value": "data:sea_level_pressure", "valid_min": "const:0", "valid_max": "const:163830"},
{"eccodes_key": "#1#nonCoordinatePressure", "value": "data:station_pressure", "valid_min": "const:50000", "valid_max": "const:108000"},
{"eccodes_key": "#1#pressureReducedToMeanSeaLevel", "value": "data:sea_level_pressure", "valid_min": "const:50000", "valid_max": "const:108000"},
{"eccodes_key": "#1#3HourPressureChange", "value": "data:3hr_pressure_change", "valid_min": "const:-5000", "valid_max": "const:5230"},
{"eccodes_key": "#1#characteristicOfPressureTendency", "value": "data:pressure_tendency_characteristic", "valid_min": "const:0", "valid_max": "const:15"},
{"eccodes_key": "#1#24HourPressureChange", "value": "data:24hr_pressure_change", "valid_min": "const:-10000", "valid_max": "const:10470"},
{"eccodes_key": "#1#pressure", "value": "data:isobaric_surface", "valid_min": "const:0", "valid_max": "const:163830"},
{"eccodes_key": "#1#pressure", "value": "data:isobaric_surface", "valid_min": "const:50000", "valid_max": "const:108000"},
{"eccodes_key": "#1#nonCoordinateGeopotentialHeight", "value": "data:geopotential_height", "valid_min": "const:-1000", "valid_max": "const:130071"},
{"eccodes_key": "#1#airTemperature", "value": "data:air_temperature", "valid_min": "const:0.0", "valid_max": "const:655.35"},
{"eccodes_key": "#1#dewpointTemperature", "value": "data:dewpoint_temperature", "valid_min": "const:0.0", "valid_max": "const:655.35"},
{"eccodes_key": "#1#relativeHumidity", "value": "data:relative_humidity", "valid_min": "const:0", "valid_max": "const:127"},
{"eccodes_key": "#1#horizontalVisibility", "value": "data:visibility", "valid_min": "const:0", "valid_max": "const:81910"},
{"eccodes_key": "#1#totalPrecipitationPast24Hours", "value": "data:precipitation_24h","valid_min": "const:-0.1", "valid_max": "const:1638.2"},
{"eccodes_key": "#1#airTemperature", "value": "data:air_temperature", "valid_min": "const:193.15", "valid_max": "const:333.15"},
{"eccodes_key": "#1#dewpointTemperature", "value": "data:dewpoint_temperature", "valid_min": "const:193.15", "valid_max": "const:308.15"},
{"eccodes_key": "#1#relativeHumidity", "value": "data:relative_humidity", "valid_min": "const:0", "valid_max": "const:100"},
{"eccodes_key": "#1#horizontalVisibility", "value": "data:visibility", "valid_min": "const:10", "valid_max": "const:81910"},
{"eccodes_key": "#1#totalPrecipitationPast24Hours", "value": "data:precipitation_24h","valid_min": "const:0.0", "valid_max": "const:500"},
{"eccodes_key": "#1#cloudCoverTotal", "value": "data:cloud_cover", "valid_min": "const:0", "valid_max": "const:127"},
{"eccodes_key": "#1#verticalSignificanceSurfaceObservations", "value": "data:cloud_vs_s1", "valid_min": "const:0", "valid_max": "const:63"},
{"eccodes_key": "#1#cloudAmount", "value": "data:cloud_amount_s1", "valid_min": "const:0", "valid_max": "const:15"},
{"eccodes_key": "#1#heightOfBaseOfCloud", "value": "data:lowest_cloud_base", "valid_min": "const:-400", "valid_max": "const:20070"},
{"eccodes_key": "#1#cloudAmount", "value": "data:cloud_amount_s1", "valid_min": "const:0", "valid_max": "const:8"},
{"eccodes_key": "#1#heightOfBaseOfCloud", "value": "data:lowest_cloud_base", "valid_min": "const:0.0", "valid_max": "const:20070"},
{"eccodes_key": "#1#cloudType", "value": "data:low_cloud_type", "valid_min": "const:0", "valid_max": "const:63"},
{"eccodes_key": "#2#cloudType", "value": "data:middle_cloud_type", "valid_min": "const:0", "valid_max": "const:63"},
{"eccodes_key": "#3#cloudType", "value": "data:high_cloud_type", "valid_min": "const:0", "valid_max": "const:63"},
{"eccodes_key": "#2#verticalSignificanceSurfaceObservations", "value": "const:7", "valid_min": "const:0", "valid_max": "const:63"},
{"eccodes_key": "#3#verticalSignificanceSurfaceObservations", "value": "const:8", "valid_min": "const:0", "valid_max": "const:63"},
{"eccodes_key": "#4#verticalSignificanceSurfaceObservations", "value": "const:9", "valid_min": "const:0", "valid_max": "const:63"},
{"eccodes_key": "#1#trueDirectionFromWhichAPhenomenonOrCloudsAreMovingOrInWhichTheyAreObserved", "value": "data:low_cloud_drift_direction", "valid_min": "const:0", "valid_max": "const:511"},
{"eccodes_key": "#2#trueDirectionFromWhichAPhenomenonOrCloudsAreMovingOrInWhichTheyAreObserved", "value": "data:middle_cloud_drift_direction", "valid_min": "const:0", "valid_max": "const:511"},
{"eccodes_key": "#3#trueDirectionFromWhichAPhenomenonOrCloudsAreMovingOrInWhichTheyAreObserved", "value": "data:high_cloud_drift_direction", "valid_min": "const:0", "valid_max": "const:511"},
{"eccodes_key": "#1#trueDirectionFromWhichAPhenomenonOrCloudsAreMovingOrInWhichTheyAreObserved", "value": "data:low_cloud_drift_direction", "valid_min": "const:0.0", "valid_max": "const:360"},
{"eccodes_key": "#2#trueDirectionFromWhichAPhenomenonOrCloudsAreMovingOrInWhichTheyAreObserved", "value": "data:middle_cloud_drift_direction", "valid_min": "const:0.0", "valid_max": "const:360"},
{"eccodes_key": "#3#trueDirectionFromWhichAPhenomenonOrCloudsAreMovingOrInWhichTheyAreObserved", "value": "data:high_cloud_drift_direction", "valid_min": "const:0.0", "valid_max": "const:360"},
{"eccodes_key": "#5#verticalSignificanceSurfaceObservations", "value": "const:7", "valid_min": "const:0", "valid_max": "const:63"},
{"eccodes_key": "#6#verticalSignificanceSurfaceObservations", "value": "const:8", "valid_min": "const:0", "valid_max": "const:63"},
{"eccodes_key": "#7#verticalSignificanceSurfaceObservations", "value": "const:9", "valid_min": "const:0", "valid_max": "const:63"},
{"eccodes_key": "#1#stateOfGround", "value": "data:ground_state", "valid_min": "const:0", "valid_max": "const:31"},
{"eccodes_key": "#1#totalSnowDepth", "value": "data:snow_depth", "valid_min": "const:-0.02", "valid_max": "const:655.33"},
{"eccodes_key": "#1#totalSnowDepth", "value": "data:snow_depth", "valid_min": "const:0.0", "valid_max": "const:25"},
{"eccodes_key": "#1#groundMinimumTemperaturePast12Hours", "value": "data:ground_temperature", "valid_min": "const:0.0", "valid_max": "const:655.35"},
{"eccodes_key": "#1#presentWeather", "value": "data:present_weather", "valid_min": "const:0", "valid_max": "const:511"},
{"eccodes_key": "#1#pastWeather1", "value": "data:past_weather_1", "valid_min": "const:0", "valid_max": "const:31"},
{"eccodes_key": "#1#pastWeather2", "value": "data:past_weather_2", "valid_min": "const:0", "valid_max": "const:31"},
{"eccodes_key": "#1#timePeriod", "value": "data:past_weather_time_period", "valid_min": "const:-2048", "valid_max": "const:2047"},
{"eccodes_key": "#2#timePeriod", "value": "const:-1", "valid_min": "const:-2048", "valid_max": "const:2047"},
{"eccodes_key": "#1#totalSunshine", "value": "data:sunshine_amount_1hr", "valid_min": "const:0", "valid_max": "const:2047"},
{"eccodes_key": "#1#totalSunshine", "value": "data:sunshine_amount_1hr", "valid_min": "const:0", "valid_max": "const:60"},
{"eccodes_key": "#3#timePeriod", "value": "const:-24", "valid_min": "const:-2048", "valid_max": "const:2047"},
{"eccodes_key": "#2#totalSunshine", "value": "data:sunshine_amount_24hr", "valid_min": "const:0", "valid_max": "const:2047"},
{"eccodes_key": "#2#totalSunshine", "value": "data:sunshine_amount_24hr", "valid_min": "const:0", "valid_max": "const:1440"},
{"eccodes_key": "#4#timePeriod", "value": "data:ps1_time_period", "valid_min": "const:-2048", "valid_max": "const:2047"},
{"eccodes_key": "#1#totalPrecipitationOrTotalWaterEquivalent", "value": "data:precipitation_s1", "valid_min": "const:-0.1", "valid_max": "const:1638.2"},
{"eccodes_key": "#1#totalPrecipitationOrTotalWaterEquivalent", "value": "data:precipitation_s1", "valid_min": "const:0.0", "valid_max": "const:500"},
{"eccodes_key": "#5#timePeriod", "value": "data:ps3_time_period", "valid_min": "const:-2048", "valid_max": "const:2047"},
{"eccodes_key": "#2#totalPrecipitationOrTotalWaterEquivalent", "value": "data:precipitation_s3", "valid_min": "const:-0.1", "valid_max": "const:1638.2"},
{"eccodes_key": "#2#totalPrecipitationOrTotalWaterEquivalent", "value": "data:precipitation_s3", "valid_min": "const:0.0", "valid_max": "const:500"},
{"eccodes_key": "#6#timePeriod", "value": "data:maximum_temperature_period_start", "valid_min": "const:-2048", "valid_max": "const:2047"},
{"eccodes_key": "#7#timePeriod", "value": "data:maximum_temperature_period_end", "valid_min": "const:-2048", "valid_max": "const:2047"},
{"eccodes_key": "#1#maximumTemperatureAtHeightAndOverPeriodSpecified", "value": "data:maximum_temperature", "valid_min": "const:0.0", "valid_max": "const:655.35"},
Expand All @@ -94,17 +94,17 @@
{"eccodes_key": "#1#instrumentationForWindMeasurement", "value": "data:wind_indicator", "valid_min": "const:0", "valid_max": "const:15"},
{"eccodes_key": "#1#timeSignificance", "value": "const:2"},
{"eccodes_key": "#10#timePeriod", "value": "const:-10"},
{"eccodes_key": "#1#windDirection", "value": "data:wind_direction", "valid_min": "const:0", "valid_max": "const:511"},
{"eccodes_key": "#1#windSpeed", "value": "data:wind_speed", "valid_min": "const:0.0", "valid_max": "const:409.5"},
{"eccodes_key": "#1#windDirection", "value": "data:wind_direction", "valid_min": "const:0.0", "valid_max": "const:360"},
{"eccodes_key": "#1#windSpeed", "value": "data:wind_speed", "valid_min": "const:0.0", "valid_max": "const:75"},
{"eccodes_key": "#11#timePeriod", "value": "const:-10"},
{"eccodes_key": "#1#maximumWindGustSpeed", "value": "data:highest_gust_1", "valid_min": "const:0.0", "valid_max": "const:409.5"},
{"eccodes_key": "#1#maximumWindGustSpeed", "value": "data:highest_gust_1", "valid_min": "const:0.0", "valid_max": "const:150"},
{"eccodes_key": "#12#timePeriod", "value": "data:past_weather_time_period", "valid_min": "const:-2048", "valid_max": "const:2047"},
{"eccodes_key": "#2#maximumWindGustSpeed", "value": "data:highest_gust_2", "valid_min": "const:0.0", "valid_max": "const:409.5"},
{"eccodes_key": "#2#maximumWindGustSpeed", "value": "data:highest_gust_2", "valid_min": "const:0.0", "valid_max": "const:150"},
{"eccodes_key": "#13#timePeriod", "value": "const:-24"},
{"eccodes_key": "#1#typeOfInstrumentationForEvaporationMeasurement", "value": "data:evaporation_instrument", "valid_min": "const:0", "valid_max": "const:15"},
{"eccodes_key": "#1#evaporation", "value": "data:evapotranspiration", "valid_min": "const:0.0", "valid_max": "const:102.3"},
{"eccodes_key": "#1#evaporation", "value": "data:evapotranspiration", "valid_min": "const:0.0", "valid_max": "const:100"},
{"eccodes_key": "#4#cloudType", "value": "data:e_cloud_genus", "valid_min": "const:0", "valid_max": "const:63"},
{"eccodes_key": "#1#bearingOrAzimuth", "value": "data:e_cloud_direction", "valid_min": "const:0.0", "valid_max": "const:655.35"},
{"eccodes_key": "#1#bearingOrAzimuth", "value": "data:e_cloud_direction", "valid_min": "const:0.0", "valid_max": "const:360"},
{"eccodes_key": "#1#elevation", "value": "data:e_cloud_elevation", "valid_min": "const:-90.0", "valid_max": "const:237.67"},
{"eccodes_key": "#14#timePeriod", "value": "const:-1"},
{"eccodes_key": "#1#netRadiationIntegratedOverPeriodSpecified", "value": "data:net_radiation_1hr", "valid_min": "const:-163840000", "valid_max": "const:163830000"},
Expand Down
Loading

0 comments on commit 732602b

Please sign in to comment.