Пример #1
0
        def opt_fun(par):
            try:
                # distribute the parameters
                SpatialVarFun.Function(par,
                                       kub=SpatialVarFun.Kub,
                                       klb=SpatialVarFun.Klb,
                                       Maskingum=SpatialVarFun.Maskingum)
                self.Parameters = SpatialVarFun.Par3d
                #run the model
                Wrapper.FW1(self)
                # calculate performance of the model
                try:
                    # error = self.OF(self.QGauges, self.qout, self.quz_routed, self.qlz_translated,*[self.GaugesTable])
                    error = self.OF(self.QGauges, self.qout,
                                    *[self.GaugesTable])
                except TypeError:  # if no of inputs less than what the function needs
                    assert False, "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
Пример #2
0
    def RunFW1(self):
        """
        =======================================================================
            RunDistwithLake(PrecPath, Evap_Path, TempPath, DemPath, FlowAccPath, FlowDPath, ParPath, p2)
        =======================================================================
        this function runs the conceptual distributed hydrological model

        Inputs:
        ----------
            1-Paths:
                1-PrecPath:
                    [String] path to the Folder contains precipitation rasters
                2-Evap_Path:
                    [String] path to the Folder contains Evapotranspiration rasters
                3-TempPath:
                    [String] path to the Folder contains Temperature rasters
                4-FlowAccPath:
                    [String] path to the Flow Accumulation raster of the catchment (it should
                    include the raster name and extension)
                5-FlowDPath:
                    [String] path to the Flow Direction raster of the catchment (it should
                    include the raster name and extension)
            7-ParPath:
                [String] path to the Folder contains parameters rasters of the catchment
            8-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

        Outputs:
        ----------
            1- st:
                [4D array] state variables
            2- q_out:
                [1D array] calculated Discharge at the outlet of the catchment
            3- q_uz:
                [3D array] Distributed discharge for each cell

        Example:
        ----------
            PrecPath = prec_path="meteodata/4000/calib/prec"
            Evap_Path = evap_path="meteodata/4000/calib/evap"
            TempPath = temp_path="meteodata/4000/calib/temp"
            DemPath = "GIS/4000/dem4000.tif"
            FlowAccPath = "GIS/4000/acc4000.tif"
            FlowDPath = "GIS/4000/fd4000.tif"
            ParPath = "meteodata/4000/parameters"
            p2=[1, 227.31]
            st, q_out, q_uz_routed = RunModel(PrecPath,Evap_Path,TempPath,DemPath,
                                              FlowAccPath,FlowDPath,ParPath,p2)
        """
        # input data validation

        # input dimensions
        assert np.shape(self.Prec)[0] == self.rows and np.shape(
            self.ET
        )[0] == self.rows and np.shape(self.Temp)[0] == self.rows and np.shape(
            self.Parameters
        )[0] == self.rows, "all input data should have the same number of rows"
        assert np.shape(self.Prec)[1] == self.cols and np.shape(
            self.ET
        )[1] == self.cols and np.shape(self.Temp)[1] == self.cols and np.shape(
            self.Parameters
        )[1] == self.cols, "all input data should have the same number of columns"
        assert np.shape(self.Prec)[2] == np.shape(self.ET)[2] and np.shape(
            self.Temp
        )[2], "all meteorological input data should have the same length"

        #run the model
        Wrapper.FW1(self)

        print("Model Run has finished")