Skip to content

Commit

Permalink
Replace Hirlam weather model with Harmonie (#42)
Browse files Browse the repository at this point in the history
* Change weather model to be Harmonie

Old Hirlam model support is going to end in September 2022. See issue #39 . Fixes #39 .

* Add parameters to harmonie requests

* Update tests and mock data

* Bump version to 0.1.2

Co-authored-by: Teemu Mikkonen <[email protected]>
  • Loading branch information
saaste and T3m3z authored Sep 19, 2022
1 parent eb087f2 commit 427bc61
Show file tree
Hide file tree
Showing 10 changed files with 249 additions and 219 deletions.
10 changes: 8 additions & 2 deletions fmi_weather_client/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,16 @@ def _create_params(request_type: RequestType,
'service': 'WFS',
'version': '2.0.0',
'request': 'getFeature',
'storedquery_id': 'fmi::forecast::hirlam::surface::point::multipointcoverage',
'storedquery_id': 'fmi::forecast::harmonie::surface::point::multipointcoverage',
'timestep': timestep_minutes,
'starttime': start_time.isoformat(timespec='seconds'),
'endtime': end_time.isoformat(timespec='seconds')
'endtime': end_time.isoformat(timespec='seconds'),
'parameters': (
'Temperature,DewPoint,Pressure,Humidity,WindDirection,WindSpeedMS,'
'WindUMS,WindVMS,WindGust,WeatherSymbol3,TotalCloudCover,LowCloudCover,'
'MediumCloudCover,HighCloudCover,Precipitation1h,RadiationGlobalAccumulation,'
'RadiationNetSurfaceSWAccumulation,RadiationNetSurfaceLWAccumulation,GeopHeight,LandSeaMask'
)
}

if lat is not None and lon is not None:
Expand Down
13 changes: 9 additions & 4 deletions fmi_weather_client/parsers/forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ def to_value(vals: Dict[str, float], variable_name: str, unit: str) -> Value:
value = vals.get(variable_name, None)
return Value(value, unit)

# Some fields were available in HIRLAM forecasts, but are not
# available in HARMONIE forecasts. These fields are kept here
# for backward compatibility. Value of those fields will
# always be None.
return WeatherData(
time=time,
temperature=to_value(values, 'Temperature', '°C'),
Expand All @@ -122,7 +126,7 @@ def to_value(vals: Dict[str, float], variable_name: str, unit: str) -> Value:
wind_speed=to_value(values, 'WindSpeedMS', 'm/s'),
wind_u_component=to_value(values, 'WindUMS', 'm/s'),
wind_v_component=to_value(values, 'WindVMS', 'm/s'),
wind_max=to_value(values, 'MaximumWind', 'm/s'),
wind_max=to_value(values, 'MaximumWind', 'm/s'), # Not supported
wind_gust=to_value(values, 'WindGust', 'm/s'),
symbol=to_value(values, 'WeatherSymbol3', ''),
cloud_cover=to_value(values, 'TotalCloudCover', '%'),
Expand All @@ -132,11 +136,12 @@ def to_value(vals: Dict[str, float], variable_name: str, unit: str) -> Value:
precipitation_amount=to_value(values, 'Precipitation1h', 'mm/h'),
radiation_short_wave_acc=to_value(values, 'RadiationGlobalAccumulation', 'J/m²'),
radiation_short_wave_surface_net_acc=to_value(values, 'RadiationNetSurfaceSWAccumulation', 'J/m²'),
radiation_long_wave_acc=to_value(values, 'RadiationLWAccumulation', 'J/m²'),
radiation_long_wave_acc=to_value(values, 'RadiationLWAccumulation', 'J/m²'), # Not supported
radiation_long_wave_surface_net_acc=to_value(values, 'RadiationNetSurfaceLWAccumulation', 'J/m²'),
radiation_short_wave_diff_surface_acc=to_value(values, 'RadiationDiffuseAccumulation', 'J/m²'),
radiation_short_wave_diff_surface_acc=to_value(values, 'RadiationDiffuseAccumulation', 'J/m²'), # Not supported
geopotential_height=to_value(values, 'GeopHeight', 'm'),
land_sea_mask=to_value(values, 'LandSeaMask', ''))
land_sea_mask=to_value(values, 'LandSeaMask', '') # Not supported
)


def _float_or_none(value: Any) -> Optional[float]:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="fmi-weather-client",
version="0.1.1",
version="0.1.2",
author="Mika Hiltunen",
author_email="[email protected]",
description="Library for fetching weather information from Finnish Meteorological Institute (FMI)",
Expand Down
125 changes: 65 additions & 60 deletions test/test_data/corner_nan_response.xml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions test/test_data/error_invalid_lat_lon_response.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xsi:schemaLocation="http://www.opengis.net/ows/1.1 http://schemas.opengis.net/ows/1.1.0/owsExceptionReport.xsd"
version="2.0.0" xml:lang="eng">
<Exception exceptionCode="OperationParsingFailed">
<ExceptionText>[Runtime error] Invalid lon-lat given to WorldTimeZones::zone_name: 124.834,160.222</ExceptionText>
<ExceptionText>URI: /wfs?endtime=2020-03-03T23%3A26%3A00Z&amp;latlon=160.2224%2C124.83385&amp;parameters=WeatherSymbol3&amp;request=GetFeature&amp;service=WFS&amp;starttime=2020-03-03T15%3A26%3A00Z&amp;storedquery_id=fmi%3A%3Aforecast%3A%3Ahirlam%3A%3Asurface%3A%3Apoint%3A%3Amultipointcoverage&amp;timestep=60&amp;version=2.0.0</ExceptionText>
<ExceptionText>Invalid lon-lat given to WorldTimeZones::zone_name: 124.834,160.222</ExceptionText>
<ExceptionText>URI: /wfs?endtime=2020-03-03T23%3A26%3A00Z&amp;latlon=160.2224%2C124.83385&amp;parameters=WeatherSymbol3&amp;request=GetFeature&amp;service=WFS&amp;starttime=2020-03-03T15%3A26%3A00Z&amp;storedquery_id=fmi%3A%3Aforecast%3A%3Aharmonie%3A%3Asurface%3A%3Apoint%3A%3Amultipointcoverage&amp;timestep=60&amp;version=2.0.0</ExceptionText>
</Exception>
</ExceptionReport>
2 changes: 1 addition & 1 deletion test/test_data/error_no_data_available_response.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
version="2.0.0" xml:lang="eng">
<Exception exceptionCode="OperationParsingFailed">
<ExceptionText>No data available for &apos;-43.3439,32.1254&apos;!</ExceptionText>
<ExceptionText>URI: /wfs?endtime=2020-03-03T23%3A26%3A00Z&amp;latlon=32.1254396%2C-43.3439002&amp;request=GetFeature&amp;service=WFS&amp;starttime=2020-03-03T15%3A26%3A00Z&amp;storedquery_id=fmi%3A%3Aforecast%3A%3Ahirlam%3A%3Asurface%3A%3Apoint%3A%3Amultipointcoverage&amp;timestep=60&amp;version=2.0.0</ExceptionText>
<ExceptionText>URI: /wfs?endtime=2020-03-03T23%3A26%3A00Z&amp;latlon=32.1254396%2C-43.3439002&amp;request=GetFeature&amp;service=WFS&amp;starttime=2020-03-03T15%3A26%3A00Z&amp;storedquery_id=fmi%3A%3Aforecast%3A%3Aharmonie%3A%3Asurface%3A%3Apoint%3A%3Amultipointcoverage&amp;timestep=60&amp;version=2.0.0</ExceptionText>
</Exception>
</ExceptionReport>
2 changes: 1 addition & 1 deletion test/test_data/error_no_locations_response.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
version="2.0.0" xml:lang="eng">
<Exception exceptionCode="OperationParsingFailed">
<ExceptionText>No locations found for the place with the requested language!</ExceptionText>
<ExceptionText>URI: /wfs?endtime=2020-03-20T17%3A27%3A00Z&amp;place=M%C3%A4kkyl%C3%A4%2CEspoosdf&amp;request=GetFeature&amp;service=WFS&amp;starttime=2020-03-20T17%3A17%3A00Z&amp;storedquery_id=fmi%3A%3Aforecast%3A%3Ahirlam%3A%3Asurface%3A%3Apoint%3A%3Amultipointcoverage&amp;timestep=10&amp;version=2.0.0</ExceptionText>
<ExceptionText>URI: /wfs?endtime=2020-03-20T17%3A27%3A00Z&amp;place=M%C3%A4kkyl%C3%A4%2CEspoosdf&amp;request=GetFeature&amp;service=WFS&amp;starttime=2020-03-20T17%3A17%3A00Z&amp;storedquery_id=fmi%3A%3Aforecast%3A%3Aharmonie%3A%3Asurface%3A%3Apoint%3A%3Amultipointcoverage&amp;timestep=10&amp;version=2.0.0</ExceptionText>
</Exception>
</ExceptionReport>
Loading

0 comments on commit 427bc61

Please sign in to comment.