# 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()
def test_add_noisemodel(): ml = test_create_model() ml.add_noisemodel(ps.NoiseModel()) return
def update(self, forcing, oseries, selection): """ Update the model with newly observed data Parameters ---------- forcing: Pandas dataframe Dataframe that holds the newly observed values of the stresses. NOTE: column names should correspond to the names of the stresses in the stressmodels of the Pastas model. The index column should consist of the dates of observations (Timestamps). The first date should succeed the last date of the oseries & forcing dataset that are currently included in the Pastas model. oseries: Pandas dataframe Dataframe that holds the newly observed values of the oseries. It should consist of one column containing the oseries. NOTE: the column name should equal the column name of the oseries in the Pastas model. The index should consist of the dates of observation (Timestamps). The first date should succeed the last date of the oseries & forcing dataset that are currently included in the Pastas model. """ # Update forcing data forc = forcing.copy() initial_data = self.model.get_stress( self.stressmodelnames[0])[:].to_frame() initial_data.columns = [self.stressmodelnames[0]] for i in range(len(list(forcing.columns)) - 1): initial_data[self.stressmodelnames[i + 1]] = self.model.get_stress( self.stressmodelnames[i + 1])[:] forc = initial_data.append(forc[:]) # Update oseries new_oseries = self.model.oseries.series.to_frame().append(oseries[:]) if selection != 'total': new_oseries = new_oseries[new_oseries.index[len(new_oseries) - 1] - timedelta(days=selection):] # Create new model new_model = ps.Model(new_oseries, name="forecast") # Add stressmodels for i in range(len(self.stressmodelnames)): # The forecast function automaticly infers the response functions from the stressmodels if self.stressmodeltypes[i] == 'Gamma': responsefunc = ps.Gamma elif self.stressmodeltypes[i] == 'Hantush': responsefunc = ps.Hantush elif self.stressmodeltypes[i] == 'Exponential': responsefunc = ps.Exponential elif self.stressmodeltypes[i] == 'One': responsefunc = ps.One elif self.stressmodeltypes[i] == 'FourParam': responsefunc = ps.FourParam elif self.stressmodeltypes[i] == 'DoubleExponential': responsefunc = ps.DoubleExponential elif self.stressmodeltypes[i] == 'Polder': responsefunc = ps.Polder ts = ps.StressModel(forc[self.stressmodelnames[i]], responsefunc, name=self.stressmodelnames[i]) # Add the stressmodels to the new model new_model.add_stressmodel(ts) if self.model.constant: c = ps.Constant() new_model.add_constant(c) if self.model.noisemodel: n = ps.NoiseModel() new_model.add_noisemodel(n) if self.model.transform: tt = ps.ThresholdTransform() new_model.add_transform(tt) # Solve the new model and initialise the real-time simulation overnew new_model.solve() self.__init__(new_model, self.name)