Skip to content

Commit

Permalink
Merge branch 'master' of github.com:jgomezdans/prosail
Browse files Browse the repository at this point in the history
  • Loading branch information
José Gómez-Dans committed Jan 25, 2016
2 parents d876ff5 + bdb89fc commit 4b01c9f
Show file tree
Hide file tree
Showing 6 changed files with 266 additions and 139 deletions.
103 changes: 103 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<img src="http://www.nceo.ac.uk/images/NCEO_logo_lrg.jpg" scale=50% alt="NCEO logo" align="right" />
<img src="http://www.esa.int/esalogo/images/logotype/img_colorlogo_darkblue.gif" scale=20% alt="ESA logo" align="left" />

<br/>
<br/>
<br/>

---

# PROSAIL Python Bindings

#### J Gomez-Dans (NCEO & UCL) ``j.gomez-dans@ucl.ac.uk``


## Description

This repository contains the Python bindings to the PROSPECT and SAIL leaf and
canopy reflectance models. The code is written in FORTRAN. The original fortran
code was downloaded from [Jussieu](http://teledetection.ipgp.jussieu.fr/prosail/).
I only added a function to simplify writing the wrappers, and you should go to
that page to get newer versions of the code. A recent review of the use of both
models is availabe in [this paper](http://webdocs.dow.wur.nl/internet/grs/Workshops/Environmental_Applications_Imaging_Spectroscopy/12_Jacquemoud_Prospect/IEEE_Jacquemoud_PROSPECT.pdf)_.


## Installing the bindings

The installation of the bindings is quite straightforward: unpack the distribution
and run the following command

python setup.py install

You can usually install it to your user's directory (if you haven't got superuser
privileges) by

python setup.py install --user

#### **Note**


You will need a working FORTRAN compiler. I have only tested this with GCC on Linux, but it should work on other systems. You can also pass optimisation flags to the compiler:

python setup.py config_fc --fcompiler=gnu95 --arch=-march=native --opt=-O3 install --user

## Using the bindings

The bindings offer several functions, which will be described in detail below:.

* ``run_prospect``: This function runs the PROSPECT 5B model in Feret et al 2008. The input parameters are the usual ``(n,cab,car,cbrown,cw,cm)`` (e.g. leaf layers, leaf Chlorophyll concentration, leaf Carotenoid concentration, leaf senescent fraction, Equivalent leaf water, leaf dry matter). It returns a spectrum between 400 and 2500 nm.
* ``run_sail``: The SAILh model, which in this case requires leaf reflectance and transmittance to be fed to the model (e.g. you have already measured these spectra in the field). The rest of the parameters are ``(refl,trans,lai,lidfa,lidfb,rsoil,psoil,hspot,tts,tto,psi,typelidf)``. Additionally, there are two optional parameters, ``soil_spectrum1``, ``soil_spectrum2``, which allow you to set the soil spectra (otherwise, some default spectra get used). Output is a spectrum in the 400-2500 nm range.
* ``run_prosail``: PROSPECT_5B and SAILh coupled together, with input parameters given by ``(n,cab,car,cbrown,cw,cm,lai,lidfa,lidfb,rsoil,psoil,hspot,tts,tto,psi,typelidf)``. Output is a spectrum in the 400-2500 nm range.


## The parameters

The parameters used by the models and their units are introduced below:

| Parameter | Description of parameter | Units |Typical min | Typical max |
|-------------|---------------------------------|--------------|------------|-------------|
| N | Leaf structure parameter | N/A | 0.8 | 2.5 |
| cab | Chlorophyll a+b concentration | ug/cm2 | 0 | 80 |
| caw | Equivalent water thickiness | cm | 0 | 200 |
| car | Carotenoid concentration | ug/cm2 | 0 | 20 |
| cbrown | Brown pigment | NA | 0 | 1 |
| cm | Dry matter content | g/cm2 | 0 | 200 |
| lai | Leaf Area Index | N/A | 0 | 10 |
| lidfa | Leaf angle distribution | N/A | - | - |
| lidfb | Leaf angle distribution | N/A | - | - |
| psoil | Dry/Wet soil factor | N/A | 0 | 1 |
| rsoil | Soil brigthness factor | N/A | - | - |
| hspot | Hotspot parameter | N/A | - | - |
| tts | Solar zenith angle | deg | 0 | 90 |
| tto | Observer zenith angle | deg | 0 | 90 |
| phi | Relative azimuth angle | deg | 0 | 360 |
| typelidf | Leaf angle distribution type | Integer | - | - |

### Specifying the leaf angle distribution

The parameter ``typelidf`` regulates the leaf angle distribution family being used. The following options are understood:

* ``typelidf = 1``: use the two parameter LAD parameterisation, where ``a`` and ``b`` control the average leaf slope and the distribution bimodality, respectively. Typical distributions
are given by the following parameter choices:

| LIDF type | ``LIDFa`` | ``LIDFb`` |
|--------------|-----------|------------------|
| Planophile | 1 | 0 |
| Erectophile| -1 | 0 |
| Plagiophile| 0 | -1 |
| Extremophile| 0 | 1 |
| Spherical | -0.35 | -0.15 |
| Uniform | 0 | 0 |

* ``typelidf = 2`` Ellipsoidal distribution, where ``LIDFa`` parameter stands for mean leaf angle (0 degrees is planophile, 90 degrees is erectophile). ``LIDFb`` parameter is ignored.

### The soil model

The soil model is a fairly simple linear mixture model, where two spectra are mixed and then a brightness term added:

rho_soil = rsoil*(psoil*soil_spectrum1+(1-psoil)*soil_spectrum2)


The idea is that one of the spectra is a dry soil and the other a wet soil, so soil moisture is then contorlled by ``psoil``. ``rsoil`` is just a brightness scaling term.


119 changes: 0 additions & 119 deletions README.rst

This file was deleted.

138 changes: 137 additions & 1 deletion prosail/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,141 @@
import numpy as np
from prosail_fortran import run_sail, run_prosail, prospect_5b
from prosail_fortran import run_sail as sail, run_prosail as prosail
from prosail_fortran import prospect_5b
from prosail_fortran import mod_dataspec_p5b as spectral_libs

def run_prosail (n,cab,car,cbrown,cw,cm,lai,lidfa,lidfb,rsoil,psoil,hspot,
tts,tto,psi,typelidf,
soil_spectrum1=None,soil_spectrum2=None ):
"""Run the PROSPECT_5B and SAILh radiative transfer models. The soil
model is a linear mixture model, where two spectra are combined together as
rho_soil = rsoil*(psoil*soil_spectrum1+(1-psoil)*soil_spectrum2)
By default, ``soil_spectrum1`` is a dry soil, and ``soil_spectrum2`` is a
wet soil, so in that case, ``psoil`` is a surface soil moisture parameter.
``rsoil`` is a soil brightness term. You can provide one or the two
soil spectra if you want. The soil spectra must be defined
between 400 and 2500 nm with 1nm spacing.
Parameters
----------
n: float
Leaf layers
cab: float
leaf chlorophyll concentration
car: float
leaf carotenoid concentration
cbrown: float
senescent pigment
cw: float
equivalent leaf water
cm: float
leaf dry matter
lai: float
leaf area index
lidfa: float
a parameter for leaf angle distribution. If ``typliedf``=2, average
leaf inclination angle.
lidfb: float
b parameter for leaf angle distribution. If ``typelidf``=2, ignored
rsoil: float
Soil scalar
psoil: float
Soil scalar
tts: float
Solar zenith angle
tto: float
Sensor zenith angle
psi: float
Relative sensor-solar azimuth angle ( saa - vaa )
soil_spectrum1: 2101-element array
First component of the soil spectrum
soil_spectrum2: 2101-element array
Second component of the soil spectrum
Returns
--------
Directional surface reflectance between 400 and 2500 nm
"""

if soil_spectrum1 is not None:
assert ( len(soil_spectrum1) == 2101 )
else:
soil_spectrum1 = spectral_libs.rsoil1

if soil_spectrum2 is not None:
assert ( len(soil_spectrum1) == 2101 )
else:
soil_spectrum2 = spectral_libs.rsoil1

rho = prosail (n,cab,car,cbrown,cw,cm,lai,lidfa,lidfb,rsoil,psoil,hspot,
tts,tto,psi,typelidf, soil_spectrum1, soil_spectrum2 )
return rho

def run_sail (refl,trans,lai,lidfa,lidfb,rsoil,psoil,hspot,tts,tto,psi,typelidf,
soil_spectrum1=None,soil_spectrum2=None ):
"""Run the SAILh radiative transfer model. The soil model is a linear
mixture model, where two spectra are combined together as
rho_soil = rsoil*(psoil*soil_spectrum1+(1-psoil)*soil_spectrum2)
By default, ``soil_spectrum1`` is a dry soil, and ``soil_spectrum2`` is a
wet soil, so in that case, ``psoil`` is a surface soil moisture parameter.
``rsoil`` is a soil brightness term. You can provide one or the two
soil spectra if you want. The soil spectra, and leaf spectra must be defined
between 400 and 2500 nm with 1nm spacing.
Parameters
----------
refl: 2101-element array
Leaf reflectance
trans: 2101-element array
leaf transmittance
lai: float
leaf area index
lidfa: float
a parameter for leaf angle distribution. If ``typliedf``=2, average
leaf inclination angle.
lidfb: float
b parameter for leaf angle distribution. If ``typelidf``=2, ignored
rsoil: float
Soil scalar
psoil: float
Soil scalar
tts: float
Solar zenith angle
tto: float
Sensor zenith angle
psi: float
Relative sensor-solar azimuth angle ( saa - vaa )
soil_spectrum1: 2101-element array
First component of the soil spectrum
soil_spectrum2: 2101-element array
Second component of the soil spectrum
Returns
--------
Directional surface reflectance between 400 and 2500 nm
"""


if soil_spectrum1 is not None:
assert ( len(soil_spectrum1) == 2101 )
else:
soil_spectrum1 = spectral_libs.rsoil1

if soil_spectrum2 is not None:
assert ( len(soil_spectrum1) == 2101 )
else:
soil_spectrum2 = spectral_libs.rsoil1

rho = sail (refl,trans,lai,lidfa,lidfb,rsoil,psoil,hspot,tts,tto,psi,typelidf,
soil_spectrum1, soil_spectrum2 )
return rho



def trans_prosail ( N, cab, car, cbrown, cw, cm, lai, lidfa, lidfb, rsoil, psoil, \
Expand Down
2 changes: 1 addition & 1 deletion prosail/dataSpec_P5B.f90
Original file line number Diff line number Diff line change
Expand Up @@ -2268,4 +2268,4 @@ MODULE MOD_dataSpec_P5B
4.960E-02,4.960E-02,4.960E-02,4.960E-02,4.959E-02,4.959E-02,4.944E-02,4.930E-02,4.915E-02,4.900E-02,&
4.885E-02/

END
END
Loading

0 comments on commit 4b01c9f

Please sign in to comment.