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.2.tar.gz (277.0 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.2-py3-none-any.whl (303.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: phytorch_lib-0.1.2.tar.gz
  • Upload date:
  • Size: 277.0 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.2.tar.gz
Algorithm Hash digest
SHA256 942c36d29e36b84eb177ef0d3c1a19fab53d0a352a17ea394a04e45192d8040c
MD5 3e4481373b04e2905ef784e00880ce62
BLAKE2b-256 9203ce214055a3a3ea35a13621c2af17b51110916cf6c7ddc19f402a9d534123

See more details on using hashes here.

File details

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

File metadata

  • Download URL: phytorch_lib-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 303.2 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7c4516be13cf0ff8df50710c4d07494fa8b4149a2f2d731f0f51f9eb1d8b8156
MD5 0189cb05eb3958aa2dbd34634c04827c
BLAKE2b-256 90e29a68ff663b774234894d05dd540313078f1417abaf2aaa05d458227e978f

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