Skip to content
Draft
Changes from 3 commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
073e272
Added angular_variable_depth_mask and angular_los_variable_depth_mask…
mwiet Feb 24, 2025
3f87848
Added new classes to the file's index
mwiet Feb 24, 2025
aa36f81
pre-commit.ci: style fixes
pre-commit-ci[bot] Feb 24, 2025
c7393fd
Updated class to follow CapWords convention
mwiet Feb 24, 2025
31a5335
Updated class to follow CapWords convention
mwiet Feb 24, 2025
cfdaa58
Updated classes in index to follow CapWords convention
mwiet Feb 24, 2025
51b0c1b
Fixed typing of variables throughout
mwiet Feb 24, 2025
d5e5863
Fixed docstrings throughout
mwiet Feb 24, 2025
2a7ea91
Changed np.trapz to np.trapezoid
mwiet Feb 24, 2025
d3eed2f
Fixed ValueError to TypeError
mwiet Feb 24, 2025
07ccec4
Added new citations for glass.observations.AngularLosVariableDepthMask
mwiet Feb 24, 2025
7ce0c2d
Removed references from AngularLosVariableDepthMask docstring and mov…
mwiet Feb 24, 2025
375d148
Fixed outstanding typing issues
mwiet Feb 24, 2025
85a337e
Merge branch 'main' into mwiet/variable-depth
paddyroddy Feb 24, 2025
5a79a47
Fixed np.trapezoid typo
mwiet Feb 24, 2025
37f2183
Fixed np.trapezoid typo
mwiet Feb 24, 2025
c5649b2
Loaded Callable type object
mwiet Feb 24, 2025
0467b0d
Added excemption to PLR0913/too many arguments
mwiet Feb 24, 2025
78d7757
Fixed typo
mwiet Feb 24, 2025
5b1268d
Removd whitespace
mwiet Feb 24, 2025
d5a0491
Added excemption to PLR0913/too many arguments
mwiet Feb 24, 2025
1a1ff3f
Fixed pre-commit issues
mwiet Feb 24, 2025
68d5089
Added excemption to PLR0913/too many arguments
mwiet Feb 24, 2025
7b637f8
Tidy up docstrings
paddyroddy Feb 25, 2025
585ea65
Run pre-commit
paddyroddy Feb 25, 2025
1847e05
Add comma
paddyroddy Feb 25, 2025
b298f4e
Suppress no any return
paddyroddy Feb 25, 2025
368b086
Adjusted typing of vardepth_tomo_functions
mwiet Feb 25, 2025
746e4d8
Ensured consitency in the typing on zbins
mwiet Feb 25, 2025
fb9f83f
Tidied up line length
mwiet Feb 25, 2025
b094792
pre-commit.ci: style fixes
pre-commit-ci[bot] Feb 25, 2025
36d6f0d
Merge branch 'main' into mwiet/variable-depth
paddyroddy Mar 3, 2025
59b17e0
Add notebook from @mwiet and clear output
paddyroddy Mar 6, 2025
6be4bfd
Fix surname
paddyroddy Mar 6, 2025
9c44912
Tidy up imports
paddyroddy Mar 7, 2025
65eecc4
Fix line length
paddyroddy Mar 7, 2025
7e0f2c4
Fix
paddyroddy Mar 7, 2025
56136cd
Fix [NPY002](https://docs.astral.sh/ruff/rules/numpy-legacy-random/)
paddyroddy Mar 7, 2025
2267bee
Remove `plt.show`
paddyroddy Mar 7, 2025
cab715e
Better formatting
paddyroddy Mar 7, 2025
df4e5fc
Import direct from namespace
paddyroddy Mar 7, 2025
3fbd7d0
Suppress plot output
paddyroddy Mar 7, 2025
dd60d4f
Reduce down to one `mollview` plot
paddyroddy Mar 7, 2025
4134346
Add rng keyword arg where possible
paddyroddy Mar 7, 2025
3228dfe
Remove duplicate rng generation
paddyroddy Mar 7, 2025
e518883
Turn off warning
paddyroddy Mar 7, 2025
059ac59
Move notebook
paddyroddy Mar 7, 2025
6f81ecb
Add title
paddyroddy Mar 7, 2025
d61e5f2
Clear output
paddyroddy Mar 7, 2025
b56028b
gh-578: mutable argument should be empty list rather than `None`
paddyroddy Mar 10, 2025
5bc2588
Merge branch 'paddy/issue-578' into mwiet/variable-depth
paddyroddy Mar 10, 2025
a9f32e4
Merge branch 'main' into mwiet/variable-depth
paddyroddy Mar 10, 2025
9bb8f8f
Fix import
paddyroddy Mar 10, 2025
67e028f
Remove `nbstripout` temporarily
paddyroddy Mar 12, 2025
e564a8e
Merge branch 'main' into mwiet/variable-depth
paddyroddy Mar 12, 2025
cd71581
Fix notebook
paddyroddy Mar 12, 2025
996e7e2
Restore
paddyroddy Mar 12, 2025
c8d1f5a
Add RNG
paddyroddy Mar 12, 2025
ab38ee3
Speed up sampling
paddyroddy Mar 12, 2025
d551fc3
Run notebook
paddyroddy Mar 12, 2025
d53e03c
Merge branch 'main' into mwiet/variable-depth
paddyroddy Mar 13, 2025
683b458
Re-use maps
paddyroddy Mar 13, 2025
a5e4c0d
Fix notebook running
paddyroddy Mar 13, 2025
eb412f7
Increase timeout
paddyroddy Mar 13, 2025
21f8cce
Change lmax
paddyroddy Mar 13, 2025
a4efa52
Revert "Increase timeout"
paddyroddy Mar 13, 2025
8746064
Test AngularVariableDepthMask
paddyroddy Mar 13, 2025
3e31f06
Rename notebook
paddyroddy Mar 14, 2025
002785e
2 digit years
paddyroddy Mar 14, 2025
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
191 changes: 191 additions & 0 deletions glass/observations.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
----------

.. autofunction:: vmap_galactic_ecliptic
.. class:: angular_variable_depth_mask
.. class:: angular_los_variable_depth_mask
Comment thread
mwiet marked this conversation as resolved.
Outdated

""" # noqa: D400

Expand Down Expand Up @@ -328,3 +330,192 @@ def tomo_nz_gausserr(
binned_nz *= nz

return binned_nz # type: ignore[no-any-return]


class angular_variable_depth_mask:
Comment thread
mwiet marked this conversation as resolved.
Outdated
r"""Variable depth mask for tomographic bins.

This class allows to create a mask with a different variable depth mask in the angular direction for each tomographic bin.
Comment thread
mwiet marked this conversation as resolved.
Outdated

Parameters
----------
vardepth_map : array_like
Map of variable which traces the depth per tomographic bin.
n_bins : int
Number of tomographic bins.
zbins : array_like
Shell redshift limits.
"""

def __init__(self, vardepth_map, n_bins, zbins):
self.vardepth_map = vardepth_map
self.n_bins = n_bins
self.zbins = zbins
Comment thread
mwiet marked this conversation as resolved.
Outdated

def test_index(self, index):
Comment thread
mwiet marked this conversation as resolved.
Outdated
Comment thread
mwiet marked this conversation as resolved.
Outdated
r"""Test the index for validity."""
if not isinstance(index, tuple):
raise ValueError("Index must be an tuple of two integers")
Comment thread
mwiet marked this conversation as resolved.
Outdated

if index[0] >= self.n_bins:
raise ValueError("Leading index cannot exceed number of tomographic bins")

if index[1] >= len(self.zbins):
raise ValueError("Trailing index cannot exceed number of shells")

def __getitem__(self, index):
r"""Get the mask for the given index.

Parameters
----------
index : tuple
Indices of the tomographic bin and shell pair.

Returns
-------
mask : array_like
Mask for the given index.

Raises
------
ValueError
If the index is invalid.
Comment thread
mwiet marked this conversation as resolved.
Outdated

"""
self.test_index(index)

return self.vardepth_map[index[0]]


class angular_los_variable_depth_mask(angular_variable_depth_mask):
Comment thread
mwiet marked this conversation as resolved.
Outdated
r"""Variable depth mask for tomographic bins.

This class allows to create a mask with a different variable depth mask in both the angular and the line-of-sight directions for each tomographic bin.
Comment thread
mwiet marked this conversation as resolved.
Outdated

Parameters
----------
vardepth_map : array_like
Map of variable which traces the depth per tomographic bin. If vardepth_tomo_functions is not provided, the values are treated like a map of galaxy count ratios.
n_bins : int
Number of tomographic bins.
zbins : array_like
Shell redshift limits.
ztomo : array_like, optional
Tomographic redshift bin limits.
dndz : array_like, optional
Redshift distributions per tomographic bin.
z : array_like, optional
Redshift domain of dndz.
dndz_vardepth : array_like
Redshift distribution affected by variable depth (n_bins x len(vardepth_values) x len(z)).
vardepth_values : array_like
Variable depth tracer domain/values of dndz_vardepth.
vardepth_los_tracer : array_like, optional
Map of the variable depth tracer for line-of-sight direction. If provided, it is assumed to cover the same domain as vardepth_values.
vardepth_tomo_functions : array_like, optional
List of functions which map the input vardepth_map to the ratio between the galaxy count due to the variable depth and the galaxy count without variable depth (for each tomographic bin). If provided, it is assumed that there is one vardepth_map which traces the variable depth for all tomographic bins.
Comment thread
mwiet marked this conversation as resolved.
Outdated

References
----------
.. [1] Joachimi B., Lin, C.-A., et al., 2021, A&A, 646, A129.
doi:10.1051/0004-6361/202038831
.. [2] von Wietesheim-Kramsta M., Lin, K., et al., 2024, A&A, 695, A223.
doi:10.1051/0004-6361/202450487
Comment thread
mwiet marked this conversation as resolved.
Outdated
"""

def __init__(
self,
vardepth_map,
n_bins,
zbins,
ztomo,
dndz,
z,
dndz_vardepth,
vardepth_values,
vardepth_los_tracer=None,
vardepth_tomo_functions=None,
Comment thread
mwiet marked this conversation as resolved.
Outdated
):
super().__init__(vardepth_map, n_bins, zbins)
Comment thread
mwiet marked this conversation as resolved.
self.ztomo = ztomo
self.dndz = dndz
self.z = z
self.dndz_vardepth = dndz_vardepth
self.vardepth_values = vardepth_values
self.vardepth_los_tracer = vardepth_los_tracer
self.vardepth_tomo_functions = vardepth_tomo_functions

if vardepth_tomo_functions is not None:
self.vardepth_map = np.atleast_2d(vardepth_map).reshape(1, -1)

def get_los_fraction(self, index):
r"""Gets the fraction of galaxies affected by variable depth in the line-of-sight direction for the given tomographic bin and shell.
Comment thread
mwiet marked this conversation as resolved.
Outdated

Parameters
----------
index : tuple
Indices of the tomographic bin and shell pair.

Returns
-------
fraction_vardepth : array_like
Fraction of galaxies affected by variable depth in the line-of-sight direction.
Comment thread
mwiet marked this conversation as resolved.
Outdated
"""
is_in_shell = (self.zbins[index[1]][0] < self.z) & (
self.z <= self.zbins[index[1]][1]
)

n_gal_in_tomo_vardepth = np.trapz(
Comment thread
mwiet marked this conversation as resolved.
Outdated
self.dndz_vardepth[index[0]][:, is_in_shell], self.z[is_in_shell]
)
n_gal_in_tomo = np.trapz(self.dndz[index[0]][is_in_shell], self.z[is_in_shell])
fraction_vardepth = np.divide(
n_gal_in_tomo_vardepth,
n_gal_in_tomo,
out=np.ones_like(n_gal_in_tomo_vardepth),
where=n_gal_in_tomo != 0,
)

return fraction_vardepth

def __getitem__(self, index):
r"""Get the mask for the given index.

Parameters
----------
index : tuple
Indices of the tomographic bin and shell pair.

Returns
-------
mask : array_like
Mask for the given index.
Comment thread
mwiet marked this conversation as resolved.
Outdated

Raises
------
ValueError
If the index is invalid.

"""
self.test_index(index)

if self.vardepth_tomo_functions is None:
angular_vardepth_map = angular_tracer_map = self.vardepth_map[index[0]]
else:
angular_vardepth_map = self.vardepth_tomo_functions[index[0]](
self.vardepth_map[0]
)
angular_tracer_map = self.vardepth_map[0]

los_fraction_vardepth = self.get_los_fraction(index)

if self.vardepth_los_tracer is None:
los_vardepth_map = np.interp(
angular_tracer_map, self.vardepth_values, los_fraction_vardepth
)
else:
los_vardepth_map = np.interp(
self.vardepth_los_tracer, self.vardepth_values, los_fraction_vardepth
)

return np.multiply(angular_vardepth_map, los_vardepth_map)