Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion glass/cosmology.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ class Cosmology(
cosmology.api.HasInverseComovingDistance[AnyArray, AnyArray], # ty: ignore[invalid-type-arguments]
cosmology.api.HasLittleH[AnyArray], # ty: ignore[invalid-type-arguments]
cosmology.api.HasOmegaM0[AnyArray], # ty: ignore[invalid-type-arguments]
cosmology.api.HasOmegaM[AnyArray, AnyArray], # ty: ignore[invalid-type-arguments]
cosmology.api.HasTransverseComovingDistance[AnyArray, AnyArray], # ty: ignore[invalid-type-arguments]
typing.Protocol,
):
"""Cosmology protocol for GLASS."""


class CosmologyWithOmegaM(
Cosmology,
cosmology.api.HasOmegaM[AnyArray, AnyArray], # ty: ignore[invalid-type-arguments]
):
Comment thread
Copilot marked this conversation as resolved.
Comment thread
paddyroddy marked this conversation as resolved.
"""Cosmology protocol for GLASS with OmegaM."""
19 changes: 11 additions & 8 deletions glass/shells.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
from types import ModuleType

from glass._types import FloatArray, IntArray, UnifiedGenerator
from glass.cosmology import Cosmology
from glass.cosmology import Cosmology, CosmologyWithOmegaM


@dataclasses.dataclass
Expand Down Expand Up @@ -141,12 +141,12 @@ class DensityWeight:

Attributes
----------
cosmo
Cosmology instance.
cosmo_omega_m
Cosmology instance with OmegaM.
Comment thread
paddyroddy marked this conversation as resolved.

"""

cosmo: Cosmology
cosmo_omega_m: CosmologyWithOmegaM

def __call__(self, z: FloatArray) -> FloatArray:
"""
Expand All @@ -163,11 +163,14 @@ def __call__(self, z: FloatArray) -> FloatArray:

"""
return (
self.cosmo.critical_density0
* self.cosmo.Omega_m(z)
* (self.cosmo.transverse_comoving_distance(z) / self.cosmo.hubble_distance)
self.cosmo_omega_m.critical_density0
* self.cosmo_omega_m.Omega_m(z)
* (
self.cosmo_omega_m.transverse_comoving_distance(z)
Comment thread
paddyroddy marked this conversation as resolved.
Outdated
/ self.cosmo_omega_m.hubble_distance
)
** 2
/ self.cosmo.H_over_H0(z)
/ self.cosmo_omega_m.H_over_H0(z)
)


Expand Down
6 changes: 3 additions & 3 deletions tests/core/test_shells.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from types import ModuleType

from glass._types import UnifiedGenerator
from glass.cosmology import Cosmology
from glass.cosmology import Cosmology, CosmologyWithOmegaM


@pytest.fixture(scope="session")
Expand Down Expand Up @@ -103,13 +103,13 @@ def test_volume_weight(
xpx.testing.assert_less(w[:-1], w[1:])


def test_density_weight(cosmo: Cosmology) -> None:
def test_density_weight(cosmo_omega_m: CosmologyWithOmegaM) -> None:
Comment thread
paddyroddy marked this conversation as resolved.
Outdated
"""Add unit tests for :class:`glass.DensityWeight`."""
z = np.linspace(0, 1, 6)

# check shape

w = glass.DensityWeight(cosmo)(z)
w = glass.DensityWeight(cosmo_omega_m)(z)
assert w.shape == z.shape

# check first value is 0
Expand Down
Loading