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.3-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (520.5 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

opencosmo-1.3.3-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (514.3 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ ARM64

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

Uploaded CPython 3.14macOS 11.0+ ARM64

opencosmo-1.3.3-cp314-cp314-macosx_10_12_x86_64.whl (483.3 kB view details)

Uploaded CPython 3.14macOS 10.12+ x86-64

opencosmo-1.3.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (520.9 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

opencosmo-1.3.3-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (513.8 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

opencosmo-1.3.3-cp313-cp313-macosx_11_0_arm64.whl (477.8 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.13macOS 10.12+ x86-64

opencosmo-1.3.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (521.5 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

opencosmo-1.3.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (513.7 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

opencosmo-1.3.3-cp312-cp312-macosx_11_0_arm64.whl (477.8 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

opencosmo-1.3.3-cp312-cp312-macosx_10_12_x86_64.whl (483.1 kB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

File details

Details for the file opencosmo-1.3.3-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for opencosmo-1.3.3-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 40091adb9db71d22ef31e8865e431fa2a1d4d173903c90a167b4044b99d052d6
MD5 903f4ea66718b0210bc72a81b05152a2
BLAKE2b-256 de8d8ffaa94e36565e609988ecbe496f55e175a652f2918f1e7ccb5da0c4fc64

See more details on using hashes here.

File details

Details for the file opencosmo-1.3.3-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for opencosmo-1.3.3-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b3ee5e49e615c6299b2373071628cb9ac71880d2323017331ff244be20471e8a
MD5 26f7eb919e8f6d7031a1ca28e0250820
BLAKE2b-256 6761335e353e84ea45c9e252a53e31d1c2caccc3a00ebb5ad3857abfcf3056dd

See more details on using hashes here.

File details

Details for the file opencosmo-1.3.3-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for opencosmo-1.3.3-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4597cf0ebda17232d529877544558db99f787e183c945199c014b0ff7f986101
MD5 9b186bcfdbf0996f59c71bffb597719f
BLAKE2b-256 4307d4b441e60fa36f4fb6691be54876250b70bca6d6e089c2bb55d228b9917d

See more details on using hashes here.

File details

Details for the file opencosmo-1.3.3-cp314-cp314-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for opencosmo-1.3.3-cp314-cp314-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 2a4d2885b7c31628debb65caf03242bc206b5ac26335ef0835acd7551b49d8f5
MD5 3e169be39cbb77fa2a9b84ae20349039
BLAKE2b-256 adaf08b29bd76161e0c5d819ccf684fdccc0da37d4c9c96bca8a66dcd24dca8d

See more details on using hashes here.

File details

Details for the file opencosmo-1.3.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for opencosmo-1.3.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6043d2005037b71981aecf00d857aef8aeeddddc3aa8059811cdd830f453958d
MD5 b4f14b3c24b042b8a44d09d8a3ecd148
BLAKE2b-256 b0ab0eae842361c0fead618127a3f453fc67eebaf513827c31da4adbfe6cef88

See more details on using hashes here.

File details

Details for the file opencosmo-1.3.3-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for opencosmo-1.3.3-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 65d66801ab5669c39fd85cc2c42044e2582151618bcb9a24d76f83bfc1ad20ed
MD5 0698c619c1006b0f45e2b6a4d44a55f3
BLAKE2b-256 a7bef228e17b12f4399b637e85b22460226f518b1b268eb3eee8092d936183a3

See more details on using hashes here.

File details

Details for the file opencosmo-1.3.3-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for opencosmo-1.3.3-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f482d7b172af74903c303461bd7380e35584f262b2482bd8ad6cdcb069abe98a
MD5 5a643a05c731f29e3ca055a33f29bf4c
BLAKE2b-256 f46523768d6786e1d8c09b3e729104044e5e1f8a96e30ae83989c8e65c2fc30b

See more details on using hashes here.

File details

Details for the file opencosmo-1.3.3-cp313-cp313-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for opencosmo-1.3.3-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 821b31337917c1b8bce0937e409cef383ab56bb346a494e980b1d1d20d858e04
MD5 1c16a930803554ade5d750bc120563c0
BLAKE2b-256 051d67dcbcf9a344bf6cd9dbcda468773ab064006853c6de7dddc5513fa54037

See more details on using hashes here.

File details

Details for the file opencosmo-1.3.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for opencosmo-1.3.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d37024fb522e40c53dddb4d4092ba120eafbd0ca3366be1038f466cae76b2cf2
MD5 434a25f0d8f613b2da95c3ee2f90d3c8
BLAKE2b-256 1e25fec86b3b195a4b90bfa490f143d7c57d64dee986d3113aeddd2c4fd419bf

See more details on using hashes here.

File details

Details for the file opencosmo-1.3.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for opencosmo-1.3.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 5654d0a488ee18e99f6bb58022e71512096e04122234a40001ef883c16948cf8
MD5 12010889a80b4456694a650139a25097
BLAKE2b-256 a12eb875e6cac36d86d2664309ac9b7ba92d0d7940104198aa7418c183a64c35

See more details on using hashes here.

File details

Details for the file opencosmo-1.3.3-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for opencosmo-1.3.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 25d8078147254348d8b7689b78e6b65a153da34fdd9b8cc9141f43eb5621480b
MD5 70668ddba4ef569b0e05ee3d076cb09f
BLAKE2b-256 a0687e7102feca3c525ff92d1b9c86c96ecf3d796df850d575a46d16ec8d8e8f

See more details on using hashes here.

File details

Details for the file opencosmo-1.3.3-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for opencosmo-1.3.3-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 398f8aaf312f5e639d713a8e1fde07f673459ca6122358befaaa9ec8042e1b3d
MD5 0c3908201380b11405721a13349e1339
BLAKE2b-256 abaef1ddff44933abf6b7b341faed29afb1598a2cd223d23059f2a7d22bf3335

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