def add_recharge(self, ml, rfunc, name="recharge", **kwargs): """Adds a recharge element to the time series model. The selection of the precipitation and evaporation time series is based on the shortest distance to the a stresses in the stresseslist. Returns ------- """ key = ml.oseries.name prec_name = self.get_nearest_stresses(key, kind="prec").iloc[0][0] prec = self.stresses.loc[prec_name, "series"] evap_name = self.get_nearest_stresses(key, kind="evap").iloc[0][0] evap = self.stresses.loc[evap_name, "series"] recharge = ps.StressModel2([prec, evap], rfunc, name=name, **kwargs) ml.add_stressmodel(recharge)
def add_recharge(self, ml: ps.Model, rfunc=ps.Gamma) -> None: """Add recharge to a pastas model. Uses closest precipitation and evaporation timeseries in database. These are assumed to be labeled with kind = 'prec' or 'evap'. Parameters ---------- ml : pastas.Model pastas.Model object rfunc : pastas.rfunc, optional response function to use for recharge in model, by default ps.Gamma (for different response functions, see pastas documentation) """ # get nearest prec and evap stns names = [] for var in ("prec", "evap"): try: name = self.get_nearest_stresses( ml.oseries.name, kind=var).iloc[0, 0] except AttributeError: msg = "No precipitation or evaporation timeseries found!" raise Exception(msg) names.append(name) if len(names) == 0: msg = "No precipitation or evaporation timeseries found!" raise Exception(msg) # get data tsdict = self.conn.get_stresses(names) stresses = [] for k, s in tsdict.items(): metadata = self.conn.get_metadata("stresses", k, as_frame=False) s = self.conn._get_dataframe_values("stresses", k, s, metadata=metadata) stresses.append(ps.TimeSeries(s, name=k, metadata=metadata)) # add recharge to model rch = ps.StressModel2(stresses, rfunc, name="recharge", metadata=[i.metadata for i in stresses], settings=("prec", "evap")) ml.add_stressmodel(rch)
def test_rfunc(rfunc_name): if rfunc_name not in []: # Import and check the observed groundwater time series obs = ps.read_dino('tests/data/dino_gwl_data.csv') # 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 the time series model ml = ps.Model(obs, name="Test_Model") ## Create stress rfunc = getattr(ps.rfunc, rfunc_name) sm = ps.StressModel2(stress=[rain, evap], rfunc=rfunc, name='test_sm') ml.add_stressmodel(sm) # Solve the time series model ml.solve()
def test_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 the time series model ml.solve() return 'model succesfull'
# R.A. Collenteur - Artesia Water 2018 import pastas as ps from pastas.stressmodels import WellModel fname = 'data/MenyanthesTest.men' meny = ps.read.MenyData(fname) # Create the time series model H = meny.H['Obsevation well'] ml = ps.Model(H['values']) # Add precipitation IN = meny.IN['Precipitation']['values'] IN.index = IN.index.round("D") IN2 = meny.IN['Evaporation']['values'] IN2.index = IN2.index.round("D") sm = ps.StressModel2([IN, IN2], ps.Gamma, 'Recharge') ml.add_stressmodel(sm) stresses = [ meny.IN['Extraction 1']["values"], meny.IN['Extraction 2']["values"], meny.IN['Extraction 3']["values"] ] w = WellModel(stresses, ps.Theis, radius=[1, 1, 1], name="Wells") ml.add_stressmodel(w) ml.solve() ml.plots.decomposition()
# 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: sm = ps.stressmodels.NoConvModel(prec, rfunc=ps.Exponential, name='prec_no_conv') ml.add_stressmodel(sm) sm = ps.stressmodels.NoConvModel(evap, rfunc=ps.Exponential, name='evap_no_conv',
squeeze=True) # add 10 cm to the series from 2007 obs["2007":] = obs["2007":] + 1.5 # 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.One) ml.add_stressmodel(sm) # solve ml.solve() ml.plots.decomposition()
# read observations fname = 'data/B32D0136001_1.csv' obs = ps.read_dino(fname) # Create the time series model ml = ps.Model(obs) # read climate data fname = 'data/KNMI_Bilt.txt' RH = ps.read_knmi(fname, variables='RH') EV24 = ps.read_knmi(fname, variables='EV24') #rech = RH.series - EV24.series # Create stress #sm = ps.Recharge(RH, EV24, ps.Gamma, ps.Linear, name='recharge') #sm = Recharge(RH, EV24, Gamma, Combination, name='recharge') sm = ps.StressModel2([RH, EV24], ps.Gamma, name='recharge') #sm = ps.StressModel(RH, ps.Gamma, name='precip') #sm1 = ps.StressModel(EV24, ps.Gamma, name='evap') ml.add_stressmodel(sm) #ml.add_tseries(sm1) # Add noise model n = ps.NoiseModel() ml.add_noisemodel(n) # Solve ml.solve(freq="7D") ml.plot()
"""This is the short example in the docs. Also edit the docs when you change something here. 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.StressModel2([rain, evap], ps.Gamma, name='recharge') ml.add_stressmodel(sm) ml.solve() ml.plots.decomposition()
R.A. Collenteur - Artesia Water 2017 """ import pastas as ps # Create a simple model taken from example.py obs = ps.read_dino('data/B58C0698001_1.csv') rain = ps.read_knmi('data/neerslaggeg_HEIBLOEM-L_967-2.txt', variables='RD') evap = ps.read_knmi('data/etmgeg_380.txt', variables='EV24') # Create a Pastas Project mls = ps.Project(name="test_project") mls.add_series(obs, "GWL", kind="oseries", metadata=dict()) mls.add_series(rain, name="Prec", kind="prec", metadata=dict()) mls.add_series(evap, name="Evap", kind="evap", metadata=dict()) ml = mls.add_model(oseries="GWL") sm = ps.StressModel2( [mls.stresses.loc["Prec", "series"], mls.stresses.loc["Evap", "series"]], ps.Exponential, name='recharge') ml.add_stressmodel(sm) n = ps.NoiseModel() ml.add_noisemodel(n) ml.solve(freq="D", warmup=1000, report=False) mls.dump("test_project.pas")