Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
knmi = KnmiStation.download(stns=260, start='2017', end='2018',
interval='hourly') # de bilt
else:
# https://www.knmi.nl/nederland-nu/klimatologie/daggegevens
knmi = KnmiStation.download(stns=260, start='1970',end='1971')
# de bilt
else:
# from a rainfall-station
knmi = KnmiStation.download(stns=550, start='2018', end='2019',
vars='RD') # de bilt
else:
# import the data from files
if meteo:
if hourly:
# hourly data without locations
knmi = KnmiStation.fromfile('../data/KNMI_Hourly.txt')
else:
# without locations, that was downloaded from the knmi-site
knmi = KnmiStation.fromfile('../data/KNMI_NoLocation.txt')
# use a file with locations:
knmi = KnmiStation.fromfile('../data/KNMI_Bilt.txt')
else:
knmi = KnmiStation.fromfile('../data/KNMI_Akkrum.txt')
# plot
f1, axarr = plt.subplots(2, sharex=True)
if 'RD' in knmi.data.columns and not np.all(np.isnan(knmi.data['RD'])):
knmi.data['RD'].plot(ax=axarr[0])
axarr[0].set_title(knmi.variables['RD'])
if 'RH' in knmi.data.columns and not np.all(np.isnan(knmi.data['RH'])):
knmi.data['RH'].plot(ax=axarr[0])
else:
# from a rainfall-station
knmi = KnmiStation.download(stns=550, start='2018', end='2019',
variables='RD') # de bilt
else:
# import the data from files
if meteo:
if hourly:
# hourly data without locations
knmi = KnmiStation.fromfile('../data/KNMI_Hourly.txt')
else:
# without locations, that was downloaded from the knmi-site
knmi = KnmiStation.fromfile('../data/KNMI_NoLocation.txt')
# use a file with locations:
knmi = KnmiStation.fromfile('../data/KNMI_Bilt.txt')
else:
knmi = KnmiStation.fromfile('../data/KNMI_Akkrum.txt')
# plot
f1, axarr = plt.subplots(2, sharex=True)
if 'RD' in knmi.data.columns and not np.all(np.isnan(knmi.data['RD'])):
knmi.data['RD'].plot(ax=axarr[0])
axarr[0].set_title(knmi.variables['RD'])
if 'RH' in knmi.data.columns and not np.all(np.isnan(knmi.data['RH'])):
knmi.data['RH'].plot(ax=axarr[0])
axarr[0].set_title(knmi.variables['RH'])
if 'EV24' in knmi.data.columns and not np.all(np.isnan(knmi.data['EV24'])):
knmi.data['EV24'].plot(ax=axarr[1])
axarr[1].set_title(knmi.variables['EV24'])
plt.show()
knmi = KnmiStation.download(stns=260, start='2017', end='2018',
interval='hourly') # de bilt
else:
# https://www.knmi.nl/nederland-nu/klimatologie/daggegevens
knmi = KnmiStation.download(stns=260, start='1970',end='1971')
# de bilt
else:
# from a rainfall-station
knmi = KnmiStation.download(stns=550, start='2018', end='2019',
variables='RD') # de bilt
else:
# import the data from files
if meteo:
if hourly:
# hourly data without locations
knmi = KnmiStation.fromfile('../data/KNMI_Hourly.txt')
else:
# without locations, that was downloaded from the knmi-site
knmi = KnmiStation.fromfile('../data/KNMI_NoLocation.txt')
# use a file with locations:
knmi = KnmiStation.fromfile('../data/KNMI_Bilt.txt')
else:
knmi = KnmiStation.fromfile('../data/KNMI_Akkrum.txt')
# plot
f1, axarr = plt.subplots(2, sharex=True)
if 'RD' in knmi.data.columns and not np.all(np.isnan(knmi.data['RD'])):
knmi.data['RD'].plot(ax=axarr[0])
axarr[0].set_title(knmi.variables['RD'])
if 'RH' in knmi.data.columns and not np.all(np.isnan(knmi.data['RH'])):
knmi.data['RH'].plot(ax=axarr[0])
knmi = KnmiStation.download(stns=550, start='2018', end='2019',
vars='RD') # de bilt
else:
# import the data from files
if meteo:
if hourly:
# hourly data without locations
knmi = KnmiStation.fromfile('../data/KNMI_Hourly.txt')
else:
# without locations, that was downloaded from the knmi-site
knmi = KnmiStation.fromfile('../data/KNMI_NoLocation.txt')
# use a file with locations:
knmi = KnmiStation.fromfile('../data/KNMI_Bilt.txt')
else:
knmi = KnmiStation.fromfile('../data/KNMI_Akkrum.txt')
# plot
f1, axarr = plt.subplots(2, sharex=True)
if 'RD' in knmi.data.columns and not np.all(np.isnan(knmi.data['RD'])):
knmi.data['RD'].plot(ax=axarr[0])
axarr[0].set_title(knmi.variables['RD'])
if 'RH' in knmi.data.columns and not np.all(np.isnan(knmi.data['RH'])):
knmi.data['RH'].plot(ax=axarr[0])
axarr[0].set_title(knmi.variables['RH'])
if 'EV24' in knmi.data.columns and not np.all(np.isnan(knmi.data['EV24'])):
knmi.data['EV24'].plot(ax=axarr[1])
axarr[1].set_title(knmi.variables['EV24'])
plt.show()
else:
# from a rainfall-station
knmi = KnmiStation.download(stns=550, start='2018', end='2019',
vars='RD') # de bilt
else:
# import the data from files
if meteo:
if hourly:
# hourly data without locations
knmi = KnmiStation.fromfile('../data/KNMI_Hourly.txt')
else:
# without locations, that was downloaded from the knmi-site
knmi = KnmiStation.fromfile('../data/KNMI_NoLocation.txt')
# use a file with locations:
knmi = KnmiStation.fromfile('../data/KNMI_Bilt.txt')
else:
knmi = KnmiStation.fromfile('../data/KNMI_Akkrum.txt')
# plot
f1, axarr = plt.subplots(2, sharex=True)
if 'RD' in knmi.data.columns and not np.all(np.isnan(knmi.data['RD'])):
knmi.data['RD'].plot(ax=axarr[0])
axarr[0].set_title(knmi.variables['RD'])
if 'RH' in knmi.data.columns and not np.all(np.isnan(knmi.data['RH'])):
knmi.data['RH'].plot(ax=axarr[0])
axarr[0].set_title(knmi.variables['RH'])
if 'EV24' in knmi.data.columns and not np.all(np.isnan(knmi.data['EV24'])):
knmi.data['EV24'].plot(ax=axarr[1])
axarr[1].set_title(knmi.variables['EV24'])
plt.show()
"""This method can be used to import KNMI data from a file in Pastas.
Parameters
----------
fname: str
Filename and path to a Dino file.
variables: str
String with the variable name to extract.
Returns
-------
ts: pastas.TimeSeries
returns a Pastas TimeSeries object or a list of objects.
"""
knmi = KnmiStation.fromfile(fname)
if variables is None:
variables = knmi.variables.keys()
if isinstance(variables, str):
variables = [variables]
stn_codes = knmi.data['STN'].unique()
ts = []
for code in stn_codes:
for variable in variables:
if variable not in knmi.data.keys():
raise (ValueError(
"variable %s is not in this dataset. Please use one of "
"the following keys: %s" % (variable, knmi.data.keys())))
series = knmi.data.loc[knmi.data['STN'] == code, variable]
"""
In this example a daily simulation is conducted from 9:00 until 9:00 (dutch standard time)
This is the time at which precipitation is logged in dutch KNMI-stations.
"""
import pastas as ps
import pandas as pd
# read observations
obs = ps.read_dino('data/B58C0698001_1.csv')
# Create the time series model
ml = ps.Model(obs)
# read weather data
knmi = ps.read.knmi.KnmiStation.fromfile(
'data/neerslaggeg_HEIBLOEM-L_967-2.txt')
rain = ps.TimeSeries(knmi.data['RD'], settings='prec')
evap = ps.read_knmi('data/etmgeg_380.txt', variables='EV24')
if True:
# also add 9 hours to the evaporation
s = evap.series_original
s.index = s.index + pd.to_timedelta(9, 'h')
evap.series_original = s
# Create stress
sm = ps.StressModel2(stress=[rain, evap], rfunc=ps.Exponential,
name='recharge')
ml.add_stressmodel(sm)
# set the time-offset of the model. This should be done automatically in the future.
def read_knmi(fname, variables='RD'):
"""This method can be used to import KNMI data.
Parameters
----------
fname: str
Filename and path to a Dino file.
Returns
-------
ts: Pandas Series
returns a standard Pastas TimeSeries object or a list of it.
"""
knmi = KnmiStation.fromfile(fname)
if variables is None:
variables = knmi.variables.keys()
if type(variables) == str:
variables = [variables]
stn_codes = knmi.data['STN'].unique()
ts = []
for code in stn_codes:
for variable in variables:
if variable not in knmi.data.keys():
raise (ValueError(
"variable %s is not in this dataset. Please use one of "
"the following keys: %s" % (variable, knmi.data.keys())))
series = knmi.data.loc[knmi.data['STN'] == code, variable]