Skip to main content

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.


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

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

opencosmo-1.3.9-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (515.4 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ ARM64

opencosmo-1.3.9-cp314-cp314-macosx_11_0_arm64.whl (480.5 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

opencosmo-1.3.9-cp314-cp314-macosx_10_12_x86_64.whl (485.5 kB view details)

Uploaded CPython 3.14macOS 10.12+ x86-64

opencosmo-1.3.9-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (522.4 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

opencosmo-1.3.9-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (515.6 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

opencosmo-1.3.9-cp313-cp313-macosx_11_0_arm64.whl (480.6 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

opencosmo-1.3.9-cp313-cp313-macosx_10_12_x86_64.whl (485.6 kB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

opencosmo-1.3.9-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (522.6 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

opencosmo-1.3.9-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (516.2 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

opencosmo-1.3.9-cp312-cp312-macosx_11_0_arm64.whl (480.5 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

opencosmo-1.3.9-cp312-cp312-macosx_10_12_x86_64.whl (485.4 kB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.9-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 64abcd86606c12f21a844b6f1b4c32c0f00e3b78f223bdf6e33579e88a154e13
MD5 88c3fdd7691d9f9675cedab354726f5e
BLAKE2b-256 0bd548a0959cabd094e0803be49435488a5f4002edf3d07133d79a2a646ff2e3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.9-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 11213adfa4676d5835608923a84e05e8a7d2399d8b91eb77ca32bfbc3796caf1
MD5 05beef739641a69f5e22c96a36744e15
BLAKE2b-256 a3c75d50324c21c265c66476ad23f53744e9ab05858c7829bb10fe3e45652c8f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.9-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5f99ca3cd1c765237461779bff963a086d4b47da59959439ffad15d8a83c218d
MD5 9b3211ff8e48e6257499ecffabac7d1f
BLAKE2b-256 2526cb652681bf12cb557ee3fafb9f5e860af1a5d87708f76a9be2c79be016e1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.9-cp314-cp314-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 166a8a5b074530aed05e2a4585ef2b833e9574e225999e29d0bcfa905fae0da8
MD5 a8e19a8655dfada55fcfeed647d71a8b
BLAKE2b-256 3ec2864dd0a1b5d745b9de832b178740e518cd49a312cf63f7b4034df4605446

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.9-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4bf0b8a11f3dd646c375eb1a56ae48a787fa9fee9461a3ecbddd30537d935a4b
MD5 941ce402e8985d04788587a218370cb9
BLAKE2b-256 3cfe523bb3c28f4b07b058c847b1cb7ebb93888f112fa5c22a3f20d20b575ac5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.9-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 500eda3241969bb6045f5f9ddf421b49a71bfc56bc5d83714b951d167f60e785
MD5 8b6d72b49ae7b0a613204377e2c45a96
BLAKE2b-256 56b4c6d19c128305802ad61c4f1ab2c8beb5efcbca2d69fc7f6ca713c8ce7a3b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.9-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 36de27c896a5103de94edb9d076a7aba8d58068a0b9aeb2088da9a0006a79b1f
MD5 c190abf87e823fd442d8f3a53685066e
BLAKE2b-256 428a4c5862de7a741ceed6eab99548cef48feff2a2b5bc20ebd458a45b953f19

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.9-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 818b2759e92f16a4569c2d1443ed6d2076de8b03387422cfbc3c802190f297f5
MD5 dd3ab95e2e972118c943642db17bb651
BLAKE2b-256 ac16c4ccdf671840713597c291a38f168bf399c16dc5b219c526f461c4cf6d82

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.9-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 72d3233d5d115349fa304056fe08c910670cc558020f86a037e9522dc122a012
MD5 9c3cfabf6ba0c17d918e5bcd3ebf0880
BLAKE2b-256 bf2647e72cad58221118f926ae86fce68c0ea1698ac7547294bb2921bb0a7a58

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.9-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 d9f2bceee1ab00885cb630d3387908c93b862fc0fcad229dab25a67babe3924f
MD5 c80620b5055cfee21b528c75ed8bfc4f
BLAKE2b-256 9ac794c3fcfd47b6ec929922d7ce4f3822cf5e00ddd882da475b078e9d1d12bc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.9-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 747fbbf644cd691c0e2e391c0dd4f8123225e254e00b84957a3ddaa82b352874
MD5 e652e8054d98577fb05fa0863d0e9856
BLAKE2b-256 0cbfbcf81ef94e3bc6d0f3e38a617cc0c8fb6c82ba15dcee7d7a1adf24c70e5f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.9-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 b2ad0a36259f50157ab44e7d4f3b5c74ed9265204b245b04849ad25b98deb284
MD5 2d2c9ca9cbb99837fb5a28a7080e6306
BLAKE2b-256 713d66b7b509a90f03c785dc3c1da9fcacd9724998be3b59c19a1a5855d2f4cb

See more details on using hashes here.

Release history Release notifications | RSS feed

1.3.11

12 files

1.3.10

12 files

This release

1.3.9 This release

12 files

1.3.8

12 files

1.3.7

12 files

1.3.6

12 files

1.3.5

12 files

1.3.4

12 files

1.3.3

12 files

1.3.2

12 files

1.3.1

12 files

1.2.7

2 files

1.2.6

2 files

1.2.5

2 files

1.2.4

2 files

1.2.3

2 files

1.2.2

2 files

1.2.1

2 files

1.2.0

2 files

1.1.5

2 files

1.1.4

2 files

1.1.3

2 files

1.1.2

2 files

1.1.1

2 files

1.1.0

2 files

1.0.4

2 files

1.0.3

2 files

1.0.2

2 files

1.0.1

2 files

1.0.0

2 files

0.9.6

2 files

0.9.5

2 files

0.9.4

2 files

0.9.3

2 files

0.9.2

2 files

0.9.1

2 files

0.9.0

2 files

0.8.1

2 files

0.8.0

2 files

0.7.3

2 files

0.7.2

2 files

0.7.1

2 files

0.7.0

2 files

0.6.1

2 files

0.6.0

2 files

0.5.0

2 files

0.4.0

2 files

0.3.0

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page