Code Monkey home page Code Monkey logo

xleaf's Introduction

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

pip install xleaf

๐Ÿ–ฅ๏ธ Depending on your OS, you may need a FORTRAN compiler. So on ubuntu you could run sudo apt install gcc. On macos you'd run brew install gcc.


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.


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 2

Twitter Follow GitHub Stars

Footnotes

  1. Planet Labs PBC, San Francisco โ†ฉ

  2. Center for Conservation Biology, Stanford University โ†ฉ

xleaf's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

xleaf's Issues

Failed to install under Python 3.12

distutils is deprecated in Python 3.12, but the setup.py file still uses this module.

python setup.py egg_info did not run successfully.
  โ”‚ exit code: 1
  โ•ฐโ”€> [6 lines of output]
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/tmp/pip-install-0opca0op/xleaf_d0d9acdf536d423eb7ab0e31ce5fcda9/setup.py", line 3, in <module>
          from numpy.distutils.core import Extension, setup
      ModuleNotFoundError: No module named 'numpy.distutils'
      [end of output]

import fails on Windows 11

Hello,
Thanks for this library. I installed the MinGW fortran compiler to be able to install xleaf on Windows 11. Install completed successfully but then when I import xleaf, it throws the following error:

>>> import xleaf
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\Python310\TestEnv\lib\site-packages\xleaf\__init__.py", line 27, in <module>
    from xleaf.simulators import simulate_canopy, simulate_leaf
  File "c:\Python310\TestEnv\lib\site-packages\xleaf\simulators.py", line 7, in <module>
    from xleaf import prosail
ImportError: DLL load failed while importing prosail: The specified module could not be found.

Would be nice if it could works straight away on Windows without having to go through WSL. It works just fine through WSL though.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.