RHESSysWorkflows  1.33
Variables
PatchToMovie Namespace Reference

Tool for making animations of patch-scale RHESSys output variables. More...

Variables

tuple PATCH_DAILY_RE = re.compile('^(.+_patch.daily)$')
 
tuple VARIABLE_EXPR_RE = re.compile(r'\b([a-zA-z]\w+)\b')
 
string RECLASS_MAP_TMP = "patchtomovietmp_%d"
 
string MPEG4_CODEC = 'mpeg4'
 
string H264_CODEC = 'libx264'
 
 DEFAULT_CODEC = MPEG4_CODEC
 
list CODECS = [MPEG4_CODEC, H264_CODEC]
 
tuple parser = argparse.ArgumentParser(description='Generate movie from patch level daily RHESSys output')
 
string help = 'The configuration file.'
 
tuple args = parser.parse_args()
 
 configFile = None
 
tuple context = Context(args.projectDir, configFile)
 
tuple ffmpegPath = context.config.get('RHESSYS', 'PATH_OF_FFMPEG')
 
tuple metadata = RHESSysMetadata.readRHESSysEntries(context)
 
tuple patchDailyFilepath = os.path.abspath(args.rhessysOutFile)
 
tuple outputDir = os.path.abspath(args.outputDir)
 
string outputFile = "%s.mp4"
 
tuple outputFilePath = os.path.join(outputDir, outputFile)
 
list variables = ['patchID']
 
tuple m = VARIABLE_EXPR_RE.findall(args.outputVariable)
 
 title = args.outputVariable
 
tuple tmpDir = tempfile.mkdtemp()
 
tuple reclassRule = os.path.join(tmpDir, 'reclass.rule')
 
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)
 
tuple result
 
tuple f = open(patchDailyFilepath)
 
tuple data = RHESSysOutput.readColumnsFromPatchDailyFile(f, variables)
 
string dateStr = "%d/%d/%d"
 
string imageFilename = "%s%04d.png"
 
tuple reclassImagePath = os.path.join(tmpDir, imageFilename)
 
list dataForDate = data[key]
 
tuple reclass = open(reclassRule, 'w')
 
list patchIDs = [ int(f) for f in dataForDate['patchID'] ]
 
tuple expr = VARIABLE_EXPR_RE.sub(r'np.array(dataForDate["\1"])', args.outputVariable)
 
tuple variable = eval(expr)
 
 tmpMap = RECLASS_MAP_TMP
 
string fromScale = "0,%d"
 
dictionary rRescaleOptions
 
string cmd = "%s -y -r %d -i %s%%04d.png -vcodec %s -pix_fmt yuv420p %s"
 
tuple cmdArray = shlex.split(cmd)
 
tuple p = subprocess.Popen(cmdArray, cwd=tmpDir)
 

Detailed Description

Tool for making animations of patch-scale RHESSys output variables.

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

Copyright (c) 2014, 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. Configuration file must define the following sections and values: 'GRASS', 'GISBASE' 'RHESSYS', 'PATH_OF_FFMPEG'
  2. 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

Post conditions

None

Variable Documentation

tuple PatchToMovie.args = parser.parse_args()
string PatchToMovie.cmd = "%s -y -r %d -i %s%%04d.png -vcodec %s -pix_fmt yuv420p %s"
tuple PatchToMovie.cmdArray = shlex.split(cmd)
list PatchToMovie.CODECS = [MPEG4_CODEC, H264_CODEC]
PatchToMovie.configFile = None
tuple PatchToMovie.context = Context(args.projectDir, configFile)
list PatchToMovie.dataForDate = data[key]
string PatchToMovie.dateStr = "%d/%d/%d"
PatchToMovie.DEFAULT_CODEC = MPEG4_CODEC
tuple PatchToMovie.expr = VARIABLE_EXPR_RE.sub(r'np.array(dataForDate["\1"])', args.outputVariable)
tuple PatchToMovie.f = open(patchDailyFilepath)
tuple PatchToMovie.ffmpegPath = context.config.get('RHESSYS', 'PATH_OF_FFMPEG')
string PatchToMovie.fromScale = "0,%d"
tuple PatchToMovie.grassConfig = GRASSConfig(context, grassDbase, metadata['grass_location'], metadata['grass_mapset'])
tuple PatchToMovie.grassDbase = os.path.join(context.projectDir, metadata['grass_dbase'])
tuple PatchToMovie.grassLib = GRASSLib(grassConfig=grassConfig)
string PatchToMovie.H264_CODEC = 'libx264'
string PatchToMovie.help = 'The configuration file.'
string PatchToMovie.imageFilename = "%s%04d.png"
tuple PatchToMovie.m = VARIABLE_EXPR_RE.findall(args.outputVariable)
tuple PatchToMovie.metadata = RHESSysMetadata.readRHESSysEntries(context)
string PatchToMovie.MPEG4_CODEC = 'mpeg4'
tuple PatchToMovie.outputDir = os.path.abspath(args.outputDir)
string PatchToMovie.outputFile = "%s.mp4"
tuple PatchToMovie.outputFilePath = os.path.join(outputDir, outputFile)
tuple PatchToMovie.p = subprocess.Popen(cmdArray, cwd=tmpDir)
tuple PatchToMovie.parser = argparse.ArgumentParser(description='Generate movie from patch level daily RHESSys output')
tuple PatchToMovie.PATCH_DAILY_RE = re.compile('^(.+_patch.daily)$')
tuple PatchToMovie.patchDailyFilepath = os.path.abspath(args.rhessysOutFile)
list PatchToMovie.patchIDs = [ int(f) for f in dataForDate['patchID'] ]
tuple PatchToMovie.reclass = open(reclassRule, 'w')
string PatchToMovie.RECLASS_MAP_TMP = "patchtomovietmp_%d"
tuple PatchToMovie.reclassImagePath = os.path.join(tmpDir, imageFilename)
tuple PatchToMovie.reclassRule = os.path.join(tmpDir, 'reclass.rule')
tuple PatchToMovie.result
Initial value:
1 = grassLib.script.run_command('r.mask',
2  input=args.mask,
3  maskcats="1",
4  flags="o")
dictionary PatchToMovie.rRescaleOptions
Initial value:
1 = {'input': RECLASS_MAP_TMP,
2  'output': tmpMap,
3  'from': fromScale,
4  'to': '0,255',
5  'overwrite': True}
PatchToMovie.title = args.outputVariable
tuple PatchToMovie.tmpDir = tempfile.mkdtemp()
string PatchToMovie.tmpMap = RECLASS_MAP_TMP
tuple PatchToMovie.variable = eval(expr)
tuple PatchToMovie.VARIABLE_EXPR_RE = re.compile(r'\b([a-zA-z]\w+)\b')
list PatchToMovie.variables = ['patchID']