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.5.tar.gz (277.5 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.5-py3-none-any.whl (303.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: phytorch_lib-0.1.5.tar.gz
  • Upload date:
  • Size: 277.5 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.5.tar.gz
Algorithm Hash digest
SHA256 57b08dcc6bd38ade49f0abeacfbcf8aea9170dd180baee9cea17aff9dd7a0d2c
MD5 9b5a6a776110f4781e79209085b46c8d
BLAKE2b-256 e612d252900c5a2cd8e2ce2b715d1dbe7c32b9cf84cacb7c5c5266712a3b8b60

See more details on using hashes here.

File details

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

File metadata

  • Download URL: phytorch_lib-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 303.6 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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 b71839f827ff699c78ee3b9168289dffcac488b7b0cf07c8b48d8005f07c6923
MD5 2a911c6d35b84f469d6caf08e37cd9d0
BLAKE2b-256 81a68df4c26e44119bc20ddf6d50a9c962c339eaf0408e89630da8ea26935155

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