Skip to main content

OpenCosmo Python Toolkit

Project description

OpenCosmo


CI PyPI - Version Conda Version GitHub License

The OpenCosmo Python Toolkit provides utilities for reading, writing and manipulating data from cosmological simulations produced by the Cosmolgical Physics and Advanced Computing (CPAC) group at Argonne National Laboratory. It can be used to work with smaller quantities data retrieved with the CosmoExplorer, as well as the much larget datasets these queries draw from. The OpenCosmo toolkit integrates with standard tools such as AstroPy, and allows you to manipulate data in a fully-consistent cosmological context.

Installation

The OpenCosmo library is available for Python 3.11 and up on Linux and MacOS (and Windows via WSL). It can be installed easily with pip:

pip install opencosmo

There's a good chance the default version of Python on your system is less than 3.11. Whether or not this is the case, we recommend installing opencosmo into a virtual environment. If you're using Conda, you can create a new environment and install opencosmo into it automatically:

conda create -n opencosmo_env conda-forge::opencosmo
conda activate opencosmo_env

or if you already have a virtual environment to use:

conda install conda-forge::opencosmo

If you plan to use opencosmo in a Jupyter notebook, you can install the ipykernel package to make the environment available as a kernel:

pip install ipykernel # can also be installed with conda
python -m ipykernel install --user --name=opencosmo

Be sure you have run the "activate" command shown above before running the ipykernel command.

Getting Started

To get started, download the "haloproperites.hdf5" from the OpenCosmo Google Drive. This file contains properties of dark-matter halos from a small hydrodynamical simulation run with HACC. You can easily open the data with the open command:

import opencosmo as oc

dataset = oc.open("haloproperties.hdf5")
print(dataset)
OpenCosmo Dataset (length=237441)
Cosmology: FlatLambdaCDM(name=None, H0=<Quantity 67.66 km / (Mpc s)>, Om0=0.3096446816186967, Tcmb0=<Quantity 0. K>, Neff=3.04, m_nu=None, Ob0=0.04897468161869667)
First 10 rows:
block fof_halo_1D_vel_disp fof_halo_center_x ... sod_halo_sfr unique_tag
             km / s               Mpc        ... solMass / yr
int32       float32             float32      ...   float32      int64
----- -------------------- ----------------- ... ------------ ----------
    0            32.088795         1.4680439 ...       -101.0      21674
    0             41.14525        0.19616994 ...       -101.0      44144
    0             73.82962         1.5071135 ...    3.1447952      48226
    0             31.17231         0.7526525 ...       -101.0      58472
    0            23.038841         5.3246417 ...       -101.0      60550
    0            37.071426         0.5153746 ...       -101.0     537760
    0            26.203058         2.1734374 ...       -101.0     542858
    0              78.7636         2.1477687 ...          0.0     548994
    0             37.12636         6.9660196 ...       -101.0     571540
    0             58.09235          6.072006 ...    1.5439711     576648

The open function returns a Dataset object, which can retrieve the relevant data from disk with a simple method call. It also holds metadata about the simulation, such as the comsology. You can easily access the data and cosmology as Astropy objects:

dataset.get_data()
dataset.cosmology

The first will return an astropy table of the data, with all associated units already applied. The second will return the astropy cosmology object that represents the cosmology the simulation was run with.

Basic Querying

Although you can access data directly, opencosmo provides tools for querying and transforming the data in a fully cosmology-aware context. For example, suppose we wanted to plot the concentration-mass relationship for the halos in our simulation above a certain mass. One way to perform this would be as follows:

dataset = dataset
    .filter(oc.col("fof_halo_mass") > 1e13)
    .take(1000, at="random")
    .select(("fof_halo_mass", "sod_halo_cdelta"))

print(dataset)
OpenCosmo Dataset (length=1000)
Cosmology: FlatLambdaCDM(name=None, H0=<Quantity 67.66 km / (Mpc s)>, Om0=0.3096446816186967, Tcmb0=<Quantity 0. K>, Neff=3.04, m_nu=None, Ob0=0.04897468161869667)
First 10 rows:
 fof_halo_mass   sod_halo_cdelta
    solMass
    float32          float32
---------------- ---------------
11220446000000.0       4.5797048
17266723000000.0       7.4097505
51242150000000.0       1.8738283
70097712000000.0       4.2764015
51028305000000.0        2.678151
11960567000000.0       3.9594727
15276915000000.0        5.793542
16002001000000.0       2.4318497
47030307000000.0       3.7146702
15839942000000.0        3.245569

We could then plot the data, or perform further transformations. This is cool on its own, but the real power of opencosmo comes from its ability to work with different data types. Go ahead and download the "haloparticles" file from the OpenCosmo Google Drive and try the following:

import opencosmo as oc

data = oc.open("haloproperties.hdf5", "haloparticles.hdf5")

This will return a data collection that will allow you to query and transform the data as before, but will associate the halos with their particles.

data = data
    .filter(oc.col("fof_halo_mass") > 1e13)
    .take(1000, at="random")

for halo in data.halos():
    halo_properties = halo["halo_properties"]
    dm_particles = halo["dm_particles"]
    star_particles = halo["star_particles"]

In each iteration, "halo properties" will be a dictionary containing the properties of the halo (such as its total mass), while "dm_particles" and "star_particles" will be OpenCosmo datasets containing the dark matter and stars associated with the halo, respectively. Because these are just like the dataset object we saw eariler, we can further query and transform the particles as needed for our analysis. For more details on how to use the library, check out the full documentation.

Testing

To run tests, first download the test data from Google Drive. Set environment variable OPENCOSMO_DATA_PATH to the path where the data is stored. Then run the tests with pytest:

export OPENCOSMO_DATA_PATH=/path/to/data
# From the repository root
pytest --ignore test/parallel 

Although opencosmo does support multi-core processing via MPI, the default installation does not include the necessary dependencies to work in an MPI environment. If you need these capabilities, check out the guide in our documentation.

Contributing

We welcome bug reports and feature requests from the community. If you would like to contribute to the project, please check out the contributing guide for more information.


Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

opencosmo-1.3.0rc2-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (520.0 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

opencosmo-1.3.0rc2-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (514.2 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ ARM64

opencosmo-1.3.0rc2-cp314-cp314-macosx_11_0_arm64.whl (477.9 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

opencosmo-1.3.0rc2-cp314-cp314-macosx_10_12_x86_64.whl (483.4 kB view details)

Uploaded CPython 3.14macOS 10.12+ x86-64

opencosmo-1.3.0rc2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (520.2 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

opencosmo-1.3.0rc2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (514.1 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

opencosmo-1.3.0rc2-cp313-cp313-macosx_11_0_arm64.whl (477.9 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

opencosmo-1.3.0rc2-cp313-cp313-macosx_10_12_x86_64.whl (483.3 kB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

opencosmo-1.3.0rc2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (521.2 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

opencosmo-1.3.0rc2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (514.2 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

opencosmo-1.3.0rc2-cp312-cp312-macosx_11_0_arm64.whl (478.0 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

opencosmo-1.3.0rc2-cp312-cp312-macosx_10_12_x86_64.whl (483.2 kB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

File details

Details for the file opencosmo-1.3.0rc2-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for opencosmo-1.3.0rc2-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3329c7834b8d3f6abd19d46e87d0625903802fe7bb509b6583bf2f5243e60b75
MD5 6b76bc0b7b0520439f44e845f842b7d2
BLAKE2b-256 e1c19e5cd17ef425d9be9b4fe6e01920303df0472799740048614b6e9cd5a8b4

See more details on using hashes here.

File details

Details for the file opencosmo-1.3.0rc2-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for opencosmo-1.3.0rc2-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 25044f1fd73956f66595e93ebea742f9573b3f0b94983a32991f17b5f5345fe5
MD5 313e96e7c03e1a69d1a130c85a56b694
BLAKE2b-256 d2dd46f440ceb3a0296aaeba68b11cac367f29f466569cbd8dd98d6c143acd79

See more details on using hashes here.

File details

Details for the file opencosmo-1.3.0rc2-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for opencosmo-1.3.0rc2-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d9197c81442415f820182d91a642582218f11c9c453e43ea34821532be8845da
MD5 23f8fb669aaadd658df141dc5362ac08
BLAKE2b-256 12403bf675370944dac780550d2d3f5c2220b7ddc12d090c1876673525f5c737

See more details on using hashes here.

File details

Details for the file opencosmo-1.3.0rc2-cp314-cp314-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for opencosmo-1.3.0rc2-cp314-cp314-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 9ede20d392fb4e61de6df58c1422221b58db93c957c811c0fb9b8bd25471370e
MD5 2319c37cd5d84ceecab4d54eacc2b074
BLAKE2b-256 5aec21a112150c838409bf11fb61c86de51d877a87daff765dae0dfffe8bf15f

See more details on using hashes here.

File details

Details for the file opencosmo-1.3.0rc2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for opencosmo-1.3.0rc2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c541c36e2eb02a0edef2de81301f8147d60fca1308dbf7656b7179dc7322a855
MD5 3f9bc539bca066f3f6d0fe8fbc50b248
BLAKE2b-256 230cbed32f734b94d7dff35915f05a602ae7b80bbe006e2d8e843ea9eae57ac2

See more details on using hashes here.

File details

Details for the file opencosmo-1.3.0rc2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for opencosmo-1.3.0rc2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 cbb3ab99fb2bbf1a30445de35cbda4ffd7c351b6d458722d3ecd77ebe43c4796
MD5 02c4165e3185c22d269fe78d293b4ec4
BLAKE2b-256 4c1b9e861f3161869a58049490f0f53d68b7ebf2910727b2e5900f8fd366734f

See more details on using hashes here.

File details

Details for the file opencosmo-1.3.0rc2-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for opencosmo-1.3.0rc2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3fa551ec0f98f01dd3a2a53ed135d7958288d1f5ed00981ba2aade3cc9bb65d8
MD5 0e252769374a9766b3bc9fa99aa2d8b9
BLAKE2b-256 0815e928e1f0554345a605bc1b2e8e939b6fbf6e28bc690da8b794b5f5b1ed5a

See more details on using hashes here.

File details

Details for the file opencosmo-1.3.0rc2-cp313-cp313-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for opencosmo-1.3.0rc2-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 e992ba3fa35e0fab76dd265adbee03afd20c20446a4f349dd6b78b8a23047c3a
MD5 1d3b5069d36d89b61de37f274d7ea6b9
BLAKE2b-256 72608e6f6c05f641582f76468441ed355ee5f07ecf1e12d9eb1b0788efc5af3a

See more details on using hashes here.

File details

Details for the file opencosmo-1.3.0rc2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for opencosmo-1.3.0rc2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f5456bdf695d5779be30e6d59ad49c2f409faea38ec92d6d470d6a94a5458ffa
MD5 329a8b689265c6f3cd34c508bcdb93a0
BLAKE2b-256 e559a5fddef234afc8934098f587c9fabfc634dfe5a9761e6846892b252f28a1

See more details on using hashes here.

File details

Details for the file opencosmo-1.3.0rc2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for opencosmo-1.3.0rc2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 40c86d04343188e5c6f49ae734fff8c04ed51c13a533d4c7b55a1eea29404503
MD5 24b532a669823c1c5c374de21d33b138
BLAKE2b-256 27b11147bc378426c7c6e082eae376ce424f9a518223dc7c830f5d270d556961

See more details on using hashes here.

File details

Details for the file opencosmo-1.3.0rc2-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for opencosmo-1.3.0rc2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1e876179bfa3d7d3b70586dcc295bf8035039feb0123d20836679573dd9fc8fe
MD5 acdfbc10534fa717f0cafd2086c823f7
BLAKE2b-256 7933e3db7057cf751344aa4750d6cd1af51ef8c1d2ef1c88af0bf4f55aec25ee

See more details on using hashes here.

File details

Details for the file opencosmo-1.3.0rc2-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for opencosmo-1.3.0rc2-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 9cf3497e120dd0efe315f921830684c50a9ae158515c43b9ef62a0e3b774faed
MD5 bce5db97de098d8775caf974ae211d59
BLAKE2b-256 862a60e2920828249d82838cdbe3a5f98271898231819ea44546d64942903066

See more details on using hashes here.

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