dsigma 1.2.3__tar.gz → 1.2.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {dsigma-1.2.3 → dsigma-1.2.4}/PKG-INFO +9 -10
- {dsigma-1.2.3 → dsigma-1.2.4}/README.md +4 -3
- {dsigma-1.2.3 → dsigma-1.2.4}/dsigma/__init__.py +1 -1
- {dsigma-1.2.3 → dsigma-1.2.4}/dsigma/helpers.py +3 -2
- {dsigma-1.2.3 → dsigma-1.2.4}/dsigma/jackknife.py +4 -4
- {dsigma-1.2.3 → dsigma-1.2.4}/dsigma/physics.py +26 -18
- {dsigma-1.2.3 → dsigma-1.2.4}/dsigma/precompute_engine.pyx +1 -1
- {dsigma-1.2.3 → dsigma-1.2.4}/dsigma/scripts/process_decade.py +2 -2
- {dsigma-1.2.3 → dsigma-1.2.4}/dsigma/stacking.py +54 -9
- {dsigma-1.2.3 → dsigma-1.2.4}/dsigma.egg-info/PKG-INFO +9 -10
- {dsigma-1.2.3 → dsigma-1.2.4}/dsigma.egg-info/requires.txt +2 -2
- {dsigma-1.2.3 → dsigma-1.2.4}/pyproject.toml +5 -6
- {dsigma-1.2.3 → dsigma-1.2.4}/tests/test_jackknife.py +8 -5
- {dsigma-1.2.3 → dsigma-1.2.4}/tests/test_physics.py +6 -10
- {dsigma-1.2.3 → dsigma-1.2.4}/tests/test_stacking.py +27 -15
- {dsigma-1.2.3 → dsigma-1.2.4}/LICENSE +0 -0
- {dsigma-1.2.3 → dsigma-1.2.4}/dsigma/precompute.py +0 -0
- {dsigma-1.2.3 → dsigma-1.2.4}/dsigma/scripts/process_des_y3.py +0 -0
- {dsigma-1.2.3 → dsigma-1.2.4}/dsigma/scripts/process_hsc_y3.py +0 -0
- {dsigma-1.2.3 → dsigma-1.2.4}/dsigma/scripts/process_kids_legacy.py +0 -0
- {dsigma-1.2.3 → dsigma-1.2.4}/dsigma.egg-info/SOURCES.txt +0 -0
- {dsigma-1.2.3 → dsigma-1.2.4}/dsigma.egg-info/dependency_links.txt +0 -0
- {dsigma-1.2.3 → dsigma-1.2.4}/dsigma.egg-info/entry_points.txt +0 -0
- {dsigma-1.2.3 → dsigma-1.2.4}/dsigma.egg-info/top_level.txt +0 -0
- {dsigma-1.2.3 → dsigma-1.2.4}/setup.cfg +0 -0
- {dsigma-1.2.3 → dsigma-1.2.4}/tests/test_full.py +0 -0
- {dsigma-1.2.3 → dsigma-1.2.4}/tests/test_precompute.py +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dsigma
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.4
|
|
4
4
|
Summary: A Galaxy-Galaxy Lensing Python Package
|
|
5
|
-
Author-email: "Johannes U. Lange" <jlange@american.edu>, Song Huang <shuang@tsinghua.edu.cn>
|
|
5
|
+
Author-email: "Johannes U. Lange" <jlange@american.edu>, Song Huang <shuang@tsinghua.edu.cn>, Alexie Leauthaud <alexie@ucsc.edu>
|
|
6
6
|
License-Expression: MIT
|
|
7
7
|
Project-URL: Homepage, https://github.com/johannesulf/dsigma
|
|
8
8
|
Project-URL: Documentation, https://dsigma.readthedocs.io
|
|
@@ -11,8 +11,6 @@ Project-URL: Issues, https://github.com/johannesulf/dsigma/issues
|
|
|
11
11
|
Project-URL: Changelog, https://github.com/johannesulf/dsigma/blob/main/CHANGELOG.md
|
|
12
12
|
Keywords: astronomy,weak-lensing
|
|
13
13
|
Classifier: Programming Language :: Python :: 3
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
16
14
|
Classifier: Programming Language :: Python :: 3.11
|
|
17
15
|
Classifier: Programming Language :: Python :: 3.12
|
|
18
16
|
Classifier: Programming Language :: Python :: 3.13
|
|
@@ -20,12 +18,12 @@ Classifier: Programming Language :: Python :: 3.14
|
|
|
20
18
|
Classifier: Operating System :: OS Independent
|
|
21
19
|
Classifier: Topic :: Scientific/Engineering :: Astronomy
|
|
22
20
|
Classifier: Intended Audience :: Science/Research
|
|
23
|
-
Requires-Python: >=3.
|
|
21
|
+
Requires-Python: >=3.11
|
|
24
22
|
Description-Content-Type: text/markdown
|
|
25
23
|
License-File: LICENSE
|
|
26
|
-
Requires-Dist: astropy
|
|
24
|
+
Requires-Dist: astropy>=8.0.0
|
|
27
25
|
Requires-Dist: astropy-healpix
|
|
28
|
-
Requires-Dist: numpy
|
|
26
|
+
Requires-Dist: numpy>=2.0.1
|
|
29
27
|
Requires-Dist: scikit-learn
|
|
30
28
|
Requires-Dist: scipy
|
|
31
29
|
Requires-Dist: tqdm
|
|
@@ -44,8 +42,7 @@ Dynamic: license-file
|
|
|
44
42
|

|
|
45
43
|

|
|
46
44
|
[](https://raw.githubusercontent.com/johannesulf/dsigma/main/LICENSE)
|
|
47
|
-
[](https://doi.org/10.5281/zenodo.20378642)
|
|
45
|
+
[](https://doi.org/10.5281/zenodo.20378642)
|
|
49
46
|
|
|
50
47
|
</div>
|
|
51
48
|
|
|
@@ -53,9 +50,11 @@ Dynamic: license-file
|
|
|
53
50
|
|
|
54
51
|

|
|
55
52
|
|
|
53
|
+
``dsigma`` focuses specifically on computing the excess surface density $\Delta\Sigma$ around a set of lens galaxies as a function of projected physical separation. In principle, the more general ``TreeCorr`` package can also be used to compute various two-point correlation functions, including galaxy-galaxy lensing. However, for galaxy-galaxy lensing, ``TreeCorr`` computes the tangential shear $\gamma_t$, not $\Delta\Sigma$. Furthermore, ``TreeCorr`` has a steeper learning curve and requires more care in implementing survey-specific correction terms.
|
|
54
|
+
|
|
56
55
|
## Authors
|
|
57
56
|
|
|
58
|
-
* Johannes Lange
|
|
57
|
+
* Johannes U. Lange
|
|
59
58
|
* Song Huang
|
|
60
59
|
|
|
61
60
|
## Installation
|
|
@@ -9,8 +9,7 @@
|
|
|
9
9
|

|
|
10
10
|

|
|
11
11
|
[](https://raw.githubusercontent.com/johannesulf/dsigma/main/LICENSE)
|
|
12
|
-
[](https://doi.org/10.5281/zenodo.20378642)
|
|
12
|
+
[](https://doi.org/10.5281/zenodo.20378642)
|
|
14
13
|
|
|
15
14
|
</div>
|
|
16
15
|
|
|
@@ -18,9 +17,11 @@
|
|
|
18
17
|
|
|
19
18
|

|
|
20
19
|
|
|
20
|
+
``dsigma`` focuses specifically on computing the excess surface density $\Delta\Sigma$ around a set of lens galaxies as a function of projected physical separation. In principle, the more general ``TreeCorr`` package can also be used to compute various two-point correlation functions, including galaxy-galaxy lensing. However, for galaxy-galaxy lensing, ``TreeCorr`` computes the tangential shear $\gamma_t$, not $\Delta\Sigma$. Furthermore, ``TreeCorr`` has a steeper learning curve and requires more care in implementing survey-specific correction terms.
|
|
21
|
+
|
|
21
22
|
## Authors
|
|
22
23
|
|
|
23
|
-
* Johannes Lange
|
|
24
|
+
* Johannes U. Lange
|
|
24
25
|
* Song Huang
|
|
25
26
|
|
|
26
27
|
## Installation
|
|
@@ -43,8 +43,9 @@ def interpolate_over_redshift(f, z, *args, **kwargs):
|
|
|
43
43
|
|
|
44
44
|
# Interpolating the sorted array is faster.
|
|
45
45
|
idx = np.argsort(z)
|
|
46
|
-
|
|
47
|
-
y
|
|
46
|
+
y_sorted = make_interp_spline(a_support, y_support)(1.0 / (1 + z[idx]))
|
|
47
|
+
y = np.empty_like(y_sorted)
|
|
48
|
+
y[idx] = y_sorted
|
|
48
49
|
|
|
49
50
|
if isinstance(y_support, u.Quantity):
|
|
50
51
|
y = y * y_support.unit
|
|
@@ -23,8 +23,8 @@ def compute_jackknife_fields(table, centers, distance_threshold=1,
|
|
|
23
23
|
Afterwards, KMeans clustering is run. The initial cluster centers are
|
|
24
24
|
random points from each continuous field. The number of initial cluster
|
|
25
25
|
centers per field is determined according to the total weight of each
|
|
26
|
-
continuous field. The centers are defined in cartesian coordinates on a
|
|
27
|
-
sphere.
|
|
26
|
+
continuous field. The centers are defined in cartesian coordinates on a
|
|
27
|
+
unit sphere.
|
|
28
28
|
|
|
29
29
|
Parameters
|
|
30
30
|
----------
|
|
@@ -195,7 +195,7 @@ def smooth_covariance_matrix(cov, sigma):
|
|
|
195
195
|
# values to the off-diagonal elements.
|
|
196
196
|
while not np.allclose(np.diag(cor), 0, rtol=0, atol=1e-12):
|
|
197
197
|
cor += (gaussian_filter(np.diag(np.diag(cor)), sigma) -
|
|
198
|
-
|
|
198
|
+
np.diag(np.diag(cor)))
|
|
199
199
|
|
|
200
200
|
for i in range(n_dim):
|
|
201
201
|
cor[i, i] = 1
|
|
@@ -236,7 +236,7 @@ def jackknife_resampling(f, table_l, table_r=None, table_l_2=None,
|
|
|
236
236
|
Default is ``True``.
|
|
237
237
|
return_samples : bool, optional
|
|
238
238
|
If ``True``, return the list of samples used to compute the covariance
|
|
239
|
-
as a second return value.
|
|
239
|
+
as a second return value. Default is ``False``.
|
|
240
240
|
**kwargs
|
|
241
241
|
Additional keyword arguments to be passed to the function.
|
|
242
242
|
|
|
@@ -141,17 +141,14 @@ def effective_critical_surface_density(
|
|
|
141
141
|
return 1.0 / sigma_crit_eff_inv
|
|
142
142
|
|
|
143
143
|
|
|
144
|
-
def _to_camb(cosmology,
|
|
144
|
+
def _to_camb(cosmology, z, k_max=1e3):
|
|
145
145
|
r"""Convert an astropy cosmology object into a CAMB result object.
|
|
146
146
|
|
|
147
147
|
Parameters
|
|
148
148
|
----------
|
|
149
149
|
cosmology : astropy.cosmology.FlatLambdaCDM
|
|
150
|
-
Astropy cosmology.
|
|
151
|
-
|
|
152
|
-
Scale of fluctuations at :math:`8 h^{-1} \, \mathrm{Mpc}`.
|
|
153
|
-
n_s : float
|
|
154
|
-
Primordial power spectrum index.
|
|
150
|
+
Astropy cosmology. Note that :math:`\sigma_8` and :math:`n_s` need to
|
|
151
|
+
be defined in the cosmology's metadata.
|
|
155
152
|
z : numpy.ndarray
|
|
156
153
|
Redshifts for which to compute the power spectrum.
|
|
157
154
|
k_max : float, optional
|
|
@@ -166,8 +163,11 @@ def _to_camb(cosmology, sigma_8, n_s, z, k_max=1e3):
|
|
|
166
163
|
|
|
167
164
|
Raises
|
|
168
165
|
------
|
|
166
|
+
ValueError:
|
|
167
|
+
If the power spectrum parameters are not defined in ``cosmology.meta``.
|
|
169
168
|
TypeError
|
|
170
|
-
If cosmology is not an instance of
|
|
169
|
+
If ``cosmology`` is not an instance of
|
|
170
|
+
``astropy.cosmology.FlatLambdaCDM``.
|
|
171
171
|
ImportError
|
|
172
172
|
If ``camb`` is not installed.
|
|
173
173
|
|
|
@@ -176,6 +176,17 @@ def _to_camb(cosmology, sigma_8, n_s, z, k_max=1e3):
|
|
|
176
176
|
msg = "Cosmology must be instance of astropy.cosmology.FlatLambdaCDM."
|
|
177
177
|
raise TypeError(msg)
|
|
178
178
|
|
|
179
|
+
for key, desc in zip(
|
|
180
|
+
['n', 'sigma8'],
|
|
181
|
+
["power spectrum index", "amplitude of matter fluctations"]):
|
|
182
|
+
if key not in cosmology.meta:
|
|
183
|
+
msg = (f"The cosmology object metadata needs a value for `{key}`, "
|
|
184
|
+
f"the {desc}.")
|
|
185
|
+
raise ValueError(msg)
|
|
186
|
+
|
|
187
|
+
sigma_8 = cosmology.meta['sigma8']
|
|
188
|
+
n_s = cosmology.meta['n']
|
|
189
|
+
|
|
179
190
|
try:
|
|
180
191
|
import camb
|
|
181
192
|
except ImportError:
|
|
@@ -256,8 +267,8 @@ def _gaussian_quadrature_2d(f, n_x, x_min, x_max, n_y, y_min, y_max):
|
|
|
256
267
|
|
|
257
268
|
|
|
258
269
|
def lens_magnification_shear_bias(
|
|
259
|
-
theta, alpha_l, z_l, z_s, cosmology=None,
|
|
260
|
-
|
|
270
|
+
theta, alpha_l, z_l, z_s, cosmology=None, n_z=10, n_ell=1000,
|
|
271
|
+
bessel_function_zeros=100, k_max=1e3):
|
|
261
272
|
r"""Compute the lens magnification bias to the mean tangential shear.
|
|
262
273
|
|
|
263
274
|
This function is based on equations (13) and (14) in Unruh et al. (2020).
|
|
@@ -275,12 +286,9 @@ def lens_magnification_shear_bias(
|
|
|
275
286
|
Redshift of source. Can also be a array if ``theta`` is an array.
|
|
276
287
|
cosmology : astropy.cosmology or None, optional
|
|
277
288
|
Cosmology to assume for calculations. If ``None``, use
|
|
278
|
-
``dsigma.default_cosmology``.
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
0.82.
|
|
282
|
-
n_s : float, optional
|
|
283
|
-
Primordial power spectrum index. Default is 0.96.
|
|
289
|
+
``dsigma.default_cosmology``. Note that :math:`\sigma_8` and
|
|
290
|
+
:math:`n_s` need to be defined in the cosmology's metadata. Default is
|
|
291
|
+
``None``.
|
|
284
292
|
n_z : int, optional
|
|
285
293
|
Number of redshift bins used in the integral. Larger numbers will be
|
|
286
294
|
more accurate. Default is 10.
|
|
@@ -311,7 +319,7 @@ def lens_magnification_shear_bias(
|
|
|
311
319
|
theta *= u.rad
|
|
312
320
|
theta = theta.to(u.rad).value
|
|
313
321
|
|
|
314
|
-
r = _to_camb(cosmology,
|
|
322
|
+
r = _to_camb(cosmology, np.linspace(np.amax(z_l), 0, 10))
|
|
315
323
|
p = r.get_matter_power_interpolator(hubble_units=False, k_hunit=False).P
|
|
316
324
|
|
|
317
325
|
def f(theta, z_l, z_s, z, ell):
|
|
@@ -320,9 +328,9 @@ def lens_magnification_shear_bias(
|
|
|
320
328
|
z_u).to(u.Mpc).value[idx])
|
|
321
329
|
return ((1 + z)**2 * ell * jv(2, ell * theta) *
|
|
322
330
|
(cosmology.H0 / cosmology.H(z_u)[idx]) *
|
|
323
|
-
cosmology.
|
|
331
|
+
cosmology.angular_diameter_distance(z_u, z_l)[idx] /
|
|
324
332
|
cosmology.angular_diameter_distance(z_l) *
|
|
325
|
-
cosmology.
|
|
333
|
+
cosmology.angular_diameter_distance(z_u, z_s)[idx] /
|
|
326
334
|
cosmology.angular_diameter_distance(z_s) *
|
|
327
335
|
np.where(k > k_max, 0, np.array(
|
|
328
336
|
[np.squeeze(p(z_i, k_i)) for z_i, k_i in zip(z, k)])))
|
|
@@ -312,7 +312,7 @@ def precompute_engine(
|
|
|
312
312
|
if has_R_matrix:
|
|
313
313
|
sum_w_ls_R_T[offset_result + i_bin] += w_ls * (
|
|
314
314
|
R_11[i_s] * cos_2phi * cos_2phi +
|
|
315
|
-
R_22[i_s] * sin_2phi * sin_2phi
|
|
315
|
+
R_22[i_s] * sin_2phi * sin_2phi -
|
|
316
316
|
(R_12[i_s] + R_21[i_s]) * sin_2phi * cos_2phi)
|
|
317
317
|
|
|
318
318
|
if progress_bar:
|
|
@@ -13,8 +13,8 @@ def process_decade():
|
|
|
13
13
|
|
|
14
14
|
* ``shear_catalog_sparse.hdf5``
|
|
15
15
|
* ``z_grid.npy``
|
|
16
|
-
* ``
|
|
17
|
-
* ``
|
|
16
|
+
* ``NGC_n_of_z.npy``
|
|
17
|
+
* ``SGC_n_of_z.npy``
|
|
18
18
|
|
|
19
19
|
It will produce two files, ``decade_ngc.hdf5`` and ``decade_sgc.hdf5``
|
|
20
20
|
containing the processed source catalog and calibration :math:`n(z)` for
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"""Module for stacking lensing results after pre-computation."""
|
|
2
2
|
|
|
3
|
+
from warnings import warn
|
|
4
|
+
|
|
3
5
|
import numpy as np
|
|
4
6
|
from astropy import units as u
|
|
5
7
|
from astropy.cosmology import units as cu
|
|
@@ -16,6 +18,31 @@ __all__ = ['boost_factor', 'excess_surface_density', 'lens_magnification_bias',
|
|
|
16
18
|
'shear_responsivity_factor', 'tangential_shear']
|
|
17
19
|
|
|
18
20
|
|
|
21
|
+
def check_required_columns(table, keys):
|
|
22
|
+
"""Convenience function to check that a table has the required columns.
|
|
23
|
+
|
|
24
|
+
Parameters
|
|
25
|
+
----------
|
|
26
|
+
table : astropy.table.Table
|
|
27
|
+
Table to be checked.
|
|
28
|
+
keys : list of str
|
|
29
|
+
Column names which are checked.
|
|
30
|
+
|
|
31
|
+
Raises
|
|
32
|
+
------
|
|
33
|
+
ValueError
|
|
34
|
+
If any of the required columns is not present in the table.
|
|
35
|
+
|
|
36
|
+
"""
|
|
37
|
+
for key in keys:
|
|
38
|
+
if key not in table.colnames:
|
|
39
|
+
msg = (f"The table is missing the required column `{key}`. "
|
|
40
|
+
"This column is added by `dsigma.precompute.precompute`. "
|
|
41
|
+
"Make sure you ran it on this table and, if applicable, "
|
|
42
|
+
"inputs needed for the required correction were provided.")
|
|
43
|
+
raise ValueError(msg)
|
|
44
|
+
|
|
45
|
+
|
|
19
46
|
def number_of_pairs(table_l):
|
|
20
47
|
"""Compute the number of lens-source pairs per bin.
|
|
21
48
|
|
|
@@ -30,6 +57,7 @@ def number_of_pairs(table_l):
|
|
|
30
57
|
The number of lens-source pairs in each radial bin.
|
|
31
58
|
|
|
32
59
|
"""
|
|
60
|
+
check_required_columns(table_l, ['sum 1'])
|
|
33
61
|
return np.sum(table_l['sum 1'].data, axis=0)
|
|
34
62
|
|
|
35
63
|
|
|
@@ -47,6 +75,7 @@ def raw_tangential_shear(table_l):
|
|
|
47
75
|
The raw, uncorrected tangential shear in each radial bin.
|
|
48
76
|
|
|
49
77
|
"""
|
|
78
|
+
check_required_columns(table_l, ['w_sys', 'sum w_ls', 'sum w_ls e_t'])
|
|
50
79
|
return (np.dot(table_l['w_sys'].data, table_l['sum w_ls e_t'].data) /
|
|
51
80
|
np.dot(table_l['w_sys'].data, table_l['sum w_ls'].data))
|
|
52
81
|
|
|
@@ -65,6 +94,8 @@ def raw_excess_surface_density(table_l):
|
|
|
65
94
|
The raw, uncorrected excess surface density in each radial bin.
|
|
66
95
|
|
|
67
96
|
"""
|
|
97
|
+
check_required_columns(table_l, [
|
|
98
|
+
'w_sys', 'sum w_ls', 'sum w_ls e_t sigma_crit'])
|
|
68
99
|
return (np.dot(table_l['w_sys'].data,
|
|
69
100
|
table_l['sum w_ls e_t sigma_crit'].quantity) /
|
|
70
101
|
np.dot(table_l['w_sys'].data, table_l['sum w_ls'].data))
|
|
@@ -84,6 +115,8 @@ def photo_z_dilution_factor(table_l):
|
|
|
84
115
|
Photometric redshift bias :math:`f_{\mathrm{bias}}`.
|
|
85
116
|
|
|
86
117
|
"""
|
|
118
|
+
check_required_columns(table_l, [
|
|
119
|
+
'w_sys', 'sum w_ls e_t sigma_crit', 'sum w_ls e_t sigma_crit f_bias'])
|
|
87
120
|
return (np.dot(table_l['w_sys'].data,
|
|
88
121
|
table_l['sum w_ls e_t sigma_crit f_bias'].data) /
|
|
89
122
|
np.dot(table_l['w_sys'].data,
|
|
@@ -109,6 +142,8 @@ def boost_factor(table_l, table_r):
|
|
|
109
142
|
Boost factor in each radial bin.
|
|
110
143
|
|
|
111
144
|
"""
|
|
145
|
+
check_required_columns(table_l, ['w_sys', 'sum w_ls'])
|
|
146
|
+
check_required_columns(table_r, ['w_sys', 'sum w_ls'])
|
|
112
147
|
return (
|
|
113
148
|
np.dot(table_l['w_sys'].data, table_l['sum w_ls'].data) /
|
|
114
149
|
np.dot(table_r['w_sys'].data, table_r['sum w_ls'].data) *
|
|
@@ -136,6 +171,7 @@ def scalar_shear_response_factor(table_l, selection_bias=False):
|
|
|
136
171
|
|
|
137
172
|
"""
|
|
138
173
|
m = 'm_sel' if selection_bias else 'm'
|
|
174
|
+
check_required_columns(table_l, ['w_sys', 'sum w_ls', f'sum w_ls {m}'])
|
|
139
175
|
|
|
140
176
|
return (np.dot(table_l['w_sys'].data, table_l[f'sum w_ls {m}'].data) /
|
|
141
177
|
np.dot(table_l['w_sys'].data, table_l['sum w_ls'].data))
|
|
@@ -158,6 +194,7 @@ def matrix_shear_response_factor(table_l):
|
|
|
158
194
|
Tangential shear response factor in each radial bin.
|
|
159
195
|
|
|
160
196
|
"""
|
|
197
|
+
check_required_columns(table_l, ['w_sys', 'sum w_ls', 'sum w_ls R_T'])
|
|
161
198
|
return (np.dot(table_l['w_sys'].data, table_l['sum w_ls R_T'].data) /
|
|
162
199
|
np.dot(table_l['w_sys'].data, table_l['sum w_ls'].data))
|
|
163
200
|
|
|
@@ -176,6 +213,8 @@ def shear_responsivity_factor(table_l):
|
|
|
176
213
|
Shear responsivity factor in each radial bin.
|
|
177
214
|
|
|
178
215
|
"""
|
|
216
|
+
check_required_columns(table_l, [
|
|
217
|
+
'w_sys', 'sum w_ls', 'sum w_ls (1 - e_rms^2)'])
|
|
179
218
|
return (
|
|
180
219
|
np.dot(table_l['w_sys'].data, table_l['sum w_ls (1 - e_rms^2)'].data) /
|
|
181
220
|
np.dot(table_l['w_sys'].data, table_l['sum w_ls'].data))
|
|
@@ -195,6 +234,7 @@ def mean_lens_redshift(table_l):
|
|
|
195
234
|
Mean lens redshift in each bin.
|
|
196
235
|
|
|
197
236
|
"""
|
|
237
|
+
check_required_columns(table_l, ['w_sys', 'sum w_ls', 'sum w_ls z_l'])
|
|
198
238
|
return (np.dot(table_l['w_sys'].data, table_l['sum w_ls z_l'].data) /
|
|
199
239
|
np.dot(table_l['w_sys'].data, table_l['sum w_ls'].data))
|
|
200
240
|
|
|
@@ -213,6 +253,7 @@ def mean_source_redshift(table_l):
|
|
|
213
253
|
Mean source redshift in each bin.
|
|
214
254
|
|
|
215
255
|
"""
|
|
256
|
+
check_required_columns(table_l, ['w_sys', 'sum w_ls', 'sum w_ls z_s'])
|
|
216
257
|
return (np.dot(table_l['w_sys'].data, table_l['sum w_ls z_s'].data) /
|
|
217
258
|
np.dot(table_l['w_sys'].data, table_l['sum w_ls'].data))
|
|
218
259
|
|
|
@@ -239,17 +280,19 @@ def mean_critical_surface_density(table_l, photo_z_dilution_correction=False):
|
|
|
239
280
|
key = 'sigma_crit f_bias'
|
|
240
281
|
else:
|
|
241
282
|
key = 'sigma_crit'
|
|
283
|
+
check_required_columns(table_l, ['w_sys', 'sum w_ls', f'sum w_ls {key}'])
|
|
242
284
|
return (
|
|
243
285
|
np.dot(table_l['w_sys'].data, table_l[f'sum w_ls {key}'].quantity) /
|
|
244
286
|
np.dot(table_l['w_sys'].data, table_l['sum w_ls'].data))
|
|
245
287
|
|
|
246
288
|
|
|
247
|
-
def lens_magnification_bias(table_l, alpha_l,
|
|
289
|
+
def lens_magnification_bias(table_l, alpha_l,
|
|
248
290
|
photo_z_dilution_correction=False, shear=False):
|
|
249
291
|
r"""Estimate the additive lens magnification bias.
|
|
250
292
|
|
|
251
293
|
Note that the assumed cosmology is taken from ``table_l.meta['cosmology']``
|
|
252
|
-
which is added by ``precompute``.
|
|
294
|
+
which is added by ``precompute``. Note that :math:`\sigma_8` and
|
|
295
|
+
:math:`n_s` need to be defined in the cosmology's metadata.
|
|
253
296
|
|
|
254
297
|
Parameters
|
|
255
298
|
----------
|
|
@@ -257,11 +300,6 @@ def lens_magnification_bias(table_l, alpha_l, sigma_8=0.82, n_s=0.96,
|
|
|
257
300
|
Precompute results for the lenses.
|
|
258
301
|
alpha_l : float
|
|
259
302
|
The response of the lenses to magnification.
|
|
260
|
-
sigma_8 : float, optional
|
|
261
|
-
Scale of fluctuations at :math:`8 h^{-1} \, \mathrm{Mpc}`. Default is
|
|
262
|
-
0.82.
|
|
263
|
-
n_s : float, optional
|
|
264
|
-
Primordial power spectrum index. Default is 0.96.
|
|
265
303
|
photo_z_dilution_correction : bool, optional
|
|
266
304
|
If ``True``, correct the mean critical surface density for photo-z
|
|
267
305
|
biases. Not used if `shear` is ``True``. This should be consistent with
|
|
@@ -294,8 +332,7 @@ def lens_magnification_bias(table_l, alpha_l, sigma_8=0.82, n_s=0.96,
|
|
|
294
332
|
z_l, cosmology=cosmology, comoving=comoving)).to(
|
|
295
333
|
u.rad, cu.with_H0(cosmology.H0))
|
|
296
334
|
|
|
297
|
-
gt = lens_magnification_shear_bias(
|
|
298
|
-
theta, alpha_l, z_l, z_s, cosmology, sigma_8=sigma_8, n_s=n_s)
|
|
335
|
+
gt = lens_magnification_shear_bias(theta, alpha_l, z_l, z_s, cosmology)
|
|
299
336
|
|
|
300
337
|
if shear:
|
|
301
338
|
return gt
|
|
@@ -355,6 +392,10 @@ def tangential_shear(table_l, table_r=None, boost_correction=False,
|
|
|
355
392
|
catalog is provided.
|
|
356
393
|
|
|
357
394
|
"""
|
|
395
|
+
if table_r is not None and not (boost_correction or random_subtraction):
|
|
396
|
+
msg = "A random catalog has been provided but will not be used."
|
|
397
|
+
warn(msg, stacklevel=2)
|
|
398
|
+
|
|
358
399
|
result = Table()
|
|
359
400
|
|
|
360
401
|
result['rp_min'] = table_l.meta['bins'][:-1]
|
|
@@ -468,6 +509,10 @@ def excess_surface_density(table_l, table_r=None,
|
|
|
468
509
|
catalog is provided.
|
|
469
510
|
|
|
470
511
|
"""
|
|
512
|
+
if table_r is not None and not (boost_correction or random_subtraction):
|
|
513
|
+
msg = "A random catalog has been provided but will not be used."
|
|
514
|
+
warn(msg, stacklevel=2)
|
|
515
|
+
|
|
471
516
|
result = Table()
|
|
472
517
|
|
|
473
518
|
result['rp_min'] = table_l.meta['bins'][:-1]
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dsigma
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.4
|
|
4
4
|
Summary: A Galaxy-Galaxy Lensing Python Package
|
|
5
|
-
Author-email: "Johannes U. Lange" <jlange@american.edu>, Song Huang <shuang@tsinghua.edu.cn>
|
|
5
|
+
Author-email: "Johannes U. Lange" <jlange@american.edu>, Song Huang <shuang@tsinghua.edu.cn>, Alexie Leauthaud <alexie@ucsc.edu>
|
|
6
6
|
License-Expression: MIT
|
|
7
7
|
Project-URL: Homepage, https://github.com/johannesulf/dsigma
|
|
8
8
|
Project-URL: Documentation, https://dsigma.readthedocs.io
|
|
@@ -11,8 +11,6 @@ Project-URL: Issues, https://github.com/johannesulf/dsigma/issues
|
|
|
11
11
|
Project-URL: Changelog, https://github.com/johannesulf/dsigma/blob/main/CHANGELOG.md
|
|
12
12
|
Keywords: astronomy,weak-lensing
|
|
13
13
|
Classifier: Programming Language :: Python :: 3
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
16
14
|
Classifier: Programming Language :: Python :: 3.11
|
|
17
15
|
Classifier: Programming Language :: Python :: 3.12
|
|
18
16
|
Classifier: Programming Language :: Python :: 3.13
|
|
@@ -20,12 +18,12 @@ Classifier: Programming Language :: Python :: 3.14
|
|
|
20
18
|
Classifier: Operating System :: OS Independent
|
|
21
19
|
Classifier: Topic :: Scientific/Engineering :: Astronomy
|
|
22
20
|
Classifier: Intended Audience :: Science/Research
|
|
23
|
-
Requires-Python: >=3.
|
|
21
|
+
Requires-Python: >=3.11
|
|
24
22
|
Description-Content-Type: text/markdown
|
|
25
23
|
License-File: LICENSE
|
|
26
|
-
Requires-Dist: astropy
|
|
24
|
+
Requires-Dist: astropy>=8.0.0
|
|
27
25
|
Requires-Dist: astropy-healpix
|
|
28
|
-
Requires-Dist: numpy
|
|
26
|
+
Requires-Dist: numpy>=2.0.1
|
|
29
27
|
Requires-Dist: scikit-learn
|
|
30
28
|
Requires-Dist: scipy
|
|
31
29
|
Requires-Dist: tqdm
|
|
@@ -44,8 +42,7 @@ Dynamic: license-file
|
|
|
44
42
|

|
|
45
43
|

|
|
46
44
|
[](https://raw.githubusercontent.com/johannesulf/dsigma/main/LICENSE)
|
|
47
|
-
[](https://doi.org/10.5281/zenodo.20378642)
|
|
45
|
+
[](https://doi.org/10.5281/zenodo.20378642)
|
|
49
46
|
|
|
50
47
|
</div>
|
|
51
48
|
|
|
@@ -53,9 +50,11 @@ Dynamic: license-file
|
|
|
53
50
|
|
|
54
51
|

|
|
55
52
|
|
|
53
|
+
``dsigma`` focuses specifically on computing the excess surface density $\Delta\Sigma$ around a set of lens galaxies as a function of projected physical separation. In principle, the more general ``TreeCorr`` package can also be used to compute various two-point correlation functions, including galaxy-galaxy lensing. However, for galaxy-galaxy lensing, ``TreeCorr`` computes the tangential shear $\gamma_t$, not $\Delta\Sigma$. Furthermore, ``TreeCorr`` has a steeper learning curve and requires more care in implementing survey-specific correction terms.
|
|
54
|
+
|
|
56
55
|
## Authors
|
|
57
56
|
|
|
58
|
-
* Johannes Lange
|
|
57
|
+
* Johannes U. Lange
|
|
59
58
|
* Song Huang
|
|
60
59
|
|
|
61
60
|
## Installation
|
|
@@ -5,18 +5,19 @@ build-backend = "setuptools.build_meta"
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "dsigma"
|
|
7
7
|
description = "A Galaxy-Galaxy Lensing Python Package"
|
|
8
|
-
requires-python = ">=3.
|
|
8
|
+
requires-python = ">=3.11"
|
|
9
9
|
authors = [
|
|
10
10
|
{name = "Johannes U. Lange", email = "jlange@american.edu"},
|
|
11
|
-
{name = "Song Huang", email = "shuang@tsinghua.edu.cn"}
|
|
11
|
+
{name = "Song Huang", email = "shuang@tsinghua.edu.cn"},
|
|
12
|
+
{name = "Alexie Leauthaud", email = "alexie@ucsc.edu"}
|
|
12
13
|
]
|
|
13
14
|
readme = "README.md"
|
|
14
15
|
keywords = ["astronomy", "weak-lensing"]
|
|
15
16
|
license = "MIT"
|
|
16
17
|
dependencies = [
|
|
17
|
-
"astropy",
|
|
18
|
+
"astropy>=8.0.0",
|
|
18
19
|
"astropy-healpix",
|
|
19
|
-
"numpy",
|
|
20
|
+
"numpy>=2.0.1",
|
|
20
21
|
"scikit-learn",
|
|
21
22
|
"scipy",
|
|
22
23
|
"tqdm"
|
|
@@ -24,8 +25,6 @@ dependencies = [
|
|
|
24
25
|
dynamic = ["version"]
|
|
25
26
|
classifiers = [
|
|
26
27
|
"Programming Language :: Python :: 3",
|
|
27
|
-
"Programming Language :: Python :: 3.9",
|
|
28
|
-
"Programming Language :: Python :: 3.10",
|
|
29
28
|
"Programming Language :: Python :: 3.11",
|
|
30
29
|
"Programming Language :: Python :: 3.12",
|
|
31
30
|
"Programming Language :: Python :: 3.13",
|
|
@@ -15,7 +15,7 @@ def test_jackknife(test_catalogs, n_jk):
|
|
|
15
15
|
table_l, table_s = test_catalogs
|
|
16
16
|
|
|
17
17
|
jackknife.compute_jackknife_fields(table_l, n_jk)
|
|
18
|
-
assert len(np.unique(table_l['field_jk']) == n_jk
|
|
18
|
+
assert len(np.unique(table_l['field_jk'])) == n_jk
|
|
19
19
|
|
|
20
20
|
n_bins = 10
|
|
21
21
|
theta_bins = np.logspace(0, 1, n_bins + 1) * u.deg
|
|
@@ -44,7 +44,7 @@ def test_jackknife(test_catalogs, n_jk):
|
|
|
44
44
|
# Test the smoothing.
|
|
45
45
|
cov = jackknife.jackknife_resampling(stacking.tangential_shear, table_l)
|
|
46
46
|
for sigma in [1.0, 2.0, 5.0]:
|
|
47
|
-
cov_smooth = jackknife.smooth_covariance_matrix(cov,
|
|
47
|
+
cov_smooth = jackknife.smooth_covariance_matrix(cov, sigma)
|
|
48
48
|
|
|
49
49
|
# Diagonal should be unchanged.
|
|
50
50
|
assert np.allclose(np.diag(cov), np.diag(cov_smooth))
|
|
@@ -57,7 +57,8 @@ def test_jackknife(test_catalogs, n_jk):
|
|
|
57
57
|
assert np.std(cor) > np.std(cor_smooth)
|
|
58
58
|
|
|
59
59
|
# The mean value of the correlation matrix should be the same.
|
|
60
|
-
assert np.isclose(np.mean(cor), np.mean(cor_smooth), rtol=0,
|
|
60
|
+
assert np.isclose(np.mean(cor), np.mean(cor_smooth), rtol=0,
|
|
61
|
+
atol=1e-12)
|
|
61
62
|
|
|
62
63
|
# With random subtraction, result should always be 0.
|
|
63
64
|
cov = jackknife.jackknife_resampling(
|
|
@@ -74,8 +75,10 @@ def test_jackknife(test_catalogs, n_jk):
|
|
|
74
75
|
|
|
75
76
|
for random_subtraction in [True, False]:
|
|
76
77
|
cov = jackknife.jackknife_resampling(
|
|
77
|
-
diff, table_l, table_r=table_l
|
|
78
|
-
|
|
78
|
+
diff, table_l, table_r=table_l if random_subtraction else None,
|
|
79
|
+
table_l_2=table_l,
|
|
80
|
+
table_r_2=table_l if random_subtraction else None,
|
|
81
|
+
random_subtraction=random_subtraction)
|
|
79
82
|
assert np.allclose(cov, 0)
|
|
80
83
|
|
|
81
84
|
# Covariance should have quantities in some cases.
|
|
@@ -38,13 +38,11 @@ def test_critical_surface_density():
|
|
|
38
38
|
def test_to_camb(m_nu):
|
|
39
39
|
# Test that we can convert to CAMB correctly.
|
|
40
40
|
|
|
41
|
-
sigma_8 = 0.7
|
|
42
41
|
cosmology_astropy = default_cosmology.clone(m_nu=m_nu, Tcmb0=3.0)
|
|
43
|
-
cosmology_camb = physics._to_camb(cosmology_astropy,
|
|
44
|
-
[1, 0.5, 0])
|
|
42
|
+
cosmology_camb = physics._to_camb(cosmology_astropy, [1, 0.5, 0])
|
|
45
43
|
|
|
46
|
-
assert np.isclose(cosmology_camb.get_sigma8_0(),
|
|
47
|
-
atol=0)
|
|
44
|
+
assert np.isclose(cosmology_camb.get_sigma8_0(),
|
|
45
|
+
cosmology_astropy.meta['sigma8'], rtol=1e-6, atol=0)
|
|
48
46
|
|
|
49
47
|
z = np.linspace(0, 5, 20)
|
|
50
48
|
|
|
@@ -91,16 +89,14 @@ def test_lens_magnification():
|
|
|
91
89
|
z_s = 0.99
|
|
92
90
|
|
|
93
91
|
# Millennium simulation cosmology
|
|
94
|
-
cosmology = FlatLambdaCDM(
|
|
95
|
-
|
|
96
|
-
n_s = 1.0
|
|
92
|
+
cosmology = FlatLambdaCDM(
|
|
93
|
+
Ob0=0.045, Om0=0.25, H0=73, Tcmb0=2.7255, meta=dict(sigma8=0.9, n=1.0))
|
|
97
94
|
|
|
98
95
|
theta = np.geomspace(0.5, 20, 30) * u.arcmin
|
|
99
96
|
|
|
100
97
|
alpha_l = 2.71
|
|
101
98
|
gt = physics.lens_magnification_shear_bias(
|
|
102
|
-
theta, alpha_l, z_l, z_s, cosmology=cosmology
|
|
103
|
-
n_s=n_s)
|
|
99
|
+
theta, alpha_l, z_l, z_s, cosmology=cosmology)
|
|
104
100
|
|
|
105
101
|
# digitized from Unruh et al. (2020)
|
|
106
102
|
gt_unruh = 1e-5 * make_interp_spline(
|
|
@@ -5,8 +5,9 @@ from dsigma import precompute, stacking
|
|
|
5
5
|
from fixtures import test_catalogs
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
@pytest.mark.parametrize('
|
|
9
|
-
|
|
8
|
+
@pytest.mark.parametrize('stacking_function', [
|
|
9
|
+
stacking.excess_surface_density, stacking.tangential_shear])
|
|
10
|
+
def test_correction_factors(test_catalogs, stacking_function):
|
|
10
11
|
# Check that all correction factors are correctly included.
|
|
11
12
|
|
|
12
13
|
table_l, table_s = test_catalogs
|
|
@@ -18,18 +19,20 @@ def test_correction_factors(test_catalogs, statistic):
|
|
|
18
19
|
shear_responsivity_correction=True,
|
|
19
20
|
selection_bias_correction=True, return_table=True)
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
result = stacking_function(table_l, **kwargs)
|
|
23
|
+
if stacking_function == stacking.excess_surface_density:
|
|
24
|
+
key = 'ds'
|
|
23
25
|
else:
|
|
24
|
-
|
|
26
|
+
key = 'gt'
|
|
25
27
|
|
|
26
28
|
assert np.allclose(
|
|
27
|
-
result[
|
|
28
|
-
result['
|
|
29
|
-
rtol=0, atol=1e-9)
|
|
29
|
+
result[key], result[f'{key}_raw'] / result['1+m'] / result['R_t'] /
|
|
30
|
+
result['2R'] / result['1+m_sel'], rtol=0, atol=1e-9)
|
|
30
31
|
|
|
31
32
|
|
|
32
|
-
|
|
33
|
+
@pytest.mark.parametrize('stacking_function', [
|
|
34
|
+
stacking.excess_surface_density, stacking.tangential_shear])
|
|
35
|
+
def test_random_subtraction(test_catalogs, stacking_function):
|
|
33
36
|
# Check that random subtraction works.
|
|
34
37
|
|
|
35
38
|
table_l, table_s = test_catalogs
|
|
@@ -42,11 +45,16 @@ def test_random_subtraction(test_catalogs):
|
|
|
42
45
|
selection_bias_correction=True,
|
|
43
46
|
table_r=table_l, random_subtraction=True)
|
|
44
47
|
|
|
45
|
-
|
|
46
|
-
|
|
48
|
+
assert np.all(0 == stacking_function(table_l, **kwargs))
|
|
49
|
+
|
|
50
|
+
kwargs['random_subtraction'] = False
|
|
51
|
+
with pytest.warns():
|
|
52
|
+
stacking_function(table_l, **kwargs)
|
|
47
53
|
|
|
48
54
|
|
|
49
|
-
|
|
55
|
+
@pytest.mark.parametrize('stacking_function', [
|
|
56
|
+
stacking.excess_surface_density, stacking.tangential_shear])
|
|
57
|
+
def test_boost_factor(test_catalogs, stacking_function):
|
|
50
58
|
# Check that the boost factor works.
|
|
51
59
|
|
|
52
60
|
table_l, table_s = test_catalogs
|
|
@@ -55,9 +63,13 @@ def test_boost_factor(test_catalogs):
|
|
|
55
63
|
table_l = precompute.precompute(table_l, table_s, rp_bins)
|
|
56
64
|
kwargs = dict(boost_correction=True, table_r=table_l)
|
|
57
65
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
66
|
+
assert np.allclose(
|
|
67
|
+
stacking_function(table_l), stacking_function(table_l, **kwargs),
|
|
68
|
+
rtol=0, atol=1e-9)
|
|
69
|
+
|
|
70
|
+
kwargs['boost_correction'] = False
|
|
71
|
+
with pytest.warns():
|
|
72
|
+
stacking_function(table_l, **kwargs)
|
|
61
73
|
|
|
62
74
|
|
|
63
75
|
def test_lens_magnification(test_catalogs):
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|