Inventory

class fuels.Inventory[source]

Bases: object

This class contains methods for converting inventory data to FVS .tre format.

This class currently does not read inventory data directly from an FVS access database. The FVS_TreeInit data table in an FVS database first needs to be exported as comma delimited values. Multiple stands can be exported in the same file, the format_fvs_tree_file() method will format a .tre string for each stand. All column headings must be default headings and unaltered during export. You can view the default format by importing this class and and calling print_format_standards(). See the FVS guide [1] for more information regarding the format of .tre files.

Example:

>>> from standfire import fuels
>>> toDotTree = fuels.Inventory()
>>> toDotTree.read_inventory("path/to/FVS_TreeInit.csv")
>>> toDotTree.format_fvs_tree_file()
>>> toDotTree.save()
References:
[1]Gary E. Dixon, Essential FVS: A User’s Guide to the Forest Vegetation Simulator Tech. Rep., U.S. Department of Agriculture , Forest Service, Forest Management Service Center, Fort Collins, Colo, USA, 2003.
convert_sp_codes()[source]

Converts species codes from USDA plant codes to 2 letter FVS codes.

crwratio_percent_to_code()[source]

Converts crown ratio from percent to ICR code

ICR code is described in the Essential FVS Guide on pages 58 and 59. This method should only be used if crown ratios values are percentages in the FVS_TreeInit.csv. If you use this method before calling format_fvs_tree_file() then you must set the optional argument cratioToCode in format_fvs_tree_file to False.

filter_by_stand(stand_list)[source]

Filters data by a list of stand IDs

Parameters:stand_list (python list) – List of stand ID to retain in the data. All other stands will be removed
format_fvs_tree_file(cratio_to_code=True)[source]

Converts data in FVS_TreeInit.csv to FVS .tre format

This methods reads entries in the pandas data frame (self.data) and writes them to a formated text string following FVS .tre data formating standards shown in FMT. If multiple stands exist in self.data then each stand will be written as a (key,value) pair in self.fvs_tree_file where the key is the stand ID and the value is the formated text string.

Parameters:cratio_to_code (boolean) – default = True

Note

If the crwratio_percent_to_code() methods has been called prior to call this methods, then the cratio_to_code optional argument must be set to False to prevent errors in crown ratio values.

Example:

>>> toDotTree.format_fvs_tree_file()
>>> toDotTree.fvs_tree_file["Stand_ID_1"]
5   1  5     0PP 189    65        3                 0 0
5   2  15    0PP 110    52        2                 0 0
5   3  5     0PP 180    64        5                 0 0
5   4  14    0PP 112    56        3                 0 0
5   5  6     0PP 167    60        4                 0 0
5   6  5     0PP 190    60        5                 0 0
5   7  7     0PP 161    62        3                 0 0
5   8  86    0PP 46     37        1                 0 0
5   9  10    0PP 130    50        2                 0 0
5   10 5     0PP 182    60        3                 0 0
5   11 8     9PP 144    50                          0 0
6   1  16    0PP 107    42        4                 0 0
6   2  109   0PP 41     27        2                 0 0
...
get_fvs_cols()[source]

Get list of FVS standard columns

Returns:FVS standard columns
Return type:list of strings
get_stands()[source]

Returns unique stand IDs

Returns:stand IDs
Return type:list of strings

Example:

>>> toDotTree.get_stands()
["BR", "TM", "SW", "HB"]
print_format_standards()[source]

Print FVS formating standards

The FVS formating standard for .tre files as described in the Essenital FVS Guide is stored in FMT as a class attribute. This method is for viewing this format. The keys of the dictionary are the row headings and values are as follows: 0 = variable name, 1 = variable type, 2 = column location, 3 = units, and 4 = implied decimal place.

Example:

>>> toDotTree.print_format_standards()
{"Plot_ID"       : ["ITRE",      "integer",  [0,3],   None,      None],
 "Tree_ID"       : ["IDTREE2",   "integer",  [4,6],   None,      None],
 "Tree_Count"    : ["PROB",      "integer",  [7,12],  None,      None],
 "History"       : ["ITH",       "integer",  [13,13], "trees",   0   ],
 "Species"       : ["ISP",       "alphanum", [14,16], None,      None],
 "DBH"           : ["DBH",       "real",     [17,20], "inches",  1   ],
 "DG"            : ["DG",        "real",     [21,23], "inches",  1   ],
 "Ht"            : ["HT",        "real",     [24,26], "feet",    0   ],
 "HtTopK"        : ["THT",       "real",     [27,29], "feet",    0   ],
 "HTG"           : ["HTG",       "real",     [30,33], "feet",    1   ],
 "CrRatio"       : ["ICR",       "integer",  [34,34], None,      None],
 "Damage1"       : ["IDCD(1)",   "integer",  [35,36], None,      None],
 "Severity1"     : ["IDCD(2)",   "integer",  [37,38], None,      None],
 "Damage2"       : ["IDCD(3)",   "integer",  [39,40], None,      None],
 "Severity2"     : ["IDCD(4)",   "integer",  [41,42], None,      None],
 "Damage3"       : ["IDCD(5)",   "integer",  [43,44], None,      None],
 "Severity3"     : ["IDCD(6)",   "integer",  [45,46], None,      None],
 "TreeValue"     : ["IMC",       "integer",  [47,47], None,      None],
 "Prescription"  : ["IPRSC",     "integer",  [48,48], None,      None],
 "Slope"         : ["IPVARS(1)", "integer",  [49,50], "percent", None],
 "Aspect"        : ["IPVARS(2)", "integer",  [51,53], "code",    None],
 "PV_Code"       : ["IPVARS(3)", "integer",  [54,56], "code",    None],
 "TopoCode"      : ["IPVARS(4)", "integer",  [57,59], "code",    None],
 "SitePrep"      : ["IPVARS(5)", "integer",  [58,58], "code",    None],
 "Age"           : ["ABIRTH",    "real",     [59,61], "years",   0   ]}

See page 61 and 62 in the Essential FVS Guide.

read_inventory(fname)[source]

Reads a .csv file containing tree records.

The csv must be in the correct format as described in FMT. This method checks the format of the file by calling a private method _is_correct_format() that raises a value error.

Parameters:fname (string) – path to and file name of the Fvs_TreeInit.csv file

Example:

>>> from standfire import fuels
>>> toDotTree = fuels.Inventory()
>>> toDotTree.readInventory("path/to/FVS_TreeInit.csv")
>>> np.mean(toDotTree.data["DBH"])
9.0028318584070828

The read_inventory() method stores the data in a pandas data frame. There are countless operations that can be performed on these objects. For example, we can explore the relationship between diameter and height by fitting a linear model

Note

The following requires statsmodels python module be installed

>>> import statsmodels.formula.api as sm
>>> fit = sm.ols(formula="HT ~ DBH", data=test.data).fit()
>>> print fit.params
Intercept    19.688167
DBH           2.161420
dtype: float64
>>> print fit.summary()
OLS Regression Results
==============================================================================
Dep. Variable:                     Ht   R-squared:                       0.738
Model:                            OLS   Adj. R-squared:                  0.736
Method:                 Least Squares   F-statistic:                     351.8
Date:                Tue, 07 Jul 2015   Prob (F-statistic):           3.77e-38
Time:                        08:32:02   Log-Likelihood:                -407.10
No. Observations:                 127   AIC:                             818.2
Df Residuals:                     125   BIC:                             823.9
Df Model:                           1
Covariance Type:            nonrobust
==============================================================================
coef    std err          t      P>|t|      [95.0% Conf. Int.]
------------------------------------------------------------------------------
Intercept     19.6882      1.205     16.338      0.000        17.303    22.073
DBH            2.1614      0.115     18.757      0.000         1.933     2.389
==============================================================================
Omnibus:                        2.658   Durbin-Watson:                   0.995
Prob(Omnibus):                  0.265   Jarque-Bera (JB):                2.115
Skew:                          -0.251   Prob(JB):                        0.347
Kurtosis:                       3.385   Cond. No.                         23.8
==============================================================================

Read more about pandas at http://pandas.pydata.org/

save(output_path)[source]

Writes formated fvs tree files to specified location

If multiple stands exist in the FVS_TreeInit then the same number of files will be created in the specified directory. The file names will be the same as the Stand_ID with a .tre extension.

Parameters:output_path (string) – directory to store output .tre files

Note

This method will throw an error if it is called prior to the format_fvs_tree_file() method.

set_fvs_variant(var)[source]

Sets FVS variant. This is needed if converting from USDA plant symbols (e.g. PSME) to FVS alpha codes (e.g. DF). If so, then all stands you wish to process must be of the same FVS variant

Parameters:var (string) – FVS variant (“iec”, “emc” …)