Tool for calculating zonal statistics for patch-scale RHESSys output variables.
More...
|
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) |
|
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:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- Neither the name of the University of North Carolina at Chapel Hill nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
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
- Configuration file must define the following sections and values: 'GRASS', 'GISBASE'
- 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