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

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

opencosmo-1.3.2-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.2-cp314-cp314-macosx_11_0_arm64.whl (478.0 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.14macOS 10.12+ x86-64

opencosmo-1.3.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (521.0 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

opencosmo-1.3.2-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.2-cp313-cp313-macosx_11_0_arm64.whl (477.9 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.13macOS 10.12+ x86-64

opencosmo-1.3.2-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.2-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.2-cp312-cp312-macosx_11_0_arm64.whl (478.0 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

opencosmo-1.3.2-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.2-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for opencosmo-1.3.2-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a1c209254ba2cde08efe93f82aa22f26c1bb0f2aba28d1fb074a3a2acbd0999d
MD5 140032f57be29400a395467a98cef368
BLAKE2b-256 1afe9ba58995ec91943229218d22d31009d2abb55ded8fb2c2c3e84e32aeb4a2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.2-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 4100dbb218d1926ee1b0c3d7ab8371ee936a493e4280c2e95b5b57a57340a421
MD5 877720c3c2121dbaa722a210d9636eb1
BLAKE2b-256 99cca316bea5182592dfb83f35d2d04b51278768e8d66b2408a78383a947f246

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.2-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5f6bf45d6a2ee696d6704f906cfa7b072c7f4c5a713dba20b27cd19662d4f835
MD5 aaf99edb72291eaf060bcc4d6a2dcfe1
BLAKE2b-256 e6fad9177e05ac82a0c71610fd1b68ad7166b7a5d6e40092a97d8ad29aa9e8e4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.2-cp314-cp314-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 1263a475d558b02e96c6a3d36e20a09b8079517778f283cce5aa8befa4db2b0b
MD5 deadfc2d9d2319070fde1531af3b9f48
BLAKE2b-256 47b12d2ea0739d2d2e17022b291391a9d8c5f69d890357665b12808098fb4b0a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8a846f081cf5c4b481ed74a60430fb676bc332bed75a0ec7733a65329b541f32
MD5 ee355811049b7557faece30d06d62699
BLAKE2b-256 d8e55b90385ecebb29891bd8c0ab3d23a6f1f15085344088e237358d4f5d80c6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 073e60256f9a4305ce1b80c2c326c0a3177fa894b83980c3f02b4dc9649640c3
MD5 21b3df2671047f659ad8b8364f16c4c9
BLAKE2b-256 f93cab5d0d4b39484d27610de03d0b866295423779b85cb34590f33b576af634

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 adf159a66cd147905fb4138c2c20e4bedeff21dbbf16d2764b2bc2b251be7920
MD5 e74a9d76a82baa7af231a10d02430e90
BLAKE2b-256 33282e0c0d95c1b3ba4dcd886777a0de5ad923a37d6129e1cf81e8b9006d71ae

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.2-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 6ec903893a5838fae44d3261369265186ecddaf2232fcc6ea7e873a15d0c211c
MD5 b7eae6c5908866fc6000f515ecf5ff62
BLAKE2b-256 de4c8062abb206fd6b0263015545660d266df9c743e719a8e82a7981ab662979

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b0f4f5a7f59f05a767b3e6de594bc0949d06f5b2f8a26dd05d17da614d958983
MD5 bdf47f59b91d4dc5fb44118ff520e50c
BLAKE2b-256 b06e9633971eb0a7a25bacadf47e8c09171649391d834ad0f276ead255354f8a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 20f98834ee6e39606dfb4cdaa7817da29cbc15741653bc89b8d92d2d522ec2a0
MD5 14038aa8ef281071ed7aa697822dcd70
BLAKE2b-256 056cef7adee2775564bd4e840b1bb2a559eb9bd0e82c85349a9dee362de784df

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 feac420b3f466dcab7a316ae3ca2b5d4dbaba385a6b9e803b8504c49c002b423
MD5 c01934ee7d4d0880ef2091e11d93c693
BLAKE2b-256 9a42af92e424dd548bea0eb0e13b510e0f41241ed3f91354a1adc9052d6408e4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.2-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 d260357db68a2dd43c179f6a7b0b013f15bd05b27f96f4ab344758bcf22da594
MD5 91e03eaee876bd9d8cb162f9cb3ffd64
BLAKE2b-256 73912be29badc166d056d141340ebf2f3a59b61c9d49c2c7873defbc9ed09169

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