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-2.6.7.tar.gz (22.6 MB view details)

Uploaded Source

Built Distributions

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

cosmosim-2.6.7-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (30.6 MB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

cosmosim-2.6.7-cp314-cp314t-macosx_11_0_arm64.whl (24.4 MB view details)

Uploaded CPython 3.14tmacOS 11.0+ ARM64

cosmosim-2.6.7-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (23.1 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

cosmosim-2.6.7-cp314-cp314-macosx_11_0_arm64.whl (19.9 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

cosmosim-2.6.7-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (23.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

cosmosim-2.6.7-cp313-cp313-macosx_11_0_arm64.whl (19.9 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

cosmosim-2.6.7-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (23.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

cosmosim-2.6.7-cp312-cp312-macosx_11_0_arm64.whl (19.9 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

cosmosim-2.6.7-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (23.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

cosmosim-2.6.7-cp311-cp311-macosx_11_0_arm64.whl (19.9 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

Details for the file cosmosim-2.6.7.tar.gz.

File metadata

  • Download URL: cosmosim-2.6.7.tar.gz
  • Upload date:
  • Size: 22.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cosmosim-2.6.7.tar.gz
Algorithm Hash digest
SHA256 b53d1657f25b93fd7e70c8a5f10b94f7cac35cd13420cab3fee40aa005d8c0b9
MD5 47f0751e7f45de372665b4fca22b8562
BLAKE2b-256 5aad92ddb4b923b9d26a11ef3aa06ab2870a9ed4df3661eed70ef49c12863518

See more details on using hashes here.

Provenance

The following attestation bundles were made for cosmosim-2.6.7.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-2.6.7-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cosmosim-2.6.7-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 611e460d5d09628a1d7ab6d777d0a74a155b60788b6ebf5ee37d91e62bf91be2
MD5 3f9ffc54b243a7a9dcaf00d9b5b9fe8b
BLAKE2b-256 37fd874c3b91efc5a6e5349e6804f748c7bfaa3890d3b5888de1b8573ecaa503

See more details on using hashes here.

Provenance

The following attestation bundles were made for cosmosim-2.6.7-cp314-cp314t-manylinux_2_27_x86_64.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-2.6.7-cp314-cp314t-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cosmosim-2.6.7-cp314-cp314t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f66d48b08b8b3fea5dff430344089a2a72b03bad99987676a5a5a274e7e50834
MD5 1b82057e2aaa4dcd68faa4541788acab
BLAKE2b-256 1b84da17fc96e82bf5daee53f1c782872f0ceb6ecc7edbc74de8b0c0aac09c71

See more details on using hashes here.

Provenance

The following attestation bundles were made for cosmosim-2.6.7-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-2.6.7-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cosmosim-2.6.7-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b2db6faa635e07ee8bf3932486c0bcfe26e44629c950e5f144ec799dc85385b9
MD5 b6c60dd52e7c51b1b58ecf7cbc8b8d90
BLAKE2b-256 92b8c4fbe4e25030a966ec863b1f753df68772ce305e2b51df176019aad99323

See more details on using hashes here.

Provenance

The following attestation bundles were made for cosmosim-2.6.7-cp314-cp314-manylinux_2_27_x86_64.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-2.6.7-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cosmosim-2.6.7-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cf4b87efcda06024bf4153d2d8e4a5b80b1c59519f5d1cd6d08f3278585816ff
MD5 a918da7c8f6c784b667f404133ae63f8
BLAKE2b-256 12ecc699253470e2c2068cdf689966a305ab590aaa33118473f9244792035f35

See more details on using hashes here.

Provenance

The following attestation bundles were made for cosmosim-2.6.7-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-2.6.7-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cosmosim-2.6.7-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1d5ba6e3c89408a97136ad129cd65fceda64567dd6f4e58a3611cda169032ee6
MD5 3fbc2b89256bf166e112728478dba468
BLAKE2b-256 c5b92cbd182f7216d639e01fd4de8ede28f4dd7e5adf0c5aa9855ed0e2e3928d

See more details on using hashes here.

Provenance

The following attestation bundles were made for cosmosim-2.6.7-cp313-cp313-manylinux_2_27_x86_64.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-2.6.7-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cosmosim-2.6.7-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0418fe16fc3910a6a73e79cd87eb68fd7d5f9782893764bfe7d08e6adfb3c21c
MD5 c9825200fc508b8db7f13ef9b4457fe8
BLAKE2b-256 c0a1ab2fd22c3d39e25a738190fbe489f8f96f5ee886c40ff563c0b679a916e7

See more details on using hashes here.

Provenance

The following attestation bundles were made for cosmosim-2.6.7-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-2.6.7-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cosmosim-2.6.7-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1ce83f7f540575580f763e8c38c87c7eea6a0379b8e4573360df2356beaf90ef
MD5 93140004ccf7f287673e55eca63e2f1f
BLAKE2b-256 8db026c165aa423a1163b420d6b0e8301dabda9eabf4c44e08fcc765124baa4d

See more details on using hashes here.

Provenance

The following attestation bundles were made for cosmosim-2.6.7-cp312-cp312-manylinux_2_27_x86_64.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-2.6.7-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cosmosim-2.6.7-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3d5810aa3c522946a8cecd3326c771f6fd68867c18e2635940728967802287f0
MD5 c2732c508f462ff5e3e3f757bbdee1c5
BLAKE2b-256 90c35a3cd70fcd64be8745f3e53cf1954ba3bac44cb48bb38a5fbf839e9f9ed7

See more details on using hashes here.

Provenance

The following attestation bundles were made for cosmosim-2.6.7-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-2.6.7-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cosmosim-2.6.7-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e146c271ada722af97aa80f1bb42e23fce2b2fb5dd61d90843d998fd839bc990
MD5 0c698207dadb749f4f281fd149d1477f
BLAKE2b-256 9526ebebd1821383aca3292355ba853effc985bef5d2852714a3a83d703d057a

See more details on using hashes here.

Provenance

The following attestation bundles were made for cosmosim-2.6.7-cp311-cp311-manylinux_2_27_x86_64.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-2.6.7-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cosmosim-2.6.7-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c4a7b1ba96205f5ffc5aca23e82b473cbc89b95dc899017435f88e7e0360bee7
MD5 981003d290f603d79355bf2f1e997542
BLAKE2b-256 c8aa1e5691e74f748c7d8db9da569c64a58c8fff7cfecfeaf5c34380a2cf1af9

See more details on using hashes here.

Provenance

The following attestation bundles were made for cosmosim-2.6.7-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