Spatial Hash Tables

postprocessing/hashtables/spatial_hashtable_NNN.hdf5

The THESAN-1 files span snapshots 000–080. A file dataset under a spatial cell contains row indices local to the snapshot chunk named by its FileName attribute.

File Reference

Hashtables provide an easy way to load particles based on their spatial position. As described in the snapshot documentation, particles are ordered by the halo and subhalo to which they belong. Locating particles within a particular volume would otherwise require searching through all the files of a snapshot.

The hashtables map the position of each particle to a cell of a Cartesian grid. For each grid cell, they list the files and indices at which those particles are stored. This enables a fast approximate selection by loading all particles in grid cells that intersect the volume of interest. This includes some particles outside the volume, so apply your exact spatial cut to the coordinates of the selected particles. For the creation and parsing of the hashtables we rely on sparepo, which also provides examples of its use.

Gas cells in one spatial bin are colored by the four snapshot chunks that supply them. The file lists below give rows in each chunk.
One spatial cell can draw gas from several snapshot chunks. The points share a position bin, while their colors identify the files that hold them. Garaldi et al. (2024), Fig. 4 · CC BY 4.0

The published diagram groups its labels by spatial cell. In the THESAN-1 file used below, the hierarchy is PartType0/Cell…/File…. The integers index rows within the chunk named by the FileName attribute.

Find a gas cell in a snapshot chunk

Paths in this example are relative to Thesan-1/postprocessing/.

import h5py

with h5py.File("hashtables/spatial_hashtable_080.hdf5") as f:
    gas = f["PartType0"]
    cell = next(iter(gas))
    file_key = next(iter(gas[cell]))
    indices = gas[cell][file_key]
    filename = indices.attrs["FileName"]
    if isinstance(filename, bytes):
        filename = filename.decode()
    row = int(indices[0])
    print(cell, filename, row)
with h5py.File(f"../output/snapdir_080/{filename}") as snap:
    print("gas coordinates [ckpc/h]:", snap["PartType0/Coordinates"][row])
Output from THESAN-1
Cell1005 snap_080.0.hdf5 0
gas coordinates [ckpc/h]: [26611.04512188  5128.88650562 52666.21669529]