Name | opencosmo JSON |
Version |
0.8.1
JSON |
| download |
home_page | None |
Summary | OpenCosmo Python Toolkit |
upload_time | 2025-07-22 21:51:06 |
maintainer | None |
docs_url | None |
author | Patrick Wells |
requires_python | <3.14,>=3.11 |
license | None |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
<h1 align="center">
<picture>
<source srcset="https://raw.githubusercontent.com/ArgonneCPAC/opencosmo/main/branding/opencosmo_dark.png" media="(prefers-color-scheme: dark)">
<source srcset="https://raw.githubusercontent.com/ArgonneCPAC/opencosmo/main/branding/opencosmo_light.png" media="(prefers-color-scheme: light)">
<img src="https://raw.githubusercontent.com/ArgonneCPAC/opencosmo/main/branding/opencosmo_light.png" alt="OpenCosmo">
</picture>
</h1><br>
[](https://github.com/ArgonneCPAC/OpenCosmo/actions/workflows/merge.yaml)




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](https://learn.microsoft.com/en-us/windows/wsl/setup/environment)). It can be installed easily with `pip`:
```bash
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](https://docs.conda.io/projects/conda/en/stable/user-guide/getting-started.html), you can create a new environment and install `opencosmo` into it automatically:
```bash
conda create -n opencosmo_env conda-forge::opencosmo
conda activate opencosmo_env
```
or if you already have a virtual environment to use:
```bash
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:
```bash
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](https://drive.google.com/drive/folders/1CYmZ4sE-RdhRdLhGuYR3rFfgyA3M1mU-?usp=sharing). 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:
```python
import opencosmo as oc
dataset = oc.open("haloproperties.hdf5")
print(dataset)
```
```text
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 holds the raw data as well as information about the simulation. You can easily access the data and cosmology as Astropy objects:
```python
dataset.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:
```python
dataset = dataset
.filter(oc.col("fof_halo_mass") > 1e13)
.take(1000, at="random")
.select(("fof_halo_mass", "sod_halo_cdelta"))
print(dataset)
```
```text
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](https://drive.google.com/drive/folders/1CYmZ4sE-RdhRdLhGuYR3rFfgyA3M1mU-?usp=sharing) and try the following:
```python
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.
```python
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](https://opencosmo.readthedocs.io/en/latest/).
### Testing
To run tests, first download the test data [from Google Drive](https://drive.google.com/drive/folders/1CYmZ4sE-RdhRdLhGuYR3rFfgyA3M1mU-?usp=sharing). Set environment variable `OPENCOSMO_DATA_PATH` to the path where the data is stored. Then run the tests with `pytest`:
```bash
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](CONTRIBUTING.md) for more information.
```
Raw data
{
"_id": null,
"home_page": null,
"name": "opencosmo",
"maintainer": null,
"docs_url": null,
"requires_python": "<3.14,>=3.11",
"maintainer_email": null,
"keywords": null,
"author": "Patrick Wells",
"author_email": "pwells@anl.gov",
"download_url": "https://files.pythonhosted.org/packages/fe/a2/ca939353ed12e20f0d7f645b4c8c4869a9d46d2f4a77952314a0f2479fb5/opencosmo-0.8.1.tar.gz",
"platform": null,
"description": "<h1 align=\"center\">\n <picture>\n <source srcset=\"https://raw.githubusercontent.com/ArgonneCPAC/opencosmo/main/branding/opencosmo_dark.png\" media=\"(prefers-color-scheme: dark)\">\n <source srcset=\"https://raw.githubusercontent.com/ArgonneCPAC/opencosmo/main/branding/opencosmo_light.png\" media=\"(prefers-color-scheme: light)\">\n <img src=\"https://raw.githubusercontent.com/ArgonneCPAC/opencosmo/main/branding/opencosmo_light.png\" alt=\"OpenCosmo\">\n </picture>\n</h1><br>\n\n[](https://github.com/ArgonneCPAC/OpenCosmo/actions/workflows/merge.yaml)\n\n\n\n\n\n\nThe 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.\n\n### Installation\n\nThe OpenCosmo library is available for Python 3.11 and up on Linux and MacOS (and Windows via [WSL](https://learn.microsoft.com/en-us/windows/wsl/setup/environment)). It can be installed easily with `pip`:\n\n```bash\npip install opencosmo\n```\n\n\nThere'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](https://docs.conda.io/projects/conda/en/stable/user-guide/getting-started.html), you can create a new environment and install `opencosmo` into it automatically:\n\n```bash\nconda create -n opencosmo_env conda-forge::opencosmo\nconda activate opencosmo_env\n```\n\nor if you already have a virtual environment to use:\n\n```bash\nconda install conda-forge::opencosmo\n```\n\nIf you plan to use `opencosmo` in a Jupyter notebook, you can install the `ipykernel` package to make the environment available as a kernel:\n\n```bash\npip install ipykernel # can also be installed with conda\npython -m ipykernel install --user --name=opencosmo\n```\n\nBe sure you have run the \"activate\" command shown above before running the `ipykernel` command.\n\n## Getting Started\n\nTo get started, download the \"haloproperites.hdf5\" from the [OpenCosmo Google Drive](https://drive.google.com/drive/folders/1CYmZ4sE-RdhRdLhGuYR3rFfgyA3M1mU-?usp=sharing). 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:\n\n```python\nimport opencosmo as oc\n\ndataset = oc.open(\"haloproperties.hdf5\")\nprint(dataset)\n```\n\n```text\nOpenCosmo Dataset (length=237441)\nCosmology: 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)\nFirst 10 rows:\nblock fof_halo_1D_vel_disp fof_halo_center_x ... sod_halo_sfr unique_tag\n km / s Mpc ... solMass / yr\nint32 float32 float32 ... float32 int64\n----- -------------------- ----------------- ... ------------ ----------\n 0 32.088795 1.4680439 ... -101.0 21674\n 0 41.14525 0.19616994 ... -101.0 44144\n 0 73.82962 1.5071135 ... 3.1447952 48226\n 0 31.17231 0.7526525 ... -101.0 58472\n 0 23.038841 5.3246417 ... -101.0 60550\n 0 37.071426 0.5153746 ... -101.0 537760\n 0 26.203058 2.1734374 ... -101.0 542858\n 0 78.7636 2.1477687 ... 0.0 548994\n 0 37.12636 6.9660196 ... -101.0 571540\n 0 58.09235 6.072006 ... 1.5439711 576648\n```\n\nThe `open` function returns a `Dataset` object, which holds the raw data as well as information about the simulation. You can easily access the data and cosmology as Astropy objects:\n```python\ndataset.data\ndataset.cosmology\n```\n\nThe 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. \n\n### Basic Querying\n\nAlthough 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:\n\n```python\ndataset = dataset\n .filter(oc.col(\"fof_halo_mass\") > 1e13)\n .take(1000, at=\"random\")\n .select((\"fof_halo_mass\", \"sod_halo_cdelta\"))\n\nprint(dataset)\n\n```\n\n```text\nOpenCosmo Dataset (length=1000)\nCosmology: 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)\nFirst 10 rows:\n fof_halo_mass sod_halo_cdelta\n solMass\n float32 float32\n---------------- ---------------\n11220446000000.0 4.5797048\n17266723000000.0 7.4097505\n51242150000000.0 1.8738283\n70097712000000.0 4.2764015\n51028305000000.0 2.678151\n11960567000000.0 3.9594727\n15276915000000.0 5.793542\n16002001000000.0 2.4318497\n47030307000000.0 3.7146702\n15839942000000.0 3.245569\n```\n\nWe 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](https://drive.google.com/drive/folders/1CYmZ4sE-RdhRdLhGuYR3rFfgyA3M1mU-?usp=sharing) and try the following:\n\n```python\nimport opencosmo as oc\n\ndata = oc.open(\"haloproperties.hdf5\", \"haloparticles.hdf5\")\n```\nThis 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. \n\n```python\n\ndata = data\n .filter(oc.col(\"fof_halo_mass\") > 1e13)\n .take(1000, at=\"random\")\n\nfor halo in data.halos():\n halo_properties = halo[\"halo_properties\"]\n dm_particles = halo[\"dm_particles\"]\n star_particles = halo[\"star_particles\"]\n```\n\nIn 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](https://opencosmo.readthedocs.io/en/latest/).\n\n### Testing\n\nTo run tests, first download the test data [from Google Drive](https://drive.google.com/drive/folders/1CYmZ4sE-RdhRdLhGuYR3rFfgyA3M1mU-?usp=sharing). Set environment variable `OPENCOSMO_DATA_PATH` to the path where the data is stored. Then run the tests with `pytest`:\n\n```bash\nexport OPENCOSMO_DATA_PATH=/path/to/data\n# From the repository root\npytest --ignore test/parallel \n```\n\nAlthough 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.\n\n### Contributing\n\nWe welcome bug reports and feature requests from the community. If you would like to contribute to the project, please check out the [contributing guide](CONTRIBUTING.md) for more information.\n\n```\n",
"bugtrack_url": null,
"license": null,
"summary": "OpenCosmo Python Toolkit",
"version": "0.8.1",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "ffa8bb03be75a05c28e59ecc5814018c1e92a51b9cf761854080c97ad60f6968",
"md5": "213427ae63089733925d6030196c15cc",
"sha256": "07f5a50f161e1dd11150e071f8b350d9692565b33f66de701d0abf10aba74cce"
},
"downloads": -1,
"filename": "opencosmo-0.8.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "213427ae63089733925d6030196c15cc",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<3.14,>=3.11",
"size": 110117,
"upload_time": "2025-07-22T21:51:05",
"upload_time_iso_8601": "2025-07-22T21:51:05.500813Z",
"url": "https://files.pythonhosted.org/packages/ff/a8/bb03be75a05c28e59ecc5814018c1e92a51b9cf761854080c97ad60f6968/opencosmo-0.8.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "fea2ca939353ed12e20f0d7f645b4c8c4869a9d46d2f4a77952314a0f2479fb5",
"md5": "d483b2c935d632ea9a5a3db0fa3985dd",
"sha256": "12c815688c66339f3f06d69b0069ea00a5644f630783b68fcf1d82fcf02360f8"
},
"downloads": -1,
"filename": "opencosmo-0.8.1.tar.gz",
"has_sig": false,
"md5_digest": "d483b2c935d632ea9a5a3db0fa3985dd",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<3.14,>=3.11",
"size": 82758,
"upload_time": "2025-07-22T21:51:06",
"upload_time_iso_8601": "2025-07-22T21:51:06.740783Z",
"url": "https://files.pythonhosted.org/packages/fe/a2/ca939353ed12e20f0d7f645b4c8c4869a9d46d2f4a77952314a0f2479fb5/opencosmo-0.8.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-22 21:51:06",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "opencosmo"
}