### Install dsigma Locally Source: https://github.com/johannesulf/dsigma/blob/main/CONTRIBUTING.md Installs the dsigma package in editable mode. Use this to test your local modifications. ```bash pip install -e . ``` -------------------------------- ### Install dsigma from GitHub Source Source: https://github.com/johannesulf/dsigma/blob/main/docs/start/installation.md Clone the dsigma repository from GitHub and install it using pip in editable mode. This is useful for development or using unreleased versions. ```bash git clone https://github.com/johannesulf/dsigma.git cd dsigma pip install -e . ``` -------------------------------- ### Install Latest Development Version Source: https://github.com/johannesulf/dsigma/blob/main/README.md Install the most recent development version of dsigma directly from its GitHub repository using pip. ```bash pip install git+https://github.com/johannesulf/dsigma ``` -------------------------------- ### Install dsigma using pip Source: https://github.com/johannesulf/dsigma/blob/main/docs/start/installation.md Use this command to install the latest stable version of dsigma from PyPI. This method automatically handles dependencies. ```bash pip install dsigma ``` -------------------------------- ### Example Output of Galaxy-Galaxy Lensing Signal Source: https://github.com/johannesulf/dsigma/blob/main/docs/workflow/stacking.md This console output displays the calculated galaxy-galaxy lensing signal, showing raw and corrected values along with various correction terms. ```console rp_min rp_max n_pairs ds_raw ds z_l z_s 1+m 2R 1+m_sel Mpc Mpc solMass / pc2 solMass / pc2 ------ ------ ---------- ------------- ------------- ----- ----- ----- ----- ------- 0.100 0.158 113251 71.999 48.512 0.414 1.092 0.875 1.682 1.008 0.158 0.251 289741 50.827 34.175 0.413 1.094 0.876 1.682 1.010 0.251 0.398 736162 34.026 22.934 0.414 1.095 0.875 1.682 1.009 0.398 0.631 1851563 21.676 14.602 0.414 1.095 0.875 1.682 1.009 0.631 1.000 4649960 14.659 9.872 0.414 1.095 0.875 1.682 1.009 1.000 1.585 11637038 9.394 6.325 0.414 1.095 0.875 1.682 1.009 1.585 2.512 29179989 5.924 3.989 0.414 1.095 0.875 1.682 1.009 2.512 3.981 73071540 3.046 2.051 0.414 1.095 0.875 1.682 1.009 3.981 6.310 183114638 1.844 1.241 0.413 1.095 0.875 1.682 1.009 6.310 10.000 459001166 1.209 0.814 0.413 1.095 0.875 1.682 1.009 10.000 15.849 1150384474 0.865 0.582 0.413 1.095 0.875 1.682 1.009 15.849 25.119 2878215211 0.592 0.398 0.414 1.095 0.875 1.682 1.009 25.119 39.811 7184234609 0.442 0.298 0.414 1.095 0.875 1.682 1.009 ``` -------------------------------- ### Estimate Lens Magnification Shear Bias Source: https://github.com/johannesulf/dsigma/blob/main/docs/workflow/magnification.md This code reproduces the pink line in Fig. 5 of Unruh et al. (2020) by estimating the tangential shear induced by lens magnification for various alpha_l values. It relies on CAMB for power spectrum estimation. Ensure astropy, numpy, and matplotlib are installed. ```python import matplotlib.pyplot as plt import numpy as np from astropy import units as u from dsigma.physics import lens_magnification_shear_bias from astropy.cosmology import FlatLambdaCDM z_l = 0.41 z_s = 0.99 # Millennium simulation cosmology cosmology = FlatLambdaCDM(Ob0=0.045, Om0=0.25, H0=73, Tcmb0=2.7) sigma_8 = 0.9 n_s = 1.0 theta = np.geomspace(0.5, 20, 30) * u.arcmin for alpha_l in [0.44, 0.66, 0.85, 1.06, 1.56, 2.03, 2.71]: gt = lens_magnification_shear_bias( theta, alpha_l, z_l, z_s, cosmology=cosmology, sigma_8=sigma_8, n_s=n_s) plt.plot(theta, gt, label=rf"$\alpha_l = {alpha_l:.2f}$") plt.legend(loc='upper center', frameon=False, ncols=3, handletextpad=0.3, columnspacing=1, handlelength=1) plt.xscale('log') plt.xlabel(r'$\theta$ in arcmin') plt.ylabel(r'Lens Magnification $\Delta \gamma_t$') plt.xlim(0.5, 20) ``` -------------------------------- ### Download KiDS-Legacy Data Source: https://github.com/johannesulf/dsigma/blob/main/docs/applications/kids_legacy.md Use wget to download the necessary KiDS-Legacy FITS files from the specified base URL. These files are then processed by dsigma-process-kids-legacy. ```bash BASE_URL=https://kids.strw.leidenuniv.nl/DR5/data_files wget $BASE_URL/{KiDS_Legacy_NS_unblind_final.fits.gz,KiDZ_Legacy_unblind_final.fits} ``` -------------------------------- ### Perform Precomputation Source: https://github.com/johannesulf/dsigma/blob/main/docs/workflow/precomputation.md This snippet demonstrates how to perform the precomputation using the `precompute` function from the `dsigma.precompute` module. It requires defining radial bins, cosmology, and optionally setting lens-source cuts. The calculation can be parallelized using the `n_jobs` parameter. ```python import numpy as np from astropy.cosmology import Planck15 from dsigma.precompute import precompute rp_bins = np.logspace(-1, 1, 11) cosmology = Planck15 table_s['z_l_max'] = table_s['z'] - 0.1 # Perform the precomputation. precompute(table_l, table_s, rp_bins, cosmology=cosmology, comoving=True, progress_bar=True, n_jobs=4) ``` -------------------------------- ### Check Code Syntax with Ruff Source: https://github.com/johannesulf/dsigma/blob/main/CONTRIBUTING.md Runs the ruff linter to check for PEP8 compliance. Code must pass this check to be accepted. ```bash ruff check dsigma ``` -------------------------------- ### Read and Prepare BOSS Lens and Random Catalogs Source: https://github.com/johannesulf/dsigma/blob/main/docs/applications/intro.md This snippet reads galaxy and random files from the BOSS survey, renames columns to a dsigma-compatible format, filters by redshift, and selects a subset of randoms. It assumes FITS files are in the working directory. ```python from astropy.table import Table, vstack table_l = vstack([Table.read('galaxy_DR12v5_CMASSLOWZTOT_South.fits.gz'), Table.read('galaxy_DR12v5_CMASSLOWZTOT_North.fits.gz')]) table_r = vstack([Table.read('random0_DR12v5_CMASSLOWZTOT_South.fits.gz'), Table.read('random0_DR12v5_CMASSLOWZTOT_North.fits.gz')]) keys = dict(z='Z', ra='RA', dec='DEC') for table in [table_l, table_r]: for new_key, old_key in keys.items(): table.rename_column(old_key, new_key) table.keep_columns(keys.keys()) table['w_sys'] = 1 table_l = table_l[table_l['z'] >= 0.15] table_r = table_r[table_r['z'] >= 0.15][::5] ``` -------------------------------- ### Download DES Y3 Catalog Data Source: https://github.com/johannesulf/dsigma/blob/main/docs/applications/des_y3.md Use wget to download the necessary DES Y3 catalog files from the public repository. These files are required for subsequent processing. ```bash BASE_URL=https://desdr-server.ncsa.illinois.edu/despublic/y3a2_files wget $BASE_URL/y3kp_cats/{DESY3_sompz_v0.50.h5,DESY3_metacal_v0.3-004.h5,DESY3_indexcat.h5} wget $BASE_URL/datavectors/2pt_NG_final_2ptunblind_02_26_21_wnz_maglim_covupdate.fits ``` -------------------------------- ### Run Unit Tests Locally Source: https://github.com/johannesulf/dsigma/blob/main/CONTRIBUTING.md Executes the unit tests for the dsigma project using pytest. Ensure all tests pass before submitting contributions. ```bash pytest tests ``` -------------------------------- ### Stack Signal and Estimate Uncertainties Source: https://github.com/johannesulf/dsigma/blob/main/docs/start/quickstart.md Stacks the lensing signal across all lenses and uses jackknife resampling to estimate uncertainties. This prepares the results for plotting. ```python from dsigma.jackknife import compute_jackknife_fields, jackknife_resampling from dsigma.stacking import excess_surface_density compute_jackknife_fields(table_l, 100) kwargs = dict(scalar_shear_response_correction=True) results = excess_surface_density(table_l, return_table=True, **kwargs) results['ds_err'] = np.sqrt(np.diag(jackknife_resampling( excess_surface_density, table_l, **kwargs))) ``` -------------------------------- ### Precomputing DECADE Lensing Signal Source: https://github.com/johannesulf/dsigma/blob/main/docs/applications/decade.md Precomputes the galaxy-galaxy lensing signal from the DECADE catalog. Requires reading the catalog and calibration data, defining redshift bins, and applying precomputation with specified cosmology and calibration. ```python import numpy as np from astropy.cosmology import Planck15 from astropy.table import Table from dsigma.precompute import precompute table_s = Table.read('decade_ngc.hdf5', path='catalog') table_s['z_l_max'] = np.array( [0.0, 0.381, 0.619, 0.803])[table_s['z_bin']] - 0.1 table_n = Table.read('decade_ngc.hdf5', path='calibration') rp_bins = np.logspace(-1, 1.6, 14) kwargs = dict(cosmology=Planck15, comoving=True, table_n=table_n, progress_bar=True) precompute(table_l, table_s, rp_bins, **kwargs) precompute(table_r, table_s, rp_bins, **kwargs) ``` -------------------------------- ### Precompute Lensing Signal Source: https://github.com/johannesulf/dsigma/blob/main/docs/applications/des_y3.md Precompute the lensing signal using dsigma.precompute, applying a lens-source separation cut and specifying cosmology and calibration data. This step prepares the data for stacking. ```python import numpy as np from astropy.cosmology import Planck15 from astropy.table import Table from dsigma.precompute import precompute table_s = Table.read('des_y3.hdf5', path='catalog') table_s['z_l_max'] = np.array( [0.0, 0.358, 0.631, 0.872])[table_s['z_bin']] - 0.1 table_n = Table.read('des_y3.hdf5', path='calibration') rp_bins = np.logspace(-1, 1.6, 14) kwargs = dict(cosmology=Planck15, comoving=True, table_n=table_n, progress_bar=True) precompute(table_l, table_s, rp_bins, **kwargs) precompute(table_r, table_s, rp_bins, **kwargs) ``` -------------------------------- ### Stack Galaxy-Galaxy Lensing Signal Source: https://github.com/johannesulf/dsigma/blob/main/docs/applications/kids_legacy.md This Python script stacks the lensing signal using dsigma.stacking.excess_surface_density. It filters lenses/randoms, computes jackknife fields for uncertainty estimation, applies corrections, and performs random subtraction. ```python import numpy as np from dsigma.jackknife import compute_jackknife_fields, jackknife_resampling from dsigma.stacking import excess_surface_density # Drop all lenses and randoms that did not have any nearby source. table_l = table_l[np.sum(table_l['sum 1'], axis=1) > 0] table_r = table_r[np.sum(table_r['sum 1'], axis=1) > 0] centers = compute_jackknife_fields( table_l, 100, weights=np.sum(table_l['sum 1'], axis=1)) compute_jackknife_fields(table_r, centers) kwargs = dict(scalar_shear_response_correction=True, random_subtraction=True) z_bins = np.array([0.15, 0.31, 0.43, 0.54, 0.70]) for lens_bin, (z_min, z_max) in enumerate(zip(z_bins[:-1], z_bins[1:])): table_l_bin = table_l[(z_min <= table_l['z']) & (table_l['z'] < z_max)] table_r_bin = table_r[(z_min <= table_r['z']) & (table_r['z'] < z_max)] result = excess_surface_density( table_l_bin, table_r=table_r_bin, return_table=True, **kwargs) result['ds_err'] = np.sqrt(np.diag(jackknife_resampling( excess_surface_density, table_l_bin, table_r=table_r_bin, **kwargs))) result.write(f'kids_{lens_bin}.csv', overwrite=True) ``` -------------------------------- ### Download and Process BOSS and KiDS Data Source: https://github.com/johannesulf/dsigma/blob/main/docs/start/quickstart.md Downloads publicly available BOSS and KiDS data, processes them, and prepares tables for lensing analysis. Ensure you have sufficient disk space as KiDS files are large. ```python from urllib.request import urlretrieve from astropy.table import Table from dsigma.scripts.process_kids_legacy import process_kids_legacy # Download the BOSS data. filename = "galaxy_DR12v5_CMASSLOWZTOT_North.fits.gz" urlretrieve(f"https://data.sdss.org/sas/dr12/boss/lss/{filename}", filename) table_l = Table.read(filename) for key in ['Z', 'RA', 'DEC']: table_l.rename_column(key, key.lower()) table_l['w_sys'] = 1 table_l = table_l[(0.2 < table_l['z']) & (table_l['z'] < 0.4)] table_l.keep_columns(['ra', 'dec', 'z', 'w_sys']) # Download and process the KiDS data. for filename in ["KiDS_Legacy_NS_unblind_final.fits.gz", "KiDZ_Legacy_unblind_final.fits"]: urlretrieve(f"https://kids.strw.leidenuniv.nl/DR5/data_files/{filename}", filename) process_kids_legacy() table_s = Table.read('kids_legacy.hdf5', path='catalog') table_n = Table.read('kids_legacy.hdf5', path='calibration') ``` -------------------------------- ### Stack Lensing Signal with Jackknife Resampling Source: https://github.com/johannesulf/dsigma/blob/main/docs/applications/des_y3.md Stack the lensing signal using dsigma.stacking.excess_surface_density, applying shear response corrections and random subtraction. Jackknife resampling is used to estimate uncertainties. Results are saved to CSV files for each lens bin. ```python import numpy as np from dsigma.jackknife import compute_jackknife_fields, jackknife_resampling from dsigma.stacking import excess_surface_density # Drop all lenses and randoms that did not have any nearby source. table_l = table_l[np.sum(table_l['sum 1'], axis=1) > 0] table_r = table_r[np.sum(table_r['sum 1'], axis=1) > 0] centers = compute_jackknife_fields( table_l, 100, weights=np.sum(table_l['sum 1'], axis=1)) compute_jackknife_fields(table_r, centers) kwargs = dict(scalar_shear_response_correction=True, matrix_shear_response_correction=True, random_subtraction=True) z_bins = np.array([0.15, 0.31, 0.43, 0.54, 0.70]) for lens_bin, (z_min, z_max) in enumerate(zip(z_bins[:-1], z_bins[1:])): table_l_bin = table_l[(z_min <= table_l['z']) & (table_l['z'] < z_max)] table_r_bin = table_r[(z_min <= table_r['z']) & (table_r['z'] < z_max)] result = excess_surface_density( table_l_bin, table_r=table_r_bin, return_table=True, **kwargs) result['ds_err'] = np.sqrt(np.diag(jackknife_resampling( excess_surface_density, table_l_bin, table_r=table_r_bin, **kwargs))) result.write(f'des_{lens_bin}.csv', overwrite=True) ``` -------------------------------- ### Precompute Lensing Signal Source: https://github.com/johannesulf/dsigma/blob/main/docs/applications/kids_legacy.md This Python script uses dsigma.precompute to process the downloaded KiDS-Legacy catalog. It defines maximum source redshift based on tomographic bins and applies cosmological parameters from Planck15. ```python import numpy as np from astropy.cosmology import Planck15 from astropy.table import Table from dsigma.precompute import precompute table_s = Table.read('kids_legacy.hdf5', path='catalog') table_s['z_l_max'] = np.array([0.1, 0.42, 0.58, 0.71, 0.90, 1.14])[ table_s['z_bin']] - 0.1 table_n = Table.read('kids_legacy.hdf5', path='calibration') rp_bins = np.logspace(-1, 1.6, 14) kwargs = dict(cosmology=Planck15, comoving=True, table_n=table_n, progress_bar=True) precompute(table_l, table_s, rp_bins, **kwargs) precompute(table_r, table_s, rp_bins, **kwargs) ``` -------------------------------- ### Stacking DECADE Lensing Signal with Corrections Source: https://github.com/johannesulf/dsigma/blob/main/docs/applications/decade.md Stacks the lensing signal from the DECADE catalog across different redshift bins. It includes lens-source separation, jackknife resampling for uncertainty estimation, and applies METACALIBRATION and scalar shear response corrections, along with random subtraction. ```python import numpy as np from dsigma.jackknife import compute_jackknife_fields, jackknife_resampling from dsigma.stacking import excess_surface_density # Drop all lenses and randoms that did not have any nearby source. table_l = table_l[np.sum(table_l['sum 1'], axis=1) > 0] table_r = table_r[np.sum(table_r['sum 1'], axis=1) > 0] centers = compute_jackknife_fields( table_l, 100, weights=np.sum(table_l['sum 1'], axis=1)) compute_jackknife_fields(table_r, centers) kwargs = dict(scalar_shear_response_correction=True, matrix_shear_response_correction=True, random_subtraction=True) z_bins = np.array([0.15, 0.31, 0.43, 0.54, 0.70]) for lens_bin, (z_min, z_max) in enumerate(zip(z_bins[:-1], z_bins[1:])): table_l_bin = table_l[(z_min <= table_l['z']) & (table_l['z'] < z_max)] table_r_bin = table_r[(z_min <= table_r['z']) & (table_r['z'] < z_max)] result = excess_surface_density( table_l_bin, table_r=table_r_bin, return_table=True, **kwargs) result['ds_err'] = np.sqrt(np.diag(jackknife_resampling( excess_surface_density, table_l_bin, table_r=table_r_bin, **kwargs))) result.write(f'decade_{lens_bin}.csv', overwrite=True) ``` -------------------------------- ### Calculate Galaxy-Galaxy Lensing Signal with Corrections Source: https://github.com/johannesulf/dsigma/blob/main/docs/workflow/stacking.md Computes the galaxy-galaxy lensing signal using precomputed data and applies shear bias, shear responsivity, and selection bias corrections. The output table is then formatted for display. ```python from astropy import units as u from astropy.cosmology import units as cu from dsigma.stacking import excess_surface_density result = excess_surface_density( table_l, return_table=True, scalar_shear_response_correction=True, shear_responsivity_correction=True, selection_bias_correction=True) for key in result.colnames: # Drop little h from units. if key[:2] == 'rp': result[key] = result[key].to(u.Mpc, cu.with_H0(Planck15.H0)) if key[:2] == 'ds': result[key] = result[key].to(u.Msun / u.pc**2, cu.with_H0(Planck15.H0)) if key != 'n_pairs': result[key].format='.3f' result.pprint_all() ``` -------------------------------- ### Construct Jackknife Fields Source: https://github.com/johannesulf/dsigma/blob/main/docs/workflow/resampling.md Constructs jackknife fields for lens and random catalogs using DBSCAN and K-means clustering. The number of jackknife fields is specified by an integer argument. The resulting jackknife field information is stored in the 'field_jk' column. ```python from dsigma.jackknife import compute_jackknife_fields centers = compute_jackknife_fields(table_l, 100) compute_jackknife_fields(table_r, centers) ``` -------------------------------- ### Precompute Lensing Signal Source: https://github.com/johannesulf/dsigma/blob/main/docs/start/quickstart.md Precomputes the lensing signal by summing contributions from lensed source galaxies around each lens. This is a computationally intensive step. ```python import numpy as np from astropy import units as u from astropy.cosmology import units as cu from dsigma.precompute import precompute rp_bins = np.logspace(-1, 1.4, 13) * u.Mpc / cu.littleh precompute(table_l, table_s, rp_bins, table_n=table_n, progress_bar=True) ``` -------------------------------- ### Estimate Selection Bias (HSC) Source: https://github.com/johannesulf/dsigma/blob/main/docs/start/background.md This approximation provides a method to estimate the selection bias \( m_{\mathrm{sel}} \) by considering the probability density \( P \) within a specified range \( \delta R_2 \) and \( \delta\mathrm{mag}_A \) around the selection cut. ```latex $m_{\mathrm{sel}} \approx \frac{A P(0.3 - \delta R_2 \leq R_2 \leq 0.3)}{\delta R_2} + \frac{B P(25.5 - \delta\mathrm{mag}_A \leq \mathrm{mag}_A \leq 25.5)}{\delta\mathrm{mag}_A}$ ``` -------------------------------- ### Calculate Shear Responsivity (R) Source: https://github.com/johannesulf/dsigma/blob/main/docs/start/background.md This formula calculates the shear responsivity \( \mathcal{R} \), which corrects for biases inherent to the shape estimator, such as \( e_{\mathrm{rms}}^2 \). The lensing signal is divided by \( 2\mathcal{R} \) to apply this correction. ```latex $\mathcal{R} = 1 - \frac{\sum_{ls} w_{\mathrm{sys}, l} w_{ls} e_{{\rm rms}, s}^2}{\sum_{ls} w_{\mathrm{sys}, l} w_{ls}}$ ``` -------------------------------- ### Stacking HSC Y3 Signal with Corrections Source: https://github.com/johannesulf/dsigma/blob/main/docs/applications/hsc_y3.md Stacks the lensing signal in BOSS redshift bins, applying various corrections and random subtraction. Uses jackknife resampling for uncertainty estimation. Filters lenses and randoms with no nearby sources. ```python import numpy as np from dsigma.jackknife import compute_jackknife_fields, jackknife_resampling from dsigma.stacking import excess_surface_density # Drop all lenses and randoms that did not have any nearby source. table_l = table_l[np.sum(table_l['sum 1'], axis=1) > 0] table_r = table_r[np.sum(table_r['sum 1'], axis=1) > 0] centers = compute_jackknife_fields( table_l, 100, weights=np.sum(table_l['sum 1'], axis=1)) compute_jackknife_fields(table_r, centers) kwargs = dict(scalar_shear_response_correction=True, shear_responsivity_correction=True, selection_bias_correction=True, random_subtraction=True) z_bins = np.array([0.15, 0.31, 0.43, 0.54, 0.70]) for lens_bin, (z_min, z_max) in enumerate(zip(z_bins[:-1], z_bins[1:])): table_l_bin = table_l[(z_min <= table_l['z']) & (table_l['z'] < z_max)] table_r_bin = table_r[(z_min <= table_r['z']) & (table_r['z'] < z_max)] result = excess_surface_density( table_l_bin, table_r=table_r_bin, return_table=True, **kwargs) result['ds_err'] = np.sqrt(np.diag(jackknife_resampling( excess_surface_density, table_l_bin, table_r=table_r_bin, **kwargs))) result.write(f'hsc_{lens_bin}.csv', overwrite=True) ``` -------------------------------- ### Precomputing HSC Y3 Signal Source: https://github.com/johannesulf/dsigma/blob/main/docs/applications/hsc_y3.md Precomputes the lensing signal from the HSC Y3 catalog. Requires the catalog and n(z) files. Applies a lens-source separation cut based on tomographic redshift bins. ```python import numpy as np from astropy.cosmology import Planck15 from astropy.table import Table from dsigma.precompute import precompute table_s = Table.read('hsc_y3.hdf5', path='catalog') table_n = Table.read('hsc_y3.hdf5', path='calibration') table_s['z_l_max'] = np.sum(table_n['z'][:, np.newaxis] * table_n['n'], axis=0)[table_s['z_bin']] - 0.3 rp_bins = np.logspace(-1, 1.6, 14) kwargs = dict(cosmology=Planck15, comoving=True, table_n=table_n, progress_bar=True) precompute(table_l, table_s, rp_bins, **kwargs) precompute(table_r, table_s, rp_bins, **kwargs) ``` -------------------------------- ### Boost Factor Calculation Formula Source: https://github.com/johannesulf/dsigma/blob/main/docs/start/background.md This formula calculates the boost factor (b), which corrects for the overabundance of physically associated sources close to lenses. ```latex $$b = \frac{\sum_{ls} w_{\mathrm{sys}, l} w_{ls}}{\sum_{rs} w_{\mathrm{sys}, r} w_{rs}} \, .$$ ``` -------------------------------- ### Multiplicative Selection Bias (HSC) Source: https://github.com/johannesulf/dsigma/blob/main/docs/start/background.md This equation defines the multiplicative selection bias \( m_{\mathrm{sel}} \) for the Hyper Suprime-Cam (HSC) survey, relating it to constants \( A \) and \( B \) and per-object properties \( R_2 \) and \( \mathrm{mag}_A \). ```latex $m_{\mathrm{sel}} = A P(R_2 = 0.3) + B P(\mathrm{mag}_A = 25.5)$ ``` -------------------------------- ### Effective Critical Surface Density Calculation Source: https://github.com/johannesulf/dsigma/blob/main/docs/start/background.md This integral defines the effective inverse critical surface density, used when only the redshift distribution of sources is known. ```latex $$\langle \Sigma_{\mathrm{crit}}^{-1} (z_l) \rangle = \int \Sigma_{\rm crit}^{-1} (z_l, z_s) n(z_s) \mathrm{d}z_s \, .$$ ``` -------------------------------- ### Calculate Average Shear Bias (m) Source: https://github.com/johannesulf/dsigma/blob/main/docs/start/background.md This formula calculates the average shear bias \( \bar{m} \) by weighting individual biases \( m_s \) with system and pair weights. It is used to correct the raw lensing signal. ```latex $\bar{m} = \frac{\sum_{ls} w_{\mathrm{sys, l}} w_{ls} m_s}{\sum_{ls} w_{\mathrm{sys, l}} w_{ls}}$ ``` -------------------------------- ### Perform Jackknife Resampling for Covariance Matrix Source: https://github.com/johannesulf/dsigma/blob/main/docs/workflow/resampling.md Calculates the covariance matrix for a given summary statistic (e.g., excess surface density) using jackknife resampling. This function takes the summary statistic function, lens table, and optionally a random table as input. ```python from dsigma.stacking import excess_surface_density from dsigma.jackknife import jackknife_resampling delta_sigma_cov = jackknife_resampling(excess_surface_density, table_l, table_r) ``` -------------------------------- ### Shear Response Tensor (R) Source: https://github.com/johannesulf/dsigma/blob/main/docs/start/background.md The shear response tensor \( \mathbf{R} \) quantifies how the measured ellipticity \( \mathbf{e} \) responds to changes in the true shear \( \boldsymbol{\gamma} \). It is used when a scalar bias estimate is insufficient. ```latex $\mathbf{R} = \frac{\partial \mathbf{e}}{\partial \boldsymbol{\gamma}} = \begin{bmatrix} R_{11} & R_{12}\\R_{21} & R_{22} \end{bmatrix}$ ``` -------------------------------- ### Plot Lensing Results Source: https://github.com/johannesulf/dsigma/blob/main/docs/start/quickstart.md Plots the calculated excess surface density (ESD) against projected radius using matplotlib. The plot visualizes the lensing signal and its uncertainties. ```python import matplotlib.pyplot as plt rp = np.sqrt(results['rp_min'] * results['rp_max']) plt.errorbar(rp, rp * results['ds'], yerr=rp * results['ds_err'], fmt='o', ms=5) plt.xscale('log') plt.xlabel(r'Projected Radius $r_p \, [\mathrm{Mpc} / h]$') plt.ylabel(r'ESD $r_p \times \Delta \Sigma \, [10^6 M_\odot / \mathrm{pc}]$') ``` -------------------------------- ### Lens Selection Bias Correction Formula Source: https://github.com/johannesulf/dsigma/blob/main/docs/start/background.md This formula shows how to apply systematic weights to lens galaxies to counteract bias caused by an incomplete lens sample. ```latex $\Delta\Sigma = \frac{\sum_{ls} w_{\mathrm{sys}, l} w_{ls} \Sigma_{\mathrm{crit}} (z_l, z_s) e_t}{\sum_{ls} w_{\mathrm{sys}, l} w_{ls}} \, .$ ``` -------------------------------- ### Delta Sigma Estimation with Effective Redshift Distribution Source: https://github.com/johannesulf/dsigma/blob/main/docs/start/background.md This formula shows the Delta Sigma estimator when no reliable redshift estimate is available for individual sources, using an effective redshift distribution n(z). ```latex $$\Delta\Sigma = \frac{\sum_{ls} w_{\mathrm{sys}, l} w_s \langle \Sigma_{\mathrm{crit}}^{-1} (z_l) \rangle e_t}{\sum_{ls} w_{\mathrm{sys}, l} w_s \langle \Sigma_{\mathrm{crit}}^{-1} (z_l) \rangle^2} \, ,$$ ``` -------------------------------- ### Tangential Shear Response (Rt) Source: https://github.com/johannesulf/dsigma/blob/main/docs/start/background.md This formula calculates the tangential component of the shear response tensor \( R_t \) for a lens-source pair, considering the polar angle \( \phi \) of the source in the lens coordinate system. This is used to average the response. ```latex $R_t = R_{11} \cos^2 (2 \phi) + R_{22} \sin^2 (2 \phi)+ (R_{12} + R_{21}) \sin (2 \phi) \cos (2 \phi)$ ``` -------------------------------- ### Delta Sigma Estimation with Photometric Redshift Correction Source: https://github.com/johannesulf/dsigma/blob/main/docs/start/background.md This formula applies the calculated bias correction factor (f_bias) to the Delta Sigma estimator when using photometric redshifts for sources. ```latex $$\Delta\Sigma = \frac{\sum_{ls} w_{\mathrm{sys}, l} w_{ls} \Sigma_{\mathrm{crit}} (z_l, z_s) e_t f_{\mathrm{bias}} (z_l)}{\sum_{ls} w_{\mathrm{sys}, l} w_{ls}} \, .$$ ``` -------------------------------- ### Photometric Redshift Bias Correction Factor Formula Source: https://github.com/johannesulf/dsigma/blob/main/docs/start/background.md This formula calculates the inverse of the bias correction factor (f_bias) for photometric redshifts, accounting for errors in source redshift estimates. ```latex $$f_{\rm bias}^{-1} (z_l) = \frac{\sum_s w_{\mathrm{sys}, s} w_s \Sigma_{\mathrm{crit, true}}^{-1} \Sigma_{\mathrm{crit, photo-z}}^{-1}}{\sum_s w_{\mathrm{sys}, s} w_s \Sigma_{ls, \mathrm{photo-z}}^{-2}} = \langle \Sigma_{\mathrm{crit, photo-z}} / \Sigma_{\mathrm{crit, true}} \rangle\, ,$$ ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.