Skip to content

Commit

Permalink
Add bbox and station name filter functions for stations
Browse files Browse the repository at this point in the history
Add units for distance filter
  • Loading branch information
gutzbenj committed Apr 5, 2021
1 parent 9ec696e commit a1a2265
Show file tree
Hide file tree
Showing 36 changed files with 4,906 additions and 7,945 deletions.
6 changes: 5 additions & 1 deletion .github/release/full/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ FROM python:3.8.8-slim as build-step
ENV DEBIAN_FRONTEND noninteractive
ENV TERM linux

# Install GDAL.
RUN apt-get update

# Install gcc compiler for python-levenstein
RUN apt-get install gcc --yes

# Install GDAL.
RUN apt-get --yes install build-essential libgdal-dev libmariadbclient-dev

# Make sure you have numpy installed before you attempt to install the GDAL Python bindings.
Expand Down
5 changes: 5 additions & 0 deletions .github/release/standard/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ FROM python:3.8.8-slim
ENV DEBIAN_FRONTEND noninteractive
ENV TERM linux

RUN apt-get update

# Install gcc compiler for python-levenstein
RUN apt-get install gcc --yes

# Use "poetry build --format=wheel" to build wheel packages.
COPY dist/wetterdienst-*.whl /tmp/

Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ Development
- Add capability to export data to Zarr format
- Add Wetterdienst UI. Thanks, @meteoDaniel!
- Add MAC ARM64 supoort with dependency restrictions
- Add support for stations filtering via bbox and name
- Add support for units in distance filtering
- Rename station_name to name
- Rename filter methods to .filter_by_station_id and .filter_by_name

0.16.1 (31.03.2021)
*******************
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Overview
.. image:: https://img.shields.io/pypi/status/wetterdienst.svg
:target: https://pypi.python.org/pypi/wetterdienst/
.. image:: https://pepy.tech/badge/wetterdienst/month
:target: https://pepy.tech/project/wetterdienst/month
:target: https://pepy.tech/project/wetterdienst
.. image:: https://img.shields.io/github/license/earthobservations/wetterdienst
:target: https://github.com/earthobservations/wetterdienst/blob/main/LICENSE
.. image:: https://zenodo.org/badge/160953150.svg
Expand Down 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=True, # default, tidy data
... humanize=True, # default, humanized parameters
... ).filter(station_id=(1048, 4411))
... ).filter_by_station_id(station_id=(1048, 4411))
>>> stations = request.df # station list
>>> values = request.values.all().df # values
Expand Down
11,482 changes: 4,024 additions & 7,458 deletions THIRD_PARTY_NOTICES

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/img/readme_img.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def create_temperature_ts_plot():

df = stations.all()

station_id, _, _, height, lat, lon, station_name, state = df.sort_values("FROM_DATE").iloc[0].values
station_name = station_name.replace(u"ß", "ss")
station_id, _, _, height, lat, lon, name, state = df.sort_values("FROM_DATE").iloc[0].values
name = name.replace(u"ß", "ss")

data = DwdObservationValues(
[station_id],
Expand Down Expand Up @@ -57,7 +57,7 @@ def create_temperature_ts_plot():

ax.set_xlabel("Date")

title = f"temperature (°C) at {station_name} (GER)\n" \
title = f"temperature (°C) at {name} (GER)\n" \
f"ID {station_id}\n" \
f"{lat}N {lon}E {height}m"
ax.set_title(title)
Expand Down
2 changes: 1 addition & 1 deletion docs/library/core.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Download
Enumerations
============

.. automodule:: wetterdienst.provider.dwd.metadata.column_names
.. automodule:: wetterdienst.metadata.columns
:members:

.. automodule:: wetterdienst.provider.dwd.metadata.datetime
Expand Down
112 changes: 106 additions & 6 deletions docs/usage/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,38 @@ Get station information for a given *parameter/parameter_set*, *resolution* and
The function returns a Pandas DataFrame with information about the available stations.

Filter for specific station ids:

.. ipython:: python
from wetterdienst.provider.dwd.observation import DwdObservationRequest, DwdObservationDataset, DwdObservationPeriod, DwdObservationResolution
stations = DwdObservationRequest(
parameter=DwdObservationDataset.PRECIPITATION_MORE,
resolution=DwdObservationResolution.DAILY,
period=DwdObservationPeriod.HISTORICAL
).filter_by_station_id(station_id=("01048", ))
df = stations.df
print(df.head())
Filter for specific station name:

.. ipython:: python
from wetterdienst.provider.dwd.observation import DwdObservationRequest, DwdObservationDataset, DwdObservationPeriod, DwdObservationResolution
stations = DwdObservationRequest(
parameter=DwdObservationDataset.PRECIPITATION_MORE,
resolution=DwdObservationResolution.DAILY,
period=DwdObservationPeriod.HISTORICAL
).filter_by_name(name="Dresden-Klotzsche")
df = stations.df
print(df.head())
Values
------

Expand All @@ -159,7 +191,7 @@ Use the ``DwdObservationRequest`` class in order to get hold of stations.
end_date="2020-01-01",
tidy=True,
humanize=True,
).filter(station_id=[3, 1048])
).filter_by_station_id(station_id=[3, 1048])
From here you can query data by station:

Expand Down Expand Up @@ -187,7 +219,12 @@ Geospatial support
Inquire the list of stations by geographic coordinates.

- Calculate weather stations close to the given coordinates and set of parameters.
- Either select by rank (n stations) or by distance in km.
- Select stations by
- rank (n stations)
- distance (km, mi,...)
- bbox

Distance with default (kilometers)

.. ipython:: python
Expand All @@ -202,14 +239,53 @@ Inquire the list of stations by geographic coordinates.
end_date=datetime(2020, 1, 20)
)
df = stations.nearby_radius(
df = stations.nearby_distance(
latitude=50.0,
longitude=8.9,
max_distance_in_km=30
distance=30
).df
print(df.head())
Distance with miles

.. ipython:: python
from datetime import datetime
from wetterdienst.provider.dwd.observation import DwdObservationRequest, DwdObservationDataset, DwdObservationPeriod, DwdObservationResolution
stations = DwdObservationRequest(
parameter=DwdObservationDataset.TEMPERATURE_AIR,
resolution=DwdObservationResolution.HOURLY,
period=DwdObservationPeriod.RECENT,
start_date=datetime(2020, 1, 1),
end_date=datetime(2020, 1, 20)
)
df = stations.nearby_distance(
latitude=50.0,
longitude=8.9,
distance=30,
unit="mi"
).df
print(df.head())
Rank selection

.. ipython:: python
from datetime import datetime
from wetterdienst.provider.dwd.observation import DwdObservationRequest, DwdObservationDataset, DwdObservationPeriod, DwdObservationResolution
stations = DwdObservationRequest(
parameter=DwdObservationDataset.TEMPERATURE_AIR,
resolution=DwdObservationResolution.HOURLY,
period=DwdObservationPeriod.RECENT,
start_date=datetime(2020, 1, 1),
end_date=datetime(2020, 1, 20)
)
df = stations.nearby_number(
latitude=50.0,
longitude=8.9,
Expand All @@ -218,6 +294,30 @@ Inquire the list of stations by geographic coordinates.
print(df.head())
Bbox selection

.. ipython:: python
from datetime import datetime
from wetterdienst.provider.dwd.observation import DwdObservationRequest, DwdObservationDataset, DwdObservationPeriod, DwdObservationResolution
stations = DwdObservationRequest(
parameter=DwdObservationDataset.TEMPERATURE_AIR,
resolution=DwdObservationResolution.HOURLY,
period=DwdObservationPeriod.RECENT,
start_date=datetime(2020, 1, 1),
end_date=datetime(2020, 1, 20)
)
df = stations.bbox(
bottom=50.0,
left=8.9,
top=50.01,
right=8.91,
).df
print(df.head())
The function returns a StationsResult with the list of stations being filtered for
distances [in km] to the given coordinates.
Expand All @@ -232,10 +332,10 @@ Again from here we can jump to the corresponding data:
period=DwdObservationPeriod.RECENT,
start_date=datetime(2020, 1, 1),
end_date=datetime(2020, 1, 20)
).nearby_radius(
).nearby_distance(
latitude=50.0,
longitude=8.9,
max_distance_in_km=30
distance=30
)
for result in stations.values.query():
Expand Down

0 comments on commit a1a2265

Please sign in to comment.