Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def create_model():
obs = read_csv("tests/data/obs.csv", index_col=0, parse_dates=True,
squeeze=True)
rain = read_csv("tests/data/rain.csv", index_col=0, parse_dates=True,
squeeze=True)
evap = read_csv("tests/data/evap.csv", index_col=0, parse_dates=True,
squeeze=True)
ml = ps.Model(obs, name="Test_Model")
sm = ps.RechargeModel(prec=rain, evap=evap, rfunc=ps.Exponential,
name='recharge')
ml.add_stressmodel(sm)
return ml
def test_create_model():
# Import and check the observed groundwater time series
obs = ps.read_dino('tests/data/dino_gwl_data.csv')
# Create the time series model
ml = ps.Model(obs, name="Test_Model")
# read weather data
rain = ps.read_knmi('tests/data/knmi_rain_data.txt', variables='RD')
evap = ps.read_knmi('tests/data/knmi_evap_data.txt', variables='EV24')
## Create stress
sm = ps.StressModel2(stress=[rain, evap], rfunc=ps.Exponential,
name='recharge')
ml.add_stressmodel(sm)
## Solve
ml.solve()
return ml
# read observations
head = pd.read_csv("notebooks/data_notebook_7/head_wellex.csv",
index_col="Date", parse_dates=True)
# Create the time series model
ml = ps.Model(head, name="groundwater head")
# read weather data
rain = pd.read_csv("notebooks/data_notebook_7/prec_wellex.csv",
index_col="Date", parse_dates=True)
evap = pd.read_csv("notebooks/data_notebook_7/evap_wellex.csv",
index_col="Date", parse_dates=True)
# Create stress
rm = ps.RechargeModel(prec=rain, evap=evap, rfunc=ps.Exponential,
recharge="Linear", name='recharge')
ml.add_stressmodel(rm)
well = pd.read_csv("notebooks/data_notebook_7/well_wellex.csv",
index_col="Date", parse_dates=True)
sm = ps.StressModel(well, rfunc=ps.Gamma, name="well", up=False)
ml.add_stressmodel(sm)
# Solve
ml.solve(noise=True, tmax="2010")
ml.plots.results()
# read observations and create the time series model
obs = pd.read_csv("data/head_nb1.csv", index_col=0, parse_dates=True,
squeeze=True)
# Create the time series model
ml = ps.Model(obs, name="head")
# read weather data
rain = pd.read_csv("data/rain_nb1.csv", index_col=0, parse_dates=True,
squeeze=True)
evap = pd.read_csv("data/evap_nb1.csv", index_col=0, parse_dates=True,
squeeze=True)
# Create stress
sm = ps.RechargeModel(prec=rain, evap=evap, rfunc=ps.Exponential,
recharge="Linear", name='recharge')
ml.add_stressmodel(sm)
# Solve
ml.solve()
ml.plot()
import pastas as ps
ps.set_log_level("ERROR")
# read observations and create the time series model
obs = pd.read_csv("data/head_nb1.csv", index_col=0, parse_dates=True,
squeeze=True)
ml = ps.Model(obs, name="groundwater head")
# read weather data and create stressmodel
rain = pd.read_csv("data/rain_nb1.csv", index_col=0, parse_dates=True,
squeeze=True)
evap = pd.read_csv("data/evap_nb1.csv", index_col=0, parse_dates=True,
squeeze=True)
sm = ps.RechargeModel(prec=rain, evap=evap, rfunc=ps.Exponential,
recharge="Linear", name='recharge')
ml.add_stressmodel(sm)
# Solve
ml.solve()
#
df = ml.fit.prediction_interval()
inside = (obs > df.loc[obs.index, 0.025]) & (obs < df.loc[obs.index, 0.975])
print('percentage inside:', np.count_nonzero(inside) / len(inside) * 100)
# # Plot some results
axes = ml.plots.results(tmin="2010", tmax="2015", figsize=(10, 6))
axes[0].fill_between(df.index, df.iloc[:, 0], df.iloc[:, 1], color="gray",
zorder=-1, alpha=0.5, label="95% Prediction interval")
axes[0].legend(ncol=3)
df = ml.fit.ci_contribution("recharge", tmin="2010", tmax="2015")
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.
ml._set_time_offset()
## Solve
ml.solve(freq='D')
ml.plots.decomposition()
# Create the time series model
ml = ps.Model(obs)
# read weather data
rain = pd.read_csv("data/rain_nb1.csv", index_col=0, parse_dates=True,
squeeze=True)
evap = pd.read_csv("data/evap_nb1.csv", index_col=0, parse_dates=True,
squeeze=True)
# create stress
sm = ps.StressModel2(stress=[rain, evap], rfunc=ps.Exponential,
name="recharge")
ml.add_stressmodel(sm)
# add a stepmodel with an exponential response
sm = ps.stressmodels.StepModel("2007", "Step", rfunc=ps.Exponential)
ml.add_stressmodel(sm)
# solve
ml.solve()
ml.plots.decomposition()
ps.set_log_level("ERROR")
# read observations
obs = ps.read_dino('data/B58C0698001_1.csv')
# Create the time series model
ml = ps.Model(obs, name="groundwater head")
# read weather data
rain = ps.read_knmi('data/neerslaggeg_HEIBLOEM-L_967-2.txt', variables='RD')
rain.multiply(1000)
evap = ps.read_knmi('data/etmgeg_380.txt', variables='EV24')
evap.multiply(1000)
# Create stress
sm = ps.RechargeModel(prec=rain, evap=evap, rfunc=ps.Exponential,
recharge="Linear", name='recharge')
ml.add_stressmodel(sm)
# Set tmin
ml.settings['tmin'] = pd.Timestamp('2010-1-1')
# Solve
ml.solve()
ml.plot()
obs = pd.read_csv("data/head_nb1.csv", index_col=0, parse_dates=True,
squeeze=True)
# add 10 cm to the series from 2007
obs["2007":] = obs["2007":] + 0.1
# Create the time series model
ml = ps.Model(obs)
# read weather data
rain = pd.read_csv("data/rain_nb1.csv", index_col=0, parse_dates=True,
squeeze=True)
evap = pd.read_csv("data/evap_nb1.csv", index_col=0, parse_dates=True,
squeeze=True)
# create stress
sm = ps.StressModel2(stress=[rain, evap], rfunc=ps.Exponential,
name="recharge")
ml.add_stressmodel(sm)
# add a stepmodel with an exponential response
sm = ps.stressmodels.StepModel("2007", "Step", rfunc=ps.Exponential)
ml.add_stressmodel(sm)
# solve
ml.solve()
ml.plots.decomposition()