Beispiel #1
0
    def RunLumped(self, Route=0, RoutingFn=[]):
        """
        =============================================================
            RunLumped(ConceptualModel,data,parameters,p2,init_st,snow,Routing=0, RoutingFn=[])
        =============================================================
        this function runs lumped conceptual model

        Inputs:
        ----------
            1-ConceptualModel:
                [function] conceptual model and it should contain a function called simulate
            2-data:
                [numpy array] meteorological data as array with the first column as precipitation
                second as evapotranspiration, third as temperature and forth column as
                long term average temperature
            3- parameters:
                [numpy array] conceptual model parameters as array
            4-p2:
                [List] list of unoptimized parameters
                p2[0] = tfac, 1 for hourly, 0.25 for 15 min time step and 24 for daily time step
                p2[1] = catchment area in km2
            5-init_st:
                [list] initial state variables values [sp, sm, uz, lz, wc].
            6-Routing:
                [0 or 1] to decide wether t route the generated discharge hydrograph or not
            7-RoutingFn:
                [function] function to route the dischrge hydrograph.

        Outputs:
        ----------
            1- st:
                [numpy array] 3d array of the 5 state variable data for each cell
            2- q_lz:
                [numpy array] 1d array of the calculated discharge.

        Examples:
        ----------
            p2=[24, 1530]
            #[sp,sm,uz,lz,wc]
            init_st=[0,5,5,5,0]
            snow=0
        """
        if self.TemporalResolution == "Daily":
            ind = pd.date_range(self.StartDate, self.EndDate, freq="D")
        else:
            ind = pd.date_range(self.StartDate, self.EndDate, freq="H")

        Qsim = pd.DataFrame(index=ind)

        Wrapper.Lumped(self, Route, RoutingFn)
        Qsim['q'] = self.Qsim
        self.Qsim = Qsim[:]

        print("Model Run has finished")
Beispiel #2
0
        def opt_fun(par):
            try:
                # parameters
                self.Parameters = par
                #run the model
                Wrapper.Lumped(self, Route, RoutingFn)
                # calculate performance of the model
                try:
                    error = self.OF(self.QGauges[self.QGauges.columns[-1]],
                                    self.Qsim, *self.OFArgs)
                except TypeError:  # if no of inputs less than what the function needs
                    assert 1 == 5, "the objective function you have entered needs more inputs please enter then in a list as *args"

                # print error
                if printError != 0:
                    print(error)
                    # print(par)

                fail = 0
            except:
                error = np.nan
                fail = 1

            return error, [], fail