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

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

opencosmo-1.3.11-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (516.1 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ ARM64

opencosmo-1.3.11-cp314-cp314-macosx_11_0_arm64.whl (481.0 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

opencosmo-1.3.11-cp314-cp314-macosx_10_12_x86_64.whl (486.1 kB view details)

Uploaded CPython 3.14macOS 10.12+ x86-64

opencosmo-1.3.11-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (522.9 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

opencosmo-1.3.11-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (516.3 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

opencosmo-1.3.11-cp313-cp313-macosx_11_0_arm64.whl (481.1 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

opencosmo-1.3.11-cp313-cp313-macosx_10_12_x86_64.whl (486.1 kB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

opencosmo-1.3.11-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (523.2 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

opencosmo-1.3.11-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (516.7 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

opencosmo-1.3.11-cp312-cp312-macosx_11_0_arm64.whl (481.0 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

opencosmo-1.3.11-cp312-cp312-macosx_10_12_x86_64.whl (485.9 kB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.11-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 159ed9a92e727d466230633c3ac103f45246ddae8225df1e00893190df6106fb
MD5 111fe4225d0b911f018262a2d3ae10fa
BLAKE2b-256 38e93724458d352bedb54a445b3219ab188706b45854c02e359820b7ee2ea34a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.11-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 0a24ac24625cbdb5f2a2fbf901df70c09981910bf52f875a759c242cb729ee34
MD5 42edd3254bf1b6b2c0d004d94e1bb7e3
BLAKE2b-256 f03b2b1a0e12eaa181e5c3195c85e4cc0a792e2c6722fc5f22afc976a27ec15e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.11-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7e4f62f9b4be2cf320053ee48c3c1bbaf8b4cb520ad6306a6780a9f9eb4fb1fd
MD5 fc597a53d12a5a1b91250a6abab84df5
BLAKE2b-256 a9448de6fdbcdccebcbd753ad6c36f08fc2b43f562b841451ad71b2c13a7a604

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.11-cp314-cp314-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 a2070f8609e775757645d1fd0b2dca5dfd32376657081805812cb297be68f1e1
MD5 68a220be06f11cff7fe24cc568136f32
BLAKE2b-256 5a4898afe55040a3b96cc3b306238c135b2b005b8356cd29cb80e4d754e3cca1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.11-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a81af5a5575d135e9075fa862dfe2b9630711bb215376d0378973a0c2626dfae
MD5 523661b74cd11f5246f201cffa63bd3b
BLAKE2b-256 8ef42e473e913d918c5155b8f62b59786d58b43e8884d103475b2ccdcd25a61c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.11-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f3cfe42eaca1bc23a0810a4ae8a17f4437eaca378dcd32ee2b2fa288c6ac2ffe
MD5 9959da422a6285afd5d269dae0e9cc6f
BLAKE2b-256 c357495e5e515ce394f85f83a88a3acb98c1e8b29e23e25f2f7f22c41617ab4a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.11-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7b895b2a9efa1c1ac3fe3b5cbf57ab41faf314e4e67d1d66545daa4edd8ea2ac
MD5 d0f21a240b935f964fb8670b6d4a3a77
BLAKE2b-256 76104fba9c55e04d993e6166d9b82a055185e649eb7f358946d1dcfbef63e23e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.11-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 95ea8ddf14293920b8662f3287b9e6cc3457e2df3c2c484b1a8b2187978c9281
MD5 9fde41c226f9be85482d30846cbacde9
BLAKE2b-256 5d2de813843557491b07c865204f5a270e874ff0a2bff22c7f14903b83fec559

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.11-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bb2acf77db90acee76a27518a056511acab821542217bdf972310b8f98d5a69f
MD5 8339d1f034f518facfdbe4c091686b93
BLAKE2b-256 64e5f1cd78de938ce0e0285b25983c3e32cbda8d65227583c958905ff3455e85

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.11-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 908e20e646371102d8bf0009ca09a02598568b0b10b3ec81cf09d5d769542ffd
MD5 63551cf649805fda74536d83a976da46
BLAKE2b-256 291808b28a267dabd4a099c7616a37ece8415195a298f8db35cf44c75e2407e9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.11-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c3844028b3767004467105ff2643932bafe80147957095a874a06f02bda19235
MD5 62724ec61336b66a1242991469aefdca
BLAKE2b-256 f21ff011a47d31a511d23cb860e4d5ec14a2fa8e06acdff77c589cf435b256fd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencosmo-1.3.11-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 15a376607db1caa28b0c54634d850c3c7abaf7fb8cd142be82a9bcb2980d3a42
MD5 2d86aee4309a07462acc1bc51b599c14
BLAKE2b-256 78a4c0718dc7bac557f78d09338bcb3b5d63992a930cdfd11462eba523d7e42c

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.3.11 This release

12 files

1.3.10

12 files

1.3.9

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