lfkit.utils.units module#

Unit conversion utilities used across LFKit.

This module provides small, self-contained helpers for converting between astronomical and cosmological unit systems commonly needed in luminosity function and correction calculations.

Currently supported conversions include:

  • Megaparsec to kilometers.

  • Gigayear to seconds.

  • Hubble constant from km/s/Mpc to 1/Gyr.

These helpers are intentionally lightweight and avoid external dependencies. They are designed for internal use by cosmology and correction modules.

lfkit.utils.units.h0_km_s_mpc_to_gyr_inv(h0_km_s_mpc)[source]#

Convert a Hubble constant from km/s/Mpc to 1/Gyr.

Parameters:

h0_km_s_mpc (float) – Hubble constant in units of km/s/Mpc.

Returns:

The Hubble constant expressed in inverse gigayears (1/Gyr).

Return type:

float

lfkit.utils.units.km_per_mpc()[source]#

Return the number of kilometers in one megaparsec.

Returns:

Conversion factor from megaparsecs (Mpc) to kilometers (km).

Return type:

float

lfkit.utils.units.mag_to_maggies(m_ab)[source]#

Converts AB magnitudes to maggies (linear flux units).

In the AB system:

m_AB = -2.5 * log10(f_nu) - 48.6

In kcorrect-style workflows, fluxes are expressed in maggies:

f_maggies = 10**(-0.4 * m_AB)

where 1 maggie corresponds to m_AB = 0.

Parameters:

m_ab (ndarray) – AB magnitudes. Can be scalar-like or array-like.

Returns:

Fluxes in maggies with the same shape as the input.

Return type:

ndarray

Notes

This is a purely algebraic transformation with no cosmology dependence. The returned values are linear flux densities in arbitrary units normalized such that m_AB = 0 corresponds to f = 1 maggie.

lfkit.utils.units.magerr_to_ivar_maggies(m_ab, sigma_m)[source]#

Converts magnitude uncertainties to inverse variance in maggies.

Flux uncertainties are computed using first-order error propagation. Given:

f = 10**(-0.4 * m)

the derivative is:

df/dm = -0.4 * ln(10) * f

so the propagated flux uncertainty is approximated as:

sigma_f = (0.4 * ln(10)) * f * sigma_m

and the inverse variance is:

ivar = 1 / sigma_f**2

Parameters:
  • m_ab (ndarray) – AB magnitudes.

  • sigma_m (ndarray) – 1σ magnitude uncertainties corresponding to m_ab.

Returns:

Inverse variance of the fluxes in maggies (1 / sigma_f**2). Entries are set to zero where the propagated uncertainty is non-finite or non-positive.

Return type:

ndarray

Notes

Uses linear (first-order) error propagation and assumes small magnitude errors. No covariance between bands is included. Non-finite or zero uncertainties yield zero inverse variance.

lfkit.utils.units.maggies_to_mag(maggies, *, floor=1e-300)[source]#

Convert maggies to magnitudes with a safety floor.

Parameters:
  • maggies (ndarray) – Fluxes in maggies.

  • floor (float) – Minimum value to avoid log(0).

Returns:

Magnitudes in AB system.

Return type:

ndarray

lfkit.utils.units.sec_per_gyr()[source]#

Return the number of seconds in one gigayear.

Returns:

Conversion factor from gigayears (Gyr) to seconds (s).

Return type:

float