Skip to content

Commit

Permalink
Added check for s4 cloud height
Browse files Browse the repository at this point in the history
  • Loading branch information
RoryPTB committed Sep 25, 2023
1 parent cb04d8c commit 91865d7
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 62 deletions.
9 changes: 9 additions & 0 deletions data/3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
SISQ01 LZIB 251500

AAXX 25151

15001 41/02 29901 10131 20108 38108 48587 52001 74100 82101

333 828//

444 28//0 =
2 changes: 2 additions & 0 deletions data/decoded_20230825T150000.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
report_type,year,month,day,hour,minute,block_no,station_no,station_id,region,WMO_station_type,lowest_cloud_base,visibility,cloud_cover,wind_indicator,template,wind_time_period,wind_direction,wind_speed,air_temperature,dewpoint_temperature,relative_humidity,station_pressure,isobaric_surface,geopotential_height,sea_level_pressure,3hr_pressure_change,pressure_tendency_characteristic,precipitation_s1,ps1_time_period,present_weather,past_weather_1,past_weather_2,past_weather_time_period,cloud_vs_s1,cloud_amount_s1,low_cloud_type,middle_cloud_type,high_cloud_type,maximum_temperature,minimum_temperature,maximum_temperature_period_start,maximum_temperature_period_end,minimum_temperature_period_start,minimum_temperature_period_end,ground_state,ground_temperature,snow_depth,evapotranspiration,evaporation_instrument,temperature_change,sunshine_amount_1hr,sunshine_amount_24hr,low_cloud_drift_direction,low_cloud_drift_vs,middle_cloud_drift_direction,middle_cloud_drift_vs,high_cloud_drift_direction,high_cloud_drift_vs,e_cloud_genus,e_cloud_direction,e_cloud_elevation,24hr_pressure_change,net_radiation_1hr,net_radiation_24hr,global_solar_radiation_1hr,global_solar_radiation_24hr,diffuse_solar_radiation_1hr,diffuse_solar_radiation_24hr,long_wave_radiation_1hr,long_wave_radiation_24hr,short_wave_radiation_1hr,short_wave_radiation_24hr,net_short_wave_radiation_1hr,net_short_wave_radiation_24hr,direct_solar_radiation_1hr,direct_solar_radiation_24hr,precipitation_s3,ps3_time_period,precipitation_24h,highest_gust_1,highest_gust_2,cloud_genus_s3_1,vs_s3_1,cloud_amount_s3_1,cloud_amount_s4_1,cloud_genus_s4_1,cloud_top_s4_1,_wsi_series,_wsi_issuer,_wsi_issue_number,_wsi_local,_latitude,_longitude,_station_height,_barometer_height
AAXX,2023,8,25,15,0,15,001,15001,VI,1,,200,25,8,307096,-10,,1,286.25,283.95,85.93925107124394,81080.0,85000,1587,,10.0,2,,,41,0,0,-3,7,2,31,20,11,,,-12,0,-12,0,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,8,1,2,2,8,0,0,20000,0,15001,0,0,503,0
2 changes: 2 additions & 0 deletions data/station_list.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
station_name,wigos_station_identifier,traditional_station_identifier,facility_type,latitude,longitude,elevation,barometer_height,territory_name
X,0-20000-0-15001,15001,Land (fixed),0,0,503,0,Switzerland
31 changes: 0 additions & 31 deletions example.py

This file was deleted.

69 changes: 38 additions & 31 deletions synop2bufr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,7 @@ def rad_convert(rad, time):

# Name the array of section 4 items
genus_array = decoded['section4']
print("genus_array", genus_array)

# Get the number of section 4 groups in the SYNOP message
num_s4_clouds = len(genus_array)
Expand Down Expand Up @@ -1539,38 +1540,44 @@ def transform(data: str, metadata: str, year: int,
# significance code 10.
# Clouds with bases and tops below station level
# have vertical significance code 11.
cloud_top_height = msg[f'cloud_height_s4_{idx+1}']

if cloud_top_height > int(station_height):
vs_s4 = 10
else:
vs_s4 = 11

# NOTE: Some of the ecCodes keys are used in
# the above, so we must add 'num_s3_clouds'
s4_mappings = [
{"eccodes_key": (
f"#{idx+num_s3_clouds+8}"
"#verticalSignificanceSurfaceObservations"
),
"value": f"const:{vs_s4}"},
{"eccodes_key":
f"#{idx+num_s3_clouds+3}#cloudAmount",
"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",
"value": f"data:cloud_height_s4_{idx+1}"},
{"eccodes_key":
f"#{idx+1}#cloudTopDescription",
"value": f"data:cloud_top_s4_{idx+1}"}
]
for m in s4_mappings:
mapping.update(m)
cloud_top_height = msg.get(f'cloud_height_s4_{idx+1}')

# Sometimes in section 4 the cloud height is omitted,
# so we need to check it exists before comparing it to
# the station height below
if cloud_top_height is not None:

if cloud_top_height > int(station_height):
vs_s4 = 10
else:
vs_s4 = 11

# NOTE: Some of the ecCodes keys are used in
# the above, so we must add 'num_s3_clouds'
s4_mappings = [
{"eccodes_key": (
f"#{idx+num_s3_clouds+8}"
"#verticalSignificanceSurfaceObservations"
),
"value": f"const:{vs_s4}"},
{"eccodes_key":
f"#{idx+num_s3_clouds+3}#cloudAmount",
"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",
"value": f"data:cloud_height_s4_{idx+1}"},
{"eccodes_key":
f"#{idx+1}#cloudTopDescription",
"value": f"data:cloud_top_s4_{idx+1}"}
]
for m in s4_mappings:
mapping.update(m)
except Exception as e:
LOGGER.error(e)
LOGGER.error(f"Missing station height for station {tsi}")
Expand Down

0 comments on commit 91865d7

Please sign in to comment.