Giter Club home page Giter Club logo

dwdweather2's Introduction

image

image

image

image

image

image

image

image

image

dwdweather2

Python client to access weather data from Deutscher Wetterdienst (DWD), the federal meteorological service in Germany.

Note

Please note this library will gradually be phased out. You should consider using its successor library "Wetterdienst".

Installation

pip install dwdweather2

Synopsis

Command line usage

Get all stations with daily resolution:

dwdweather stations --resolution=daily

Get all stations with hourly resolution (default):

dwdweather stations --resolution=hourly

Get all stations with 10_minutes resolution:

dwdweather stations --resolution=10_minutes

Get closest station (first argument is longitude, second is latitude):

dwdweather station 7.0 51.0

Export stations as CSV:

dwdweather stations --type csv --file stations.csv

Export stations as GeoJSON:

dwdweather stations --type geojson --file stations.geojson

Get weather at station for certain hour (UTC):

dwdweather weather 2667 2019-06-01T15:00

To restrict the import to specified categories, run the program like:

dwdweather weather 2667 2019-06-01T15:00 --categories air_temperature precipitation pressure

Finally, to drop the cache database before performing any work, use the --reset-cache option:

dwdweather stations --reset-cache

Choose dataset with daily resolution:

dwdweather weather 44 2020-06-01 --resolution=daily

Choose dataset with hourly resolution:

dwdweather weather 44 2020-06-01T08 --resolution=hourly

Choose dataset with 10_minutes resolution:

dwdweather weather 2667 2019-06-01T15:20 --resolution=10_minutes

Usage as library

from datetime import datetime
from dwdweather import DwdWeather

# Create client object.
dwd = DwdWeather(resolution="hourly")

# Find closest station to position.
closest = dwd.nearest_station(lon=7.0, lat=51.0)

# The hour you're interested in.
# The example is 2014-03-22 12:00 (UTC).
query_hour = datetime(2014, 3, 22, 12)

result = dwd.query(station_id=closest["station_id"], timestamp=query_hour)
print(result)

DwdWeather.query() returns a dictionary with the full set of possible keys as outlined in doc/usage-library.rst.

Notes

  • Data is cached in a local sqlite3 database to improve query performance for consecutive invocations.
  • The "stations cache" is filled upon first request to DwdWeather.stations() or DwdWeather.nearest_station()
  • The "stations cache" will not be refreshed automatically. Use DwdWeather.import_stations() to do this.
  • The "measures cache" is filled upon first access to measures using DwdWeather.query() and updated whenever a query cannot be fulfilled from the cache.
  • The cache by default resides in the ~/.dwd-weather directory. This can be controlled using the cachepath argument of DwdWeather().
  • The amount of data can be ~60 MB per station for full historic extent and will obviously increase by time.
  • If weather data is queried and the query can't be fulfilled from the cache, data is loaded from the server - even if the data has been updated a second before. If the server doesn't have data for the requested time (e.g. since it's not yet available), this unnecessarily causes network traffic and wait time. Certainly space for improvement here.

Licenses

Code license

Licensed under the MIT license. See LICENSE for details.

Data license

The DWD has information about their terms of use policy in German and English.

Project information

Credits

Thanks to Marian Steinbach, all other contributors and the DWD.

Changelog

See file CHANGES.rst.

Other projects

dwdweather2's People

Contributors

amotl avatar jlewis91 avatar marians avatar noordsestern avatar pklaus avatar schmiddim avatar stianchris avatar wtfuii avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

dwdweather2's Issues

Getting data for a list of N closest stations

Hi,

I want to get a list of the x nearest stations (and not just the closest). How can I do this? It seems in the command line this is possible, but I am using the library. Am I missing it or is it not possible yet?

Just some context: I want to get the e.g. 3 closest stations that have data for e.g. wind speed around a given point.

TIA
Antje

DwdWeather: queried weather data isn't stored correctly in local db

I have recurring queries on several stations, each time asking the same data. However, for some stations, the information seems not to be stored correctly.
Instead of using local sqlite db, the data is queried from the ftp server.

dw = DwdWeather(resolution="hourly", categories='air_temperature')
dw.categories = [{'key': 'TU', 'name': 'air_temperature'}]

Stations i'm querying e.g.:

4275 Rotenburg (Wümme)
3667 Nürnberg-Netzstall

Requests restricted

When installing dwdweather2 I find dwdweather2 0.14.0 has requirement requests<2.23,>=2.22

Is there a reason why requests 2.24.0 is banned?

Encoding problem during `pip install`

System:

  • Windows 10
  • Python 3.7

I run in to the following problem when running pip install dwdweather2:

PS D:\workspaces\robotframework-dwdweather> pip install dwdweather2
Collecting dwdweather2
  Using cached https://files.pythonhosted.org/packages/b9/0c/fb48f9e43f263a493f0a5e13d00bbe6ca0a31d11958b444836d218951a25/dwdweather2-0.8.0.tar.gz
    ERROR: Complete output from command python setup.py egg_info:
    ERROR: Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\Daidalos\AppData\Local\Temp\pip-install-pa4hwo8d\dwdweather2\setup.py", line 6, in <module>
        README = open(os.path.join(here, 'README.rst')).read()
      File "d:\programs\python\python37\lib\encodings\cp1252.py", line 23, in decode
        return codecs.charmap_decode(input,self.errors,decoding_table)[0]
    UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 2062: character maps to <undefined>
    ----------------------------------------
ERROR: Command "python setup.py egg_info" failed with error code 1 in C:\Users\Daidalos\AppData\Local\Temp\pip-install-pa4hwo8d\dwdweather2\

Installation works with dwdweather (is this project related to you) but not with dwdweather2.

Installing dwdweather:

PS D:\workspaces\robotframework-dwdweather> pip install dwdweather
Collecting dwdweather
  Downloading https://files.pythonhosted.org/packages/ee/4f/4bd3ceff7b6158133d6e7cbfd68f27e4d72fd2f80c83d032944e16bbbb2f/dwdweather-0.7.tar.gz
Installing collected packages: dwdweather
  Running setup.py install for dwdweather ... done
Successfully installed dwdweather-0.7

requests dependency outdated

Hi!

I cannot embed this into my project as the request library is outdated.

dwdweather2 (0.14.0) depends on requests (>=2.22,<2.23)

Does it have to be limited to <2.23?

Forecast data

This looks promising, thanks! From the code it appears to be fetching observations data. Are there any plans to add functionality to access forecast data too?

Differences in column names between macOS and Windows?

Hi,

i'm getting the older columnnames e.g. "soiltemp_temperature_005" when requesting data on macos. When running on windows, i get the newer "soil_temperature_005" for the same value.

Is there a way to control which columnnames are used?

thanks!

markus

Running on Windows fails silently due to certificate verification problem

Trying to get dwdweather 0.11.1 running on Python 3.7.4.

Problem:
Issuing the command
dwdweather weather 02667 20190717T11 --resolution hourly --categories air_temperature
leads to
2020-01-07 16:33:48,803 [dwdweather.client ] INFO : Requesting https://opendata.dwd.de/climate_environment/CDC/observations_germany/climate/hourly/air_temperature/recent
2020-01-07 16:33:48,928 [dwdweather.client ] WARNING: Station "2667" has no data for category "air_temperature"

The issue is also present when importing DwdWeather in python using the minimal example in the readme.

I tracked the problem to the client.py. For some reason the find_resource_file function in get_measurements gets stuck in the try block, but there is no Error raised.

resource_list = self.get_resource_index(index_uri, "zip")

Retrieve and merge current weather information from stations close to each other

Hello,

I am trying to locate nearest dwd sensors from a list, therefore wanted to install the new library of dwd. However when I try to run the sample code seen at the Usage as a library documentation, I get this error.

dw = DwdWeather() # Sample code 
No schema information for resolution "None" found in knowledge base.
An exception has occurred, use %tb to see the full traceback.

SystemExit: 1

/home/halden/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py:3333: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D.
  warn("To exit: use 'exit', 'quit', or Ctrl-D.", stacklevel=1)

Edit: Apparently I forgot to specify the resolution parameter. It was a problem from my end. therefore I closed the topic.
I googled possible solutions but nothing worked so far. Any ideas about troubleshooting?

Object-oriented library interface

@JohannesRol follows a more object-oriented library interface approach with his dwdopendata package. There, you will create a location object from a factory function obtaining the geolocation and subsequently be able to invoke appropriate methods on that object for acquiring actual weather information.

We like that approach, so it would be nice to see a similar interface here.


Original example

import dwdopendata as dwd

# Acquire location object from coordinates of nearest station.
location = dwd.location(51.898, 8.9876)

# Acquire wind speed data for specific location and time range from specified resolution dataset.
wind_speed = location.wind('2019-05-01T00:00:00', '2019-05-02T00:00:00', '10min')

Float data mapped as int in Dataset

Station "662" has no data for category "soil_temperature" 50%|████████████████ | 271257/541989 [01:20<01:05, 4125.29it/s]Error in converting field 'solar_duration', value '118.0' to int. File "/home/xxxxxxx/.local/lib/python3.6/site-packages/dwdweather/core.py", line 469, in import_measures_textfile cell = int(cell)

How to reproduce:


from dwdweather import DwdWeather
from datetime import datetime

dw = DwdWeather(resolution="hourly")

dw.query(station_id=662, timestamp=datetime.now())

My Fix:
#20

Implementation of solar retrieval seems to be incorrect

Hello @amotl,

first of all thank you for your great work.
After exploring dwdweather2, I noticed that solar_* returns always None.

However, e.g. for station ID 5856 (hourly resolution) there clearly is data available (see https://opendata.dwd.de/climate_environment/CDC/observations_germany/climate/hourly/solar/)

e.g:

query_hour = datetime(2019, 7, 17, 11)
result = dw.query(station_id=5856, timestamp=query_hour)
for item in result.items():
     print(item)

should return solar-values unequal None:
5856;2019071711:12; 1; -999; 57.0; 321.0; 60; 28.00;2019071712:00;eor

Am I missing something here?
Kind regards

Daily Data

Hi,

I am currently working with the dwdweather2 package and everything is working just fine. Thanks for the nice package!

What I want to get as a result is daily data from different stations. Until now, the package only supports hourly and 10-minutes resolution. Is it possible to add the daily data functionality to the package? Then I don't need to aggregate the data and that would save me a lot of time.

The data is already available in CDC.

Many thanks in advance.

Problem using categories on daily data

If I try to restrict the categories in library usage (daily resolution), no precipitation is found for any station. Without the restriction to category_names I can derive "precipitation_height" from results. Is that wanted behaviour or a bug?

Library usage example is wrong

The library usage example is wrong. It lacks the required parameter resolution is missing and the hour parameter of query was renamed.
It should be the following:

from datetime import datetime
from dwdweather import DwdWeather

# Create client object.
- dw = DwdWeather()
+ DW = DwdWeather(resolution="hourly") 

# Find closest station to position.
closest = dw.nearest_station(lon=7.0, lat=51.0)

# The hour you're interested in.
# The example is 2014-03-22 12:00 (UTC).
query_hour = datetime(2014, 3, 22, 12)

- result = dw.query(station_id=closest["station_id"], hour=query_hour) 
+ result = dw.query(closest["station_id"], query_hour)
print(result)

Took me several hours to figure that out. :/

Add support for RADOLAN data

Dear @mmaelicke,

within jeremiahpslewis/dwdbulk#5, you asked for RADOLAN support. Most probably, reading the binary files would prove to be more efficient.

Integrating wradlib [2] or radproc [3] into dwdweather2 should be possible, but would it make any sense? I am happy to receive any thoughts about this.

With kind regards,
Andreas.

[1] https://opendata.dwd.de/climate_environment/CDC/grids_germany/hourly/radolan/recent/bin/
[2] https://wradlib.org/
[3] https://github.com/jkreklow/radproc

Building upon the dwdbulk codebase

@jlewis91 maintains a well done implementation at [1]. While it is somehow derived from this project, it is based on modern Python (Python 3.7+ & Pandas). Thanks for this, @jlewis91!

It currently seems to implement acquisition of "observation" data [2] of

  • precipitation for the 1_minute resolution
  • air_temperature, precipitation, solar, wind, extreme_temperature and extreme_wind for the 10_minutes resolution

as well as acquisition of "forecast" data.

It would be cool to join both projects again in any way. The best thing would be to build upon @jlewis91's efforts and add back improved versions of a CLI interface and a caching layer. SQLite support should be dropped altogether.

[1] https://github.com/jlewis91/dwdbulk
[2] https://github.com/jlewis91/dwdbulk/blob/6892c2c/tests/test_dwdbulk.py#L64-L65

cc @wetterfrosch

paths still correct? get no values...

Hi,

the paths are still correct?

I do not get daily data or hourly data for any station...

dwdweather weather 3987 2022-02-04T19:00

Messages like:
Station "3987" has no data for category "air_temperature"
Station "3987" has no data for category "cloud_type"
....

If I check https://opendata.dwd.de/climate_environment/CDC/observations_germany/climate/hourly/air_temperature/
then I see only directories "historical", "recent","timeseries_overview" - but not "now"

I think something was there updated?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.