synthesizer.utils

A module containing general utility functions.

Example usage:

planck(frequency, temperature=10000 * K) rebin_1d(arr, 10, func=np.sum)

Functions

synthesizer.utils.has_units(x)[source]

Check whether the passed variable has units, i.e. is a unyt_quanity or unyt_array.

Parameters:

x (generic variable) – The variables to check.

Returns:

bool

True if the variable has units, False otherwise.

synthesizer.utils.parse_grid_id(grid_id)[source]

Parse a grid name for the properties of the grid.

This is used for parsing a grid ID to return the SPS model, version, and IMF

Parameters:

grid_id (str) – string grid identifier

synthesizer.utils.planck(nu, temperature)[source]

Planck’s law.

Parameters:
  • nu (unyt_array/array-like, float) – The frequencies at which to calculate the distribution.

  • temperature (float/array-like, float) – The dust temperature. Either a single value or the same size as nu.

Returns:

array-like, float

The values of the distribution at nu.

synthesizer.utils.rebin_1d(arr, resample_factor, func=<function sum>)[source]

A simple function for rebinning a 1D array using a specificed function (e.g. sum or mean).

Parameters:
  • arr (array-like) – The input 1D array.

  • resample_factor (int) – The integer rebinning factor, i.e. how many bins to rebin by.

  • func (func) – The function to use (e.g. mean or sum).

Returns:

array-like

The input array resampled by i.

synthesizer.utils.value_to_array(value)[source]

A helper functions for converting a single value to an array holding a single value.

Parameters:

value (float/unyt_quantity) – The value to wrapped into an array.

Returns:

array-like/unyt_array

An array containing the single value

Raises:

InconsistentArguments – If the argument is not a float or unyt_quantity.

synthesizer.utils.wavelength_to_rgba(wavelength, gamma=0.8, fill_red=(0, 0, 0, 0.5), fill_blue=(0, 0, 0, 0.5), alpha=1.0)[source]

Convert wavelength float to RGBA tuple.

Taken from https://stackoverflow.com/questions/44959955/ matplotlib-color-under-curve-based-on-spectral-color

Who originally took it from http://www.noah.org/wiki/ Wavelength_to_RGB_in_Python

Parameters:
  • wavelength (float) – Wavelength in nm.

  • gamma (float) – Gamma value.

  • fill_red (bool or tuple) – The colour (RGBA) to use for wavelengths red of the visible. If None use final nearest visible colour.

  • fill_blue (bool or tuple) – The colour (RGBA) to use for wavelengths red of the visible. If None use final nearest visible colour.

  • alpha (float) – The value of the alpha channel (between 0 and 1).

Returns:

rgba (tuple)

RGBA tuple.

synthesizer.utils.wavelengths_to_rgba(wavelengths, gamma=0.8)[source]

Convert wavelength array to RGBA list.

Parameters:

wavelength (unyt_array) – Wavelength in nm.

Returns:

rgba (list)

list of RGBA tuples.