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.1-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.1-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (513.9 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ ARM64

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

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.14macOS 10.12+ x86-64

opencosmo-1.3.1-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.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (514.0 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

opencosmo-1.3.1-cp313-cp313-macosx_10_12_x86_64.whl (483.2 kB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

opencosmo-1.3.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (521.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

opencosmo-1.3.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (514.0 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

opencosmo-1.3.1-cp312-cp312-macosx_11_0_arm64.whl (477.9 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

opencosmo-1.3.1-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.1-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for opencosmo-1.3.1-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4e74163c389f91ec39ce05b92ab57412bb0b3c1d17b355a2b28b2e7ab82c9e82
MD5 9f32313e8e8c5cc41e36ea8875f0fecb
BLAKE2b-256 4ca4517514149b4a27a54ed96fed130564fa91305e9af5baccc702781926103e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.1-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 8e7bae19c7dfe13b5689447e5509b06e21dcf112a1ebf2abc5dbc1ece266c4e6
MD5 2da24fdade97030e0e4117d08caf2991
BLAKE2b-256 3beedbb69d6b99d18ed9b01381e9d50adf02c2100925b0fef52a6989b0e538c7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.1-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fce5b662e40ff47331209a61d1e618d58cc1103acb5c06d85937c6657d3a0c30
MD5 16ea591b55104be3e07f8058cfeb9a55
BLAKE2b-256 7c2acc3b3636a04dd2cf0dc2919dba1f509a9b726a5a63ff505d820798a6d5dc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.1-cp314-cp314-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 2cf01f9dd9d40491f4569bfcb9f5bfe876b5773a20ec937aa6e9d7311acee4cb
MD5 525f1877e09db07e6f91beb668761811
BLAKE2b-256 66e26e48196a42fd3495a6da23220d2f9401ea3979c039ff3e13b76fdce2d111

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7a5045902921ba68cc3d96892308e28f861064efd11216c2e6880a69da5d2d7a
MD5 6369e525629d9568c33d3d9360097728
BLAKE2b-256 92a8e89b52fb27cf0d63f7487475d006b5961367d0f7b1769a5689819b08be19

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 7f26d5e27f55ad2f85f9a9121dbcecc535788019c93d47e47f3409aab4dc1e1e
MD5 08484cf42d938a871cd2dbfa46207bf4
BLAKE2b-256 01df1ff286193b9411d157f7322ad98aa174bfe797e0e610b168e0f60d765b34

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e4638cd53bf0decdd5d0d8c0a4885fb0e89af96cf06ee4ebadde0a6be670ee2d
MD5 81e2a73d65aac0318ed2ba7417b49bd2
BLAKE2b-256 a830d14bff1eb6864100ab3e6aa3005606573a103ee773e7ce5ebe3cf4f79415

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.1-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 590132095a216ba2f6821f94c4548a1015bc8acdfdf7a76c43c98f22cebf8343
MD5 44996f15b6972efebd30a5002469c4e8
BLAKE2b-256 ac658a8e510527f64a5bcf96df99a29f7d77ff115cd1f195f7d4adfbfec5bb87

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f8a49d0df3f795b2103e86ff47195c5db631b9413ba13b7c0f50b83be92c4a4b
MD5 e78aaf8f84c041c788e29dd4b3c3faff
BLAKE2b-256 91e9969992a4f6e4f0a59a488beaa95d9c9736258b233efd34e00302d38067f1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 1115ec5bbfc1d1557cb55c2c641d2483e5dc02a245339f329dc26d06150b272b
MD5 09d9e3dfa4ed6e7c8303f26deb214501
BLAKE2b-256 3f9d451c12f9767d8d03480e8ece9e76569c64e5312c0d016e44e7ea5281a0eb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d5f78b84151a30d49ca4ac44291f42b1a986332a523e32ecc1c46359f7a44763
MD5 97d12cf8d162d0c3566b634103580c52
BLAKE2b-256 cd36812826e5176d2feafe60f326ebe1fd35fb51508c1c4e44a0399f1e00a767

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.1-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 a69c8bfe4dbe0bb11dae9335eeacd8db7bad93e2cdf0408a38eb3c85a5edf357
MD5 a2aa4d642f9fab0c54fbf9c372791d38
BLAKE2b-256 8106b406f4db39c9448c866f734150f2d142c028926e39e66596eb2641281b76

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