RHESSysWorkflows  1.33
Namespaces | Variables
PatchToMovie.py File Reference

Namespaces

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

Variables

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