synthesizer.utils.util_funcs

A module containing general utility functions.

Example usage:

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

Functions

synthesizer.utils.util_funcs.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.util_funcs.planck(frequency, temperature)[source]

Compute the planck distribution for a given frequency and temperature.

This function computes the spectral radiance of a black body at a given frequency and temperature using Planck’s law. The spectral radiance is then converted to spectral luminosity density assuming a luminosity distance of 10 pc.

Parameters:
  • frequency (float or unyt_quantity) – Frequency of the radiation in Hz.

  • temperature (float or unyt_quantity) – Temperature in Kelvin.

Returns:

Spectral luminosity density in erg/s/Hz.

Return type:

unyt_quantity

synthesizer.utils.util_funcs.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.util_funcs.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.util_funcs.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.util_funcs.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.