Code Monkey home page Code Monkey logo

fortyp's Introduction

ForTyp

A C++ implementation of the Arner et al. 2001 forest typing algorithm.

This library is largely translated from the FVS codebase (stkval.f and fortyp.f) but also references the Arner documents.

Variable names were kept the same as the FVS FORTRAN code. There are a number of unused variables in the original code that are included but commented out.

Functions

The library provides a function forest_type(treelist, false) which uses DBH, species (using FIA numeric codes), and TPA expansion values and returns the forest type classification. Due to some implementation details, there is a second bool parameter to simulate southern variant specific logic.

There are also convenience lookup tables to convert between forest type, forest type group, and their text names.

fortyp_name() returns the string name of a given forest type code fortypgroup() returns the forest type group int of a given forest type fortypgroup_name() returns the string name of a given forest type group code

If the forest type code is not found, it will just return a null string.

Compilation Instructions

A library libfortyp can be built using CMake and supports out-of-source builds.

git clone

cd fortyp

mkdir build #or whatever you want to call it

cd build

cmake .. #add -DBUILD_SHARED_LIBS=ON for shared library, otherwise will be static

make

Demo

There is a small demo with some example data included in the demo folder. To compile the demo replace the cmake statement above with:

cmake -DBUILD_DEMO=ON ..

which can then be executed by running the ./demo_stocking executable.

Calling from other languages

Python

from ctypes import *
fortyplib = cdll.LoadLibrary("./path/to/libfortyp.so")

#convert a forest type to forest type group
fortyplib.fortypgroup.restype = c_int
fortyplib.fortypgroup.argtypes = [c_int]
fortyplib.fortypgroup(101) #100

#get the name of a forest type group
fortyplib.fortypgroup_name.restype = c_char_p
fortyplib.fortypgroup_name.argtypes = [c_int]
fortyplib.fortypgroup_name(200).decode("utf-8") #"Douglas-fir"

#get the name of a forest type
fortyplib.fortyp_name.restype = c_char_p
fortyplib.fortyp_name.argtypes = [c_int]
fortyplib.fortyp_name(201).decode("utf-8") #"Douglas-fir"

Julia

using Libdl
lib = Libdl.dlopen("./build2/lib/libfortyp.so")

ccall(Libdl.dlsym(lib, :fortypgroup), Int32, (
    Ref{Cint},
), Ptr{Cint}(201))


x1 = ccall(Libdl.dlsym(lib, :fortypgroup_name), Ptr{UInt8}, (
    Ref{Cint},
), Ptr{Cint}(200))

unsafe_string(x1)

x2 = ccall(Libdl.dlsym(lib, :fortyp_name), Ptr{UInt8}, (
    Ref{Cint},
), Ptr{Cint}(201))

unsafe_string(x2)

TO DO?:

  1. generalize and clean up input structure
  2. add some error handling to map lookups
  3. cleaner way to handle variant logic?
  4. add python / R interop examples

PRs/issues welcome

fortyp's People

Contributors

crghilardi avatar

Watchers

James Cloos avatar  avatar

fortyp's Issues

Error in total stocking sum for forest type

In forest_type.cpp lines 647-649 where the total stocking is summed up the loop is getting each value from the stocking array s and then trying to use it as an index for the array.

//! TOTAL FOREST STOCKING (1-210) for (auto i : s) { totstk += s[i]; };

Can be fixed with:
//! TOTAL FOREST STOCKING (1-210) for (auto i : s) { totstk += i; };

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.