synthesizer.emissions.scaling¶
Shared helpers for scaling emission arrays.
Provides normalised mask handling and a unified scaling dispatcher that
hands the common 2D scaling cases over to the specialised C++ kernels,
while retaining a NumPy fallback for the more general broadcast shapes.
Both Sed.scale and LineCollection.scale delegate here for the
single-array path.
Example usage:
from synthesizer.emissions.scaling import (
normalise_scale_masks,
scale_array,
)
scaled = scale_array(array, scaling, mask=mask, nthreads=4)
Functions
- synthesizer.emissions.scaling.normalise_line_scaling(scaling, get_nu, lum_units, cont_units)[source]¶
Resolve a line scaling into luminosity and continuum factors.
Line luminosity and continuum carry different units (erg/s and erg/s/Hz respectively), so a single unit-bearing scaling may need to be converted into two different raw arrays. The frequency coordinate is only constructed when we actually need one of those unit conversions.
- Parameters:
scaling (float, np.ndarray, or unyt quantity) – Scaling factor supplied by the caller.
get_nu (Callable[[], unyt_array]) – Callable returning the frequency coordinate for the lines.
lum_units (unyt.Unit) – Units of the luminosity array.
cont_units (unyt.Unit) – Units of the continuum array.
- Returns:
(scaling_lum, scaling_cont)as raw values.- Return type:
tuple
- synthesizer.emissions.scaling.normalise_scale_masks(mask, lam_mask, shape)[source]¶
Normalise row and wavelength masks for scaling helpers.
- Parameters:
mask (np.ndarray or None) – Optional mask supplied by the caller.
lam_mask (np.ndarray or None) – Optional explicit wavelength mask.
shape (tuple) – Target array shape.
- Returns:
(mask, lam_mask)in a form the scaling helper understands.- Return type:
tuple
- synthesizer.emissions.scaling.normalise_scaling_for_units(scaling, units)[source]¶
Convert a scaling factor into raw values compatible with
units.- Parameters:
scaling (float, np.ndarray, or unyt quantity) – Scaling factor supplied by the caller.
units (unyt.Unit) – Units expected by the target array.
- Returns:
Raw scaling values with any units stripped.
- Return type:
float or np.ndarray
- synthesizer.emissions.scaling.scale_array(array, scaling, mask=None, lam_mask=None, nthreads=1, out=None)[source]¶
Scale an emission array with optional row and wavelength masks.
- Parameters:
array (np.ndarray) – The array to scale.
scaling (float or np.ndarray) – The scaling to apply.
mask (np.ndarray or None) – Optional row or element mask.
lam_mask (np.ndarray or None) – Optional wavelength mask.
nthreads (int) – The number of OpenMP threads available to compatible kernels.
out (np.ndarray or None) – Optional output buffer. When provided and compatible with the fast 2D path the result is written directly into this array, avoiding an allocation.
- Returns:
The scaled array (may be
outif the fast path was used).- Return type:
np.ndarray
- synthesizer.emissions.scaling.scale_inplace(array, scaling, mask=None, lam_mask=None, nthreads=1)[source]¶
Scale an array into its existing buffer.
- Parameters:
array (np.ndarray) – Raw array to mutate.
scaling (float or np.ndarray) – Raw scaling values.
mask (np.ndarray or None) – Optional row or element mask.
lam_mask (np.ndarray or None) – Optional wavelength mask.
nthreads (int) – The number of OpenMP threads available to compatible kernels.
- Returns:
The mutated
arraybuffer.- Return type:
np.ndarray
- synthesizer.emissions.scaling.scale_line_arrays(luminosity, continuum, scaling_lum, scaling_cont, mask=None, lam_mask=None, nthreads=1, out_lum=None, out_cont=None)[source]¶
Scale a luminosity/continuum pair, using the fused kernel when useful.
This keeps the Python-side dispatch rules for line scaling in one place. When both scaling arrays are 1D row factors we hand straight over to the fused C++ kernel; otherwise we delegate to
scale_arrayfor each array.- Parameters:
luminosity (np.ndarray) – Raw luminosity array.
continuum (np.ndarray) – Raw continuum array.
scaling_lum (float or np.ndarray) – Raw luminosity scaling values.
scaling_cont (float or np.ndarray) – Raw continuum scaling values.
mask (np.ndarray or None) – Optional row or element mask.
lam_mask (np.ndarray or None) – Optional wavelength mask.
nthreads (int) – The number of OpenMP threads available to compatible kernels.
out_lum (np.ndarray or None) – Optional output buffer for luminosity.
out_cont (np.ndarray or None) – Optional output buffer for continuum.
- Returns:
Tuple of scaled
(luminosity, continuum)arrays.- Return type:
tuple
- synthesizer.emissions.scaling.scale_to_quantity(array, scaling, units, mask=None, lam_mask=None, nthreads=1)[source]¶
Scale an array and wrap the result in units without copying again.
- Parameters:
array (np.ndarray) – Raw array to scale.
scaling (float or np.ndarray) – Raw scaling values.
units (unyt.Unit) – Units to attach to the scaled result.
mask (np.ndarray or None) – Optional row or element mask.
lam_mask (np.ndarray or None) – Optional wavelength mask.
nthreads (int) – The number of OpenMP threads available to compatible kernels.
- Returns:
Scaled result wrapped in
units.- Return type:
unyt_array