Menu

PyFVS

Anonymous Dan Wagner

FVS Home Repository Has Moved

Please note, the official FVS repository has recently migrated from Source Forge to GitHub. Please visit us at https://github.com/USDAForestService/ForestVegetationSimulator for the latest in code and wiki updates. This Source Forge repository will no longer be maintained, and is kept here as archival reference only.


Introduction

PyFVS provides an interface to the FVS shared library in a Pythonic manner. From Python the full FVS API is available (similar to the R). Additionally, all FVS common data and arrays can be accessed at run-time. PyFVS utilizes the F2PY toolset for wrapping the FVS code in a Python C extension module.

Note: The PyFVS code has not been maintained. If you have it running and know it is up-to-date please update this notice.

Usage Example

"""
Demonstrates basic PyFVS functionality with mixed API and direct access.
"""
import numpy
import pyfvspnc as fvs

#array to store cycle summary variables
cycle_sum= numpy.zeros(20,dtype='I4')

cmd = '--keywordfile=foo.key'
fvs.fvssetcmdline(cmd)
for year in range(2010,2120,10):
  fvs.fvssetstoppointcodes(6,year)
  fvs.fvs()

  #get summary variables for the current growth cycle
  fvs.fvssummary(cycle_sum)

  #get tree variables directly from the FVS arrays
  #PyFVS returns Numpy Arrays
  tn = fvs.contrl.itrn #current number of tree records
  tpa = fvs.arrays.prob[:tn]
  dbh = fvs.arrays.dbh[:tn]
  baa = sum(dbh*dbh*0.005454154*tpa)

  print 'Year: {:<d} BAA: {:<.1f}'.format(year,baa)

Building PyFVS

Building the PyFVS extension is integrated with the Open-FVS CMake build system. Follow the instructions provided elsewhere in the wiki to setup a CMake build environment, BuildProcess_MinGW, BuildProcess_UnixAlike. Note that currently the PyFVS branch has a modified CMakeLists.txt configuration file. See the associated readme_cmake.txt file for a description of usage and options.

The PyFVS build step is enabled by adding -DWITH_PYMOD=ON to the CMake configuration command.

PyFVS is known to build on 32 bit Windows XP using MinGW GCC version 4.7.0. I has also built successfully on 64 bit UBuntu 13.10 with GCC 4.8.

Other compilers (Visual C, Intel) and platforms should work, but will likely require some modification to the CMakeLists.txt file for F2PY to function correctly. Any modifications to support other compilers would be a welcome contribution.

Support for SCons and Distutils has been dropped.

Build Requirements

Python

PyFVS is known to work with Python version 2.7 on Windows XP. However, it will likely work with any version and distribution supporting the Numpy Python library. PyFVS uses F2PY, which is currently included with Numpy. The build should work with any of the mainstream Python distributions, Python.org, Python(x,y), ArcGIS, etc.

PyFVS requires a 2.7+ Python installation to be available in the PATH environment variable at configuration time.

Check your version

python -V

F2PY

The F2PY Fortran interface generator is used to automate wrapping FVS subroutines and data objects into a Python CAPI extension. F2PY is provided within the Numpy library. Numpy is under the umbrella of SciPy, a suite of Python libraries for scientific and mathematical applications.

Install Numpy

Numpy is available from several sources:

Useful F2PY references


Related

Wiki: BuildProcess_UnixAlike

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.