The lensing pipeline of the future: GPU-accelerated, automatically-differentiable, highly modular. Currently under heavy development: expect interface changes and some imprecise/untested calculations.
Project description
caustics
The lensing pipeline of the future: GPU-accelerated, automatically-differentiable, highly modular. Currently under heavy development: expect interface changes and some imprecise/untested calculations.
Installation
Simply install caustics from PyPI:
pip install caustics
Minimal Example
import matplotlib.pyplot as plt
import caustics
import torch
cosmology = caustics.cosmology.FlatLambdaCDM()
sie = caustics.lenses.SIE(cosmology=cosmology, name="lens")
src = caustics.light.Sersic(name="source")
lnslt = caustics.light.Sersic(name="lenslight")
x = torch.tensor([
# z_s z_l x0 y0 q phi b x0 y0 q phi n Re
1.5, 0.5, -0.2, 0.0, 0.4, 1.5708, 1.7, 0.0, 0.0, 0.5, -0.985, 1.3, 1.0,
# Ie x0 y0 q phi n Re Ie
5.0, -0.2, 0.0, 0.8, 0.0, 1., 1.0, 10.0
]) # fmt: skip
minisim = caustics.sims.Lens_Source(
lens=sie, source=src, lens_light=lnslt, pixelscale=0.05, pixels_x=100
)
plt.imshow(minisim(x, quad_level=3), origin="lower")
plt.axis("off")
plt.show()
Batched simulator
newx = x.repeat(20, 1)
newx += torch.normal(mean=0, std=0.1 * torch.ones_like(newx))
images = torch.vmap(minisim)(newx)
fig, axarr = plt.subplots(4, 5, figsize=(20, 16))
for ax, im in zip(axarr.flatten(), images):
ax.imshow(im, origin="lower")
plt.show()
Automatic Differentiation
J = torch.func.jacfwd(minisim)(x)
# Plot the new images
fig, axarr = plt.subplots(3, 7, figsize=(20, 9))
for i, ax in enumerate(axarr.flatten()):
ax.imshow(J[..., i], origin="lower")
plt.show()
Documentation
Please see our documentation page for more detailed information.
Contribution
We welcome contributions from collaborators and researchers interested in our work. If you have improvements, suggestions, or new findings to share, please submit an issue or pull request. Your contributions help advance our research and analysis efforts.
To get started with your development (or fork), click the "Open with GitHub Codespaces" button below to launch a fully configured development environment with all the necessary tools and extensions.
Instruction on how to contribute to this project can be found in the CONTRIBUTION.md
Some guidelines:
- Please use
isort
andblack
to format your code. - Use
CamelCase
for class names andsnake_case
for variable and method names. - Open up issues for bugs/missing features.
- Use pull requests for additions to the code.
- Write tests that can be run by
pytest
.
Thanks to our contributors so far!
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 caustics-0.7.0.tar.gz
.
File metadata
- Download URL: caustics-0.7.0.tar.gz
- Upload date:
- Size: 2.1 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 09634bc5240f7a76693445e7074c3c81f102edab08bad2c0adb189aeb5171b10 |
|
MD5 | e91999f97801df82b44becc58a14c67e |
|
BLAKE2b-256 | 40dab26534ce520bf284690de44c496b3de8bf95141e9b3f11c2c500ef958329 |
File details
Details for the file caustics-0.7.0-py3-none-any.whl
.
File metadata
- Download URL: caustics-0.7.0-py3-none-any.whl
- Upload date:
- Size: 66.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3362021c98a2888f56ad04bb1c58fc8e2fe6ccc8ffd99db9617c3aae8ff29d08 |
|
MD5 | c8433e890fa821e7a635118e85103dc3 |
|
BLAKE2b-256 | 2cf41666854c573f7b1e4889247b4bfc9ce7f3382c6959e1aa5b273bad22920c |