Skip to main content

Simulator of Gravitational Lenses

Project description


title: The CosmoAI project

The CosmoSim software

This project provides a simulator for gravitational lensing based on Chris Clarkson's Roulettes framework. The code is experimental, and intended for research, with many loose ends. If you think it may be useful, we shall be happy to discuss collaboration and help you get started.

The core team is

Installation Guide

CosmoSim is set up to build python packages (wheels) that can be installed with pip.

pip install CosmoSim

We successfully build CosmoSim for Linux/x86_64 and MacOS/arm, for python 3.11 trough 3.14, and 3.14.t Buiilding for python 3.10 is impossible because tomllib is required. Building on Windows (amd64, python 3.11-3.14) sometimes works, but currently not.

To build locally from source, you can run (from the root of the repo),

pip install build
python -m build

This is highly dependent on the local configuration, and may fail for a number of reasons. If it succeeds, the binary file for the python module appears under src/CosmoSim.

If you can build, pip can also install the package from the working directory. Again, from the root of the repo,

pip install .

For non-standard building, see BUILD.md.

Running the GUI

python3 -m CosmoSim.GUI

The GUI tool is hopefully quite self-explanatory.
The images shown are the actual source on the left and the distorted (lensed) image on the right.

The Command Line Interface (CLI)

Overview of Tools

The modules that can be run as command line scripts are the following:

  • python -m CosmoSim.datagen (simulate images from lens parameters)
  • python -m CosmoSim.roulettegen (simulate images from roulette amplitudes)
  • python -m CosmoSim.roulettestatistics (descriptive statistics of roulette amplitudes)

Testing

Once built, an illustrative test set can be generated by

the following command issued from the root directory. Note that you have to install python dependencies from the requirements file. You may want to install python libraries in a virtual environment. Here this is given to do that in global user space.

mkdir images
python3 -m CosmoSim.datagen -CR -Z 400 --csvfile Datasets/debug.csv --directory images

This generates a range of images in the newly created images directory. This should be on the .gitignore.

The flags may be changed; -C centres det distorted image in the centre of the image (being debugged); -Z sets the image size; -R prints an axes cross.

Dataset generation

The basic use case is bulk generation of images. The parameter distribution can be specified in a TOML file, see Datasets/dataset.toml for an example.

The following command generates a dataset.

python3 -m CosmoSim.datagen --toml dataset.toml --csvfile dataset.csv --outfile roulette.csv --directory images -C

Note the following

  • dataset.csv - contains the dataset with all the lens and source parameters.
  • The images directory contains the images generated from the dataset.
  • roulette.csv gives the dataset with roulette amplitudes.
  • -C centres the images on the centre of mass (luminence). This is necessary to avoid leaking information to a machine learning model. Most of the options are optional, and further options are available. See below.

Two-step generation

It is possible two generate the dataset and the images in two separate steps.

python3 -m CosmoSim.dataset input.toml output.csv
python3 -m CosmoSim.datagen --csvfile output.csv --outfile roulette.csv --directory images -C

Roulette Resimulation

TODO

python3 -m CosmoSim.roulettegen 

Generating individual images

To generate images from specified parameters, you can use

python3 -m CosmoSim.datagen -S sourcemodel -L lensmodel -x x -y y -s sigma -X chi -E einsteinR -n n -I imageSize -N name -R -C

Here are the options specified:

  • lensmodel is p for point mass (exact), r for Roulette (point mass), or s for SIS (Roulette).
  • sourcemodel is s for sphere, e for ellipse, or t for triangle.
  • -C centres the image on the centre of mass (centre of light)
  • -R draw the axes cross
  • x and y are the coordinates of the actual source
  • s is the standard deviation of the source
  • chi is the distance to the lens in percent of the distance to the source
  • einsteinR is the Einstein radius of the lens
  • n is the number of terms to use in roulette sum.
    (Not used for the point mass model.)
  • imageSize size of output image in pixels. The image will be imageSize$\times$imageSize pixels.
  • name is the name of the simulation, and used to generate filenames.
  • --help for a complete list of options.

Use cases

Training sets for roulette amplitudes

The datasets generated from datasetgen.py give the parameters for the lens and the source, as well as the image file. This allows us to train a machine learning model to identify the lens parameters, assuming a relatively simple lens model. It is still a long way to go to map cluster lenses.

An alternative approach is to try to estimate the effect (lens potential) in a neighbourhood around a point in the image. For instance, we may want to estimate the roulette amplitudes in the centre of the image. The datagen.py script can generate a CSV file containing these data along with the image, as follows:

mkdir images
python3 -m CosmoSim.datagen -C -Z 400 --csvfile Datasets/debug.csv \
        --directory images --outfile images.csv --nterms 5

The images should be centred (-C); the amplitudes may not be meaningful otherwise. The --directory flag puts images in the given directory which must exist. The image size is given by -Z and is square. The input and output files go without saying. The number of terms (--nterms) is the maximum $m$ for which the amplitudes are generated; 5 should give about 24 scalar values.

The amplitudes are labeled alpha[$s$,$m$] and beta[$s$,$m$] in the outout CSV file. One should focus on predicting the amplitudes for low values of $m$ first. The file also reproduces the source parameters, and the centre of mass $(x,y)$ in the original co-ordinate system using image coordinates with the origin in the upper left corner.

The most interesting lens model for this exercise is PsiFunctionSIS (fs), which gives the most accurate computations. The roulette amplitudes have not been implemented for any of the point mass lenses yet, and it also does not work for «SIS (rotated)» which is a legacy implementation of the roulette model with SIS and functionally equivalent to «Roulette SIS« (rs).

Warning This has yet to be tested properly.

Other scripts

The python/ directory contains scripts which do not depend on C++ code.

  • compare.py is used to compare images in the Regression Tests.
  • Several scripts used to calculate roulette amplitudes.

Versions

  • The imortant git branches are
    • develop is the current state of the art
    • pypitest is used for final testing with automatic deployment to the PyPI test index.
    • master should be the last stable version
  • Releases
    • v-test-* are test releases, used to debug workflows. Please ignore.
    • see the releases on githun and CHANGELOG.md
  • Prior to v2.0.0 some releases have been tagged, but not registered as releases in github.
    • v0.1.0, v0.2.0, v1.0.0 are versions made by the u/g students Spring 2022.
    • v1.0.1 is cleaned up to be able to build v1.0.0

Caveats

The simulator makes numerical calculations and there will always be approximation errors.

  1. The images generated from the same parameters have changed slightly between version. Some changes are because some unfortunate uses of integers and single-precision numbers have later been avoided, and some simply because the order of calculation has changed.
  2. The SIS model is implemented in two versions, one rotating to have the source on the x-axis and one working directly with arbitrary position. Difference are not perceptible by visual comparison, but the difference image shows noticeable difference.

Contributors

The initial prototype was an undergraduate final year project by Ingebrigtsen, Remøy, Westbø, Nedreberg, and Austnes (2022). The software includes both a GUI simulator for interactive experimentation, and a command line interface for batch generation of datasets.

  • Idea and Current Maintainance Hans Georg Schaathun hasc@ntnu.no
  • Mathematical Models Ben David Normann
  • Initial Prototype Simon Ingebrigtsen, Sondre Westbø Remøy, Einar Leite Austnes, and Simon Nedreberg Runde
  • Other Contributors Oda Hjemli

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

cosmosim-3.0.1b1.tar.gz (32.4 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

cosmosim-3.0.1b1-cp314-cp314t-manylinux_2_28_x86_64.whl (40.7 MB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.28+ x86-64

cosmosim-3.0.1b1-cp314-cp314t-macosx_11_0_arm64.whl (34.4 MB view details)

Uploaded CPython 3.14tmacOS 11.0+ ARM64

cosmosim-3.0.1b1-cp314-cp314-manylinux_2_28_x86_64.whl (33.1 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.28+ x86-64

cosmosim-3.0.1b1-cp314-cp314-macosx_11_0_arm64.whl (29.9 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

cosmosim-3.0.1b1-cp313-cp313-manylinux_2_28_x86_64.whl (33.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

cosmosim-3.0.1b1-cp313-cp313-macosx_11_0_arm64.whl (29.9 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

cosmosim-3.0.1b1-cp312-cp312-manylinux_2_28_x86_64.whl (33.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

cosmosim-3.0.1b1-cp312-cp312-macosx_11_0_arm64.whl (29.9 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

cosmosim-3.0.1b1-cp311-cp311-manylinux_2_28_x86_64.whl (33.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

cosmosim-3.0.1b1-cp311-cp311-macosx_11_0_arm64.whl (29.9 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

Details for the file cosmosim-3.0.1b1.tar.gz.

File metadata

  • Download URL: cosmosim-3.0.1b1.tar.gz
  • Upload date:
  • Size: 32.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for cosmosim-3.0.1b1.tar.gz
Algorithm Hash digest
SHA256 2ed4e6e0ea476c3d43905a34be28c321bc57ffedf367c8d8c5112486b47b59d8
MD5 3592444e77f675c717adeb3cbd8ef7b7
BLAKE2b-256 86d55ebf3107f331f2597563b94853d36bb967dc9c93be0749ac4226db18c6be

See more details on using hashes here.

Provenance

The following attestation bundles were made for cosmosim-3.0.1b1.tar.gz:

Publisher: pypideploy.yml on CosmoAI-AES/CosmoSim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cosmosim-3.0.1b1-cp314-cp314t-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cosmosim-3.0.1b1-cp314-cp314t-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 fce099f01bbda020324425be05837b76faabdebbf904ddfe67da94476430d736
MD5 793b4510e0a4c47e69f32da912e7c5cd
BLAKE2b-256 dd6e25f273762b81936d890927f1db48b0244900cd7453e9aee69c9c882a0943

See more details on using hashes here.

Provenance

The following attestation bundles were made for cosmosim-3.0.1b1-cp314-cp314t-manylinux_2_28_x86_64.whl:

Publisher: pypideploy.yml on CosmoAI-AES/CosmoSim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cosmosim-3.0.1b1-cp314-cp314t-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cosmosim-3.0.1b1-cp314-cp314t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4b052a63a2dc5cba815fffeaf83addbf54fdda9ba6baaf67d67b253d7b0744cb
MD5 2a148550590aa97263889e893138c2b8
BLAKE2b-256 0b414101113763cda50fbdc08b189e645e4f2670a415539a4bd3b0100422e580

See more details on using hashes here.

Provenance

The following attestation bundles were made for cosmosim-3.0.1b1-cp314-cp314t-macosx_11_0_arm64.whl:

Publisher: pypideploy.yml on CosmoAI-AES/CosmoSim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cosmosim-3.0.1b1-cp314-cp314-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cosmosim-3.0.1b1-cp314-cp314-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 848e51f8162777d82eb15c73ed62e0b528724e19beb72760b635ce40da75d91c
MD5 6e6866eb05618b9cb1b8bf0ded2dd1c3
BLAKE2b-256 f6ed16b4b0ebc8bca61891a8ca7f51f2541a93d82d912ec91e4e3d55ee62ed26

See more details on using hashes here.

Provenance

The following attestation bundles were made for cosmosim-3.0.1b1-cp314-cp314-manylinux_2_28_x86_64.whl:

Publisher: pypideploy.yml on CosmoAI-AES/CosmoSim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cosmosim-3.0.1b1-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cosmosim-3.0.1b1-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 691f15cd880dae30d1ed75197c2e4a03f4b844817c389274a52cd7f410d457d4
MD5 85c6e624785696bb60df2b72e1c40a0b
BLAKE2b-256 d00fa4319662bd58c3b86cf2ec72d7da07e2c48c4f040ff29726115e789ef62d

See more details on using hashes here.

Provenance

The following attestation bundles were made for cosmosim-3.0.1b1-cp314-cp314-macosx_11_0_arm64.whl:

Publisher: pypideploy.yml on CosmoAI-AES/CosmoSim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cosmosim-3.0.1b1-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cosmosim-3.0.1b1-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d26ba8addca8f1d961a7e2cb7b6cf705451c9dfbe5adf6892f06a60ec7f2a963
MD5 b64c1e284d66cae23e726b9aab8eb166
BLAKE2b-256 6b5b2e84c416eca98cf87a5f8d16e90d1972f86ec29230a8195366079df5459b

See more details on using hashes here.

Provenance

The following attestation bundles were made for cosmosim-3.0.1b1-cp313-cp313-manylinux_2_28_x86_64.whl:

Publisher: pypideploy.yml on CosmoAI-AES/CosmoSim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cosmosim-3.0.1b1-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cosmosim-3.0.1b1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a65c6f784925f07cfbc84cef6100dde2014074bd6556dc062c017c5b542596c9
MD5 7137cdd44d365ac8897446dbc11a1c85
BLAKE2b-256 f4d90a5defd2ce76caf80aaedb4ffdc9cd081f9c1a6bef74086a002410171844

See more details on using hashes here.

Provenance

The following attestation bundles were made for cosmosim-3.0.1b1-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: pypideploy.yml on CosmoAI-AES/CosmoSim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cosmosim-3.0.1b1-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cosmosim-3.0.1b1-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 73f534584948166bd338738781b617282dec0f2ebe7767711886c8e1cda1e61e
MD5 0e0e0bc4d0d3e5d0280f88efed4eb7c1
BLAKE2b-256 e49ed57397579865d456223e5995fe2d8d0f50d75e1a04359d447fc3f63d3bd7

See more details on using hashes here.

Provenance

The following attestation bundles were made for cosmosim-3.0.1b1-cp312-cp312-manylinux_2_28_x86_64.whl:

Publisher: pypideploy.yml on CosmoAI-AES/CosmoSim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cosmosim-3.0.1b1-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cosmosim-3.0.1b1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0a5c130b742e68ffb4acc113c0e5b7ad3cbdcf3c4b5b80a65708bf2f36956e41
MD5 5ef90177cddf6b2f02e65dc2be2c4eb6
BLAKE2b-256 22f7c0dc87e11ec0832a84835c90076539acdd2a9bcbca8938d05f38167cfaa6

See more details on using hashes here.

Provenance

The following attestation bundles were made for cosmosim-3.0.1b1-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: pypideploy.yml on CosmoAI-AES/CosmoSim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cosmosim-3.0.1b1-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cosmosim-3.0.1b1-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 91428661cfcca50bdebc64905a1643b59a416416d1a343c52960c782d026d919
MD5 d951eaa43c41a01820445f1b0fa7242c
BLAKE2b-256 668e486b5f6a144eae58ea1df29bbfebc08c7f0a935c2dfe024c9164771746a7

See more details on using hashes here.

Provenance

The following attestation bundles were made for cosmosim-3.0.1b1-cp311-cp311-manylinux_2_28_x86_64.whl:

Publisher: pypideploy.yml on CosmoAI-AES/CosmoSim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cosmosim-3.0.1b1-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cosmosim-3.0.1b1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 24bb8af8ec2da30bc694ebbb1a4743f1a6dc3f70f29e2c54e786469b4f87a4a7
MD5 53c520c5fe8b86868160eb8d468abc97
BLAKE2b-256 62f2e89a5384a745a32b952ad185bc83cf44fd23cb9b95435c69ff26e54fc66e

See more details on using hashes here.

Provenance

The following attestation bundles were made for cosmosim-3.0.1b1-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: pypideploy.yml on CosmoAI-AES/CosmoSim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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