Code Monkey home page Code Monkey logo

knmi-py's People

Contributors

jrtpec avatar mattbrst avatar timotk avatar

Stargazers

 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  avatar

knmi-py's Issues

StopIteration - stations_raw = [line.strip("# ") for line in stations_raw] # strip away the prefix '# '

Hello,

First of all, great and useful package!

I experienced an error when using the function 'get_hour_data_dataframe'. Below the code I runned with the error message. Don't know if the issue is known and already worked on, otherwise I will try fixing it myself.

Best regards,

Olivier

df = knmi.get_hour_data_dataframe(stations=[260,280],start="2020080101",end="2020080105" )

/local_disk0/pythonVirtualEnvDirs/virtualEnv-810100ee-3db0-4457-9149-f4b75ed9df4f/lib/python3.7/site-packages/knmi/parsers.py in parse_day_data(raw)
28
29 # parse the station list
---> 30 stations_raw = next(chunks)
31 stations_raw = [line.strip("# ") for line in stations_raw] # strip away the prefix '# '
32 stations = {}

StopIteration:

next(chunks)

I get the following error:

Traceback (most recent call last):

File "", line 1, in
knmi.get_day_data_raw(stations=[240],start="20120101",end="20130101")

File "c:\python\python37\lib\site-packages\knmi\knmi.py", line 62, in get_day_data_raw
disclaimer, stations, legend, data = parse_day_data(raw=r.text)

File "c:\python\python37\lib\site-packages\knmi\parsers.py", line 30, in parse_day_data
stations_raw = next(chunks)

StopIteration

no matter what settings or function I use.. In this example I tried the following:

import knmi
knmi.get_day_data_raw(stations=[240],start="20120101",end="20130101")

Numpy version

When running the test case on a raspberry pi zero, I get the following error:

ValueError: numpy.ufunc size changed, may indicate binary incompatibility. Expected 124 from C header, got 112 from PyObject

which may indicate an incompatibility error between the current version of numpy '1.14.0' installed on my system and what other libraries expect.

Maybe consider adding a specific version of numpy to the setup.py?

Different urls @KNMI and in the code

It looks like KNMI has updated their API urls.

https://www.knmi.nl/kennis-en-datacentrum/achtergrond/data-ophalen-vanuit-een-script

The error messages given are very confusing:
Traceback (most recent call last):
File "C:...\lib\site-packages\IPython\core\interactiveshell.py", line 3418, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "", line 1, in
df = knmi.get_day_data_dataframe(stations=WEATHER_STATIONS_WITH_DATA_NUMBER, start=from_datetime, end=until_datetime)
File "C:...\lib\site-packages\knmi\knmi.py", line 98, in get_day_data_dataframe
variables=variables)
File "C:...\lib\site-packages\knmi\knmi.py", line 62, in get_day_data_raw
disclaimer, stations, legend, data = parse_day_data(raw=r.text)
File "C:...\lib\site-packages\knmi\parsers.py", line 30, in parse_day_data
stations_raw = next(chunks)
StopIteration

FutureWarning: Support for nested sequences for 'parse_dates' in pd.read_csv is deprecated

/Users/mayk/miniconda3/lib/python3.12/site-packages/knmi/parsers.py:119:
FutureWarning: Support for nested sequences for 'parse_dates' in pd.read_csv is deprecated.

Combine the desired columns with pd.to_datetime after parsing instead.
df = pd.read_csv(StringIO(data), parse_dates=[['YYYYMMDD', 'H']],

/Users/mayk/miniconda3/lib/python3.12/site-packages/knmi/parsers.py:119:
FutureWarning: The argument 'date_parser' is deprecated and will be removed in a future version.

Please use 'date_format' instead, or read your data in as 'object' dtype and then call 'to_datetime'.
df = pd.read_csv(StringIO(data), parse_dates=[['YYYYMMDD', 'H']],

"variables" argument in `get_day_data_dataframe` returns all variables

When I call the function get_day_data_dataframe for a specified variable (e.g. TEMP), the returned DataFrame instead contains all variables.

For example:
knmi.get_day_data_dataframe([260], dt.datetime(2020, 2, 2), dt.datetime(2020, 5, 2), ['TEMP'])
returns a DataFrame with 40 columns.

Forecast data does not match historic data

Hey,

I was just trying it out after merging the pull request, but there are some issues I encountered.

For example:

  • Some of the temperature conversions are wrong, because historic temperature is 0.1 degrees Celsius, not in degrees Celsius. In conform values it should be temperature * 10. Also occurs with wind speed and precipitation.

  • Today is missing in the forecast. Not sure how this can be solved, because it seems to be only there in text format on the KNMI website.

                           STN  DDVEC    FG    TN     TX  SP     RH
2018-04-04 00:00:00+02:00  260    186  37.0  78.0  147.0  17   49.0
2018-04-05 00:00:00+02:00  260    278  46.0   1.0   99.0  37   24.0
2018-04-06 00:00:00+02:00  260    133  55.0   0.0  147.0  90    0.0
2018-04-07 00:00:00+02:00  260    154  39.0  86.0  216.0  75    0.0
2018-04-08 00:00:00+02:00  260    336  20.0  77.0  234.0  72    0.0
2018-04-10 00:00:00+02:00  260    135   4.4  11.0   18.0  30   10.0 <----- forecast start
2018-04-11 00:00:00+02:00  260     90   4.4  10.0   18.0  20    4.0
2018-04-12 00:00:00+02:00  260     90   6.7  10.0   19.0  20    5.0
2018-04-13 00:00:00+02:00  260    180   6.7   9.0   17.0  30    6.0
2018-04-14 00:00:00+02:00  260    225   4.4   9.0   18.0  40    1.0
2018-04-15 00:00:00+02:00  260    180   4.4  10.0   19.0  60    2.0

df.disclaimer doesn't work,

print(df.disclaimer)
print(df.stations)
print(df.legend)

df = df.rename(columns=df.legend)

`knmi.disclaimer
Traceback (most recent call last):

Cell In[31], line 1
knmi.disclaimer

AttributeError: module 'knmi' has no attribute 'disclaimer'`

Example.py connection error

from:

from knmi import knmi, metadata

print(metadata.stations)# provides a list of all available stations

print(metadata.variables)# provides a list of all variables and explanations

station_de_bilt=260
station_eelde=280
print("Ophalen dagdata")
df = knmi.get_day_data_dataframe(stations=[station_de_bilt,station_eelde],start="20200501",end="20200601" )
print(df)
print("Ophalen uurdata")
df = knmi.get_hour_data_dataframe(stations=[station_de_bilt,station_eelde],start="2020080101",end="2020080105" )
print(df)
print("Ophalen uurdata alleen temp en zon")
df = knmi.get_hour_data_dataframe(stations=[station_de_bilt,station_eelde],start="2020080101",end="2020080124" ,variables=['TEMP','SUNR'])
print(df)

ConnectionError: ('Connection aborted.', ConnectionResetError(10054, 'De externe host heeft een verbinding verbroken', None, 10054, None))

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.