xopto.pf.util.pfmapmhg module

class MHgMap(gmhg: Optional[numpy.ndarray] = None, b: Optional[numpy.ndarray] = None, ng: int = 15, filename: Optional[str] = None, ncostheta: Optional[int] = None)[source]

Bases: xopto.pf.util.pfmapbase.PfMap2DBase

Prepares maps of the first ng Legendre moments of the Modified Henyey-Greenstein (MHG) scattering phase function, over the specified range of the MHG parameters g and b. If ng >= 2, a map of gamma is preapred and if ng >= 3 maps of delta and sigma are prepared as well. The maps are used to obtain an initial estimate when calculating the MHG scattering phase function parameters from Legendre moments, gamma and/or delta.

Parameters
  • gmhg (np.ndarray vector) – A Vector of equally spaced values defining the grid density of parameter gg of the MHG scattering phase function.

  • b (np.ndarray vector) – A Vector of equally spaced values defining the grid density of parameter b of the MHG scattering phase function (HG contribution).

  • ng (int) – Maps are created for the first ng Legendre moments. If ng >= 2, a map of gamma is prepared and if g >= 3 maps of delta and sigma are prepared as well.

  • filename (str) – File with saved data. The values of all the other parameters are ignored and restored from the file.

  • ncostheta (int) – Number of nodes used to compute the Legendre moments. Use a large number (> 1000) for accurate results. If None, adaptive step integration is used, which is accurate but can become slow.

Note

The value of parameter ng should be >> 3 to accurately estimate the value of parameter sigma.

Examples

Prepares maps of gamma and delta, and estimates the MHG parameters given a) g and gamma are known b) gamma and delta are known.

>>> import numpy as np
>>>
>>> m = MHgMap(np.linspace(0.0, 0.99, 100), np.linspace(0.0, 0.99, 100), ng=3)
>>> gmhg, b = m.invgammadelta(gamma=2.2, delta=3.5)
>>> print('gamma=2.2, delta=3.5 ==>', 'gmhg:', gmhg, 'b:', b)
>>> gmhg, b = m.invgamma(g=0.8, gamma=2.2)
>>> print('g=0.8, gamma=2.2 ==>', 'gmhg:', gmhg, 'b:', b)
>>>

Load maps from the default file included in the data/pf folder.

>>> m = MHgMap.fromfile()
>>> gmhg, b = m.invgammadelta(gamma=2.2, delta=3.5)
>>> print('gamma=2.2, delta=3.5 ==>', 'gmhg:', gmhg, 'b:', b)
>>> gmhg, b = m.invgamma(g=0.8, gamma=2.2)
>>> print('g=0.8, gamma=2.2 ==>', 'gmhg:', gmhg, 'b:', b)
>>>
DEFAULT_MAP_FILE = 'mhg_map.npz'

A filename for the default map. Overload this static member in derived classes.

PLOTSCALEFACTORX = 1.0
PLOTSCALEFACTORY = 1.0

Base class for computing maps of scattering phase function quantifiers as a function ot the scattering phase functions parameters - only for two-parametric scattering phase functions.

XLABEL = '$g_{mhg}$'
YLABEL = '$b_{mgk}$'
b()numpy.ndarray[source]

Returns a vector of points defining the grid of b parameter of the MHg scattering phase function.

b_grid()[source]

Returns a 2D map (meshgrid) of the second scattering phase function parameter (b).

gmhg()numpy.ndarray[source]

Returns a vector of points defining the grid of g parameter of the MHg scattering phase function

gmhg_grid()[source]

Returns a 2D map (meshgrid) of the first scattering phase function parameter (gmhg).

invgamma(g: float, gamma: float)float[source]

Overloading the base class method with analytical solution to the inverse problem.

Parameters
  • g (float) – Target value of the first Legendre moment.

  • gamma (float) – Target value of parameter gamma.

Returns

param1, param2 – Phase function input parameters.

Return type

float, float

invgammadelta(gamma, delta, **kwargs)[source]

Overloading the base class method with analytical solution to the inverse problem.

Parameters
  • gamma (float) – Target value of parameter gamma.

  • delta (float) – Target value of parameter gamma.

  • kwargs (dict) – Keyword arguments passed to the fmin_l_bfgs_b optimization function.

Returns

param1, param2 – Phase function input parameters.

Return type

float, float

classmethod precalculate(n: int = 100, filename: Optional[str] = None, verbose: bool = True)[source]

Precalculate MHg scattering phase function lookup table.

Parameters
  • n (int) – Number of steps along the scattering phase function parameters.

  • filename (str) – Output file or None to save as the default lookup table.

  • verbose (bool) – Turn on verbose progress report.