Skip to content

Commit

Permalink
Add coverage and licence information
Browse files Browse the repository at this point in the history
Fix cli and service
  • Loading branch information
gutzbenj committed Mar 27, 2021
1 parent 0aa0744 commit ddc83ac
Show file tree
Hide file tree
Showing 14 changed files with 88 additions and 53 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ Acquisition of historical data for specific stations using ``wetterdienst`` as l
... end_date="2020-01-01", # Timezone: UTC
... tidy_data=True, # default
... humanize_parameters=True, # default
... ).filter(station_id=[1048, 4411])
... ).filter(station_id=(1048, 4411))
>>> stations = request.df # station list
>>> values = request.values.all().df # values
Expand Down
14 changes: 14 additions & 0 deletions docs/data/coverage/eccc.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
ECCC (Environment and Climate Change Canada)
********************************************

- Historical Weather Observations
- Historical (last ~180 years)
- Hourly, daily, monthly, (annual) resolution
- Time series of stations in Canada

.. ipython:: python
from wetterdienst.provider.eccc.observation import EcccObservationRequest
observations_meta = EcccObservationRequest.discover(flatten=False)
# Selection of daily historical data
print(observations_meta)
26 changes: 26 additions & 0 deletions docs/data/license/eccc.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,28 @@
ECCC (Environment and Climate Change Canada)
********************************************

The licence for the use of ECCC data is given at

https://climate.weather.gc.ca/prods_servs/attachment1_e.html

Specifically we want to quote and therewith highlight two passages from ECCC:

- REDISTRIBUTION RESTRICTIONS
"You are authorized to further distribute the data or software, including any portion
of it, contained in this product under the following conditions only. No fee will be
charged explicitly for this Environment and Climate Change Canada product to any party
to whom it is distributed. (Charges for value-added services are permitted.). In
consideration of the licence you are herein granted, you have the obligation to
acknowledge the source of the Environment and Climate Change Canada Data with the
following layout or something similar: based on Environment and Climate Change Canada
data. Redistribution must occur so that any other party must agree to the same
redistribution restrictions before use of the redistributed product is allowed."

- NO WARRANTIES
"Environment and Climate Change Canada does not warrant the quality,
accuracy, or completeness of any information or data. Such information and data is
provided "AS IS" without warranty or condition of any nature. Environment and Climate
Change Canada disclaims all other warranties, expressed or implied, including but not
limited to implied warranties of merchantability and fitness for a particular purpose,
with respect to the software, the data retrieved from this product, and any accompanying
materials."
4 changes: 2 additions & 2 deletions docs/usage/code_snippets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ Get available parameters for daily historical data of DWD:
API = Wetterdienst("dwd", "observation")
observations_meta = API.discover(
resolution=Resolution.DAILY,
filter_=Resolution.DAILY,
)
# Available parameter sets
print(observations_meta)
# Available individual parameters
observations_meta = API.discover(
resolution=Resolution.DAILY, flatten=False
filter_=Resolution.DAILY, flatten=False
)
print(observations_meta)
Expand Down
22 changes: 11 additions & 11 deletions example/climate_observations.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/provider/dwd/observation/test_api_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


def test_dwd_observation_metadata_discover_parameters():
parameters = DwdObservationRequest.discover(resolution="minute_1", flatten=True)
parameters = DwdObservationRequest.discover(filter_="minute_1", flatten=True)

assert (
json.dumps(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def test_dwd_readings_no_station():
)

assert response.status_code == 400
assert response.json() == {"detail": "Query argument 'station' is required"}
assert response.json() == {"detail": "Query argument 'stations' is required"}


def test_dwd_readings_no_parameter():
Expand Down
5 changes: 1 addition & 4 deletions wetterdienst/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@
# Copyright (c) 2018-2021, earthobservations developers.
# Distributed under the MIT License. See LICENSE for more info.
import json
from typing import TypeVar, Type

from wetterdienst.core.scalar.request import ScalarRequestCore
from wetterdienst.metadata.kind import Kind
from wetterdienst.metadata.provider import Provider
from wetterdienst.provider.dwd.forecast import DwdMosmixRequest
from wetterdienst.provider.dwd.observation import DwdObservationRequest
from wetterdienst.provider.dwd.radar import DwdRadarValues
from wetterdienst.provider.eccc.observation.api import EcccObservationRequest
from wetterdienst.provider.eccc.observation import EcccObservationRequest
from wetterdienst.util.enumeration import parse_enumeration_from_template


API_ENDPOINTS = {
Provider.DWD: {
Kind.OBSERVATION: DwdObservationRequest,
Expand Down
6 changes: 3 additions & 3 deletions wetterdienst/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
def run():
"""
Usage:
wetterdienst dwd observation stations --parameter=<parameter> --resolution=<resolution> --period=<period> [--station=<station>] [--latitude=<latitude>] [--longitude=<longitude>] [--number=<number>] [--distance=<distance>] [--sql=<sql>] [--format=<format>] [--target=<target>]
wetterdienst dwd observation stations --parameter=<parameter> --resolution=<resolution> --period=<period> [--station=<station>] [--latitude=<latitude>] [--longitude=<longitude>] [--number=<number>] [--distance=<distance>] [--sql=<sql>] [--format=<format>] [--target=<target>]
wetterdienst dwd observation values --parameter=<parameter> --resolution=<resolution> [--station=<station>] [--period=<period>] [--date=<date>] [--tidy] [--sql=<sql>] [--format=<format>] [--target=<target>]
wetterdienst dwd observation values --parameter=<parameter> --resolution=<resolution> --latitude=<latitude> --longitude=<longitude> [--period=<period>] [--number=<number>] [--distance=<distance>] [--tidy] [--date=<date>] [--sql=<sql>] [--format=<format>] [--target=<target>]
wetterdienst dwd forecast stations --parameter=<parameter> [--mosmix-type=<mosmix-type>] [--date=<date>] [--station=<station>] [--latitude=<latitude>] [--longitude=<longitude>] [--number=<number>] [--distance=<distance>] [--sql=<sql>] [--format=<format>] [--target=<target>]
wetterdienst dwd forecast stations --parameter=<parameter> [--mosmix-type=<mosmix-type>] [--date=<date>] [--station=<station>] [--latitude=<latitude>] [--longitude=<longitude>] [--number=<number>] [--distance=<distance>] [--sql=<sql>] [--format=<format>] [--target=<target>]
wetterdienst dwd forecast values --parameter=<parameter> [--mosmix-type=<mosmix-type>] --station=<station> [--date=<date>] [--tidy] [--sql=<sql>] [--format=<format>] [--target=<target>]
wetterdienst dwd about [parameters] [resolutions] [periods]
wetterdienst dwd about coverage [--parameter=<parameter>] [--resolution=<resolution>] [--period=<period>]
Expand Down Expand Up @@ -338,7 +338,7 @@ def output(thing):

elif options.coverage:
metadata = DwdObservationRequest.discover(
resolution=options.resolution,
filter_=options.resolution,
dataset=read_list(options.parameter),
flatten=False,
)
Expand Down
31 changes: 13 additions & 18 deletions wetterdienst/core/scalar/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ def _parameter_base(self) -> Enum:
@property
@abstractmethod
def _has_datasets(self) -> bool:
""" Boolean if weather service has datasets (when multiple parameters are stored
in one table/file """
"""Boolean if weather service has datasets (when multiple parameters are stored
in one table/file"""
pass

@property
Expand All @@ -117,16 +117,16 @@ def _dataset_tree(self) -> Optional[object]:

@property
def _unique_dataset(self) -> bool:
""" If ALL parameters are stored in one dataset e.g. all daily data is stored in
one file """
"""If ALL parameters are stored in one dataset e.g. all daily data is stored in
one file"""
if self._has_datasets:
raise NotImplementedError("define if only one big dataset is available")
return False

@property
def _dataset_accessor(self) -> str:
""" Accessor for dataset, by default the resolution is used as we expect
datasets to be divided in resolutions """
"""Accessor for dataset, by default the resolution is used as we expect
datasets to be divided in resolutions"""
return self.resolution.name

@property
Expand Down Expand Up @@ -347,19 +347,17 @@ def discover(cls, filter_=None, dataset=None, flatten: bool = True) -> str:
return json.dumps(parameters, indent=4)

datasets_filter = (
pd.Series(dataset)
.apply(parse_enumeration_from_template, args=(cls._dataset_base,))
.tolist()
or cls._dataset_base
pd.Series(dataset)
.apply(parse_enumeration_from_template, args=(cls._dataset_base,))
.tolist()
or cls._dataset_base
)

datasets_filter = [ds.name for ds in datasets_filter]

parameters = {}

for f in filter_:
f = f.name

parameters[f] = {}

for dataset in cls._dataset_tree[f].__dict__:
Expand All @@ -380,12 +378,9 @@ def _setup_discover_filter(cls, filter_):

filter_ = [cls.resolution]

filter_ = (
pd.Series(filter_)
.apply(parse_enumeration_from_template, args=(cls._resolution_base,))
.tolist()
or [*cls._resolution_base]
)
filter_ = pd.Series(filter_).apply(
parse_enumeration_from_template, args=(cls._resolution_base,)
).tolist() or [*cls._resolution_base]

return filter_

Expand Down
9 changes: 3 additions & 6 deletions wetterdienst/provider/dwd/forecast/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,9 @@ def _dataset_accessor(self) -> str:

@classmethod
def _setup_discover_filter(cls, filter_):
filter_ = (
pd.Series(filter_)
.apply(parse_enumeration_from_template, args=(cls._dataset_base,))
.tolist()
or [*cls._dataset_base]
)
filter_ = pd.Series(filter_).apply(
parse_enumeration_from_template, args=(cls._dataset_base,)
).tolist() or [*cls._dataset_base]

return filter_

Expand Down
1 change: 0 additions & 1 deletion wetterdienst/provider/dwd/observation/api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2018-2021, earthobservations developers.
# Distributed under the MIT License. See LICENSE for more info.
import json
import logging
from datetime import datetime
from typing import Dict, List, Optional, Tuple, Union
Expand Down
7 changes: 7 additions & 0 deletions wetterdienst/provider/eccc/observation/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2018-2021, earthobservations developers.
# Distributed under the MIT License. See LICENSE for more info.
from wetterdienst.provider.eccc.observation.api import EcccObservationRequest
from wetterdienst.provider.eccc.observation.metadata.dataset import (
EccObservationDataset,
)
from wetterdienst.provider.eccc.observation.metadata.parameter import (
EccObservationParameter,
)
10 changes: 5 additions & 5 deletions wetterdienst/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ def dwd_stations(
max_distance_in_km: int = Query(default=None),
sql: str = Query(default=None),
):
provider = "dwd" # for now fixed

if kind not in ["observation", "forecast"]:
return HTTPException(status_code=404, detail=f"product {kind} not found")

Expand Down Expand Up @@ -148,13 +146,15 @@ def dwd_values(
:param tidy: Whether to return data in tidy format. Default: True.
:return:
"""
provider = "dwd"
if kind not in ["observation", "mosmix"]:
return HTTPException(status_code=404, detail=f"product {kind} not found")
return HTTPException(
status_code=404,
detail=f"Unknown value for query argument 'kind={kind}' {kind}",
)

if stations is None:
raise HTTPException(
status_code=400, detail="Query argument 'station' is required"
status_code=400, detail="Query argument 'stations' is required"
)

station_ids = map(str, read_list(stations))
Expand Down

0 comments on commit ddc83ac

Please sign in to comment.