synthesizer.load_data.utils¶
Utilities for data loading methods.
These utilities are used through the load_data module as helpers for loading data from different simulations sources.
Examples usage:
lengths = np.array([10, 20, 30]) begin, end = get_begin_end_pointers(lengths) print(begin) # Output: [ 0 10 30]
table = age_lookup_table(ages, redshift=0.5, delta_a=0.1) print(table) # Output: (array([0.1, 0.2, 0.3]), array([10., 20., 30.]))
ages = lookup_age(0.2, table[0], table[1])
Functions
- synthesizer.load_data.utils.age_lookup_table(cosmo, redshift=0.0, delta_a=0.001, low_lim=0.0001)[source]¶
Create a look-up table for age as a function of scale factor.
Defaults to start at the lower resolution limit (delta_a), and proceeds in steps of delta-a until the scale factor given by the input redshift minus the low_lim.
- Parameters:
cosmo (astropy.cosmology) – Astropy cosmology object.
redshift (float) – Redshift of the snapshot.
delta_a (int) – Scale factor resolution to approximate.
low_lim (float) – Lower limit of scale factor.
- Returns:
Array of scale factors. age (unyt_array of float):
Array of ages (Gyr).
- Return type:
scale_factor (np.ndarray of float)
Examples using synthesizer.load_data.utils.age_lookup_table¶
- synthesizer.load_data.utils.bin_overlap_matrix(lo, hi, grid_ages)[source]¶
Fraction of each top-hat age bin falling in each grid age cell.
Cell edges follow
parametric.Stars: zero, the linear midpoints between adjacent grid ages, then infinity so mass older than the grid is kept in the last cell. A zero-width bin is an instantaneous burst placed wholly in the cell containing its age.- Parameters:
lo (np.ndarray of float) – Lower (younger) edge of each bin, in years.
hi (np.ndarray of float) – Upper (older) edge of each bin, in years.
grid_ages (np.ndarray of float) – Ascending grid ages, in years.
- Returns:
(nbin, ngrid) overlap fractions.
- Return type:
np.ndarray of float
- synthesizer.load_data.utils.cast_component_dtype(component, dtype)[source]¶
Cast floating-point arrays in component input data to one dtype.
- Parameters:
component (mapping or None) – Component constructor arguments from any data source.
dtype (numpy dtype) – Target floating-point dtype.
- Returns:
Shallow copy with floating-point arrays cast, preserving units.
- Return type:
dict or None
- synthesizer.load_data.utils.cic_matrix(values, grid)[source]¶
Cloud-in-cell weights placing values on an ascending grid.
Values beyond the grid are clamped to the end points.
- Parameters:
values (np.ndarray of float) – The values to place (e.g. log10 metallicities).
grid (np.ndarray of float) – Ascending grid coordinates.
- Returns:
(nvalues, ngrid) weights, each row summing to 1.
- Return type:
np.ndarray of float
- synthesizer.load_data.utils.get_begin_end_pointers(length)[source]¶
Find the beginning and ending indices from a length array.
- Parameters:
length (np.ndarray of int) – The number of particles in each galaxy.
- Returns:
Beginning indices. end (np.ndarray of int): Ending indices.
- Return type:
begin (np.ndarray of int)
- synthesizer.load_data.utils.lookup_age(scale_factor, scale_factors, ages)[source]¶
Look up the age given a scale factor.
- Parameters:
scale_factor (np.ndarray of float) – Scale factors to convert to ages.
scale_factors (np.ndarray of float) – Array of lookup scale factors.
ages (unyt_array of float) – Array of lookup ages.
- Returns:
Age based on the input scale factor/s.
- Return type:
age (float)
Examples using synthesizer.load_data.utils.lookup_age¶
- synthesizer.load_data.utils.split_age_bins(lo, hi, grid_ages)[source]¶
Split top-hat age bins at every grid age they contain.
A bin narrower than the grid spacing is returned unchanged (one segment at its midpoint). Wider bins become one segment per grid age they straddle, so a constant SFR across the bin is resolved by the grid. A zero-width bin is an instantaneous burst: one segment at its age.
- Parameters:
lo (np.ndarray of float) – Lower (younger) edge of each bin, in years.
hi (np.ndarray of float) – Upper (older) edge of each bin, in years.
grid_ages (np.ndarray of float) – Ascending grid ages, in years.
- Returns:
(bin index, midpoint age, width fraction) per segment.
- Return type:
tuple