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.3.tar.gz (277.2 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.3-py3-none-any.whl (303.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: phytorch_lib-0.1.3.tar.gz
  • Upload date:
  • Size: 277.2 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.3.tar.gz
Algorithm Hash digest
SHA256 0326f7e48a6920280af698b70ce839ea8f4f398b70bf0c0637a3d13931e31fd5
MD5 d82bc524b29fa00516a933f6bd32c1ad
BLAKE2b-256 f3faae7416532d39fe53292372d4390a488610ccf0907ef8ef53e69fd0642e84

See more details on using hashes here.

File details

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

File metadata

  • Download URL: phytorch_lib-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 303.3 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 613da00b1dcbbf1a894870575047127e8b232b4bc256c835f4bcc57c0fe7d310
MD5 03033299bde9b1ae0c0fd270318224e4
BLAKE2b-256 62bf7b1ec4b5ab99a7fc58eaca6ddb9cb3ab998745e16a313cb307ab48be73f9

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