High-level interface for PROSPECT leaf optical model.
This class provides a user-friendly wrapper around the native Helios LeafOptics plugin for computing spectral reflectance and transmittance of plant leaves based on their biochemical properties.
The PROSPECT model computes spectral optical properties for wavelengths from 400 nm to 2500 nm at 1 nm resolution (2101 data points).
System requirements:
- Cross-platform support (Windows, Linux, macOS)
- No GPU required
- Requires spectral_data assets (~475KB XML file)
- LeafOptics plugin compiled into PyHelios
- Example
- >>> from pyhelios import Context, LeafOptics, LeafOpticsProperties >>> >>> with Context() as context: ... with LeafOptics(context) as leafoptics: ... # Get properties for a known species ... props = leafoptics.getPropertiesFromLibrary("sunflower") ... print(f"Sunflower chlorophyll: {props.chlorophyllcontent} ug/cm^2") ... ... # Compute spectra ... wavelengths, reflectance, transmittance = leafoptics.getLeafSpectra(props) ... print(f"Spectral range: {wavelengths[0]}-{wavelengths[-1]} nm") ... ... # Apply to geometry ... leaf_uuid = context.addPatch(center=[0, 0, 1], size=[0.1, 0.1]) ... leafoptics.run([leaf_uuid], props, "sunflower_leaf")
Definition at line 378 of file LeafOptics.py.
|
| | __init__ (self, Context context) |
| | Initialize LeafOptics with graceful plugin handling.
|
| |
| | __enter__ (self) |
| | Context manager entry.
|
| |
| | __exit__ (self, exc_type, exc_value, traceback) |
| | Context manager exit with proper cleanup.
|
| |
| | __del__ (self) |
| | Destructor to ensure C++ resources freed even without 'with' statement.
|
| |
| None | run (self, List[int] UUIDs, Union[LeafOpticsProperties, LeafOpticsProperties_Nauto] leafproperties, Optional[str] label=None) |
| | Run the LeafOptics model to generate spectra and assign them to primitives.
|
| |
| None | updateNitrogenBasedSpectra (self) |
| | Re-read leaf nitrogen and reassign spectra for the primitives tracked in nitrogen mode.
|
| |
| None | runNoUUIDs (self, LeafOpticsProperties leafproperties, str label) |
| | Run the LeafOptics model without assigning to primitives.
|
| |
| Tuple[List[float], List[float], List[float]] | getLeafSpectra (self, LeafOpticsProperties leafproperties) |
| | Compute leaf reflectance and transmittance spectra.
|
| |
| None | setProperties (self, List[int] UUIDs, LeafOpticsProperties leafproperties) |
| | Set leaf optical properties for primitives as Context primitive data.
|
| |
| None | getPropertiesFromSpectrum (self, List[int] UUIDs) |
| | Get PROSPECT parameters from reflectivity spectrum for primitives.
|
| |
| LeafOpticsProperties | getPropertiesFromLibrary (self, str species) |
| | Get leaf optical properties from the built-in species library.
|
| |
| None | disableMessages (self) |
| | Disable command-line output messages from LeafOptics.
|
| |
| None | enableMessages (self) |
| | Enable command-line output messages from LeafOptics.
|
| |
| None | optionalOutputPrimitiveData (self, str label) |
| | Selectively output specific biochemical properties as primitive data.
|
| |
| None pyhelios.LeafOptics.LeafOptics.getPropertiesFromSpectrum |
( |
| self, |
|
|
List[int] | UUIDs ) |
Get PROSPECT parameters from reflectivity spectrum for primitives.
This method retrieves the "reflectivity_spectrum" primitive data for each
primitive and checks if it matches a spectrum generated by this LeafOptics
instance. If a match is found, the corresponding PROSPECT model parameters
are assigned as primitive data.
- Parameters
-
| UUIDs | List of primitive UUIDs to query |
- Note
- Primitives without matching spectra are silently skipped.
Definition at line 685 of file LeafOptics.py.
Run the LeafOptics model to generate spectra and assign them to primitives.
Two modes, selected by the type of ``leafproperties``:
- :class:`LeafOpticsProperties` with a ``label``: computes one reflectance and
transmittance spectrum, stores it as global data ``"leaf_reflectivity_<label>"`` /
``"leaf_transmissivity_<label>"``, and assigns it to every primitive.
- :class:`LeafOpticsProperties_Nauto` without a label (nitrogen mode): groups the
primitives by parent object, reads ``"leaf_nitrogen_gN_m2"`` object data from each,
derives chlorophyll and carotenoid content from it, and assigns each object the
spectrum of its nitrogen bin (global data ``"leaf_reflectivity_Nauto_<i>"`` etc.).
The first nitrogen-mode call creates the bins and fixes the parameters; later calls
track added/removed primitives, reassign leaves whose nitrogen changed, and rebuild
the bins if nitrogen moves outside their range. Parameters passed on later calls are
ignored. Primitives without a parent object are skipped with a warning.
- Parameters
-
- Exceptions
-
| ValueError | If parameters are invalid |
| LeafOpticsError | If computation fails (e.g. an object lacks "leaf_nitrogen_gN_m2") |
- Example
- >>> props = LeafOpticsProperties(chlorophyllcontent=40.0, watermass=0.02) >>> leafoptics.run([leaf_uuid], props, "my_leaf") >>> # Creates: "leaf_reflectivity_my_leaf" and "leaf_transmissivity_my_leaf" >>> >>> context.setObjectDataFloat(leaf_objID, "leaf_nitrogen_gN_m2", 2.0) >>> leafoptics.run(context.getObjectPrimitiveUUIDs(leaf_objID), LeafOpticsProperties_Nauto())
Definition at line 510 of file LeafOptics.py.
| None pyhelios.LeafOptics.LeafOptics.setProperties |
( |
| self, |
|
|
List[int] | UUIDs, |
|
|
LeafOpticsProperties | leafproperties ) |
Set leaf optical properties for primitives as Context primitive data.
This assigns the biochemical properties as primitive data using labels:
"chlorophyll", "carotenoid", "anthocyanin", "brown", "water", "drymass"
(or "protein" + "cellulose" in PROSPECT-PRO mode).
- Parameters
-
- Exceptions
-
Definition at line 655 of file LeafOptics.py.