Classes

class pymsg.SpecGrid(file_name)

The SpecGrid class represents a grid of spectroscopic intensity data.

This grid may be used to interpolate the intensity (or related quantities) across a wavelength abscissa and for a set of photospheric parameter values.

__init__(file_name)

SpecGrid constructor (via loading data from a specgrid file).

Parameters:

file_name (string) – Name of the file

Returns:

Constructed object.

Return type:

pymsg.SpecGrid

Raises:
  • FileNotFound – If the the file cannot be found.

  • IOError – If the file contains invalid data.

property rank

Number of dimensions in grid.

Type:

int

property axis_labels

Photospheric parameter axis labels.

Type:

list

property axis_x_min

Photospheric parameter axis minima.

Type:

dict

property axis_x_max

Photospheric parameter axis maxima.

Type:

dict

property lam_min

Minimum wavelength of grid (Å).

Type:

float

property lam_max

Maximum wavelength of grid (Å).

Type:

float

property cache_lam_min

Minimum wavelength of grid cache (Å).

Type:

float

property cache_lam_max

Maximum wavelength of grid cache (Å).

Type:

float

property cache_usage

Current memory usage of grid cache (MB).

Type:

int

property cache_limit

Maximum memory usage of grid cache (MB).

Type:

int

flush_cache()

Flush the grid cache

intensity(x, mu, z, lam, deriv=None, order=3)

Interpolate the spectroscopic specific intensity for a photospheric element.

Parameters:
  • x (dict) – Photospheric parameters; keys must match axis_labels property, values must be float.

  • mu (float) – Cosine of angle of emergence relative to element normal.

  • z (float) – Redshift of element relative to observer’s frame.

  • lam (numpy.ndarray) – Wavelength abscissa (Å) in observer’s frame.

  • deriv (dict, optional) – Flags indicating whether to evaluate derivative with respect to each photospheric parameter; keys must match the axis_labels property, values must be boolean.

  • order (int, optional) – Interpolation order; valid values are 1 or 3.

Returns:

Spectroscopic specific intensity (erg/cm^2/s/Å/sr) in bins delineated by lam; length len(lam)-1.

Return type:

numpy.ndarray

Raises:
  • KeyError – If x does not define all keys appearing in the axis_labels property.

  • ValueError – If x, mu, or any part of the wavelength abscissa falls outside the bounds of the grid.

  • LookupError – If x falls in a grid void.

E_moment(x, k, z, lam, deriv=None, order=3)

Interpolate the spectroscopic intensity E-moment for a photospheric element.

Parameters:
  • x (dict) – Photospheric parameters; keys must match axis_labels property, values must be float.

  • k (int) – Degree of moment.

  • z (float) – Redshift of element relative to observer’s frame.

  • lam (numpy.ndarray) – Wavelength abscissa (Å) in observer’s frame.

  • deriv (dict, optional) – Flags indicating whether to evaluate derivative with respect to each photospheric parameter; keys must match the axis_labels property, values must be boolean.

  • order (int, optional) – Interpolation order; valid values are 1 or 3.

Returns:

Spectroscopic intensity E-moment (erg/cm^2/s/Å) in bins delineated by lam; length len(lam)-1.

Return type:

numpy.ndarray

Raises:
  • KeyError – If x does not define all keys appearing in the axis_labels property.

  • ValueError – If x, k, or any part of the wavelength abscissa falls outside the bounds of the grid.

  • LookupError – If x falls in a grid void.

P_moment(x, l, z, lam, deriv=None, order=3)

Interpolate the spectroscopic intensity P-moment for a photospheric element.

Parameters:
  • x (dict) – Photospheric parameters; keys must match axis_labels property, values must be float.

  • l (int) – Harmonic degree of moment.

  • z (float) – Redshift of element relative to observer’s frame.

  • lam (numpy.ndarray) – Wavelength abscissa in observer’s frame (Å).

  • deriv (dict, optional) – Flags indicating whether to evaluate derivative with respect to each photospheric parameter; keys must match the axis_labels property, values must be boolean.

  • order (int, optional) – Interpolation order; valid values are 1 or 3.

Returns:

Spectroscopic intensity P-moment (erg/cm^2/s/Å) in bins delineated by lam; length len(lam)-1.

Return type:

numpy.ndarray

Raises:
  • KeyError – If x does not define all keys appearing in the axis_labels property.

  • ValueError – If x, l, or any part of the wavelength abscissa falls outside the bounds of the grid.

  • LookupError – If x falls in a grid void.

irradiance(x, mu, dOmega, z, lam, deriv=None, order=3)

Interpolate the spectroscopic irradiance for an object composed of multiple photospheric elements.

Parameters:
  • x (dict) – Photospheric parameters; keys must match axis_labels property, values must be numpy.ndarrays of equal length.

  • mu (np.ndarray) – Cosines of angles of emergence relative to element normals; length len(x[]).

  • dOmega (np.ndarray) – Solid angles (sr) of elements; length len(x[]).

  • z (float) – Redshifts of elements relative to observer’s frame.

  • lam (numpy.ndarray) – Wavelength abscissa (Å) in observer’s frame.

  • deriv (dict, optional) – Flags indicating whether to evaluate derivative with respect to each photospheric parameter; keys must match the axis_labels property, values must be boolean.

  • order (int, optional) – Interpolation order; valid values are 1 or 3.

Returns:

Spectroscopic irradiance (erg/cm^2/s/Å) in bins delineated by lam; length len(lam)-1.

Return type:

numpy.ndarray

Raises:
  • KeyError – If x does not define all keys appearing in the axis_labels property.

  • ValueError – If x, mu, or any part of the wavelength abscissa falls outside the bounds of the grid; or if the or if mu, dOmega, or the values of x have mismatched length.

  • LookupError – If x falls in a grid void.

flux(x, z, lam, deriv=None, order=3)

Interpolate the spectroscopic flux for a photospheric element.

Parameters:
  • x (dict) – Photospheric parameters; keys must match axis_labels property, values must be float.

  • z (float) – Redshift of element relative to observer’s frame.

  • lam (numpy.ndarray) – Wavelength abscissa (Å) in observer’s frame.

  • deriv (dict, optional) – Flags indicating whether to evaluate derivative with respect to each photospheric parameter; keys must match the axis_labels property, values must be boolean.

  • order (int, optional) – Interpolation order; valid values are 1 or 3.

Returns:

Spectroscopic flux (erg/cm^2/s/Å) in bins delineated by lam; length len(lam)-1.

Return type:

numpy.ndarray

Raises:
  • KeyError – If x does not define all keys appearing in the axis_labels property.

  • ValueError – If x or any part of the wavelength abscissa falls outside the bounds of the grid.

  • LookupError – If x falls in a grid void.

adjust_x(x, dx)

Adjust photospheric parameters in a specified direction, until they fall within the valid part of the grid.

Parameters:
  • x (dict) – Photospheric parameters; keys must match axis_labels property, values must be float.

  • dx (dict) – Photospheric parameter adjustment direction; keys must match axis_labels property, values must be float. The overall scaling is unimportant, but at least one value must be non-zero.

Returns:

Adjusted photospheric parameters.

Return type:

numpy.ndarray

Raises:
  • KeyError – If x does not define all keys appearing in the axis_labels property.

  • ValueError – If no valid x can be found, or if dx is invalid; or if x and dx have mismatched length.

class pymsg.PhotGrid(file_name, passband_file_name=None)

The PhotGrid class represents a grid of photometric intensity data.

This grid may be used to interpolate the intensity (or related quantities) for a set of photospheric parameter values.

__init__(file_name, passband_file_name=None)
PhotGrid constructor (via loading data from a photgrid file, or

from a specgrid file together with a passband file).

Parameters:
  • file_name (string) – Name of grid file.

  • passband_file_name (string) – Name of passband file (if file_name corresponds to a specgrid file)

Returns:

Constructed object.

Return type:

pymsg.PhotGrid

Raises:
  • FileNotFound – If either file cannot be found.

  • IOError – If either file contains invalid data.

property rank

Number of dimensions in grid.

Type:

int

property axis_labels

Photospheric parameter axis labels.

Type:

list

property axis_x_min

Photospheric parameter axis minima.

Type:

dict

property axis_x_max

Photospheric parameter axis maxima.

Type:

dict

property cache_usage

Current memory usage of grid cache (MB).

Type:

int

property cache_limit

Maximum memory usage of grid cache (MB).

Type:

int

flush_cache()

Flush the grid cache

intensity(x, mu, deriv=None, order=3)

Interpolate the photometric specific intensity for a photospheric element, normalized by the zero-point flux.

Parameters:
  • x (dict) – Photospheric parameters; keys must match axis_labels property, values must be float.

  • mu (float) – Cosine of angle of emergence relative to element normal.

  • deriv (dict, optional) – Flags indicating whether to evaluate derivative with respect to each photospheric parameter; keys must match the axis_labels property, values must be boolean.

  • order (int, optional) – Interpolation order; valid values are 1 or 3.

Returns:

Photometric specific intensity (/sr).

Return type:

float

Raises:
  • KeyError – If x does not define all keys appearing in the axis_labels property.

  • ValueError – If x or mu falls outside the bounds of the grid.

  • LookupError – If x falls in a grid void.

E_moment(x, k, deriv=None, order=3)

Interpolate the photometric intensity E-moment for a photospheric element, normalized to the zero-point flux.

Parameters:
  • x (dict) – Photospheric parameters; keys must match axis_labels property, values must be float.

  • k (int) – Degree of moment.

  • deriv (dict, optional) – Flags indicating whether to evaluate derivative with respect to each photospheric parameter; keys must match the axis_labels property, values must be boolean.

  • order (int, optional) – Interpolation order; valid values are 1 or 3.

Returns:

Photometric intensity E-moment (dimensionless).

Return type:

float

Raises:
  • KeyError – If x does not define all keys appearing in the axis_labels property.

  • ValueError – If x or k falls outside the bounds of the grid.

  • LookupError – If x falls in a grid void.

P_moment(x, l, deriv=None, order=3)

Interpolate the photometric intensity P-moment for a photospheric element, normalized to the zero-point flux.

Parameters:
  • x (dict) – Photospheric parameters; keys must match axis_labels property, values must be float.

  • l (int) – Harmonic degree of moment.

  • deriv (dict, optional) – Flags indicating whether to evaluate derivative with respect to each photospheric parameter; keys must match the axis_labels property, values must be boolean.

  • order (int, optional) – Interpolation order; valid values are 1 or 3.

Returns:

Photometric intensity P-moment (dimensionless).

Return type:

float

Raises:
  • KeyError – If x does not define all keys appearing in the axis_labels property.

  • ValueError – If x or l falls outside the bounds of the grid.

  • LookupError – If x falls in a grid void.

irradiance(x, mu, dOmega, deriv=None, order=3)

Interpolate the photometric irradiance for an object composed of multiple photospheric elements, normalized by the zero- point flux.

Parameters:
  • x (dict) – Photospheric parameters; keys must match axis_labels property, values must be numpy.ndarrays of equal length.

  • mu (np.ndarray) – Cosines of angles of emergence relative to element normals; length len(x[]).

  • dOmega (np.ndarray) – Solid angles (sr) of elements; length len(x[]).

  • deriv (dict, optional) – Flags indicating whether to evaluate derivative with respect to each photospheric parameter; keys must match the axis_labels property, values must be boolean.

  • order (int, optional) – Interpolation order; valid values are 1 or 3.

Returns:

Photometric irradiance (dimensionless).

Return type:

numpy.ndarray

Raises:
  • KeyError – If x does not define all keys appearing in the axis_labels property.

  • ValueError – If x or mu fall outside the bounds of the grid; or if mu, dOmega, or the values of x have mismatched length.

  • LookupError – If x falls in a grid void.

flux(x, deriv=None, order=3)

Interpolate the photometric flux for a photospheric element, normalized by the zero-point flux.

Parameters:
  • x (dict) – Photospheric parameters; keys must match axis_labels property, values must be float.

  • deriv (dict, optional) – Flags indicating whether to evaluate derivative with respect to each photospheric parameter; keys must match the axis_labels property, values must be boolean.

  • order (int, optional) – Interpolation order; valid values are 1 or 3.

Returns:

Photometric flux (dimensionless).

Return type:

float

Raises:
  • KeyError – If x does not define all keys appearing in the axis_labels property.

  • ValueError – If x or l falls outside the bounds of the grid.

  • LookupError – If x falls in a grid void.

adjust_x(x, dx)

Adjust photospheric parameters in a specified direction, until they fall within the valid part of the grid.

Parameters:
  • x (dict) – Photospheric parameters; keys must match axis_labels property, values must be float.

  • dx (dict) – Photospheric parameter adjustment direction; keys must match axis_labels property, values must be float. The overall scaling is unimportant, but at least one value must be non-zero.

Returns:

Adjusted photospheric parameters.

Return type:

numpy.ndarray

Raises:
  • KeyError – If x does not define all keys appearing in the axis_labels property.

  • ValueError – If no valid x can be found, or if dx is invalid; or if x and dx have mismatched length.