From 26fbb3d9e2c2802248c98ca8d789c1d1933598b8 Mon Sep 17 00:00:00 2001 From: Patrick Roddy Date: Tue, 7 Jul 2026 16:58:42 +0100 Subject: [PATCH 1/6] Add CosmologyWithOmegaM class --- glass/cosmology.py | 9 ++++++++- glass/shells.py | 6 +++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/glass/cosmology.py b/glass/cosmology.py index 40e0cb1d2..0ca4da014 100644 --- a/glass/cosmology.py +++ b/glass/cosmology.py @@ -16,8 +16,15 @@ 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] + typing.Protocol, +): + """Cosmology protocol for GLASS with OmegaM.""" diff --git a/glass/shells.py b/glass/shells.py index 954718900..212936d92 100644 --- a/glass/shells.py +++ b/glass/shells.py @@ -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 @@ -142,11 +142,11 @@ class DensityWeight: Attributes ---------- cosmo - Cosmology instance. + Cosmology instance with OmegaM. """ - cosmo: Cosmology + cosmo: CosmologyWithOmegaM def __call__(self, z: FloatArray) -> FloatArray: """ From ad364f1bd661965a491ad5257fd53579ac2683b1 Mon Sep 17 00:00:00 2001 From: Patrick Roddy Date: Tue, 7 Jul 2026 17:04:44 +0100 Subject: [PATCH 2/6] Fix tests --- tests/core/test_shells.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/core/test_shells.py b/tests/core/test_shells.py index 831773ce4..94448aee9 100644 --- a/tests/core/test_shells.py +++ b/tests/core/test_shells.py @@ -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") @@ -103,7 +103,7 @@ def test_volume_weight( xpx.testing.assert_less(w[:-1], w[1:]) -def test_density_weight(cosmo: Cosmology) -> None: +def test_density_weight(cosmo: CosmologyWithOmegaM) -> None: """Add unit tests for :class:`glass.DensityWeight`.""" z = np.linspace(0, 1, 6) From c81c39f01d0652e1c6fdf8bb6cf43e0f565adf25 Mon Sep 17 00:00:00 2001 From: Patrick Roddy Date: Tue, 7 Jul 2026 17:09:01 +0100 Subject: [PATCH 3/6] Remove duplicate `typing.Protocol` Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- glass/cosmology.py | 1 - 1 file changed, 1 deletion(-) diff --git a/glass/cosmology.py b/glass/cosmology.py index 0ca4da014..c9d8f4410 100644 --- a/glass/cosmology.py +++ b/glass/cosmology.py @@ -25,6 +25,5 @@ class Cosmology( class CosmologyWithOmegaM( Cosmology, cosmology.api.HasOmegaM[AnyArray, AnyArray], # ty: ignore[invalid-type-arguments] - typing.Protocol, ): """Cosmology protocol for GLASS with OmegaM.""" From 8583fccb22029241b83925ffa0149f1cc254da99 Mon Sep 17 00:00:00 2001 From: Patrick Roddy Date: Wed, 8 Jul 2026 12:34:00 +0100 Subject: [PATCH 4/6] Explicitly rename to omega_m --- glass/shells.py | 15 +++++++++------ tests/core/test_shells.py | 4 ++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/glass/shells.py b/glass/shells.py index 212936d92..00424975c 100644 --- a/glass/shells.py +++ b/glass/shells.py @@ -141,12 +141,12 @@ class DensityWeight: Attributes ---------- - cosmo + cosmo_omega_m Cosmology instance with OmegaM. """ - cosmo: CosmologyWithOmegaM + cosmo_omega_m: CosmologyWithOmegaM def __call__(self, z: FloatArray) -> FloatArray: """ @@ -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) + / self.cosmo_omega_m.hubble_distance + ) ** 2 - / self.cosmo.H_over_H0(z) + / self.cosmo_omega_m.H_over_H0(z) ) diff --git a/tests/core/test_shells.py b/tests/core/test_shells.py index 94448aee9..750e66a51 100644 --- a/tests/core/test_shells.py +++ b/tests/core/test_shells.py @@ -103,13 +103,13 @@ def test_volume_weight( xpx.testing.assert_less(w[:-1], w[1:]) -def test_density_weight(cosmo: CosmologyWithOmegaM) -> None: +def test_density_weight(cosmo_omega_m: CosmologyWithOmegaM) -> None: """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 From 1a725a3bd30edecf100e6df4ffede9202f66e711 Mon Sep 17 00:00:00 2001 From: Patrick Roddy Date: Wed, 8 Jul 2026 12:42:38 +0100 Subject: [PATCH 5/6] Rename to `cosmo` --- glass/shells.py | 13 +++++-------- tests/core/test_shells.py | 6 +++--- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/glass/shells.py b/glass/shells.py index 00424975c..b95b6c5dc 100644 --- a/glass/shells.py +++ b/glass/shells.py @@ -146,7 +146,7 @@ class DensityWeight: """ - cosmo_omega_m: CosmologyWithOmegaM + cosmo: CosmologyWithOmegaM def __call__(self, z: FloatArray) -> FloatArray: """ @@ -163,14 +163,11 @@ def __call__(self, z: FloatArray) -> FloatArray: """ return ( - self.cosmo_omega_m.critical_density0 - * self.cosmo_omega_m.Omega_m(z) - * ( - self.cosmo_omega_m.transverse_comoving_distance(z) - / self.cosmo_omega_m.hubble_distance - ) + self.cosmo.critical_density0 + * self.cosmo.Omega_m(z) + * (self.cosmo.transverse_comoving_distance(z) / self.cosmo.hubble_distance) ** 2 - / self.cosmo_omega_m.H_over_H0(z) + / self.cosmo.H_over_H0(z) ) diff --git a/tests/core/test_shells.py b/tests/core/test_shells.py index 750e66a51..831773ce4 100644 --- a/tests/core/test_shells.py +++ b/tests/core/test_shells.py @@ -16,7 +16,7 @@ from types import ModuleType from glass._types import UnifiedGenerator - from glass.cosmology import Cosmology, CosmologyWithOmegaM + from glass.cosmology import Cosmology @pytest.fixture(scope="session") @@ -103,13 +103,13 @@ def test_volume_weight( xpx.testing.assert_less(w[:-1], w[1:]) -def test_density_weight(cosmo_omega_m: CosmologyWithOmegaM) -> None: +def test_density_weight(cosmo: Cosmology) -> None: """Add unit tests for :class:`glass.DensityWeight`.""" z = np.linspace(0, 1, 6) # check shape - w = glass.DensityWeight(cosmo_omega_m)(z) + w = glass.DensityWeight(cosmo)(z) assert w.shape == z.shape # check first value is 0 From daf5c15849944fc238ed9827cb8f8c7950a9471d Mon Sep 17 00:00:00 2001 From: Patrick Roddy Date: Wed, 8 Jul 2026 12:43:15 +0100 Subject: [PATCH 6/6] Rename to combo --- glass/shells.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glass/shells.py b/glass/shells.py index b95b6c5dc..212936d92 100644 --- a/glass/shells.py +++ b/glass/shells.py @@ -141,7 +141,7 @@ class DensityWeight: Attributes ---------- - cosmo_omega_m + cosmo Cosmology instance with OmegaM. """