RHESSysWorkflows  1.33
Variables
GenerateWorldTemplate Namespace Reference

Variables

tuple parser = argparse.ArgumentParser(description='Create RHESSys world template used to create initial world file')
 
string help = 'The configuration file. Must define section "GRASS" and option "GISBASE"'
 
tuple args = parser.parse_args()
 
tuple cmdline = RHESSysMetadata.getCommandLine()
 
 configFile = None
 
tuple context = Context(args.projectDir, configFile)
 
tuple studyArea = RHESSysMetadata.readStudyAreaEntries(context)
 
tuple grassMetadata = RHESSysMetadata.readGRASSEntries(context)
 
tuple metadata = RHESSysMetadata.readRHESSysEntries(context)
 
list climateStations = metadata['climate_stations']
 
list rhessysDir = metadata['rhessys_dir']
 
tuple paths = RHESSysPaths(args.projectDir, rhessysDir)
 
tuple paramDbPath = os.path.join(context.projectDir, metadata['paramdb'])
 
tuple params = importlib.import_module('rhessys.params')
 
tuple paramConst = importlib.import_module('rhessys.constants')
 
tuple paramDB = params.paramDB(filename=paramDbPath)
 
tuple modulePath = context.config.get('GRASS', 'MODULE_PATH')
 
tuple grassDbase = os.path.join(context.projectDir, metadata['grass_dbase'])
 
tuple grassConfig = GRASSConfig(context, grassDbase, metadata['grass_location'], metadata['grass_mapset'])
 
tuple grassLib = GRASSLib(grassConfig=grassConfig)
 
list demRast = grassMetadata['dem_rast']
 
tuple result = grassLib.script.run_command('g.region', rast=demRast)
 
string dem1000Rast = "%s_1000"
 
list basinRast = grassMetadata['basin_rast']
 
tuple bbox = bboxFromString(studyArea['bbox_wgs84'])
 
tuple paramsFound
 
dictionary defFiles = {}
 
tuple contents = os.listdir(paths.RHESSYS_DEF)
 
tuple typeRe = re.compile("^%s_.+\.def$" % (type,) )
 
list defs = defFiles[type]
 
tuple m = typeRe.match(entry)
 
tuple templateTemplatePath = os.path.join(context.projectDir, metadata['template_template'])
 
tuple templateTemplateFile = open(templateTemplatePath)
 
tuple templateTemplate = string.Template(templateTemplateFile.read())
 
dictionary subs = {}
 
tuple numDefin = len(defs)
 
string numDefinKey = "num_%s_defs"
 
tuple defStr = os.path.join(paths._DEF, defs[0])
 
string defStrKey = "%s_defs"
 
string climParamFilename = "%s.base"
 
tuple baseFile = os.path.join(paths._CLIM, climParamFilename)
 
tuple climParams = readParameterFile( os.path.join(paths.RHESSYS_CLIM, climParamFilename) )
 
string climateStationIDStr = "base_station_ID\tdvalue %s"
 
tuple rasterIds = oset()
 
tuple pipe = grassLib.script.pipe_command('r.stats', flags='licn', input=grassMetadata['basestations_rast'])
 
tuple values = line.strip()
 
tuple baseIds = oset()
 
dictionary baseFiles = {}
 
tuple id = int(climParams['base_station_id'])
 
 includedBaseIds = rasterIds&baseIds
 
list climateStationsStr = baseFiles[includedBaseIds[0]]
 
list isohyet = grassMetadata['isohyet_rast']
 
string isohyet100 = isohyet+'100'
 
string templateStr = ''
 
tuple templateFilename = os.path.splitext( os.path.split( metadata['template_template'] )[1] )
 
tuple templateFilepath = os.path.join(paths.RHESSYS_TEMPLATES, templateFilename)
 
tuple f = open(templateFilepath, 'w')
 

Variable Documentation

tuple GenerateWorldTemplate.args = parser.parse_args()
tuple GenerateWorldTemplate.baseFile = os.path.join(paths._CLIM, climParamFilename)
dictionary GenerateWorldTemplate.baseFiles = {}
tuple GenerateWorldTemplate.baseIds = oset()
list GenerateWorldTemplate.basinRast = grassMetadata['basin_rast']
tuple GenerateWorldTemplate.bbox = bboxFromString(studyArea['bbox_wgs84'])
string GenerateWorldTemplate.climateStationIDStr = "base_station_ID\tdvalue %s"
list GenerateWorldTemplate.climateStations = metadata['climate_stations']
list GenerateWorldTemplate.climateStationsStr = baseFiles[includedBaseIds[0]]
string GenerateWorldTemplate.climParamFilename = "%s.base"
tuple GenerateWorldTemplate.climParams = readParameterFile( os.path.join(paths.RHESSYS_CLIM, climParamFilename) )
tuple GenerateWorldTemplate.cmdline = RHESSysMetadata.getCommandLine()
GenerateWorldTemplate.configFile = None
tuple GenerateWorldTemplate.contents = os.listdir(paths.RHESSYS_DEF)
tuple GenerateWorldTemplate.context = Context(args.projectDir, configFile)
dictionary GenerateWorldTemplate.defFiles = {}
  1. Determine the number of definition files of each type and save their names for inclusion in the world file
list GenerateWorldTemplate.defs = defFiles[type]
tuple GenerateWorldTemplate.defStr = os.path.join(paths._DEF, defs[0])
string GenerateWorldTemplate.defStrKey = "%s_defs"
string GenerateWorldTemplate.dem1000Rast = "%s_1000"
list GenerateWorldTemplate.demRast = grassMetadata['dem_rast']
tuple GenerateWorldTemplate.f = open(templateFilepath, 'w')
tuple GenerateWorldTemplate.grassConfig = GRASSConfig(context, grassDbase, metadata['grass_location'], metadata['grass_mapset'])
tuple GenerateWorldTemplate.grassDbase = os.path.join(context.projectDir, metadata['grass_dbase'])
tuple GenerateWorldTemplate.grassLib = GRASSLib(grassConfig=grassConfig)
tuple GenerateWorldTemplate.grassMetadata = RHESSysMetadata.readGRASSEntries(context)
string GenerateWorldTemplate.help = 'The configuration file. Must define section "GRASS" and option "GISBASE"'
tuple GenerateWorldTemplate.id = int(climParams['base_station_id'])
GenerateWorldTemplate.includedBaseIds = rasterIds&baseIds
list GenerateWorldTemplate.isohyet = grassMetadata['isohyet_rast']
string GenerateWorldTemplate.isohyet100 = isohyet+'100'
tuple GenerateWorldTemplate.m = typeRe.match(entry)
tuple GenerateWorldTemplate.metadata = RHESSysMetadata.readRHESSysEntries(context)
tuple GenerateWorldTemplate.modulePath = context.config.get('GRASS', 'MODULE_PATH')
tuple GenerateWorldTemplate.numDefin = len(defs)
string GenerateWorldTemplate.numDefinKey = "num_%s_defs"
tuple GenerateWorldTemplate.paramConst = importlib.import_module('rhessys.constants')
tuple GenerateWorldTemplate.paramDB = params.paramDB(filename=paramDbPath)
tuple GenerateWorldTemplate.paramDbPath = os.path.join(context.projectDir, metadata['paramdb'])
tuple GenerateWorldTemplate.params = importlib.import_module('rhessys.params')
tuple GenerateWorldTemplate.paramsFound
Initial value:
1 = paramDB.search(paramConst.SEARCH_TYPE_CONSTRAINED, None, 'basin', None, None, None, None, None, None, None, None,
2  limitToBaseClasses=False, defaultIdOverride=str(1))
  1. Get default files for basin, hillslope, and zone from default database
tuple GenerateWorldTemplate.parser = argparse.ArgumentParser(description='Create RHESSys world template used to create initial world file')
tuple GenerateWorldTemplate.paths = RHESSysPaths(args.projectDir, rhessysDir)
tuple GenerateWorldTemplate.pipe = grassLib.script.pipe_command('r.stats', flags='licn', input=grassMetadata['basestations_rast'])
tuple GenerateWorldTemplate.rasterIds = oset()
tuple GenerateWorldTemplate.result = grassLib.script.run_command('g.region', rast=demRast)
list GenerateWorldTemplate.rhessysDir = metadata['rhessys_dir']
tuple GenerateWorldTemplate.studyArea = RHESSysMetadata.readStudyAreaEntries(context)
dictionary GenerateWorldTemplate.subs = {}
tuple GenerateWorldTemplate.templateFilename = os.path.splitext( os.path.split( metadata['template_template'] )[1] )
tuple GenerateWorldTemplate.templateFilepath = os.path.join(paths.RHESSYS_TEMPLATES, templateFilename)
tuple GenerateWorldTemplate.templateStr = ''
tuple GenerateWorldTemplate.templateTemplate = string.Template(templateTemplateFile.read())
tuple GenerateWorldTemplate.templateTemplateFile = open(templateTemplatePath)
tuple GenerateWorldTemplate.templateTemplatePath = os.path.join(context.projectDir, metadata['template_template'])
  1. Open worldfile template template and substitute values
tuple GenerateWorldTemplate.typeRe = re.compile("^%s_.+\.def$" % (type,) )
tuple GenerateWorldTemplate.values = line.strip()