Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
gutzbenj committed Jan 5, 2025
1 parent 05efb99 commit 9a88792
Show file tree
Hide file tree
Showing 17 changed files with 316 additions and 333 deletions.
5 changes: 0 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,6 @@ def settings_si_false_wide_shape():
return Settings(ts_shape="wide", ts_convert_units=False)


@pytest.fixture
def settings_si_true():
return Settings(ts_convert_units=True)


@pytest.fixture
def settings_wide_shape():
return Settings(ts_shape="wide")
Expand Down
2 changes: 1 addition & 1 deletion tests/core/timeseries/test_interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_interpolation_temperature_air_mean_2m_hourly_by_coords(default_settings
"station_id": "f674568e",
"parameter": "temperature_air_mean_2m",
"date": dt.datetime(2022, 1, 2, tzinfo=ZoneInfo("UTC")),
"value": 277.71,
"value": 4.56,
"distance_mean": 13.37,
"taken_station_ids": ["02480", "04411", "07341", "00917"],
}
Expand Down
6 changes: 3 additions & 3 deletions tests/core/timeseries/test_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,23 @@ def test_summary_temperature_air_mean_2m_daily(default_settings):
"station_id": "7ac6c582",
"parameter": "temperature_air_mean_2m",
"date": selected_dates[0],
"value": 273.65,
"value": 0.5,
"distance": 13.42,
"taken_station_id": "01048",
},
{
"station_id": "7ac6c582",
"parameter": "temperature_air_mean_2m",
"date": selected_dates[1],
"value": 267.65,
"value": -5.5,
"distance": 5.05,
"taken_station_id": "01051",
},
{
"station_id": "7ac6c582",
"parameter": "temperature_air_mean_2m",
"date": selected_dates[2],
"value": 270.45,
"value": -2.7,
"distance": 0.0,
"taken_station_id": "01050",
},
Expand Down
2 changes: 1 addition & 1 deletion tests/provider/dwd/observation/test_api_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ def test_dwd_observation_data_result_wide_single_parameter(


@pytest.mark.remote
def test_dwd_observation_data_result_wide_si(
def test_dwd_observation_data_result_wide_convert_units(
settings_humanize_false_wide_shape_drop_nulls_complete,
dwd_climate_summary_wide_columns,
):
Expand Down
2 changes: 1 addition & 1 deletion tests/provider/dwd/road/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_dwd_road_weather():
"station_group": "KK",
}
values = request.values.all().df.drop_nulls(subset="value")
assert 230 <= values.get_column("value").min() <= 313 # approx. -+40 K
assert -40 <= values.get_column("value").min() <= 40 # approx. -+40 K


@pytest.mark.xfail(reason="number of station groups may change")
Expand Down
56 changes: 28 additions & 28 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ def test_metadata_units(unit_converter, unit_converter_unit_type_units, metadata
assert parameter.unit in unit_converter_unit_type_units[parameter.unit_type]


def test_api_dwd_observation(settings_si_true):
request = DwdObservationRequest(parameters=[("daily", "kl")], periods="recent", settings=settings_si_true).all()
def test_api_dwd_observation(default_settings):
request = DwdObservationRequest(parameters=[("daily", "kl")], periods="recent", settings=default_settings).all()
assert not request.df.is_empty()
assert set(request.df.columns).issuperset(DF_STATIONS_MINIMUM_COLUMNS)
first_start_date = request.df.get_column("start_date").to_list()[0]
Expand All @@ -124,8 +124,8 @@ def test_api_dwd_observation(settings_si_true):
assert not values.drop_nulls(subset="value").is_empty()


def test_api_dwd_mosmix(settings_si_true):
request = DwdMosmixRequest(parameters=[("hourly", "large")], settings=settings_si_true).all()
def test_api_dwd_mosmix(default_settings):
request = DwdMosmixRequest(parameters=[("hourly", "large")], settings=default_settings).all()
assert not request.df.is_empty()
assert set(request.df.columns).issuperset(DF_STATIONS_MINIMUM_COLUMNS)
first_start_date = request.df.get_column("start_date").to_list()[0]
Expand All @@ -138,8 +138,8 @@ def test_api_dwd_mosmix(settings_si_true):
assert not values.drop_nulls(subset="value").is_empty()


def test_api_dwd_dmo(settings_si_true):
request = DwdDmoRequest(parameters=[("hourly", "icon")], settings=settings_si_true).all()
def test_api_dwd_dmo(default_settings):
request = DwdDmoRequest(parameters=[("hourly", "icon")], settings=default_settings).all()
assert not request.df.is_empty()
assert set(request.df.columns).issuperset(DF_STATIONS_MINIMUM_COLUMNS)
first_start_date = request.df.get_column("start_date").to_list()[0]
Expand All @@ -153,9 +153,9 @@ def test_api_dwd_dmo(settings_si_true):


@pytest.mark.skipif(not ensure_eccodes(), reason="eccodes not installed")
def test_api_dwd_road(settings_si_true):
def test_api_dwd_road(default_settings):
request = DwdRoadRequest(
parameters=[("15_minutes", "data", "temperature_air_mean_2m")], settings=settings_si_true
parameters=[("15_minutes", "data", "temperature_air_mean_2m")], settings=default_settings
).all()
assert not request.df.is_empty()
assert set(request.df.columns).issuperset(DF_STATIONS_MINIMUM_COLUMNS)
Expand All @@ -170,8 +170,8 @@ def test_api_dwd_road(settings_si_true):


@pytest.mark.xfail
def test_api_eccc_observation(settings_si_true):
request = EcccObservationRequest(parameters=[("daily", "data")], settings=settings_si_true).all()
def test_api_eccc_observation(default_settings):
request = EcccObservationRequest(parameters=[("daily", "data")], settings=default_settings).all()
assert not request.df.is_empty()
assert set(request.df.columns).issuperset(DF_STATIONS_MINIMUM_COLUMNS)
first_start_date = request.df.get_column("start_date").to_list()[0]
Expand All @@ -186,8 +186,8 @@ def test_api_eccc_observation(settings_si_true):

@pytest.mark.xfail
@pytest.mark.remote
def test_api_imgw_hydrology(settings_si_true):
request = ImgwHydrologyRequest(parameters=[("daily", "hydrology")], settings=settings_si_true).all()
def test_api_imgw_hydrology(default_settings):
request = ImgwHydrologyRequest(parameters=[("daily", "hydrology")], settings=default_settings).all()
assert not request.df.is_empty()
assert set(request.df.columns).issuperset(DF_STATIONS_MINIMUM_COLUMNS)
first_start_date = request.df.get_column("start_date").to_list()[0]
Expand All @@ -202,8 +202,8 @@ def test_api_imgw_hydrology(settings_si_true):

@pytest.mark.xfail
@pytest.mark.remote
def test_api_imgw_meteorology(settings_si_true):
request = ImgwMeteorologyRequest(parameters=[("daily", "climate")], settings=settings_si_true).filter_by_station_id(
def test_api_imgw_meteorology(default_settings):
request = ImgwMeteorologyRequest(parameters=[("daily", "climate")], settings=default_settings).filter_by_station_id(
"249200180"
)
assert not request.df.is_empty()
Expand All @@ -218,9 +218,9 @@ def test_api_imgw_meteorology(settings_si_true):
assert not values.drop_nulls(subset="value").is_empty()


def test_api_noaa_ghcn_hourly(settings_si_true):
def test_api_noaa_ghcn_hourly(default_settings):
request = NoaaGhcnRequest(
parameters=[("hourly", "data", "precipitation_height")], settings=settings_si_true
parameters=[("hourly", "data", "precipitation_height")], settings=default_settings
).filter_by_station_id("AQC00914594")
assert not request.df.is_empty()
assert set(request.df.columns).issuperset(DF_STATIONS_MINIMUM_COLUMNS)
Expand All @@ -234,9 +234,9 @@ def test_api_noaa_ghcn_hourly(settings_si_true):
assert not values.drop_nulls(subset="value").is_empty()


def test_api_noaa_ghcn_daily(settings_si_true):
def test_api_noaa_ghcn_daily(default_settings):
request = NoaaGhcnRequest(
parameters=[("daily", "data", "precipitation_height")], settings=settings_si_true
parameters=[("daily", "data", "precipitation_height")], settings=default_settings
).filter_by_station_id("AQC00914594")
assert not request.df.is_empty()
assert set(request.df.columns).issuperset(DF_STATIONS_MINIMUM_COLUMNS)
Expand All @@ -251,8 +251,8 @@ def test_api_noaa_ghcn_daily(settings_si_true):


@pytest.mark.xfail
def test_api_wsv_pegel(settings_si_true):
request = WsvPegelRequest(parameters=[("dynamic", "data", "stage")], settings=settings_si_true).all()
def test_api_wsv_pegel(default_settings):
request = WsvPegelRequest(parameters=[("dynamic", "data", "stage")], settings=default_settings).all()
assert not request.df.is_empty()
assert set(request.df.columns).issuperset(DF_STATIONS_MINIMUM_COLUMNS)
first_date = request.df.get_column("start_date").to_list()[0]
Expand All @@ -265,8 +265,8 @@ def test_api_wsv_pegel(settings_si_true):
assert not values.drop_nulls(subset="value").is_empty()


def test_api_ea_hydrology(settings_si_true):
request = EAHydrologyRequest(parameters=[("daily", "data", "discharge")], settings=settings_si_true).all()
def test_api_ea_hydrology(default_settings):
request = EAHydrologyRequest(parameters=[("daily", "data", "discharge")], settings=default_settings).all()
assert not request.df.is_empty()
assert set(request.df.columns).issuperset(DF_STATIONS_MINIMUM_COLUMNS)
first_date = request.df.get_column("start_date").to_list()[0]
Expand All @@ -279,9 +279,9 @@ def test_api_ea_hydrology(settings_si_true):
assert not values.drop_nulls(subset="value").is_empty()


def test_api_nws_observation(settings_si_true):
def test_api_nws_observation(default_settings):
request = NwsObservationRequest(
parameters=[("hourly", "data", "temperature_air_mean_2m")], settings=settings_si_true
parameters=[("hourly", "data", "temperature_air_mean_2m")], settings=default_settings
).filter_by_station_id("KBHM")
assert not request.df.is_empty()
assert set(request.df.columns).issuperset(DF_STATIONS_MINIMUM_COLUMNS)
Expand All @@ -295,8 +295,8 @@ def test_api_nws_observation(settings_si_true):
assert not values.drop_nulls(subset="value").is_empty()


def test_api_eaufrance_hubeau(settings_si_true):
request = HubeauRequest(parameters=[("dynamic", "data", "discharge")], settings=settings_si_true).all()
def test_api_eaufrance_hubeau(default_settings):
request = HubeauRequest(parameters=[("dynamic", "data", "discharge")], settings=default_settings).all()
assert not request.df.is_empty()
assert set(request.df.columns).issuperset(DF_STATIONS_MINIMUM_COLUMNS)
first_date = request.df.get_column("start_date").to_list()[0]
Expand All @@ -309,9 +309,9 @@ def test_api_eaufrance_hubeau(settings_si_true):
assert not values.drop_nulls(subset="value").is_empty()


def test_api_geosphere_observation(settings_si_true):
def test_api_geosphere_observation(default_settings):
request = GeosphereObservationRequest(
parameters=[("daily", "data", "precipitation_height")], settings=settings_si_true
parameters=[("daily", "data", "precipitation_height")], settings=default_settings
).filter_by_station_id("5882")

assert not request.df.is_empty()
Expand Down
10 changes: 5 additions & 5 deletions tests/ui/cli/test_cli_interpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,15 @@ def test_cli_interpolate_geojson():
"station_id": "6754d04d",
"parameter": "temperature_air_mean_2m",
"date": "1986-10-31T00:00:00+00:00",
"value": 279.52,
"value": 6.37,
"distance_mean": 16.99,
"taken_station_ids": ["00072", "02074", "02638", "04703"],
},
{
"station_id": "6754d04d",
"date": "1986-11-01T00:00:00+00:00",
"parameter": "temperature_air_mean_2m",
"value": 281.85,
"value": 8.7,
"distance_mean": 0.0,
"taken_station_ids": ["00071"],
},
Expand Down Expand Up @@ -256,7 +256,7 @@ def test_cli_interpolate_interpolation_station_distance():
"station_id": "6754d04d",
"parameter": "temperature_air_mean_2m",
"date": "1986-11-01T00:00:00+00:00",
"value": 281.85,
"value": 8.7,
"distance_mean": 0.0,
"taken_station_ids": ["00071"],
},
Expand Down Expand Up @@ -288,15 +288,15 @@ def test_cli_interpolate_dont_use_nearby_station():
"station_id": "6754d04d",
"parameter": "temperature_air_mean_2m",
"date": "1986-10-31T00:00:00+00:00",
"value": 279.52,
"value": 6.37,
"distance_mean": 16.99,
"taken_station_ids": ["00072", "02074", "02638", "04703"],
},
{
"station_id": "6754d04d",
"parameter": "temperature_air_mean_2m",
"date": "1986-11-01T00:00:00+00:00",
"value": 281.85,
"value": 8.7,
"distance_mean": 11.33,
"taken_station_ids": ["00071", "00072", "02074", "02638"],
},
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/cli/test_cli_summarize.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ def test_cli_summarize_geojson():
"station_id": "a87291a8",
"parameter": "temperature_air_mean_2m",
"date": "1986-10-31T00:00:00+00:00",
"value": 279.75,
"value": 6.6,
"distance": 6.97,
"taken_station_id": "00072",
},
{
"station_id": "a87291a8",
"parameter": "temperature_air_mean_2m",
"date": "1986-11-01T00:00:00+00:00",
"value": 281.85,
"value": 8.7,
"distance": 0.0,
"taken_station_id": "00071",
},
Expand Down
18 changes: 9 additions & 9 deletions tests/ui/test_restapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,11 @@ def test_values_dwd_sql_tabular(client):
assert len(data) >= 8
item = data[0]
assert item == {
"cloud_cover_total": 6.9,
"cloud_cover_total": 0.8625,
"qn_cloud_cover_total": 10.0,
"dataset": "climate_summary",
"date": "2020-01-25T00:00:00+00:00",
"humidity": 89.0,
"humidity": 0.89,
"qn_humidity": 10.0,
"precipitation_form": 0.0,
"qn_precipitation_form": 10.0,
Expand Down Expand Up @@ -404,15 +404,15 @@ def test_interpolate_dwd(client):
"station_id": "6754d04d",
"parameter": "temperature_air_mean_2m",
"date": "1986-10-31T00:00:00+00:00",
"value": 279.52,
"value": 6.37,
"distance_mean": 16.99,
"taken_station_ids": ["00072", "02074", "02638", "04703"],
},
{
"station_id": "6754d04d",
"parameter": "temperature_air_mean_2m",
"date": "1986-11-01T00:00:00+00:00",
"value": 281.85,
"value": 8.7,
"distance_mean": 0.0,
"taken_station_ids": ["00071"],
},
Expand Down Expand Up @@ -446,7 +446,7 @@ def test_interpolate_dwd_lower_interpolation_distance(client):
"station_id": "6754d04d",
"parameter": "temperature_air_mean_2m",
"date": "1986-11-01T00:00:00+00:00",
"value": 281.85,
"value": 8.7,
"distance_mean": 0.0,
"taken_station_ids": ["00071"],
},
Expand All @@ -472,15 +472,15 @@ def test_interpolate_dwd_dont_use_nearby_station(client):
"station_id": "6754d04d",
"parameter": "temperature_air_mean_2m",
"date": "1986-10-31T00:00:00+00:00",
"value": 279.52,
"value": 6.37,
"distance_mean": 16.99,
"taken_station_ids": ["00072", "02074", "02638", "04703"],
},
{
"station_id": "6754d04d",
"parameter": "temperature_air_mean_2m",
"date": "1986-11-01T00:00:00+00:00",
"value": 281.85,
"value": 8.7,
"distance_mean": 11.33,
"taken_station_ids": ["00071", "00072", "02074", "02638"],
},
Expand Down Expand Up @@ -542,15 +542,15 @@ def test_summarize_dwd(client):
"station_id": "a87291a8",
"parameter": "temperature_air_mean_2m",
"date": "1986-10-31T00:00:00+00:00",
"value": 279.75,
"value": 6.6,
"distance": 6.97,
"taken_station_id": "00072",
},
{
"station_id": "a87291a8",
"parameter": "temperature_air_mean_2m",
"date": "1986-11-01T00:00:00+00:00",
"value": 281.85,
"value": 8.7,
"distance": 0.0,
"taken_station_id": "00071",
},
Expand Down
2 changes: 0 additions & 2 deletions wetterdienst/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ def __new__(cls, provider: str, network: str) -> type[TimeseriesRequest]:
:param network: data network e.g. NOAAs observation
"""
# Both provider and network should be fine (if not an exception is raised)
provider = provider.strip().lower()
network = network.strip().lower()
return cls.resolve(provider, network)

@classmethod
Expand Down
Loading

0 comments on commit 9a88792

Please sign in to comment.