RHESSysWorkflows  1.33
Functions | Variables
PatchZonalStats Namespace Reference

Tool for calculating zonal statistics for patch-scale RHESSys output variables. More...

Functions

def line_legend
 Use proxy objects to force lines in legend display. More...
 
def simple_axis
 
def plot_cdf
 

Variables

list LINE_TYPES = ['solid', 'dashed', 'dashdot', 'dotted']
 
tuple NUM_LINE_TYPES = len(LINE_TYPES)
 
int INT_RESCALE = 100
 
tuple VARIABLE_EXPR_RE = re.compile(r'\b([a-zA-z][a-zA-Z0-9_\.]+)\b')
 
tuple RANDOM = random.randint(100000, 999999)
 
string RECLASS_MAP_TMP = "patchzonalstats_cover_{0}"
 
string STATS_MAP_TMP = "patchzonalstats_output_{0}"
 
list methods
 
tuple parser = argparse.ArgumentParser(description='Generate cummulative map of patch-scale RHESSys output variables')
 
string help = 'The configuration file.'
 
list choices = ['ultralight','light','normal','regular','book','medium','roman','semibold','demibold','demi','bold','heavy','extra bold','black']
 
string default = 'regular'
 
tuple args = parser.parse_args()
 
 configFile = None
 
tuple context = Context(args.projectDir, configFile)
 
 linestyles = None
 
 outputFileNames = args.legend
 
tuple metadata = RHESSysMetadata.readRHESSysEntries(context)
 
list patchFilepaths = []
 
tuple outputDir = os.path.abspath(args.outputDir)
 
string outputFile = "{0}.pdf"
 
tuple outputFilePath = os.path.join(outputDir, outputFile)
 
 variableLabels = args.variableName
 
list variables = ['patchID']
 
tuple m = VARIABLE_EXPR_RE.findall(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
 
list variablesList = []
 
tuple data = np.genfromtxt(patchFilepath, names=True)
 
list patchIDs = [ int(p) for p in data['patchID'] ]
 
tuple expr = VARIABLE_EXPR_RE.sub(r'data["\1"]', args.outputVariable)
 
tuple var = eval(expr)
 
 zones = args.zones
 
tuple maps_to_delete = set()
 
string reclass_map = "{0}_{1}"
 
 variable_scaled = variable*INT_RESCALE
 
tuple variable_int = variable_scaled.astype(int)
 
tuple reclass = open(reclassRule, 'w')
 
string permrast = "{0}_{1}_{2}"
 
string rMapcalcExpr = '$permrast=@$tmprast/float($scale)'
 
 scale = True)
 
tuple pipe = grassLib.script.pipe_command('r.stats', flags='ln', input=STATS_MAP_TMP)
 
list stats_scaled = []
 
tuple stats = np.array(stats_scaled)
 
list tmp_data = data[zone]
 
int min_x = 0
 
tuple max_x = max(np.max(datum), max_x)
 
int fig_width = 4
 
tuple fig = plt.figure(figsize=(fig_width, 3), dpi=80, tight_layout=True)
 
tuple num_zones = len(zones)
 
list var_label = variableLabels[i]
 
int fig_num = i+1
 
tuple ax = fig.add_subplot(1, num_zones, fig_num)
 
 linetype = linestyles,
 
 linewidth = args.linewidth,
 
 legend_fontsize = args.legendfontsize,
 
 fontweight = args.fontweight,
 
 axes_fontsize = args.axesfontsize,
 
 ticklabel_fontsize = args.ticklabelfontsize,
 
tuple range = (min_x, max_x)
 

Detailed Description

Tool for calculating zonal statistics for 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'
  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

Function Documentation

def PatchZonalStats.line_legend (   ax,
  loc = 'lower right',
  fontsize = 6,
  fontweight = 'normal',
  frameon = False 
)

Use proxy objects to force lines in legend display.

def PatchZonalStats.plot_cdf (   ax,
  data,
  legend_items,
  legend_loc = 'lower right',
  numbins = 1000,
  xlabel = None,
  ylabel = None,
  title = None,
  linetype = None,
  linewidth = None,
  range = None,
  fontweight = 'normal',
  legend_fontsize = 6,
  axes_fontsize = 8,
  ticklabel_fontsize = 6,
  fig_num = 1,
  log = False 
)
def PatchZonalStats.simple_axis (   ax,
  noy = False 
)

Variable Documentation

tuple PatchZonalStats.args = parser.parse_args()
tuple PatchZonalStats.ax = fig.add_subplot(1, num_zones, fig_num)
PatchZonalStats.axes_fontsize = args.axesfontsize,
list PatchZonalStats.choices = ['ultralight','light','normal','regular','book','medium','roman','semibold','demibold','demi','bold','heavy','extra bold','black']
PatchZonalStats.configFile = None
tuple PatchZonalStats.context = Context(args.projectDir, configFile)
dictionary PatchZonalStats.data = np.genfromtxt(patchFilepath, names=True)
int PatchZonalStats.default = 'regular'
tuple PatchZonalStats.expr = VARIABLE_EXPR_RE.sub(r'data["\1"]', args.outputVariable)
tuple PatchZonalStats.fig = plt.figure(figsize=(fig_width, 3), dpi=80, tight_layout=True)
int PatchZonalStats.fig_num = i+1
int PatchZonalStats.fig_width = 4
PatchZonalStats.fontweight = args.fontweight,
tuple PatchZonalStats.grassConfig = GRASSConfig(context, grassDbase, metadata['grass_location'], metadata['grass_mapset'])
tuple PatchZonalStats.grassDbase = os.path.join(context.projectDir, metadata['grass_dbase'])
tuple PatchZonalStats.grassLib = GRASSLib(grassConfig=grassConfig)
string PatchZonalStats.help = 'The configuration file.'
int PatchZonalStats.INT_RESCALE = 100
PatchZonalStats.legend_fontsize = args.legendfontsize,
list PatchZonalStats.LINE_TYPES = ['solid', 'dashed', 'dashdot', 'dotted']
list PatchZonalStats.linestyles = None
PatchZonalStats.linetype = linestyles,
PatchZonalStats.linewidth = args.linewidth,
tuple PatchZonalStats.m = VARIABLE_EXPR_RE.findall(args.outputVariable)
tuple PatchZonalStats.maps_to_delete = set()
tuple PatchZonalStats.max_x = max(np.max(datum), max_x)
tuple PatchZonalStats.metadata = RHESSysMetadata.readRHESSysEntries(context)
list PatchZonalStats.methods
Initial value:
1 = ['average', 'mode', 'median', 'avedev', 'stddev', 'variance',
2  'skewness', 'kurtosis', 'min', 'max', 'sum']
tuple PatchZonalStats.min_x = 0
tuple PatchZonalStats.NUM_LINE_TYPES = len(LINE_TYPES)
tuple PatchZonalStats.num_zones = len(zones)
tuple PatchZonalStats.outputDir = os.path.abspath(args.outputDir)
string PatchZonalStats.outputFile = "{0}.pdf"
PatchZonalStats.outputFileNames = args.legend
tuple PatchZonalStats.outputFilePath = os.path.join(outputDir, outputFile)
tuple PatchZonalStats.parser = argparse.ArgumentParser(description='Generate cummulative map of patch-scale RHESSys output variables')
list PatchZonalStats.patchFilepaths = []
list PatchZonalStats.patchIDs = [ int(p) for p in data['patchID'] ]
string PatchZonalStats.permrast = "{0}_{1}_{2}"
tuple PatchZonalStats.pipe = grassLib.script.pipe_command('r.stats', flags='ln', input=STATS_MAP_TMP)
tuple PatchZonalStats.RANDOM = random.randint(100000, 999999)
tuple PatchZonalStats.range = (min_x, max_x)
tuple PatchZonalStats.reclass = open(reclassRule, 'w')
string PatchZonalStats.reclass_map = "{0}_{1}"
string PatchZonalStats.RECLASS_MAP_TMP = "patchzonalstats_cover_{0}"
tuple PatchZonalStats.reclassRule = os.path.join(tmpDir, 'reclass.rule')
tuple PatchZonalStats.result
Initial value:
1 = grassLib.script.run_command('r.mask',
2  input=args.mask,
3  maskcats="1",
4  flags="o")
string PatchZonalStats.rMapcalcExpr = '$permrast=@$tmprast/float($scale)'
PatchZonalStats.scale = True)
tuple PatchZonalStats.stats = np.array(stats_scaled)
string PatchZonalStats.STATS_MAP_TMP = "patchzonalstats_output_{0}"
list PatchZonalStats.stats_scaled = []
PatchZonalStats.ticklabel_fontsize = args.ticklabelfontsize,
list PatchZonalStats.tmp_data = data[zone]
tuple PatchZonalStats.tmpDir = tempfile.mkdtemp()
tuple PatchZonalStats.var = eval(expr)
list PatchZonalStats.var_label = variableLabels[i]
tuple PatchZonalStats.VARIABLE_EXPR_RE = re.compile(r'\b([a-zA-z][a-zA-Z0-9_\.]+)\b')
tuple PatchZonalStats.variable_int = variable_scaled.astype(int)
PatchZonalStats.variable_scaled = variable*INT_RESCALE
list PatchZonalStats.variableLabels = args.variableName
list PatchZonalStats.variables = ['patchID']
list PatchZonalStats.variablesList = []
PatchZonalStats.zones = args.zones