builtins Author: Austin Peel, Email: austin.peel@cea.fr, Year: 2019, A collection of weak lensing tools in Python
Project description
lenspack
Author: Austin Peel
Email: austin.peel@cea.fr
Year: 2019
This repository is a collection of python codes useful for the weak-lensing analysis of galaxy catalogs and shear/convergence maps. The full documentation can be found here.
Contents
In progress.
Dependencies
- python (version 3.5 or later)
- numpy
- scipy
- astropy
- emcee (optional)
- nicaea (optional)
- iSAP (optional)
Installation
Clone this repository to your local machine. You might find it helpful to do this in a virtual environment in order to keep a clean workspace.
$ git clone https://github.com/cosmostat/lenspack.git
A new directory lenspack
will be generated. Navigate into it.
$ cd lenspack
Run the setup script to install lenspack and its necessary dependencies.
$ pip install .
The package will also soon be available to install directly using pip.
Examples
Peak detection
Suppose you have a galaxy catalog cat
containing sky position columns ra
and dec
, along with ellipticity components e1
and e2
. You can bin the galaxies into pixels, invert the shear to obtain convergence (Kaiser & Squires, 1993), detect peaks above a given threshold, and plot the result as follows.
import matplotlib.pyplot as plt
from lenspack.utils import bin2d
from lenspack.image.inversion import ks93
from lenspack.peaks import find_peaks2d
# Bin ellipticity components based on galaxy position into a 128 x 128 map
e1map, e2map = bin2d(cat['ra'], cat['dec'], v=(cat['e1'], cat['e2']), npix=128)
# Recover convergence via Kaiser-Squires inversion
kappaE, kappaB = ks93(e1map, e2map)
# Detect peaks on the convergence E-mode map
x, y, h = find_peaks2d(kappaE, threshold=0.03, include_border=True)
# Plot peak positions over the convergence
fig, ax = plt.subplots(1, 1, figsize=(7, 5.5))
mappable = ax.imshow(kappaE, origin='lower', cmap='bone')
ax.scatter(y, x, s=10, c='orange') # reverse x and y due to array indexing
ax.set_axis_off()
fig.colorbar(mappable)
plt.show()
Wavelet transform
Take the starlet transform of an image using two different methods. Compare results to the equivalent aperture mass filter at a given scale.
import numpy as np
import matplotlib.pyplot as plt
from lenspack.image.transforms import starlet2d, mr_transform
from lenspack.image.filters import aperture_mass
# Generate a test image
img = np.random.randn(256, 256)
# Take the starlet transform with 5 wavelet scales
st = starlet2d(img, nscales=5)
mrt = mr_transform(img, nscales=5) # The iSAP mr_transform binary is required for this wrapper function to work
# Compute the aperture mass map at scale 4 using the starlet filter
apm = aperture_mass(img, theta=2**4, filter='starlet')
# Plot
fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(12, 5))
ax1.imshow(st[3], cmap='magma')
ax2.imshow(mrt[3], cmap='magma')
ax3.imshow(apm, cmap='magma')
for ax in (ax1, ax2, ax3):
ax.set_axis_off()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file lenspack-1.0.0.tar.gz
.
File metadata
- Download URL: lenspack-1.0.0.tar.gz
- Upload date:
- Size: 32.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e528a5409473eb996b39695cccb744db067341eb5fac6f240cd8d0aa669c85ec |
|
MD5 | 4db3a4dbec6982b94b113fcb59db3b51 |
|
BLAKE2b-256 | 73de18cfc64028334a1907d44ba2b40e233a2c7a06d7c1e827acfd1785c0b293 |
File details
Details for the file lenspack-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: lenspack-1.0.0-py3-none-any.whl
- Upload date:
- Size: 37.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f9c632697516bb681e16b3eff66a7210d6355926179b95aa7060c8936c2259cc |
|
MD5 | 970b3d27db23469161a131b5004e951f |
|
BLAKE2b-256 | 1b3da93a1332b1412301ddb454f206507b5e0b3679e012471fbbb075ca3b0845 |