RHESSysWorkflows  1.33
Variables
RunLAIRead Namespace Reference

Run lairead utility to initializes vegetation carbon stores. More...

Variables

tuple parser
 
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 grassMetadata = RHESSysMetadata.readGRASSEntries(context)
 
tuple metadata = RHESSysMetadata.readRHESSysEntries(context)
 
list rhessysDir = metadata['rhessys_dir']
 
tuple paths = RHESSysPaths(args.projectDir, rhessysDir)
 
list worldfileZero = metadata['worldfile_zero']
 
string headerZero = "%s.hdr"
 
tuple worldfileZeroPath = os.path.join(context.projectDir, worldfileZero)
 
tuple worldfileDir = os.path.dirname(worldfileZeroPath)
 
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']
 Make sure mask and region are properly set. More...
 
tuple result = grassLib.script.run_command('g.region', rast=demRast)
 
list basinRast = grassMetadata['basin_rast']
 
tuple headerZeroPath = os.path.join(context.projectDir, headerZero)
 
tuple stations = getClimateBaseStationFilenames(headerZeroPath)
 
tuple firstStationPath = os.path.normpath( os.path.join(paths.RHESSYS_DIR, stations[0]) )
 
tuple fourDays = datetime.timedelta(days=4)
 
tuple tecDurRedef = datetime.timedelta(days=1)
 
 tecRedef = startDate+tecDurRedef
 
tuple laireadPath = os.path.join(context.projectDir, metadata['lairead_bin'])
 
tuple oldWorldPath = os.path.join(context.projectDir, worldfileZero)
 
string redefWorldName = "%s.Y%dM%dD%dH%d"
 
tuple redefWorldPath = os.path.join(context.projectDir, redefWorldName)
 
tuple allomPath = os.path.join(context.projectDir, metadata['allometric_table'])
 
tuple p
 
string tecName = 'tec.lairead'
 
tuple tecPath = os.path.join(paths.RHESSYS_TEC, tecName)
 
tuple tecDurOutput = datetime.timedelta(days=2)
 
 tecOutput = startDate+tecDurOutput
 
tuple f = open(tecPath, 'w')
 
 rhessysStart = startDate
 
tuple rhessysDur = datetime.timedelta(days=3)
 
 rhessysEnd = startDate+rhessysDur
 
tuple surfaceFlowtablePath = os.path.join(context.projectDir, metadata['surface_flowtable'])
 
tuple subSurfaceFlowtablePath = os.path.join(context.projectDir, metadata['subsurface_flowtable'])
 
tuple rhessysBinPath = os.path.join(context.projectDir, metadata['rhessys_bin'])
 
tuple rhessysCmd
 
tuple cmdArgs = rhessysCmd.split()
 
tuple process = Popen(cmdArgs, cwd=paths.RHESSYS_DIR, stdout=PIPE, stderr=PIPE)
 
string outputWorldName = "%s.Y%dM%dD%dH%d.state"
 
tuple outputWorldPath = os.path.join(context.projectDir, outputWorldName)
 
string newWorldName = 'world'
 
tuple newWorldPath = os.path.join(paths.RHESSYS_WORLD, newWorldName)
 
string header = "%s.hdr"
 
tuple headerPath = os.path.join(paths.RHESSYS_WORLD, header)
 

Detailed Description

Run lairead utility to initializes vegetation carbon stores.

Will: (1) run lairead to produce a redefine worldfile; (2) run RHESSys simulation for 3-days to generate base worldfile

This software is provided free of charge under the New BSD License. Please see the following license information:

Copyright (c) 2013, University of North Carolina at Chapel Hill All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Author
Brian Miles brian.nosp@m._mil.nosp@m.es@un.nosp@m.c.ed.nosp@m.u

Pre conditions

  1. The following metadata entry(ies) must be present in the RHESSys section of the metadata associated with the project directory: grass_dbase grass_location grass_mapset rhessys_dir rhessys_bin lairead_bin worldfile_zero surface_flowtable subsurface_flowtable allometric_table
  2. The following metadata entry(ies) must be present in the GRASS section of the metadata associated with the project directory: basin_rast dem_rast hillslope_rast zone_rast patch_rast stratum_rast lai_rast

Post conditions

  1. Worldfile with initialized vegetation carbon stores will be saved to the appropriate location of the project directory
  2. Will write the following entry(ies) to the RHESSys section of metadata associated with the project directory: worldfile tec_lairead

Usage:

1 RunLAIRead.py -p /path/to/project_dir
Note
EcoHydroWorkflowLib configuration file must be specified by environmental variable 'ECOHYDROWORKFLOW_CFG', or -i option must be specified.

Variable Documentation

tuple RunLAIRead.allomPath = os.path.join(context.projectDir, metadata['allometric_table'])
tuple RunLAIRead.args = parser.parse_args()
list RunLAIRead.basinRast = grassMetadata['basin_rast']
tuple RunLAIRead.cmdArgs = rhessysCmd.split()
tuple RunLAIRead.cmdline = RHESSysMetadata.getCommandLine()
RunLAIRead.configFile = None
tuple RunLAIRead.context = Context(args.projectDir, configFile)
list RunLAIRead.demRast = grassMetadata['dem_rast']

Make sure mask and region are properly set.

tuple RunLAIRead.f = open(tecPath, 'w')
tuple RunLAIRead.firstStationPath = os.path.normpath( os.path.join(paths.RHESSYS_DIR, stations[0]) )
tuple RunLAIRead.fourDays = datetime.timedelta(days=4)
tuple RunLAIRead.grassConfig = GRASSConfig(context, grassDbase, metadata['grass_location'], metadata['grass_mapset'])
tuple RunLAIRead.grassDbase = os.path.join(context.projectDir, metadata['grass_dbase'])
tuple RunLAIRead.grassLib = GRASSLib(grassConfig=grassConfig)
tuple RunLAIRead.grassMetadata = RHESSysMetadata.readGRASSEntries(context)
string RunLAIRead.header = "%s.hdr"
tuple RunLAIRead.headerPath = os.path.join(paths.RHESSYS_WORLD, header)
string RunLAIRead.headerZero = "%s.hdr"
tuple RunLAIRead.headerZeroPath = os.path.join(context.projectDir, headerZero)
  1. Determine legal simulation start and date from climate data Read first climate station from worldfile
string RunLAIRead.help = 'The configuration file. Must define section "GRASS" and option "GISBASE"'
tuple RunLAIRead.laireadPath = os.path.join(context.projectDir, metadata['lairead_bin'])
tuple RunLAIRead.metadata = RHESSysMetadata.readRHESSysEntries(context)
tuple RunLAIRead.modulePath = context.config.get('GRASS', 'MODULE_PATH')
string RunLAIRead.newWorldName = 'world'
tuple RunLAIRead.newWorldPath = os.path.join(paths.RHESSYS_WORLD, newWorldName)
tuple RunLAIRead.oldWorldPath = os.path.join(context.projectDir, worldfileZero)
string RunLAIRead.outputWorldName = "%s.Y%dM%dD%dH%d.state"
  1. Rename redefine worldfile, write to metadata
tuple RunLAIRead.outputWorldPath = os.path.join(context.projectDir, outputWorldName)
tuple RunLAIRead.p
Initial value:
1 = grassLib.script.pipe_command(laireadPath, old=oldWorldPath, redef=redefWorldPath,
2  allom=allomPath, lai=grassMetadata['lai_rast'],
3  vegid=grassMetadata['stratum_rast'],
4  zone=grassMetadata['zone_rast'],
5  hill=grassMetadata['hillslope_rast'],
6  patch=grassMetadata['patch_rast'],
7  mask=grassMetadata['basin_rast'])
tuple RunLAIRead.parser
Initial value:
1 = argparse.ArgumentParser(description='Run lairead utility to initializes vegetation carbon stores. Will: (1) run lairead to ' +
2  'produce a redefine worldfile; (2) run RHESSys simulation for 3-days to generate base worldfile')
tuple RunLAIRead.paths = RHESSysPaths(args.projectDir, rhessysDir)
tuple RunLAIRead.process = Popen(cmdArgs, cwd=paths.RHESSYS_DIR, stdout=PIPE, stderr=PIPE)
string RunLAIRead.redefWorldName = "%s.Y%dM%dD%dH%d"
tuple RunLAIRead.redefWorldPath = os.path.join(context.projectDir, redefWorldName)
tuple RunLAIRead.result = grassLib.script.run_command('g.region', rast=demRast)
tuple RunLAIRead.rhessysBinPath = os.path.join(context.projectDir, metadata['rhessys_bin'])
tuple RunLAIRead.rhessysCmd
Initial value:
1 = generateCommandString(rhessysBinPath, None,
2  rhessysStart, rhessysEnd,
3  tecPath, oldWorldPath,
4  subSurfaceFlowtablePath, surfaceFlowtablePath)
def generateCommandString(binPath, outputPrefix, startDate, endDate, tecPath, worldPath, subsurfaceFlowPath=None, surfaceFlowPath=None, flags="", kwargs)
Return a string representing a properly formatted RHESSys command with the executable and all command...
Definition: rhessys.py:366
list RunLAIRead.rhessysDir = metadata['rhessys_dir']
tuple RunLAIRead.rhessysDur = datetime.timedelta(days=3)
RunLAIRead.rhessysEnd = startDate+rhessysDur
RunLAIRead.rhessysStart = startDate
  1. Run RHESSys for the first 4 legal days with redefine TEC
tuple RunLAIRead.stations = getClimateBaseStationFilenames(headerZeroPath)
tuple RunLAIRead.subSurfaceFlowtablePath = os.path.join(context.projectDir, metadata['subsurface_flowtable'])
tuple RunLAIRead.surfaceFlowtablePath = os.path.join(context.projectDir, metadata['surface_flowtable'])
tuple RunLAIRead.tecDurOutput = datetime.timedelta(days=2)
tuple RunLAIRead.tecDurRedef = datetime.timedelta(days=1)
  1. Run LAI read to generate redefine worldfile
string RunLAIRead.tecName = 'tec.lairead'
  1. Write TEC file for redefining the initial world file Redefine on the second day of the simulation, write output on the third day
RunLAIRead.tecOutput = startDate+tecDurOutput
tuple RunLAIRead.tecPath = os.path.join(paths.RHESSYS_TEC, tecName)
RunLAIRead.tecRedef = startDate+tecDurRedef
tuple RunLAIRead.worldfileDir = os.path.dirname(worldfileZeroPath)
list RunLAIRead.worldfileZero = metadata['worldfile_zero']
tuple RunLAIRead.worldfileZeroPath = os.path.join(context.projectDir, worldfileZero)