Skip to main content

xleaf

Canopy reflectance simulated in rainbows.

Leaf and canopy radiative transfer modeling tools built on PROSPECT-D and SAIL.

GitHub PyPI version GitHub last commit


Introduction

🌳 xleaf is a python package for running leaf and canopy simulation models using PROSAIL. It provides python bindings to the PROSPECT-D & 4SAIL Fortran code.

🌿 It includes sensible defaults that make it easy to get up and running quickly, and clear code documentation in the form of docstrings and type hints.

📚 All credit for the fundamental modeling code and for the underlying science belongs to the original researchers. xleaf is mostly a wrapper. Please cite their most recent research:

@article{feret2017prospect,
  title={PROSPECT-D: Towards modeling leaf optical properties through a complete lifecycle},
  author={Feret, J-B and Gitelson, AA and Noble, SD and Jacquemoud, S},
  journal={Remote Sensing of Environment},
  volume={193},
  pages={204--215},
  year={2017},
  publisher={Elsevier}
}

🧙 Shout out to my man JB.


Install

Install from PyPI:

pip install xleaf

Development

This project uses pixi to manage dependencies and builds. To set up a development environment:

pixi install

This installs all dependencies including the Fortran compiler (gfortran), meson, and numpy. To run tests:

pixi run test

Leaf and canopy simulations

import xleaf
import matplotlib.pyplot as plt

# run with off-the-shelf defaults
leaf = xleaf.simulate_leaf()

# or specify detailed parameters
canopy = xleaf.simulate_canopy(
    chl = 40, # ug/cm2
    car = 8, # ug/cm2
    antho = 0.5, # ug/cm2
    ewt = 0.01, # cm
    lma = 0.009, # g/cm2
    N = 1.5, # unitless
    lai = 3.0, # m2/m2
    lidf = 30, # degrees
    soil_dryness = 0.75, # %
    solar_zenith = 35, # degrees
    solar_azimuth = 120, # degrees
    view_zenith = 0, # degrees
    view_azimuth = 60, # degrees
    hot_spot = 0.01, # unitless
)

# and plot them together
plt.plot(xleaf.wavelengths, leaf, label='leaf')
plt.plot(xleaf.wavelengths, canopy, label='canopy')
plt.legend()

📄 The definitions and expected range of values for each parameter are described in the xleaf docstrings.


Chaining leaf and canopy models

🔗 simulate_canopy runs PROSPECT and 4SAIL together. If you'd rather run the canopy model on a leaf spectrum you already have — a measured spectrum, or one from a different leaf model — use simulate_sail. It takes leaf reflectance and transmittance directly, so you can pair it with simulate_leaf(transmittance=True):

import xleaf
import matplotlib.pyplot as plt

# simulate a leaf, returning both reflectance and transmittance
reflectance, transmittance = xleaf.simulate_leaf(
    chl = 40, # ug/cm2
    car = 8, # ug/cm2
    antho = 0.5, # ug/cm2
    ewt = 0.01, # cm
    lma = 0.009, # g/cm2
    N = 1.5, # unitless
    transmittance = True,
)

# then run the canopy model on that leaf spectrum
canopy = xleaf.simulate_sail(
    reflectance,
    transmittance,
    lai = 3.0, # m2/m2
    lidf = 30, # degrees
    soil_dryness = 0.75, # %
    solar_zenith = 35, # degrees
    solar_azimuth = 120, # degrees
    view_zenith = 0, # degrees
    view_azimuth = 60, # degrees
    hot_spot = 0.01, # unitless
)

plt.plot(xleaf.wavelengths, reflectance, label='leaf')
plt.plot(xleaf.wavelengths, canopy, label='canopy')
plt.legend()

Random forests

📊 xleaf provides classes for generating random parameters within the global range of expected values. These classes have a .sample() method for generating an appropriate random value based on a literature review.

import xleaf
import matplotlib.pyplot as plt

# generate 5 random leaf spectra from global defaults
for idx in range(5):
    chl = xleaf.ChlorophyllSampler.sample()
    car = xleaf.CarotenoidSampler.sample()
    antho = xleaf.AnthocyaninSampler.sample()
    ewt = xleaf.EWTSampler.sample()
    lma = xleaf.LMASampler.sample()
    N = xleaf.NSampler.sample()
    leaf = xleaf.simulate_leaf(chl, car, antho, ewt, lma, N)
    plt.plot(xleaf.wavelengths, leaf, label=f"leaf {idx+1}")

plt.legend()

🧪 Or experiment by setting the range of values yourself:

import xleaf
import matplotlib.pyplot as plt

MyLAISampler = xleaf.UniformSampler(min=2, max=6)
MyVZASampler = xleaf.NormalSampler(mean=0, stdv=3, min=-10, max=10)

# generate 5 random canopy spectra just varying LAI/VZA
for idx in range(5):
    lai = MyLAISampler.sample()
    vza = MyVZASampler.sample()
    canopy = xleaf.simulate_canopy(lai=lai, view_zenith=vza)
    plt.plot(xleaf.wavelengths, canopy, label=f"lai: {lai:0.2f}, vza: {vza:0.2f}")

plt.legend()

⚡ These parameters don't always vary independently. Try to exercise caution when constructing parameter estimates to ensure biological realism.


Developed by

Christopher Anderson1

Twitter Follow GitHub Stars

  1. Planet Labs PBC, San Francisco ↩

Metadata

Release files for xleaf 1.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for xleaf 1.2.2
File Size Uploaded Provenance
xleaf-1.2.2.tar.gz 282.2 kB Without provenance Details

Built distributions (wheels)

Table of built distributions (wheels) for xleaf 1.2.2
File Interpreter ABI Platform
xleaf-1.2.2-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
xleaf-1.2.2-cp311-cp311-manylinux_2_24_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.24+ x86-64 Details
xleaf-1.2.2-cp311-cp311-macosx_26_0_arm64.whl CPython 3.11 CPython 3.11 macOS 26.0+ ARM64 Details

Total release size: 5.9 MB

Release files / xleaf-1.2.2.tar.gz

Download URL xleaf-1.2.2.tar.gz
Size 282.2 kB
Tags Source
SHA-256 checksum
How to use checksums
1813a4cc81865d16b7212960d2ab28054d004bcf30fa4b047bbfc9d69365db64
BLAKE2b-256 checksum
How to use checksums
5761a014424d609b4c0916c0764c6c9e85404331122dcb1559ebd6e4a1f9818b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / xleaf-1.2.2-cp311-cp311-win_amd64.whl

Download URL xleaf-1.2.2-cp311-cp311-win_amd64.whl
Size 1.5 MB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
f3423b6982253998514715a840e5af79329bbe3c52d295ea99139d9f585ae2d8
BLAKE2b-256 checksum
How to use checksums
b0a11f177e6a12073d059281e74209c8ba56cd34cc3928a81b4128768a583afc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / xleaf-1.2.2-cp311-cp311-manylinux_2_24_x86_64.whl

Download URL xleaf-1.2.2-cp311-cp311-manylinux_2_24_x86_64.whl
Size 4.0 MB
Tags CPython 3.11 Linux glibc 2.24+ x86-64
SHA-256 checksum
How to use checksums
2311fa943fcd5e1187b6b103463ba148e470d29d34d31a9642136debb6183d38
BLAKE2b-256 checksum
How to use checksums
2fd9fe2f56c71799153c06d39717441a127388b4b065c9536b5bb30882bfc83a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / xleaf-1.2.2-cp311-cp311-macosx_26_0_arm64.whl

Download URL xleaf-1.2.2-cp311-cp311-macosx_26_0_arm64.whl
Size 128.1 kB
Tags CPython 3.11 macOS 26.0+ ARM64
SHA-256 checksum
How to use checksums
06009709d1c90f1ee26c5987c24403a76f3d1a01989e97a3e5bfb5f528bba32e
BLAKE2b-256 checksum
How to use checksums
d1f204bf9fcc56f9f49dc96594ea6612631cfdecb7367be8735dc213b8697478
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Security for xleaf 1.2.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page