Skip to content

skais_mapper.cosmology

Utilities for handling cosmology-dependent calculations.

Classes:

Name Description
CosmoModel

Set cosmological parameter for distance calculations, mass projections, etc.

CosmoModel dataclass

CosmoModel(
    omega_m: float = 0.279952,
    omega_l: float = 0.72,
    omega_k: float = 0.0,
    z: float = 0.0,
    c: ac.Constant = (lambda: ac.c)(),
    h: float = 0.718,
    u_H0: au.CompositeUnit = au.km / au.s / au.Mpc,
)

Set cosmological parameter for distance calculations, mass projections, etc.

Parameters:

Name Type Description Default
omega_m float

matter energy fraction

0.279952
omega_l float

dark energy fraction

0.72
omega_k float

curvature fraction

0.0
omega_r float

radiation energy fraction (will be calculated assuming flat universe if not given)

required
h float

'little' H (H0 / 100 km/s/Mpc)

0.718
c ac.Constant

speed of light

(lambda: ac.c)()
z float

redshift

0.0

Methods:

Name Description
H

The Hubble parameter at a given scale factor a.

arcsec2kpc

Angular distance d_z from a redshift z within given cosmology.

d_comov

Calculate the comoving distance from scale factor (for solve_ivp).

d_z

Angular distance d_z from a redshift z within given cosmology.

d_z2kpc

Given scale-less distance d, return scaled distance c/H0 * d [kpc].

Attributes:

Name Type Description
H0 au.Quantity

The Hubble constant getter.

a float

The scale parameter getter.

omega_r float

The radiation density parameter getter.

rho_crit au.Quantity

The critical density getter.

H0 property writable

H0: au.Quantity

The Hubble constant getter.

a property writable

a: float

The scale parameter getter.

omega_r property writable

omega_r: float

The radiation density parameter getter.

rho_crit property

rho_crit: au.Quantity

The critical density getter.

H

H(a: float | None = None) -> au.Quantity

The Hubble parameter at a given scale factor a.

Parameters:

Name Type Description Default
a float | None

scale factor

None

Returns:

Type Description
float

value of the Hubble parameter

Source code in skais_mapper/cosmology.py
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
def H(self, a: float | None = None) -> au.Quantity:
    """The Hubble parameter at a given scale factor `a`.

    Args:
        a: scale factor

    Returns:
        (float): value of the Hubble parameter
    """
    if a is None and self.z and self.a:
        a = self.a
    elif a is None:
        a = 1.0
    return (
        self.H0
        * (self.omega_m / a**3 + self.omega_r / a**4 + self.omega_k / a**2 + self.omega_l)
        ** 0.5
    )

arcsec2kpc staticmethod

arcsec2kpc(
    z: float,
    dist_z: float | None = None,
    cosmo_model: TCosmo | None = None,
) -> au.Quantity

Angular distance d_z from a redshift z within given cosmology.

Parameters:

Name Type Description Default
z float

redshift

required
dist_z float | None

scaled comoving distance

None
cosmo_model TCosmo | None

cosmological parameter lookup class

None
Return

(float): kpc/arcsec scaling within given redshift and cosmology

Source code in skais_mapper/cosmology.py
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
@staticmethod
def arcsec2kpc(
    z: float,
    dist_z: float | None = None,
    cosmo_model: TCosmo | None = None,
) -> au.Quantity:
    """Angular distance d_z from a redshift z within given cosmology.

    Args:
        z: redshift
        dist_z: scaled comoving distance
        cosmo_model: cosmological parameter lookup class

    Return:
        (float): kpc/arcsec scaling within given redshift and cosmology
    """
    if dist_z is None:
        dist_z = CosmoModel.d_z(z, cosmo_model=cosmo_model, scaled=True)
    d_kpc_arcsec = (dist_z / au.rad).to(au.kpc / au.arcsec)
    return d_kpc_arcsec

d_comov staticmethod

d_comov(
    a: float, r: float, cosmo_model: TCosmo | None = None
) -> au.Quantity

Calculate the comoving distance from scale factor (for solve_ivp).

Parameters:

Name Type Description Default
a float

scale factor

required
r float

distance

required
cosmo_model TCosmo | None

cosmological parameter lookup class

None

Returns:

Type Description
float

comoving radial distance (scale-free)

Source code in skais_mapper/cosmology.py
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
@staticmethod
def d_comov(a: float, r: float, cosmo_model: TCosmo | None = None) -> au.Quantity:
    """Calculate the comoving distance from scale factor (for solve_ivp).

    Args:
        a: scale factor
        r: distance
        cosmo_model: cosmological parameter lookup class

    Returns:
        (float): comoving radial distance (scale-free)
    """
    if cosmo_model is None:
        cosmo_model = CosmoModel()
    return 1.0 / (a * a * cosmo_model.H(a))

d_z staticmethod

d_z(
    z: float | None = None,
    cosmo_model: TCosmo | None = None,
    scaled: bool = False,
) -> au.Quantity

Angular distance d_z from a redshift z within given cosmology.

Parameters:

Name Type Description Default
z float | None

redshift

None
cosmo_model TCosmo | None

cosmological parameter lookup class

None
scaled bool

return result with c/H0 in units of kpc

False
Return

(float): apparent distance d_z

Source code in skais_mapper/cosmology.py
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
@staticmethod
def d_z(
    z: float | None = None,
    cosmo_model: TCosmo | None = None,
    scaled: bool = False,
) -> au.Quantity:
    """Angular distance d_z from a redshift z within given cosmology.

    Args:
        z: redshift
        cosmo_model: cosmological parameter lookup class
        scaled: return result with c/H0 in units of kpc

    Return:
        (float): apparent distance d_z
    """
    if cosmo_model is None:
        cosmo_model = CosmoModel()
    comov = partial(CosmoModel.d_comov, cosmo_model=cosmo_model)
    if z is None and cosmo_model.a:
        a = cosmo_model.a
    else:
        a = 1.0 / (1.0 + z)
    a_lim = [a, 1]
    res = solve_ivp(comov, a_lim, [0])
    if res["success"]:
        r = res["y"][0]
        D = a * (r[-1] - r[0])
        if scaled:
            return CosmoModel.d_z2kpc(D)
        return D
    raise ValueError(f"No solution found for the inputs z={z}, " f"cosmo_model={cosmo_model}")

d_z2kpc staticmethod

d_z2kpc(
    distance: float | np.ndarray,
    cosmo_model: TCosmo | None = None,
) -> au.Quantity

Given scale-less distance d, return scaled distance c/H0 * d [kpc].

Parameters:

Name Type Description Default
distance float | np.ndarray

scale-less distance

required
cosmo_model TCosmo | None

cosmological parameter lookup class

None
Source code in skais_mapper/cosmology.py
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
@staticmethod
def d_z2kpc(
    distance: float | np.ndarray, cosmo_model: TCosmo | None = None
) -> au.Quantity:
    """Given scale-less distance d, return scaled distance c/H0 * d [kpc].

    Args:
        distance: scale-less distance
        cosmo_model: cosmological parameter lookup class
    """
    if cosmo_model is None:
        cosmo_model = CosmoModel()
    c = cosmo_model.c
    H0 = cosmo_model.H0
    return (distance * c / H0).to(au.kpc)