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

Uploaded CPython 3.14manylinux: glibc 2.17+ ARM64

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

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.14macOS 10.12+ x86-64

opencosmo-1.3.4-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.4-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.4-cp313-cp313-macosx_11_0_arm64.whl (477.8 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.13macOS 10.12+ x86-64

opencosmo-1.3.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (521.6 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

opencosmo-1.3.4-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (513.8 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

opencosmo-1.3.4-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.4-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for opencosmo-1.3.4-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 590a7f65dd6607fb963ddcd5bf84ee8c1e9a99f4e060ad5a82b0784901483eb9
MD5 2931e367cba05adb34a41db9cc4061d9
BLAKE2b-256 b400af1a61f8f96574f6e082de78701918de00f31a829a15373ff96723584d40

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.4-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 720cd4253bfbba2855e3d789605408346df776dedd57576d992da413e3a348a3
MD5 7806a5adc04d8d25a39954a887ebd9aa
BLAKE2b-256 b7a5f1652940f63fd9fe38992c5cc21feda2e014b280b5b53ea3c9a4ead80ca6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.4-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 88c3f220591f1eb13cdeda6bdef4f75c9fad88827135a1f89007737363aaef87
MD5 14bf3fec0e5cfa28c2629bf293e3d57f
BLAKE2b-256 66585fe87a9d595470fd72a625ccaa64f1d4839d3e724c32e4ba640556e91eac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.4-cp314-cp314-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 91dc49bf71d3a9446f81e38ebe8c4786433f94aecbfbe02f0a68106b08821ac0
MD5 cd9a26c8dc9d3fbfcc5659a4289155fb
BLAKE2b-256 2736fe263f27e45d64ef160cc2995db5480b813469b84a7fc8ff6bc11a6840bf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 30cea7aaa91a2ef3400642e60cd32b7be56e882c4472bd72d86ff2d7b208b2a7
MD5 c0874cc6693f30c09ff003214c1aa4e4
BLAKE2b-256 e947e614e83a1884cb6b9be1608062146d7948957df112ab7782d3c877998082

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.4-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 bdd1a73945bc77f2efad447b1435c791a1ce8372284fb9a8dad5bc30b2ad692b
MD5 d00e9d68bbc6a3690b3637b1999e1e5f
BLAKE2b-256 51ab313e7057b3396336121974b8956dd3c723816614a3f38c13dc800e04d7cd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.4-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c660e6432a0e252d756f64204e1df602cddb9cb5bc3740ccd536fbbd519648d9
MD5 e8c320bc23f165fc8bd123b75aab1a49
BLAKE2b-256 a1d000455fd7b6d3e6432d698849bc5504d80121c5d3a26b892c8f322348b31d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.4-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 e054e1628d0d27be87cf25dded920d32d8f6eb160e8f112697745a35c1a1cd80
MD5 127de9f67d7167e8d421d38a3e495e8f
BLAKE2b-256 c2d057393d5945de58a4ff1a7fbac7a865df926bddaff489219a2b7a576f0ae4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 67fbbd03b1149d566d4fc804b005a3665eeb02b991c1cc322ceeb7ac64e91f3f
MD5 ba19d2eb02289cfaea51f82426e0221a
BLAKE2b-256 e5d784ec782a296319dd48d15272ceb7d6b830de8b7a89f8f165951abcc783f8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.4-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e15fc2cb0f57f8740e6812a73727b35a2bda301370f43ff301d1e95ae3fa90d4
MD5 5821dac7b4931ac3914706eeb88cce97
BLAKE2b-256 d1b65e2617ba1d8fa0ac7d1bdd5d33c7c3846d2937a180fb858d9223c8b2271a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fc61e87adcdb1d41102c4bdfee29a4c01e53a8cee9a491dd1372052c671f7e5f
MD5 6c24a918022a16521911f6dcb2076547
BLAKE2b-256 09fdb3e437d3178ac4c4320abaf646393c40a88ebdac4f76f62ccb710e95ad1a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.4-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 80eaf12392f447fcbfdb33af2e213b398a84de68ee36c3437a759ad319902d76
MD5 cde63e027bb033bfd8d9234692e20cf7
BLAKE2b-256 9505c2d70151e7e6288633c75b8f947eb1727bb6808d7cfd3952e10e2ac557d5

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