Esempio n. 1
0
    def __init__(self, globeCloneMapFileName, localCloneMapFileName, \
                       netcdf_input, \
                       pcraster_output, \
                       modelTime, \
                       inputEPSG, outputEPSG, resample_method):
        DynamicModel.__init__(self)

        # clone map file names:
        self.globeCloneMapFileName = globeCloneMapFileName
        self.localCloneMapFileName = localCloneMapFileName

        # time variable/object
        self.modelTime = modelTime

        # netcdf input and pcraster output files
        self.netcdf_input = netcdf_input
        self.pcraster_output = pcraster_output

        # input and output projection/coordinate systems
        self.inputEPSG = inputEPSG
        self.outputEPSG = outputEPSG

        # resampling method
        self.resample_method = resample_method

        # initial clone
        pcr.setclone(self.globeCloneMapFileName)

        # monthly step
        self.i_month = 0
Esempio n. 2
0
    def __init__(self, cloneMapFileName,\
                       pcraster_files, \
                       output, \
                       modelTime):
        DynamicModel.__init__(self)           # 
        pcr.setclone(cloneMapFileName)
        
        self.modelTime = modelTime
        
        self.pcraster_files = pcraster_files
        
        # move to the input folder
        os.chdir(self.pcraster_files['directory'])
        
        self.output = output
        self.output['file_name'] = vos.getFullPath(self.output['file_name'], self.output['folder'])
        
        # object for reporting
        self.netcdf_report = OutputNetcdf(cloneMapFileName, self.output['description'])       

        print(self.output['long_name'])
        
        # make a netcdf file
        self.netcdf_report.createNetCDF(self.output['file_name'],\
                                        self.output['variable_name'],\
                                        self.output['unit'],\
                                        self.output['long_name'])
    def __init__(self, configuration, modelTime):
        DynamicModel.__init__(self)

        self.modelTime = modelTime
        self.model = ModflowOfflineCoupling(configuration, modelTime)

        self.reporting = Reporting(configuration, self.model, modelTime)
    def __init__(self, input_netcdf,\
                       output_netcdf,\
                       modelTime,\
                       tmpDir = "/dev/shm/"):
        DynamicModel.__init__(self) 

        self.input_netcdf = input_netcdf
        self.output_netcdf = output_netcdf 
        self.tmpDir = tmpDir
        self.modelTime = modelTime

        # set clone
        self.clone_map_file = self.input_netcdf['cell_area']
        pcr.setclone(self.clone_map_file)
        self.clone = {}
        self.clone['cellsize'] = pcr.clone().cellSize() ; print self.clone['cellsize']
        self.clone['rows']     = int(pcr.clone().nrRows()) 
        self.clone['cols']     = int(pcr.clone().nrCols())
        self.clone['xUL']      = round(pcr.clone().west(), 2)
        self.clone['yUL']      = round(pcr.clone().north(), 2)

        # cell area (unit: m2)
        self.cell_area = pcr.readmap(self.input_netcdf['cell_area'])

        # an object for netcdf reporting
        self.output = OutputNetcdf(self.clone, self.output_netcdf)       
        
        # preparing the netcdf file and make variable:
        self.output.createNetCDF(self.output_netcdf['file_name'],
                                 self.output_netcdf['gross_variable_name'],
                                 self.output_netcdf['variable_unit'])
        self.output.addNewVariable(self.output_netcdf['file_name'],
                                   self.output_netcdf['netto_variable_name'],
                                   self.output_netcdf['variable_unit'])
    def __init__(self, cloneMapFileName,\
                       input_files, \
                       modelTime, \
                       output):
        DynamicModel.__init__(self)
        
        # set the clone map
        self.cloneMapFileName = cloneMapFileName
        pcr.setclone(self.cloneMapFileName)
        
        # time variable/object
        self.modelTime = modelTime
        
        # output folder 
        self.output = output
        
        # prepare temporary directory
        self.tmpDir = self.output['folder'] +"/tmp/"
        try:
            os.makedirs(self.tmpDir)
        except:
            os.system('rm -r /' + tmpDir + "/*")
        
        # input files
        self.input_files = input_files

        # object for reporting
        self.netcdf_report = OutputNetcdf(cloneMapFileName, self.output['netcdf_format'], self.output['netcdf_attributes'])       

        # make netcdf files for daily/monthly evaporation values:
        self.variable_name = "potential_evaporation"
        self.variable_unit = "m.day-1"               # This must be in daily average value
        # for daily values:
        for lc_type in ["forest", "grassland", "irrPaddy", "irrNonPaddy"]:
            file_name = self.output['folder'] + "/daily_potential_evaporation_" + self.variable_unit + "_" + lc_type + ".nc"
            self.netcdf_report.createNetCDF(file_name,\
                                            self.variable_name,\
                                            self.variable_unit,\
                                            self.variable_name)
        # for monthly values:
        for lc_type in ["forest", "grassland", "irrPaddy", "irrNonPaddy"]:
            file_name = self.output['folder'] + "/monthly_potential_evaporation_" + self.variable_unit + "_" + lc_type + ".nc"
            self.netcdf_report.createNetCDF(file_name,\
                                            self.variable_name,\
                                            self.variable_unit,\
                                            self.variable_name)
        
        # initiate acummulator variables for calculating monthly averages:
        self.monthly_accumulator = {}
        for lc_type in ["forest", "grassland", "irrPaddy", "irrNonPaddy"]:
            self.monthly_accumulator[lc_type] = pcr.scalar(0.0)
    def __init__(self, cloneMapFileName,\
                       pcraster_files, \
                       modelTime, \
                       output, inputEPSG = None, outputEPSG = None, resample_method = None):
        DynamicModel.__init__(self)

        # set the clone map
        self.cloneMapFileName = cloneMapFileName
        pcr.setclone(self.cloneMapFileName)

        # time variable/object
        self.modelTime = modelTime

        # output file name, folder name, etc.
        self.output = output
        self.output['file_name'] = vos.getFullPath(self.output['file_name'],
                                                   self.output['folder'])

        # input and output projection/coordinate systems
        self.inputEPSG = inputEPSG
        self.outputEPSG = outputEPSG
        self.resample_method = resample_method

        # prepare temporary directory
        self.tmpDir = output['folder'] + "/tmp/"
        try:
            os.makedirs(self.tmpDir)
            os.system('rm -r ' + tmpDir + "/*")
        except:
            pass

        # pcraster input files
        self.pcraster_files = pcraster_files
        # - the begining part of pcraster file names (e.g. "pr" for "pr000000.001")
        self.pcraster_file_name = self.pcraster_files['directory']+"/"+\
                                  self.pcraster_files['file_name']

        # object for reporting
        self.netcdf_report = OutputNetcdf(mapattr_dict = None,\
                                          cloneMapFileName = cloneMapFileName,\
                                          netcdf_format = "NETCDF3_CLASSIC",\
                                          netcdf_zlib = False,\
                                          netcdf_attribute_dict = None,\
                                          netcdf_attribute_description = self.output['description'])

        # make a netcdf file
        self.netcdf_report.createNetCDF(self.output['file_name'],\
                                        self.output['variable_name'],\
                                        self.output['unit'],\
                                        self.output['long_name'])
    def __init__(self, cloneMapFileName,\
                       pcraster_files, \
                       modelTime, \
                       output, inputEPSG = None, outputEPSG = None, resample_method = None):
        DynamicModel.__init__(self)
        
        # set the clone map
        self.cloneMapFileName = cloneMapFileName
        pcr.setclone(self.cloneMapFileName)
        
        # time variable/object
        self.modelTime = modelTime
        
        # output file name, folder name, etc. 
        self.output = output
        self.output['file_name'] = vos.getFullPath(self.output['file_name'], self.output['folder'])
        
        # input and output projection/coordinate systems 
        self.inputEPSG  =  inputEPSG
        self.outputEPSG = outputEPSG
        self.resample_method = resample_method

        # prepare temporary directory
        self.tmpDir = output['folder']+"/tmp/"
        try:
            os.makedirs(self.tmpDir)
            os.system('rm -r '+tmpDir+"/*")
        except:
            pass
        
        # pcraster input files
        self.pcraster_files = pcraster_files
        # - the begining part of pcraster file names (e.g. "pr" for "pr000000.001")
        self.pcraster_file_name = self.pcraster_files['directory']+"/"+\
                                  self.pcraster_files['file_name']

        # object for reporting
        self.netcdf_report = OutputNetcdf(mapattr_dict = None,\
                                          cloneMapFileName = cloneMapFileName,\
                                          netcdf_format = "NETCDF3_CLASSIC",\
                                          netcdf_zlib = False,\
                                          netcdf_attribute_dict = None,\
                                          netcdf_attribute_description = self.output['description'])       

        # make a netcdf file
        self.netcdf_report.createNetCDF(self.output['file_name'],\
                                        self.output['variable_name'],\
                                        self.output['unit'],\
                                        self.output['long_name'])
Esempio n. 8
0
 def __init__(self,
              model,
              configuration,
              modelTime,
              variable_list,
              initialState=None,
              suffix=None):
     DynamicModel.__init__(self)
     self.modelTime = modelTime
     self.model = model(configuration, modelTime, initialState)
     self.model.initial()
     self.reporting = Reporting(self.model, configuration.outNCDir,
                                configuration.NETCDF_ATTRIBUTES,
                                configuration.reportingOptions,
                                variable_list, suffix)
Esempio n. 9
0
    def __init__(self,
                 configuration,
                 modelTime,
                 initialState=None,
                 system_argument=None):
        DynamicModel.__init__(self)

        self.modelTime = modelTime
        self.model = PCRGlobWB(configuration, modelTime, initialState)
        self.reporting = Reporting(configuration, self.model, modelTime)

        # the model will set paramaters based on global pre-multipliers given in the argument:
        self.adusting_parameters(configuration, system_argument)

        # make the configuration available for the other method/function
        self.configuration = configuration
    def __init__(self, configuration, modelTime, initialState = None, system_argument = None):
        DynamicModel.__init__(self)

        self.modelTime = modelTime        
        self.model = PCRGlobWB(configuration, modelTime, initialState)
        self.reporting = Reporting(configuration, self.model, modelTime)
        
        # the model will set paramaters based on global pre-multipliers given in the argument:
        if system_argument != None: self.adusting_parameters(configuration, system_argument)

        # option to include merging processes for pcraster maps and netcdf files:
        self.with_merging = True
        if ('with_merging' in configuration.globalOptions.keys()) and (configuration.globalOptions['with_merging'] == "False"):
            self.with_merging = False

        # make the configuration available for the other method/function
        self.configuration = configuration
    def __init__(self, input_files,\
                      output_files,\
                       modelTime,\
                       main_tmp_dir = "/dev/shm/"):
        DynamicModel.__init__(self) 

        self.input_files  = input_files
        self.output_files = output_files 

        self.modelTime = modelTime

        # main temporary directory 
        self.main_tmp_dir = main_tmp_dir+"/"+vos.get_random_word()
        # make the temporary directory if not exist yet 
        try: 
            os.makedirs(self.main_tmp_dir)
        except:
            os.system('rm -r '+str(self.main_tmp_dir)+'*')
            os.makedirs(self.main_tmp_dir)

        # clone map for pcraster process - depend on the resolution of the basin/catchment map
        pcr.setclone(self.input_files["basin30minmap"]) 
        self.clone_map = pcr.boolean(1.0)
        #
        # catchment ids map
        self.catchment = pcr.nominal(\
                         pcr.readmap(self.input_files["basin30minmap"]))
        self.catchment = pcr.ifthen(pcr.scalar(self.catchment) > 0.0,\
                             self.catchment)
        # cell area map
        self.cell_area = pcr.cover(pcr.readmap(self.input_files["area30min_map"]), 0.0)
        
        # prepare grace monthly and annual anomaly time series
        self.pre_process_grace_file()

        # prepare model monthly and annual anomaly time series
        self.pre_process_model_file()

        # prepare object for writing netcdf files:
        self.output = OutputNetcdf(self.input_files["area30min_map"])
        self.output.createNetCDF(self.output_files['basinscale_tws_month_anomaly']['grace'], "lwe_thickness","m")
        self.output.createNetCDF(self.output_files['basinscale_tws_month_anomaly']['model'], "pcrglobwb_tws","m")
        self.output.createNetCDF(self.output_files['basinscale_tws_annua_anomaly']['grace'], "lwe_thickness","m")
        self.output.createNetCDF(self.output_files['basinscale_tws_annua_anomaly']['model'], "pcrglobwb_tws","m")
Esempio n. 12
0
    def __init__(self, input_files,\
                      output_files,\
                       modelTime,\
                       tmpDir = "/dev/shm/"):
        DynamicModel.__init__(self)           # 

        self.input_files  = input_files
        self.output_files = output_files 
        self.tmpDir = tmpDir

        self.modelTime = modelTime

        pcr.setclone(self.input_files["model_cell_area"])
        clone_map = pcr.boolean(1)
        
        # cell area (m2)
        self.cell_area = vos.readPCRmapClone(\
                        self.input_files["model_cell_area"],\
                        self.input_files["model_cell_area"],\
                        self.tmpDir)
        
        # resampling factor: ratio between target (coarse) and original (fine) resolution
        self.resample_factor = round(
                               vos.getMapAttributes(self.input_files["one_degree_id"],'cellsize')/\
                               vos.getMapAttributes(self.input_files["model_cell_area"],'cellsize'))
        
        # unique ids for upscaling to one degree resolution (grace resolution)
        self.one_degree_id = pcr.nominal(\
                             vos.readPCRmapClone(\
                            self.input_files["one_degree_id"],\
                            self.input_files["model_cell_area"],\
                            self.tmpDir))
        
        # object for reporting at coarse resolution (i.e. one arc degree - grace resolution)
        self.output = OutputNetcdf(self.input_files["one_degree_id"], self.input_files["model_cell_area"])       
        # preparing the netcdf file at coarse resolution:
        self.output.createNetCDF(self.output_files['one_degree_tws']['model'], "pcrglobwb_tws","m")
        #
        # edit some attributes:
        attributeDictionary = {}
        attributeDictionary['description']      = "One degree resolution total water storage (tws), upscaled from PCR-GLOBWB result. "
        self.output.changeAtrribute(self.output_files['one_degree_tws']['model'],\
                                    attributeDictionary)                       
    def __init__(self, configuration, modelTime):
        DynamicModel.__init__(self)

        # model time object
        self.modelTime = modelTime

        # make the configuration available for the other method/function
        self.configuration = configuration

        # indicating whether this run includes modflow or merging processes
        # - Only the "Global" and "part_one" runs include modflow or merging processes
        self.include_merging_or_modflow = True
        if self.configuration.globalOptions['cloneAreas'] == "part_two":
            self.include_merging_or_modflow = False

        if self.include_merging_or_modflow:

            # netcdf merging options
            self.netcdf_format = self.configuration.mergingOutputOptions[
                'formatNetCDF']
            self.zlib_option = self.configuration.mergingOutputOptions['zlib']

            # output files/variables that will be merged
            nc_report_list = [
                "outDailyTotNC", "outMonthTotNC", "outMonthAvgNC",
                "outMonthEndNC", "outMonthMaxNC", "outAnnuaTotNC",
                "outAnnuaAvgNC", "outAnnuaEndNC", "outAnnuaMaxNC"
            ]
            for nc_report_type in nc_report_list:
                vars(self)[
                    nc_report_type] = self.configuration.mergingOutputOptions[
                        nc_report_type]

        # model and reporting objects
        # - Note that both are still needed even
        if self.configuration.online_coupling_between_pcrglobwb_and_modflow:
            self.model = ModflowCoupling(configuration, modelTime)
            self.reporting = Reporting(configuration, self.model, modelTime)
        else:
            # somehow you need to set the clone map (as the dynamic framework needs it and the "self.model" is not made)
            pcr.setclone(configuration.cloneMap)
    def __init__(self, configuration, \
                       modelTime, \
                       landmask, \
                       cellArea):
        DynamicModel.__init__(self)

        # configuration (based on the ini file)
        self.configuration = configuration

        # time variable/object
        self.modelTime = modelTime

        # cloneMapFileName
        self.cloneMapFileName = self.configuration.cloneMap
        pcr.setclone(self.cloneMapFileName)

        # cell area and landmask maps
        self.landmask = landmask
        self.cellArea = pcr.ifthen(self.landmask, cellArea)

        # output variables that will be compared (at daily resolution)
        self.debug_state_variables = [
            'temperature', 'snowCoverSWE', 'snowFreeWater', 'interceptStor',
            'storUppTotal', 'storLowTotal', 'storGroundwater'
        ]
        self.debug_flux_variables = [
            'precipitation', 'referencePotET', 'interceptEvap',
            'actSnowFreeWaterEvap', 'actBareSoilEvap', 'actTranspiTotal',
            'actTranspiUppTotal', 'actTranspiLowTotal', 'infiltration',
            'gwRecharge', 'runoff', 'directRunoff', 'interflowTotal',
            'baseflow', 'actualET'
        ]
        self.debug_variables = self.debug_state_variables + self.debug_flux_variables

        # folder/location of oldcalc input maps
        self.maps_folder = self.configuration.mapsDir

        # folder/location of oldcalc results maps
        self.results_folder = self.configuration.globalOptions[
            'outputDir'] + "/oldcalc_results/"
        # - preparing the directory
        if os.path.exists(self.results_folder):
            shutil.rmtree(self.results_folder)
        os.makedirs(self.results_folder)
        # - preparing the folder to store netcdf files
        self.netcdf_folder = self.configuration.globalOptions[
            'outputDir'] + "/oldcalc_results/netcdf/"
        os.makedirs(self.netcdf_folder)

        # go to the starting directory and copy/backup the oldcalc_script and parameter_table files
        os.chdir(self.configuration.starting_directory)

        # the oldscript scripts used:
        self.oldcalc_script_file = vos.getFullPath(
            self.configuration.globalOptions['oldcalc_script_file'],
            self.configuration.starting_directory)
        self.parameter_tabel_file = vos.getFullPath(
            self.configuration.globalOptions['parameter_tabel_file'],
            self.configuration.starting_directory)

        # make the backup of oldscript scripts used
        shutil.copy(self.oldcalc_script_file, self.configuration.scriptDir)
        shutil.copy(self.parameter_tabel_file, self.configuration.scriptDir)

        # attribute information used in netcdf files:
        netcdfAttributeDictionary = {}
        netcdfAttributeDictionary[
            'institution'] = self.configuration.globalOptions['institution']
        netcdfAttributeDictionary['title'] = "PCR-GLOBWB 1 output"
        netcdfAttributeDictionary[
            'description'] = self.configuration.globalOptions[
                'description'] + " (this is the output from the oldcalc PCR-GLOBWB version 1)"

        # netcdf object for reporting
        self.netcdf_report = PCR2netCDF(configuration,
                                        netcdfAttributeDictionary)

        # make/prepare netcdf files
        for var in self.debug_variables:

            short_name = varDicts.netcdf_short_name[var]
            unit = varDicts.netcdf_unit[var]
            long_name = varDicts.netcdf_long_name[var]
            if long_name == None: long_name = short_name

            netcdf_file_name = self.netcdf_folder + "/" + str(
                var) + "_dailyTot_output_version_one.nc"

            logger.info(
                "Creating the netcdf file for daily reporting for the variable %s to the file %s (output from PCR-GLOBWB version 1).",
                str(var), str(netcdf_file_name))

            self.netcdf_report.createNetCDF(netcdf_file_name, short_name, unit,
                                            long_name)
    def __init__(self, netcdf_input_file, \
                       areaMapFileName,\
                       areaPointMapFileName,\
                       netcdf_input_clone_map_file, \
                       output_folder, \
                       unit_conversion_factor, \
                       unit_conversion_offset, \
                       modelTime, \
                       inputProjection, \
                       outputProjection, \
                       resample_method, \
                       tss_daily_output_file, \
                       tss_10day_output_file, \
                       report_10day_pcr_files = False
                       ):

        DynamicModel.__init__(self)

        # netcdf input file
        self.netcdf_input_file = netcdf_input_file

        # clone maps
        self.inputClone = netcdf_input_clone_map_file
        self.outputClone = areaMapFileName

        # time variable/object
        self.modelTime = modelTime

        # output folder
        self.output_folder = output_folder

        # prepare temporary directory
        logger.debug('Preparing tmp directory.')
        self.tmpDir = self.output_folder + "/tmp/"
        if os.path.exists(self.tmpDir): shutil.rmtree(self.tmpDir)
        os.makedirs(self.tmpDir)

        # prepare maps directory (to store 10-day pcraster files )
        self.report_10day_pcr_files = report_10day_pcr_files
        if self.report_10day_pcr_files:
            logger.info(
                'Preparing map directory (for saving 10 day pcraster files).')
            self.mapDir = self.output_folder + "/map/"
            if os.path.exists(self.mapDir): shutil.rmtree(self.mapDir)
            os.makedirs(self.mapDir)

        # unit conversion variables
        self.unit_conversion_factor = unit_conversion_factor
        self.unit_conversion_offset = unit_conversion_offset

        # input and output projection/coordinate systems
        self.inputProjection = inputProjection
        self.outputProjection = outputProjection

        # resample method
        self.resample_method = resample_method

        # get the properties of output clone map (in string, needed for resampling with gdalwarp command)
        pcr.setclone(self.outputClone)
        self.cell_length = str(pcr.clone().cellSize())
        self.x_min_output = str(pcr.clone().west())
        self.x_max_output = str(pcr.clone().west() +
                                pcr.clone().nrCols() * pcr.clone().cellSize())
        self.y_min_output = str(pcr.clone().north() -
                                pcr.clone().nrRows() * pcr.clone().cellSize())
        self.y_max_output = str(pcr.clone().north())

        # pcraster area/class map
        self.area_class = pcr.readmap(areaMapFileName)
        # - landmask
        self.landmask = pcr.defined(self.area_class)
        self.landmask = pcr.ifthen(self.landmask, self.landmask)

        # - choose a point for each area/class as its station representative (needed for tss reporting)
        if areaPointMapFileName == None:
            logger.info("Get stations/representatives for all classes")
            self.point_area_class = pcr.nominal(
                pcr.ifthen(
                    pcr.areaorder(pcr.scalar(self.area_class),
                                  self.area_class) == 1, self.area_class))
            #~ pcr.aguila(self.point_area_class)
            #~ raw_input("Press Enter to continue...")
        else:
            self.point_area_class = pcr.readmap(areaPointMapFileName)
            self.point_area_class = pcr.ifthen(self.landmask,
                                               self.point_area_class)

        # output tss file
        self.tss_daily_output_file = tss_daily_output_file
        self.tss_10day_output_file = tss_10day_output_file
Esempio n. 16
0
    def __init__(self, modelTime, input_file, output_file, variable_name,
                 variable_unit):
        DynamicModel.__init__(self)

        self.modelTime = modelTime

        # netcdf input file - based on PCR-GLOBWB output
        self.input_file = "/projects/0/dfguu/users/edwin/pcr-globwb-aqueduct/historical/1951-2005/gfdl-esm2m/temperature_annuaAvg_output_%s-12-31_to_%s-12-31.nc"
        self.input_file = input_file

        # output file - in netcdf format
        self.output_file = output_folder + "/mekong/basin_temperature_annuaAvg_output.nc"
        self.output_file = output_file

        # output variable name and unit
        self.variable_name = variable_name
        self.variable_unit = variable_unit

        # preparing temporary directory
        self.temporary_directory = output_folder + "/tmp/"
        os.makedirs(self.temporary_directory)

        # clone and landmask maps
        logger.info("Set the clone and landmask maps.")
        self.clonemap_file_name = "/projects/0/dfguu/users/edwinhs/data/mekong_etc_clone/version_2018-10-22/final/clone_mekong.map"
        pcr.setclone(self.clonemap_file_name)
        landmask_file_name = "/projects/0/dfguu/users/edwinhs/data/mekong_etc_clone/version_2018-10-22/final/mask_mekong.map"
        self.landmask = vos.readPCRmapClone(landmask_file_name, \
                                            self.clonemap_file_name, \
                                            self.temporary_directory, \
                                            None, False, None, True)

        # pcraster input files
        # - river network map and sub-catchment map
        ldd_file_name = "/projects/0/dfguu/data/hydroworld/PCRGLOBWB20/input5min/routing/lddsound_05min.map"
        # - cell area (unit: m2)
        cell_area_file_name = "/projects/0/dfguu/data/hydroworld/PCRGLOBWB20/input5min/routing/cellsize05min.correct.map"

        # loading pcraster input maps
        self.ldd_network   = vos.readPCRmapClone(ldd_file_name, \
                                                 self.clonemap_file_name, \
                                                 self.temporary_directory, \
                                                 None, \
                                                 True)
        self.ldd_network = pcr.lddrepair(pcr.ldd(self.ldd_network))
        self.ldd_network = pcr.lddrepair(self.ldd_network)
        self.cell_area     = vos.readPCRmapClone(cell_area_file_name, \
                                                 self.clonemap_file_name, \
                                                 self.temporary_directory, \
                                                 None)

        # set/limit all input maps to the defined landmask
        self.ldd_network = pcr.ifthen(self.landmask, self.ldd_network)
        self.cell_area = pcr.ifthen(self.landmask, self.cell_area)

        # calculate basin/catchment area
        self.basin_area = pcr.catchmenttotal(self.cell_area, self.ldd_network)
        self.basin_area = pcr.ifthen(self.landmask, self.basin_area)

        # preparing an object for reporting netcdf files:
        self.netcdf_report = netcdf_writer.PCR2netCDF(self.clonemap_file_name)

        # preparing netcdf output files:
        self.netcdf_report.createNetCDF(self.output_file, \
                                        self.variable_name, \
                                        self.variable_unit)
Esempio n. 17
0
    def __init__(self, configuration, modelTime, initialState = None):
        DynamicModel.__init__(self)

        self.modelTime = modelTime        
        self.model = PCRGlobWB(configuration, modelTime, initialState)
        self.reporting = Reporting(configuration, self.model, modelTime)
Esempio n. 18
0
    def __init__(self, modelTime, output_folder, totat_runoff_input_file):
        DynamicModel.__init__(self)

        self.modelTime = modelTime
        
        # netcdf input files - based on PCR-GLOBWB output
        # - total runoff (m/month)
        self.totat_runoff_input_file = "/scratch-shared/edwin/05min_runs_for_gmd_paper_30_oct_2017/05min_runs_4LCs_accutraveltime_cru-forcing_1958-2015/non-natural_starting_from_1958/merged_1958_to_2015/totalRunoff_monthTot_output_1958-01-31_to_2015-12-31.nc"
        self.totat_runoff_input_file = totat_runoff_input_file
        #
        #~ # - discharge (m3/s) - NOT USED anymore
        #~ self.discharge_input_file    = "/scratch-shared/edwin/05min_runs_for_gmd_paper_30_oct_2017/05min_runs_4LCs_accutraveltime_cru-forcing_1958-2015/non-natural_starting_from_1958/merged_1958_to_2015/discharge_monthAvg_output_1958-01-31_to_2015-12-31.nc"

        # output files - in netcdf format
        self.total_flow_output_file    = output_folder + "/total_flow.nc"
        self.internal_flow_output_file = output_folder + "/internal_flow.nc" 
        # - all will have unit m3/s

        # preparing temporary directory
        self.temporary_directory = output_folder + "/tmp/"
        os.makedirs(self.temporary_directory)
        
        # clone map
        logger.info("Set the clone map")
        self.clonemap_file_name = "/home/edwinvua/github/edwinkost/estimate_discharge_from_local_runoff/making_subcatchment_map/version_20180202/clone_version_20180202.map"
        pcr.setclone(self.clonemap_file_name)
        
        # pcraster input files
        landmask_file_name      = None
        # - river network map and sub-catchment map
        ldd_file_name           = "/projects/0/dfguu/data/hydroworld/PCRGLOBWB20/input5min/routing/lddsound_05min.map"
        sub_catchment_file_name = "/home/edwinvua/github/edwinkost/estimate_discharge_from_local_runoff/making_subcatchment_map/version_20180202/subcatchments_of_station_pcraster_ids.nom.bigger_than_zero.map"
        # - cell area (unit: m2)
        cell_area_file_name     = "/projects/0/dfguu/data/hydroworld/PCRGLOBWB20/input5min/routing/cellsize05min.correct.map"
        
        # loading pcraster input maps
        self.sub_catchment = vos.readPCRmapClone(sub_catchment_file_name, \
                                                 self.clonemap_file_name, \
                                                 self.temporary_directory, \
                                                 None, False, None, \
                                                 True)
        self.ldd_network   = vos.readPCRmapClone(ldd_file_name, \
                                                 self.clonemap_file_name, \
                                                 self.temporary_directory, \
                                                 None, \
                                                 True)
        self.ldd_network   = pcr.lddrepair(pcr.ldd(self.ldd_network))
        self.ldd_network   = pcr.lddrepair(self.ldd_network)
        self.cell_area     = vos.readPCRmapClone(cell_area_file_name, \
                                                 self.clonemap_file_name, \
                                                 self.temporary_directory, \
                                                 None)

        # define the landmask
        self.landmask = pcr.defined(self.ldd_network)
        if landmask_file_name != None:
            self.landmask  = vos.readPCRmapClone(landmask_file_name, \
                                                 self.clonemap_file_name, \
                                                 self.temporary_directory, \
                                                 None)
        self.landmask = pcr.ifthen(pcr.defined(self.ldd_network), self.landmask)
        self.landmask = pcr.ifthen(self.landmask, self.landmask)
        
        # set/limit all input maps to the defined landmask
        self.sub_catchment = pcr.ifthen(self.landmask, self.sub_catchment)
        self.ldd_network   = pcr.ifthen(self.landmask, self.ldd_network)
        self.cell_area     = pcr.ifthen(self.landmask, self.cell_area)
        
        # preparing an object for reporting netcdf files:
        self.netcdf_report = netcdf_writer.PCR2netCDF(self.clonemap_file_name)
        
        # preparing netcdf output files:
        # - for total inflow
        self.netcdf_report.createNetCDF(self.total_flow_output_file,\
                                        "total_flow",\
                                        "m3/s")
        self.netcdf_report.createNetCDF(self.internal_flow_output_file,\
                                        "internal_flow",\
                                        "m3/s")
    def __init__(self, input_netcdf,\
                       output_netcdf,\
                       modelTime,\
                       tmpDir = "/dev/shm/"):
        DynamicModel.__init__(self) 

        self.input_netcdf = input_netcdf
        self.output_netcdf = output_netcdf 
        self.tmpDir = tmpDir
        self.modelTime = modelTime

        # a dictionary contains input clone properties (based on the input netcdf file)
        #~ self.input_clone = vos.netcdfCloneAttributes(self.input_netcdf['file_name'],\
                                                     #~ np.round(self.input_netcdf['cell_resolution']*60.,1),\
                                                     #~ True)
        pcr.setclone(self.input_netcdf['clone_file'])
        self.input_clone = {}
        self.input_clone['cellsize'] = pcr.clone().cellSize()
        self.input_clone['rows']     = int(pcr.clone().nrRows()) 
        self.input_clone['cols']     = int(pcr.clone().nrCols())
        self.input_clone['xUL']      = round(pcr.clone().west(), 2)
        self.input_clone['yUL']      = round(pcr.clone().north(), 2)

        # resampling factor: ratio between output and input resolutions
        self.resample_factor = self.output_netcdf["cell_resolution"]/\
                                self.input_netcdf['cell_resolution']
        
        # clone map 
        if self.resample_factor > 1.0: # upscaling

            # the resample factor must be a rounded value without decimal
            self.resample_factor = round(self.resample_factor)
            
            # output clone properties
            self.output_netcdf['rows'    ] = int(round(float(self.input_clone['rows'])/float(self.resample_factor))) 
            self.output_netcdf['cols'    ] = int(round(float(self.input_clone['cols'])/float(self.resample_factor)))
            self.output_netcdf['cellsize'] = self.output_netcdf["cell_resolution"]
            self.output_netcdf['xUL'     ] = self.input_clone['xUL']
            self.output_netcdf['yUL'     ] = self.input_clone['yUL']

            # get the unique ids for the output resolution
            # - use the clone for the output resolution (only for a temporary purpose)
            pcr.setclone(self.output_netcdf['rows'    ],
                         self.output_netcdf['cols'    ],
                         self.output_netcdf['cellsize'],
                         self.output_netcdf['xUL'     ],
                         self.output_netcdf['yUL'     ])
            # - unique_ids in a numpy object
            cell_unique_ids = pcr.pcr2numpy(pcr.scalar(pcr.uniqueid(pcr.boolean(1.))),vos.MV)

            # the remaining pcraster calculations are performed at the input resolution
            pcr.setclone(self.input_clone['rows'    ],
                         self.input_clone['cols'    ],
                         self.input_clone['cellsize'],
                         self.input_clone['xUL'     ],
                         self.input_clone['yUL'     ])
            
            # clone map file 
            self.clone_map_file = self.input_netcdf['clone_file']
            
            # cell unique ids in a pcraster object
            self.unique_ids = pcr.nominal(pcr.numpy2pcr(pcr.Scalar,
                              vos.regridData2FinerGrid(self.resample_factor,cell_unique_ids, vos.MV), vos.MV))

            # cell area (m2)
            self.cell_area = vos.readPCRmapClone(\
                             self.input_netcdf["cell_area"],\
                             self.clone_map_file,\
                             self.tmpDir)
            
        else: # downscaling / resampling to smaller cell length

            # all pcraster calculations are performed at the output resolution
            pcr.setclone(self.output_netcdf['rows'    ],
                         self.output_netcdf['cols'    ],
                         self.output_netcdf['cellsize'],
                         self.output_netcdf['xUL'     ],
                         self.output_netcdf['yUL'     ])

            # clone map file
            self.clone_map_file = self.output_netcdf['clone_file']
        
        # an object for netcdf reporting
        self.output = OutputNetcdf(mapattr_dict = self.output_netcdf,\
                                   cloneMapFileName = None,\
                                   netcdf_format = self.output_netcdf['format'],\
                                   netcdf_zlib = self.output_netcdf['zlib'],\
                                   netcdf_attribute_dict = self.output_netcdf['netcdf_attribute'],\
                                   netcdf_attribute_description = None)
        
        # preparing the netcdf file at coarse resolution:
        self.output.createNetCDF(self.output_netcdf['file_name'],\
                                 self.output_netcdf['variable_name'],\
                                 self.output_netcdf['variable_unit'])
Esempio n. 20
0
    def __init__(self, configuration, modelTime, initialState=None):
        DynamicModel.__init__(self)

        self.modelTime = modelTime
        self.model = RoutingModel(configuration, modelTime, initialState)
        self.configuration = configuration