Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_create_model():
obs = read_csv("tests/data/obs.csv", index_col=0, parse_dates=True,
squeeze=True)
ml = ps.Model(obs, name="Test_Model")
sm = test_create_rechargemodel()
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
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
Below is an example of a short script to simulate groundwater levels
(the csv-files with the data can be found in the examples directory on GitHub)
"""
import pandas as pd
import pastas as ps
oseries = pd.read_csv('data/head_nb1.csv', parse_dates=['date'],
index_col='date', squeeze=True)
rain = pd.read_csv('data/rain_nb1.csv', parse_dates=['date'], index_col='date',
squeeze=True)
evap = pd.read_csv('data/evap_nb1.csv', parse_dates=['date'], index_col='date',
squeeze=True)
ml = ps.Model(oseries)
sm = ps.RechargeModel(prec=rain, evap=evap, rfunc=ps.Exponential,
recharge="Linear", name='recharge')
ml.add_stressmodel(sm)
ml.solve()
ml.plots.decomposition()
"""
This test file is meant for developing purposes. Providing an easy method to
test the functioning of PASTAS during development.
"""
import pandas as pd
import pastas as ps
# Read observations
obs = ps.read_dino('data/B58C0698001_1.csv')
obs = obs.iloc[::5]
obs = obs[obs.index > pd.to_datetime('1-1-2010')]
# Create the time series model
ml = ps.Model(obs)
# Read weather data
prec = ps.read_knmi('data/neerslaggeg_HEIBLOEM-L_967-2.txt', variables='RD')
evap = ps.read_knmi('data/etmgeg_380.txt', variables='EV24')
# Create stress
if False:
sm = ps.StressModel2(stress=[prec, evap], rfunc=ps.Exponential,
name='recharge')
ml.add_stressmodel(sm)
elif False:
sm = ps.StressModel(prec, rfunc=ps.Exponential, name='prec')
ml.add_stressmodel(sm)
sm = ps.StressModel(evap, rfunc=ps.Exponential, name='evap', up=False)
ml.add_stressmodel(sm)
else:
import numpy as np
import pandas as pd
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)
"""
This test file is meant for developing purposes. Providing an easy method to
test the functioning of Pastas during development.
"""
import pastas as ps
fname = 'data/MenyanthesTest.men'
meny = ps.read.MenyData(fname)
# Create the time series model\
H=meny.H['Obsevation well']
ml = ps.Model(H['values'])
# round to days (precipitation is measured at 9:00)
IN = meny.IN['Precipitation']
IN['values'].index = IN['values'].index.normalize()
#round to days (evaporation is measured at 1:00)
IN2 = meny.IN['Evaporation']
IN2['values'].index = IN2['values'].index.normalize()
sm = ps.StressModel2([IN['values'], IN2['values']], ps.Gamma, 'Recharge')
ml.add_stressmodel(sm)
settings = dict(freq='W')
# Add well extraction 1
IN = meny.IN['Extraction 1']
This is an example with a step in the observations, which we add artificially.
We model this step through a StepModel.
"""
import pandas as pd
import pastas as ps
# read observations
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)
Author: R.A. Collenteur, University of Graz.
"""
import pandas as pd
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)
# 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()