caustics


Namecaustics JSON
Version 0.10.1 PyPI version JSON
download
home_pageNone
SummaryThe lensing pipeline of the future: GPU-accelerated, automatically-differentiable, highly modular. Currently under heavy development: expect interface changes and some imprecise/untested calculations.
upload_time2024-04-25 20:29:53
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseMIT License Copyright (c) [2023] [caustics authors] Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords astronomy astrophysics caustics differentiable programming gravitational lensing lensing pytorch strong lensing
VCS
bugtrack_url
requirements astropy graphviz h5py mpmath numpy safetensors scipy torch
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <picture>
  <source media="(prefers-color-scheme: dark)" srcset="https://github.com/Ciela-Institute/caustics/blob/main/media/caustics_logo.png?raw=true">
  <source media="(prefers-color-scheme: light)" srcset="https://github.com/Ciela-Institute/caustics/blob/main/media/caustics_logo_white.png?raw=true">
  <img alt="caustics logo" src="media/caustics_logo.png" width="70%">
</picture>

[![ssec](https://img.shields.io/badge/SSEC-Project-purple?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAAOCAQAAABedl5ZAAAACXBIWXMAAAHKAAABygHMtnUxAAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAAMNJREFUGBltwcEqwwEcAOAfc1F2sNsOTqSlNUopSv5jW1YzHHYY/6YtLa1Jy4mbl3Bz8QIeyKM4fMaUxr4vZnEpjWnmLMSYCysxTcddhF25+EvJia5hhCudULAePyRalvUteXIfBgYxJufRuaKuprKsbDjVUrUj40FNQ11PTzEmrCmrevPhRcVQai8m1PRVvOPZgX2JttWYsGhD3atbHWcyUqX4oqDtJkJiJHUYv+R1JbaNHJmP/+Q1HLu2GbNoSm3Ft0+Y1YMdPSTSwQAAAABJRU5ErkJggg==&style=plastic)](https://escience.washington.edu/software-engineering/ssec/)
[![CI](https://github.com/Ciela-Institute/caustics/actions/workflows/ci.yml/badge.svg)](https://github.com/Ciela-Institute/caustics/actions/workflows/ci.yml)
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/Ciela-Institute/caustics/main.svg)](https://results.pre-commit.ci/latest/github/Ciela-Institute/caustics/main)
[![Documentation Status](https://readthedocs.org/projects/caustics/badge/?version=latest)](https://caustics.readthedocs.io/en/latest/?badge=latest)
[![PyPI version](https://badge.fury.io/py/caustics.svg)](https://pypi.org/project/caustics/)
[![coverage](https://img.shields.io/codecov/c/github/Ciela-Institute/caustics)](https://app.codecov.io/gh/Ciela-Institute/caustics)
[![DOI](https://zenodo.org/badge/521722463.svg)](https://zenodo.org/doi/10.5281/zenodo.10806382)

# 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:

```bash
pip install caustics
```

## Minimal Example

```python
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.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()
```

![Caustics lensed image](./media/minimal_example.png)

### Batched simulator

```python
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](./media/minisim_vmap.png)

### Automatic Differentiation

```python
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](./media/minisim_jacobian.png)

## Documentation

Please see our [documentation page](https://caustics.readthedocs.io/en/latest/)
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](https://github.com/codespaces/badge.svg)](https://codespaces.new/uw-ssec/caustics?quickstart=1)

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`](https://docs.pytest.org/).

Thanks to our contributors so far!

[![Contributors](https://contrib.rocks/image?repo=Ciela-Institute/caustics)](https://github.com/Ciela-Institute/caustics/graphs/contributors)

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "caustics",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "astronomy, astrophysics, caustics, differentiable programming, gravitational lensing, lensing, pytorch, strong lensing",
    "author": null,
    "author_email": "Connor Stone <connor.stone@mila.quebec>, Alexandre Adam <alexandre.adam@mila.quebec>, UW SSEC <ssec@uw.edu>",
    "download_url": "https://files.pythonhosted.org/packages/e5/6e/ae76a83ebb748a0cf6cc85452463ecdcd7ebf13de567bac4e932aa68d6cf/caustics-0.10.1.tar.gz",
    "platform": null,
    "description": "<picture>\n  <source media=\"(prefers-color-scheme: dark)\" srcset=\"https://github.com/Ciela-Institute/caustics/blob/main/media/caustics_logo.png?raw=true\">\n  <source media=\"(prefers-color-scheme: light)\" srcset=\"https://github.com/Ciela-Institute/caustics/blob/main/media/caustics_logo_white.png?raw=true\">\n  <img alt=\"caustics logo\" src=\"media/caustics_logo.png\" width=\"70%\">\n</picture>\n\n[![ssec](https://img.shields.io/badge/SSEC-Project-purple?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAAOCAQAAABedl5ZAAAACXBIWXMAAAHKAAABygHMtnUxAAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAAMNJREFUGBltwcEqwwEcAOAfc1F2sNsOTqSlNUopSv5jW1YzHHYY/6YtLa1Jy4mbl3Bz8QIeyKM4fMaUxr4vZnEpjWnmLMSYCysxTcddhF25+EvJia5hhCudULAePyRalvUteXIfBgYxJufRuaKuprKsbDjVUrUj40FNQ11PTzEmrCmrevPhRcVQai8m1PRVvOPZgX2JttWYsGhD3atbHWcyUqX4oqDtJkJiJHUYv+R1JbaNHJmP/+Q1HLu2GbNoSm3Ft0+Y1YMdPSTSwQAAAABJRU5ErkJggg==&style=plastic)](https://escience.washington.edu/software-engineering/ssec/)\n[![CI](https://github.com/Ciela-Institute/caustics/actions/workflows/ci.yml/badge.svg)](https://github.com/Ciela-Institute/caustics/actions/workflows/ci.yml)\n[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/Ciela-Institute/caustics/main.svg)](https://results.pre-commit.ci/latest/github/Ciela-Institute/caustics/main)\n[![Documentation Status](https://readthedocs.org/projects/caustics/badge/?version=latest)](https://caustics.readthedocs.io/en/latest/?badge=latest)\n[![PyPI version](https://badge.fury.io/py/caustics.svg)](https://pypi.org/project/caustics/)\n[![coverage](https://img.shields.io/codecov/c/github/Ciela-Institute/caustics)](https://app.codecov.io/gh/Ciela-Institute/caustics)\n[![DOI](https://zenodo.org/badge/521722463.svg)](https://zenodo.org/doi/10.5281/zenodo.10806382)\n\n# caustics\n\nThe lensing pipeline of the future: GPU-accelerated,\nautomatically-differentiable, highly modular. Currently under heavy development:\nexpect interface changes and some imprecise/untested calculations.\n\n## Installation\n\nSimply install caustics from PyPI:\n\n```bash\npip install caustics\n```\n\n## Minimal Example\n\n```python\nimport matplotlib.pyplot as plt\nimport caustics\nimport torch\n\ncosmology = caustics.FlatLambdaCDM()\nsie = caustics.SIE(cosmology=cosmology, name=\"lens\")\nsrc = caustics.Sersic(name=\"source\")\nlnslt = caustics.Sersic(name=\"lenslight\")\n\nx = torch.tensor([\n#   z_s  z_l   x0   y0   q    phi     b    x0   y0   q     phi    n    Re\n    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,\n#   Ie    x0   y0   q    phi  n   Re   Ie\n    5.0, -0.2, 0.0, 0.8, 0.0, 1., 1.0, 10.0\n])  # fmt: skip\n\nminisim = caustics.Lens_Source(\n    lens=sie, source=src, lens_light=lnslt, pixelscale=0.05, pixels_x=100\n)\nplt.imshow(minisim(x, quad_level=3), origin=\"lower\")\nplt.axis(\"off\")\nplt.show()\n```\n\n![Caustics lensed image](./media/minimal_example.png)\n\n### Batched simulator\n\n```python\nnewx = x.repeat(20, 1)\nnewx += torch.normal(mean=0, std=0.1 * torch.ones_like(newx))\n\nimages = torch.vmap(minisim)(newx)\n\nfig, axarr = plt.subplots(4, 5, figsize=(20, 16))\nfor ax, im in zip(axarr.flatten(), images):\n    ax.imshow(im, origin=\"lower\")\nplt.show()\n```\n\n![Batched Caustics lensed images](./media/minisim_vmap.png)\n\n### Automatic Differentiation\n\n```python\nJ = torch.func.jacfwd(minisim)(x)\n\n# Plot the new images\nfig, axarr = plt.subplots(3, 7, figsize=(20, 9))\nfor i, ax in enumerate(axarr.flatten()):\n    ax.imshow(J[..., i], origin=\"lower\")\nplt.show()\n```\n\n![Jacobian Caustics lensed image](./media/minisim_jacobian.png)\n\n## Documentation\n\nPlease see our [documentation page](https://caustics.readthedocs.io/en/latest/)\nfor more detailed information.\n\n## Contribution\n\nWe welcome contributions from collaborators and researchers interested in our\nwork. If you have improvements, suggestions, or new findings to share, please\nsubmit an issue or pull request. Your contributions help advance our research\nand analysis efforts.\n\nTo get started with your development (or fork), click the \"Open with GitHub\nCodespaces\" button below to launch a fully configured development environment\nwith all the necessary tools and extensions.\n\n[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/uw-ssec/caustics?quickstart=1)\n\nInstruction on how to contribute to this project can be found in the\nCONTRIBUTION.md\n\nSome guidelines:\n\n- Please use `isort` and `black` to format your code.\n- Use `CamelCase` for class names and `snake_case` for variable and method\n  names.\n- Open up issues for bugs/missing features.\n- Use pull requests for additions to the code.\n- Write tests that can be run by [`pytest`](https://docs.pytest.org/).\n\nThanks to our contributors so far!\n\n[![Contributors](https://contrib.rocks/image?repo=Ciela-Institute/caustics)](https://github.com/Ciela-Institute/caustics/graphs/contributors)\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) [2023] [caustics authors]  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "The lensing pipeline of the future: GPU-accelerated, automatically-differentiable, highly modular. Currently under heavy development: expect interface changes and some imprecise/untested calculations.",
    "version": "0.10.1",
    "project_urls": {
        "Documentation": "https://caustics.readthedocs.io/en/latest/",
        "Homepage": "https://mila.quebec/en/",
        "Issues": "https://github.com/Ciela-Institute/caustics/issues",
        "Repository": "https://github.com/Ciela-Institute/caustics"
    },
    "split_keywords": [
        "astronomy",
        " astrophysics",
        " caustics",
        " differentiable programming",
        " gravitational lensing",
        " lensing",
        " pytorch",
        " strong lensing"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1a0fb149df84e9bf07e14533c2bd3abd4c0145c0ca57d2459558f3a6740eb332",
                "md5": "808fcceb0d0968606d9bb81f9c2832a0",
                "sha256": "adb3b29fde7c87550517b4e2d8b09b14dcec92ae4572b04b780f77fb3084db07"
            },
            "downloads": -1,
            "filename": "caustics-0.10.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "808fcceb0d0968606d9bb81f9c2832a0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 94773,
            "upload_time": "2024-04-25T20:29:50",
            "upload_time_iso_8601": "2024-04-25T20:29:50.919349Z",
            "url": "https://files.pythonhosted.org/packages/1a/0f/b149df84e9bf07e14533c2bd3abd4c0145c0ca57d2459558f3a6740eb332/caustics-0.10.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e56eae76a83ebb748a0cf6cc85452463ecdcd7ebf13de567bac4e932aa68d6cf",
                "md5": "93bacb999f8d12526ed7faff50466559",
                "sha256": "4500e6ca4761dd81084cb1a932f65deb1b1e685a8fd305a79dcd03511129e27f"
            },
            "downloads": -1,
            "filename": "caustics-0.10.1.tar.gz",
            "has_sig": false,
            "md5_digest": "93bacb999f8d12526ed7faff50466559",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 2152062,
            "upload_time": "2024-04-25T20:29:53",
            "upload_time_iso_8601": "2024-04-25T20:29:53.700910Z",
            "url": "https://files.pythonhosted.org/packages/e5/6e/ae76a83ebb748a0cf6cc85452463ecdcd7ebf13de567bac4e932aa68d6cf/caustics-0.10.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-25 20:29:53",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Ciela-Institute",
    "github_project": "caustics",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "astropy",
            "specs": [
                [
                    "<",
                    "6.0.0"
                ],
                [
                    ">=",
                    "5.2.1"
                ]
            ]
        },
        {
            "name": "graphviz",
            "specs": [
                [
                    "==",
                    "0.20.1"
                ]
            ]
        },
        {
            "name": "h5py",
            "specs": [
                [
                    ">=",
                    "3.8.0"
                ]
            ]
        },
        {
            "name": "mpmath",
            "specs": [
                [
                    ">=",
                    "1.3.0"
                ],
                [
                    "<",
                    "1.4.0"
                ]
            ]
        },
        {
            "name": "numpy",
            "specs": [
                [
                    ">=",
                    "1.23.5"
                ]
            ]
        },
        {
            "name": "safetensors",
            "specs": [
                [
                    ">=",
                    "0.4.1"
                ]
            ]
        },
        {
            "name": "scipy",
            "specs": [
                [
                    ">=",
                    "1.8.0"
                ]
            ]
        },
        {
            "name": "torch",
            "specs": [
                [
                    ">=",
                    "2.0.0"
                ]
            ]
        }
    ],
    "lcname": "caustics"
}
        
Elapsed time: 0.32049s