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.0rc1-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (519.8 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

opencosmo-1.3.0rc1-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (513.8 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ ARM64

opencosmo-1.3.0rc1-cp314-cp314-macosx_11_0_arm64.whl (477.7 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

opencosmo-1.3.0rc1-cp314-cp314-macosx_10_12_x86_64.whl (483.1 kB view details)

Uploaded CPython 3.14macOS 10.12+ x86-64

opencosmo-1.3.0rc1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (519.9 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

opencosmo-1.3.0rc1-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.0rc1-cp313-cp313-macosx_11_0_arm64.whl (477.7 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

opencosmo-1.3.0rc1-cp313-cp313-macosx_10_12_x86_64.whl (483.1 kB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

opencosmo-1.3.0rc1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (521.0 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

opencosmo-1.3.0rc1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (513.9 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

opencosmo-1.3.0rc1-cp312-cp312-macosx_11_0_arm64.whl (477.7 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

opencosmo-1.3.0rc1-cp312-cp312-macosx_10_12_x86_64.whl (482.9 kB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.0rc1-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 93e9f66a9d29347ae53a7df083bcb95e1d815b7e979f078bed065b21b4901305
MD5 ae8b44847b82d1108743fb56beb630ee
BLAKE2b-256 dd50b701cbeacace9e7599bf4e77dc15c075114a75547deac74a4c8ae7db0be7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.0rc1-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 ef34689ca976ea417a4912ebb110d7417182c4cb0701eb434896a62f6bc7715c
MD5 fa5dabd19cbce9f07d89a39dc0df40f2
BLAKE2b-256 25ed7e406b2997f0e2072eb6017f3af19b16b0161bc362b2a1ff7f2b31aced69

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.0rc1-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 be5d8502e8692c5f0b45779cc5739a54010e92dc905985949adda974f5da82cd
MD5 59f0d0a82cb583d41d08673e8abfdbf6
BLAKE2b-256 fe2d3af584c1fff1c832ef3f017b212fc2aba36dcb913451e7d7d114720b8fa9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.0rc1-cp314-cp314-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 c845380b89bc633ba8951679473fe139685cf208a27bb0f18ea9b71d07a28d74
MD5 ccbf47d0c4694a75fdd129458dbfa8d3
BLAKE2b-256 6173b8bb90f6a9ac6edda48123b13bcbdedea2a1a54d5fbb1502127546c629b9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.0rc1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 45bdf7812819686a00cb0d600f1d1a566234030f7c9c446e32375851ef227993
MD5 980681eee389192baef8fe47f789bbe6
BLAKE2b-256 9b9f39755665b11a6f967ce9a7ce0f0a24c0a75da71d3fa1bb0ce16f311b5227

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.0rc1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 ffe27d4a811088a8619e1f0e5b34fc3172c89cbc5682f709e163e608cb404ac8
MD5 36b74e98272df398ef3331d71fb3eb83
BLAKE2b-256 53aa9f3d84a42ab9b0a776c83bec2ffe96b46c994960423c3f247b9eb336bb1b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.0rc1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2c500bbec66c33069de3fd881e33b02f3636f6354db21d8c0485737a51e801eb
MD5 cd2ff4dede4a094e2c3d7b42bee3a3ce
BLAKE2b-256 d7807bf74dfd3cd68d19ec2035623cd50b7b4335261f8dcfd9b77d5cbbfd8642

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.0rc1-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 6baff7bb4cbe7fc67397ce596edf23c308bef3cffb9b1dffa5b584941fcdff33
MD5 60151842f1620e1bc95e4ef2b58de170
BLAKE2b-256 88bb07cc95d621741da595e0ce078c80c3ccbbd058cad128bab97cbd8260bbc9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.0rc1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3e6fe181555a802d8e4944c2e2cc9e46f12ee853c338803642ccb6662db61938
MD5 9d564f74c5b164a8480314bb6b3799fa
BLAKE2b-256 869668d74b9482c88fabb5872d5afa967e78ec26b3e427f1836858168d1abc08

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.0rc1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a12dd8160dfffc5819d84aa4dd44f1e28aadd4350e36d8bc2a31ae2668dc02c7
MD5 969928a58f2a23d5cea2da3687b4ae48
BLAKE2b-256 1765111466a90d3e9823ad4ed88ce74a195c9d5934b9e2d1d6c0bc0766ceacd5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.0rc1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 34d370447e027e5a6f260fb1fda264251fe76b94ccf5a192da9aaa7a08c98df6
MD5 54c783fdf0502ce0376692f7413c0226
BLAKE2b-256 e2ded430c3700a495c237a767183d84b917e81d5346f6a5f42b362ec1c39fa4f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.0rc1-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 8c5f8363489d42f15ffd3f6c0bc748834c2cb8dab22069e92262cf2260d97c90
MD5 1a3184a0a486c53adf0e3a9ee5a138c8
BLAKE2b-256 0bb6dfc72bb6213f0e1fec27c210194029cd31e42860947d00aca45ff5edccce

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