Skip to main content

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 logo

ssec CI pre-commit.ci status Documentation Status PyPI version coverage status Zenodo arXiv

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.FlatLambdaCDM()
sie = caustics.SIE(cosmology=cosmology, name="lens")
src = caustics.Sersic(name="source")
lnslt = caustics.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.LensSource(
    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()

Caustics lensed image

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()

Batched Caustics lensed images

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()

Jacobian Caustics lensed image

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.

Open in GitHub Codespaces

Instruction on how to contribute to this project can be found in the CONTRIBUTION.md

Some guidelines:

  • Please use isort and black to format your code.
  • Use CamelCase for class names and snake_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!

Contributors

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

caustics-0.11.0.tar.gz (3.4 MB view details)

Uploaded Source

Built Distribution

caustics-0.11.0-py3-none-any.whl (105.3 kB view details)

Uploaded Python 3

File details

Details for the file caustics-0.11.0.tar.gz.

File metadata

  • Download URL: caustics-0.11.0.tar.gz
  • Upload date:
  • Size: 3.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for caustics-0.11.0.tar.gz
Algorithm Hash digest
SHA256 d2ad2e987d38b72b72be437420829b9eb76073750048031324c5808a52e8c270
MD5 c1a3336378c0ab7133b09a5a11d6f181
BLAKE2b-256 cb88c3d55575ca0f2ffdaba5dc8207eec441a3f4eff26ca49f11b389909f3b4b

See more details on using hashes here.

File details

Details for the file caustics-0.11.0-py3-none-any.whl.

File metadata

  • Download URL: caustics-0.11.0-py3-none-any.whl
  • Upload date:
  • Size: 105.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for caustics-0.11.0-py3-none-any.whl
Algorithm Hash digest
SHA256 816af2406086194d7adcb643d627b10bfcf3ad944bff7be549b3a8c5e8d0be8b
MD5 96e14f77b8e6b0dd8f8ab9eb159facbf
BLAKE2b-256 174be2ffba4e6c9061646b77a3badd367e1a866d0aa6e451538ee918022578a0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page