Legendre

The legendre module provides functions for making Legendre decompositions.

pyrt.legendre.decompose_phase_function(phase_function, angles, n_moments, n_samples)[source]

Decompose a phase function into its Legendre moments.

Parameters
  • phase_function (numpy.ndarray) – The phase function to decompose.

  • angles (numpy.ndarray) – The angles where the phase function is defined.

  • n_moments (int) – The number of Legendre moments to decompose the phase function into.

  • n_samples (int) – The number of samples to use for the resampling. Must be greater than or equal to n_moments.

Return type

numpy.ndarray

Examples

Let’s suppose we have a Henyey-Greenstein phase function with asymmetry parameter of 0.6. Let’s create its first 65 moments along with the angles where it’s defined.

>>> from pyRT_DISORT.aerosol import HenyeyGreenstein
>>> analytic_moments = HenyeyGreenstein(0.6).legendre_decomposition(65)
>>> angles = np.radians(np.linspace(0, 180, num=181))

We can convert it to a phase fuction with the following:

>>> import numpy as np
>>> phase = np.polynomial.legendre.legval(np.cos(angles), analytic_moments)

If we decompose the phase fuction into Legendre coefficients, we should get what we started with. Let’s decompose the phase fuction back into 65 moments and use 360 samples to make sure the resolution is good.

>>> from pyRT_DISORT.legendre import decompose_phase_function
>>> decomp_moments = decompose_phase_function(phase, angles, 65, 360)
>>> np.amax((analytic_moments - decomp_moments)**2)
1.6443715589020334e-07

We’ve recovered the original moments pretty well!