|
|
|
|
|
Support
:: FAQ's
Using Python with TreeAge Pro 2007/2008


Overview and Links

Any TreeAge Pro user can make use of Python scripts/functions within their models:

  • Program user-defined functions
  • Access a tree's global matrices, tables, etc.
  • Access Python libraries for random numbers, scientific programming, etc.

For details and tutorials on user-defined functions in TreeAge, see Chapter 21 of the TreeAge Pro user's manual, and various Technical Notes (including #10):

For background on Python programming syntax, 3rd-party modules, etc:


User-Defined Distributions – Changes in TreeAge Pro v2008

Starting with TreeAge Pro 2008, a distribution’s behavior can be customized by writing a simple Python class to override selected distribution methods. This is similar to defining a tree variable using a Python user-defined function, but offers some additional options. For example, the Python class definition can override the “ev” (expected value) method of the distribution, so that EV calculations in the tree use a specific value – perhaps the mode rather than the default, arithmetic mean. Or, a complex resampling algorithm could be substituted for the default "resample" method.

Click to enlarge

Standard Python class definition syntax is used, with the custom class overriding TreeAge's "DistBase" base class. The default (overriden) methods of the distribution can still be accessed from a custom method, using “DistBase.methodname(self, …)” syntax. As in a user-defined function in a TreeAge variable definition, the class definition can include import statements from standard (like "random") or 3rd-party Python modules (like "numeric").

The available methods that can be overriden or called from the "DistBase" are:


User-Defined Functions – Changes in TreeAge Pro v2007

In TreeAge Pro 2005/6, Python commands had to be written akwardly, on a single line inside double quotes within the Python() functions. For example:

Starting with TreeAge Pro 2007, standard Python function syntax can be used to write multi-line functions within a TreeAge variable definition, including import statements for additional Python modules, etc:


Python Version Numbers

The standard/built-in Python functionality embedded in TreeAge Pro uses the library "Python24.dll", installed in "..\Program Files\TreeAge\TreeAge Pro\".

If you want to import Python modules into your user-defined functions (other than built-ins like "math"), and you have the newer Python v2.5 installed (e.g., "C:\Python25\"), you may need to update your Python24.dll:

This 2.5 version of the library (still called "Python24.dll" however) is required for some imports from a Python 2.5 installation to work (but not all require it). Rename or backup the current Python24.dll, and then unzip the newer version of the library in its place

Alternatively, you can uninstall Python 2.5.x and install Python 2.4.x (http://www.python.org/download/).