Skip to content

Commit

Permalink
Add top-level API with general tests
Browse files Browse the repository at this point in the history
Fix issue with Mosmix station location conversion
  • Loading branch information
gutzbenj committed Mar 7, 2021
1 parent 690222b commit 858470d
Show file tree
Hide file tree
Showing 22 changed files with 336 additions and 211 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Expand Up @@ -8,6 +8,8 @@ Development
values request
- Add accessor .values to Stations class to get straight to values for a request
- Rename Stations to Request and use upper camel case e.g. DwdObservationRequest
- Add top-level API
- Fix issue with Mosmix station location

0.14.1 (21.02.2021)
*******************
Expand Down
5 changes: 3 additions & 2 deletions README.rst
Expand Up @@ -211,8 +211,9 @@ Acquisition of historical data for specific stations using ``wetterdienst`` as l

.. code-block:: python
>>> from wetterdienst.dwd.observations import DwdObservationRequest
>>> request = DwdObservationRequest(
>>> from wetterdienst import Wetterdienst
>>> API = Wetterdienst("dwd", "observation")
>>> request = API(
... parameter=["climate_summary"],
... resolution="daily",
... start_date="1990-01-01", # Timezone: UTC
Expand Down
21 changes: 21 additions & 0 deletions docs/usage/api.rst
Expand Up @@ -19,6 +19,27 @@ you might want to try the :ref:`cli`.

.. _example: https://github.com/earthobservations/wetterdienst/tree/main/example

Available APIs
==============

The available APIs can be accessed by the top-level API Wetterdienst. This API also
allows the user to discover the available APIs of each service included:

.. ipython:: python
from wetterdienst import Wetterdienst
Wetterdienst.discover()
To load any of the available APIs pass the provider and the kind of data to the
Wetterdienst API:

.. ipython:: python
from wetterdienst import Wetterdienst
API = Wetterdienst("dwd", "observation")
Request arguments
=================

Expand Down
193 changes: 88 additions & 105 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion requirements.txt
Expand Up @@ -54,5 +54,5 @@ surrogate==0.*,>=0.1.0
tabulate==0.*,>=0.8.7
tomlkit==0.*,>=0.7.0
tqdm==4.*,>=4.47.0
uvicorn==0.*,>=0.11.8
uvicorn==0.*,>=0.13.3; python_version == "3.*" and python_version >= "3.6.0"
wradlib==1.*,>=1.9.0
25 changes: 19 additions & 6 deletions tests/dwd/forecasts/test_api_data.py
Expand Up @@ -33,8 +33,14 @@ def test_dwd_mosmix_l():
assert station_ids == ["01001"]
assert len(response.df) > 200

assert len(response.df.columns) == 4
assert list(response.df.columns) == ["STATION_ID", "DATE", "PARAMETER", "VALUE"]
assert len(response.df.columns) == 5
assert list(response.df.columns) == [
"STATION_ID",
"DATE",
"PARAMETER",
"VALUE",
"QUALITY",
]

assert set(response.df["PARAMETER"]).issuperset(
[
Expand Down Expand Up @@ -184,8 +190,14 @@ def test_dwd_mosmix_s():
assert station_ids == ["01028"]
assert len(response.df) > 200

assert len(response.df.columns) == 4
assert list(response.df.columns) == ["STATION_ID", "DATE", "PARAMETER", "VALUE"]
assert len(response.df.columns) == 5
assert list(response.df.columns) == [
"STATION_ID",
"DATE",
"PARAMETER",
"VALUE",
"QUALITY",
]

assert set(response.df["PARAMETER"]).issuperset(
[
Expand Down Expand Up @@ -244,7 +256,7 @@ def test_mosmix_l_parameters():
parameter=["DD", "ww"],
humanize_parameters=False,
).filter(
station_id=["01001"],
station_id=("01001", "123"),
)
response = next(request.values.query())

Expand All @@ -253,11 +265,12 @@ def test_mosmix_l_parameters():
assert station_ids == ["01001"]
assert len(response.df) > 200

assert len(response.df.columns) == 4
assert len(response.df.columns) == 5
assert list(response.df.columns) == [
"STATION_ID",
"DATE",
"PARAMETER",
"VALUE",
"QUALITY",
]
assert set(response.df["PARAMETER"]).issuperset(["DD", "ww"])
4 changes: 2 additions & 2 deletions tests/dwd/forecasts/test_api_stations.py
Expand Up @@ -29,8 +29,8 @@ def test_dwd_mosmix_stations_success():
"FROM_DATE": pd.to_datetime([pd.NA], utc=True),
"TO_DATE": pd.to_datetime([pd.NaT], utc=True),
"HEIGHT": [10.0],
"LATITUDE": [70.34],
"LONGITUDE": [-8.64],
"LATITUDE": [70.93],
"LONGITUDE": [-8.0],
"STATION_NAME": ["JAN MAYEN"],
"STATE": ["nan"],
}
Expand Down
49 changes: 49 additions & 0 deletions tests/test_api.py
@@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2018-2021, earthobservations developers.
# Distributed under the MIT License. See LICENSE for more info.
import pytest

from wetterdienst import Wetterdienst


@pytest.mark.parametrize(
"provider,kind,kwargs",
[
(
"dwd",
"observation",
{"parameter": "kl", "resolution": "daily", "period": "recent"},
),
("dwd", "forecast", {"mosmix_type": "large"}),
],
)
def test_api(provider, kind, kwargs):
api = Wetterdienst(provider, kind)

request = api(**kwargs).all()

stations = request.df

assert set(stations.columns).issuperset(
{
"STATION_ID",
"FROM_DATE",
"TO_DATE",
"HEIGHT",
"LATITUDE",
"LONGITUDE",
"STATION_NAME",
"STATE",
}
)

assert not stations.empty

values = next(request.values.query()).df

# TODO: DWD Forecast has no quality
assert set(values.columns).issuperset(
{"STATION_ID", "PARAMETER", "DATE", "VALUE", "QUALITY"}
)

assert not values.empty

0 comments on commit 858470d

Please sign in to comment.