Metadata-Version: 2.4
Name: dsigma
Version: 1.2.5
Summary: A Galaxy-Galaxy Lensing Python Package
Author-email: "Johannes U. Lange" <jlange@american.edu>, Song Huang <shuang@tsinghua.edu.cn>, Alexie Leauthaud <alexie@ucsc.edu>
License-Expression: MIT
Project-URL: Homepage, https://github.com/johannesulf/dsigma
Project-URL: Documentation, https://dsigma.readthedocs.io
Project-URL: Repository, https://github.com/johannesulf/dsigma.git
Project-URL: Issues, https://github.com/johannesulf/dsigma/issues
Project-URL: Changelog, https://github.com/johannesulf/dsigma/blob/main/CHANGELOG.md
Keywords: astronomy,weak-lensing
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Classifier: Topic :: Scientific/Engineering :: Astronomy
Classifier: Intended Audience :: Science/Research
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: astropy>=8.0.0
Requires-Dist: astropy-healpix
Requires-Dist: numpy>=2.0.1
Requires-Dist: scikit-learn
Requires-Dist: scipy
Requires-Dist: tqdm
Provides-Extra: process
Requires-Dist: h5py>=3.0.0; extra == "process"
Provides-Extra: tests
Requires-Dist: camb; extra == "tests"
Requires-Dist: pytest; extra == "tests"
Requires-Dist: treecorr; extra == "tests"
Dynamic: license-file

<div align="center">

![logo](https://raw.githubusercontent.com/johannesulf/dsigma/main/docs/dsigma.png)

[![Unit Testing Status](https://img.shields.io/github/actions/workflow/status/johannesulf/dsigma/tests.yml?branch=main&label=tests)](https://github.com/johannesulf/dsigma/actions)
[![Documentation Status](https://img.shields.io/readthedocs/dsigma)](https://dsigma.readthedocs.io/en/latest/)
[![Code Coverage](https://img.shields.io/coverallsCoverage/github/johannesulf/dsigma)](https://coveralls.io/github/johannesulf/dsigma?branch=main)
![Downloads](https://img.shields.io/pypi/dm/dsigma)
![Python Version from PEP 621 TOML](https://img.shields.io/python/required-version-toml?tomlFilePath=https%3A%2F%2Fraw.githubusercontent.com%2Fjohannesulf%2Fdsigma%2Frefs%2Fheads%2Fmain%2Fpyproject.toml)
![PyPI - Version](https://img.shields.io/pypi/v/dsigma)
[![License: MIT](https://img.shields.io/github/license/johannesulf/dsigma?color=blue)](https://raw.githubusercontent.com/johannesulf/dsigma/main/LICENSE)
[![DOI](https://img.shields.io/badge/doi-10.5281%2Fzenodo.20378642-blue)](https://doi.org/10.5281/zenodo.20378642)

</div>

``dsigma`` is an easy-to-use Python package for measuring gravitational galaxy-galaxy lensing. Using a lensing catalog, it estimates excess surface density around a population of lenses, such as galaxies in the Sloan Digital Sky Survey or the Baryon Oscillation Spectroscopic Survey. It has a flexible API and can utilize data from, DECADE, the Dark Energy Survey (DES), the Kilo-Degree Survey (KiDS), and the Hyper Suprime-Cam (HSC) lensing surveys, among others. With core computations written in C, ``dsigma`` is very fast. Additionally, ``dsigma`` provides out-of-the-box support for estimating covariances with jackknife resampling and calculating various summary statistics.

## Example

The example below shows the basic usage of ``dsigma``. It measures the galaxy-galaxy lensing signal around 100,000 lens galaxies using 10 million source galaxies.

```python
import numpy as np
from astropy import units as u
from astropy.table import Table
from dsigma.precompute import precompute
from dsigma.jackknife import compute_jackknife_fields, jackknife_resampling
from dsigma.stacking import excess_surface_density

n_l = 100_000
rng = np.random.default_rng(0)
table_l = Table(dict(
    ra=rng.uniform(0, 360, n_l),
    dec=np.rad2deg(np.arcsin(rng.uniform(-1, 1, n_l))),
    z=np.full(n_l, 0.3), w_sys=np.ones(n_l)))

n_s = 10_000_000
sigma_e = 0.26
table_s = Table(dict(
    ra=rng.uniform(0, 360, n_s),
    dec=np.rad2deg(np.arcsin(rng.uniform(-1, 1, n_s))),
    z=np.full(n_s, 0.7), w=np.ones(n_s), e_1=rng.normal(0, sigma_e, n_s),
    e_2=rng.normal(0, sigma_e, n_s)))

rp_bins = np.geomspace(0.1, 10, 11) * u.Mpc
precompute(table_l, table_s, rp_bins, progress_bar=True)
result = excess_surface_density(table_l, return_table=True)
compute_jackknife_fields(table_l, 100, seed=0)
ds_cov = jackknife_resampling(excess_surface_density, table_l)
result['ds_err'] = np.sqrt(np.diag(ds_cov))

result.keep_columns(['rp_min', 'rp_max', 'ds', 'ds_err'])
for key in result.colnames:
    result[key].info.format = '.3e'

print(result)
```

```
  rp_min    rp_max            ds                  ds_err       
   Mpc       Mpc    littleh solMass / pc2 littleh solMass / pc2
--------- --------- --------------------- ---------------------
1.000e-01 1.585e-01             3.613e+01             1.981e+01
1.585e-01 2.512e-01            -1.153e+01             1.394e+01
2.512e-01 3.981e-01             1.236e-01             8.948e+00
3.981e-01 6.310e-01            -2.513e+00             5.448e+00
6.310e-01 1.000e+00             3.046e+00             3.862e+00
1.000e+00 1.585e+00             1.094e+00             1.989e+00
1.585e+00 2.512e+00             4.080e-01             1.555e+00
2.512e+00 3.981e+00            -2.152e-02             8.493e-01
3.981e+00 6.310e+00            -4.896e-01             5.198e-01
6.310e+00 1.000e+01             2.721e-01             3.673e-01
```

The lenses and sources in this toy example have random positions and shapes, so the expected signal is zero. For a measurement on real lensing data, see the plot below.

![plot](https://raw.githubusercontent.com/johannesulf/dsigma/main/docs/plot.png)

## Authors

* Johannes U. Lange
* Song Huang
* Alexie Leauthaud

## Installation

The easiest way to install ``dsigma`` is to use ``pip`` for the latest stable version from the Python Package Index (PyPI).

    pip install dsigma

Alternatively, you can install the latest development version from GitHub.

    pip install git+https://github.com/johannesulf/dsigma

## Documentation

Documentation for ``dsigma`` with concept introductions, examples, and API documentation is available on [readthedocs](https://dsigma.readthedocs.io/).

## Attribution

``dsigma`` is listed in the [Astronomy Source Code Library](https://ascl.net/2204.006). If you find the code useful in your research, please cite [Lange & Huang (2022)](https://ui.adsabs.harvard.edu/abs/2022ascl.soft04006L/abstract).

## License

``dsigma`` is licensed under the MIT License.

## Generative AI

Generative AI was used to search for potential bugs in the code, to copyedit the documentation and suggest rewordings, to help set up automated PyPI releases, and to discuss design decisions. AI occasionally suggested small code changes, typically a single line, which were adopted after review. The core developers did not use AI to write any significant part of the ``dsigma`` code itself. Code contributions from other developers may use AI, as described in the respective pull requests, and are carefully vetted by the core developers.
