Skip to main content

PhyTorch is a PyTorch-based modeling toolkit for fitting common plant physiological models of photosynthesis, stomatal conductance, leaf hydraulics, and optical properties.

Project description

PhyTorch

A Comprehensive Physiological Plant Modeling Toolkit

License: GPL v3 Python PyTorch

PhyTorch is a PyTorch-based package for fitting and analyzing plant physiological models. It provides a unified, simple API for model fitting with efficient GPU-accelerated optimization and automatic differentiation.

Features

  • Unified API: Simple fit(model, data) interface for all models
  • Photosynthesis Models: FvCB (Farquhar-von Caemmerer-Berry) model with flexible temperature and light response functions
  • Stomatal Conductance: Multiple empirical and semi-empirical models (Medlyn, Ball-Woodrow-Berry, Buckley-Mott-Farquhar)
  • Leaf Optical Properties: PROSPECT model for leaf spectral reflectance and transmittance
  • Leaf Hydraulics: Pressure-volume curves (SJB2018), sigmoidal vulnerability curves
  • Canopy Architecture: Leaf angle distribution models with automatic classification into canonical types
  • Generic Models: Arrhenius, peaked Arrhenius, Weibull, beta distribution, Gaussian, sigmoidal, and hyperbolic functions
  • GPU Acceleration: Leverage PyTorch for fast parameter optimization on CPU or GPU
  • Automatic Differentiation: Efficient gradient-based optimization for model fitting
  • Custom Plotting: Model-specific diagnostic plots with publication-ready styling

Installation

From PyPI (recommended)

pip install phytorch-lib

From source

git clone https://github.com/ktrizzo/phytorch.git
cd phytorch
pip install -e .

Quick Start

PhyTorch uses a unified fit(model, data) API for all models:

Pressure-Volume Curves

from phytorch import fit
from phytorch.models.hydraulics import SJB2018
import pandas as pd

# Load pressure-volume data
df = pd.read_csv('pv_data.csv')
data = {
    'w': df['RWC'].values,      # Relative water content
    'psi': df['Psi_MPa'].values # Water potential (MPa)
}

# Fit model
model = SJB2018()
result = fit(model, data)

# View results
print(f"πₒ = {result.parameters['pi_o']:.3f} MPa")
print(f"w_tlp = {result.parameters['w_tlp']:.3f}")
print(f"R² = {result.r_squared:.4f}")

# Plot with custom diagnostics
result.plot(save='pv_curve.png')

Leaf Angle Distribution

from phytorch import fit
from phytorch.models.canopy import LeafAngleDistribution, bin_leaf_angles
import pandas as pd

# Load and bin leaf angle measurements
df = pd.read_csv('leaf_angles.csv')
data = bin_leaf_angles(df['zenith'].values, angle_type='zenith')

# Fit model
model = LeafAngleDistribution()
result = fit(model, data)

# Classify canopy architecture
classification = model.classify(result.parameters)
print(f"Canopy type: {classification['type']}")
print(f"R² = {result.r_squared:.4f}")

# Plot with classification
result.plot(save='leaf_angles.png')

Generic Models

from phytorch import fit
from phytorch.models.generic import Arrhenius, Weibull, Beta

# Temperature response with Arrhenius
model = Arrhenius()
data = {'x': temperatures, 'y': rates}
result = fit(model, data)

# Weibull distribution
model = Weibull()
result = fit(model, data)

# Beta distribution
model = Beta()
result = fit(model, data)

Package Structure

phytorch/
├── fit.py               # Unified fit() function
├── models/              # Model library
│   ├── generic/         # Generic mathematical models
│   ├── hydraulics/      # Leaf hydraulics models
│   └── canopy/          # Canopy architecture models
├── photosynthesis/      # FvCB photosynthesis models (legacy API)
├── stomatalconductance/ # Stomatal conductance models (legacy API)
├── leafoptics/          # PROSPECT leaf optical properties (legacy API)
├── leafhydraulics/      # Leaf hydraulics (legacy API)
├── core/                # Core optimization and fitting infrastructure
└── data/                # Example datasets

Documentation

Full documentation is available at https://phytorch.org

Citation

If you use PhyTorch in your research, please cite:

Lei, T., Rizzo, K. T., & Bailey, B. N. (2025). PhoTorch: A robust and generalized
biochemical photosynthesis model fitting package. (In preparation)

Credits

PhyTorch is an extension and reorganization of PhoTorch, developed by:

  • Tong Lei
  • Kyle T. Rizzo
  • Brian N. Bailey

License

PhyTorch is licensed under the GNU General Public License v3.0. See LICENSE for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Contact

For questions or issues, please open an issue on GitHub.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

phytorch_lib-0.1.4.tar.gz (277.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

phytorch_lib-0.1.4-py3-none-any.whl (303.4 kB view details)

Uploaded Python 3

File details

Details for the file phytorch_lib-0.1.4.tar.gz.

File metadata

  • Download URL: phytorch_lib-0.1.4.tar.gz
  • Upload date:
  • Size: 277.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for phytorch_lib-0.1.4.tar.gz
Algorithm Hash digest
SHA256 b7c41337476dd6587424d991fd67c6371bb9eaaf54da11932895f59c103ff86e
MD5 e8aa2f27afe9cca5d379b69c093f25dd
BLAKE2b-256 2d18bf074993bca985d5fe3499852e7fe63c5beb8472a03815245da77d7d34d2

See more details on using hashes here.

File details

Details for the file phytorch_lib-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: phytorch_lib-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 303.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for phytorch_lib-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 1a62bb275ce77636fb32ce6bcf061879ec8b92962e7aaf44293676ff95000bec
MD5 eb5991930c67be0d2c8f1d4d975754c6
BLAKE2b-256 2c87b3c05aa1f36b1211f8335e01a6d74717230263570959064be7e78090f9bf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page