DEGRACE Helpers

halocat.degrace contains project-specific helpers for the DEGRACE-pilot simulation products.

Main workflow

The typical sequence is:

  1. Reformat a raw BDM halo catalogue into halo.hdf5.
  2. Copy the matching matter power spectrum into pk_mm.dat.
  3. Measure and save the halo mass function into hmf.hdf5.

All three stages write into a standard output tree:

gravity_{gravity}/
  z_{redshift:.2f}/
    imodel_{imodel}/
      box_{ibox}/
        halo.hdf5
        pk_mm.dat
        hmf.hdf5

Path helpers

These functions build the expected input and output paths:

  • degrace_pilot_run_path(...)
  • degrace_pilot_source_path(...)
  • degrace_pilot_pk_source_path(...)
  • degrace_pilot_output_path(...)

The default roots are:

  • DEGRACE_PILOT_SOURCE_ROOT
  • DEGRACE_PILOT_OUTPUT_ROOT

format_redshift(redshift) formats the directory component used in output paths.

Reformatting halo catalogues

Use reformat_degrace_pilot_halo_catalogue(...) for one box or reformat_degrace_pilot_halo_catalogues(...) for multiple boxes:

from halocat import reformat_degrace_pilot_halo_catalogue

path = reformat_degrace_pilot_halo_catalogue(
    gravity="fRn1",
    imodel=1,
    snapnum=137,
    redshift=0.25,
    ibox=1,
    overwrite=True,
)

This reads a raw BDM CatshortV file, loads all supported columns, and writes an HDF5 file with:

  • one dataset per halo field
  • per-dataset unit and description metadata
  • file-level attributes such as gravity, imodel, ibox, snapnum, boxsize, and redshift
  • a metadata_json payload containing units and field descriptions

Supported BDM columns

load_bdm_catshort(...) reads the full BDM_COLUMNS schema, including:

  • positions and velocities
  • mass_bound and mass
  • rvir, vrms, vcirc, and cvir
  • halo_id, n_particles, and parent_id
  • shape, offset, and spin-related columns

The current convention for parent_id matches the stored BDM metadata:

  • 0 denotes a distinct halo
  • non-zero values identify the host halo

Matter power spectra

Use copy_degrace_pilot_pk_mm(...) or copy_degrace_pilot_pk_mms(...) to copy raw PowerDM.log.*.dat files into the DEGRACE output tree:

from halocat import copy_degrace_pilot_pk_mm

path = copy_degrace_pilot_pk_mm(
    gravity="fRn1",
    imodel=1,
    snapnum=137,
    redshift=0.25,
    ibox=1,
    overwrite=True,
)

Halo mass functions

Use measure_degrace_pilot_hmf(...) or measure_degrace_pilot_hmfs(...) to measure HMFs from the reformatted halo.hdf5 files:

from halocat import measure_degrace_pilot_hmf

path = measure_degrace_pilot_hmf(
    gravity="fRn1",
    imodel=1,
    snapnum=137,
    redshift=0.25,
    ibox=1,
    log10mass_edges=[12.0, 12.5, 13.0, 13.5],
    overwrite=True,
)

If log10mass_edges is omitted, the function builds bin edges from the halo masses using:

  • log10mass_min
  • log10mass_max
  • dlog10mass

The output hmf.hdf5 stores:

  • log10mass_edges
  • log10mass_centres
  • mass_edges
  • mass_centres
  • counts
  • dndlog10M
  • cumulative_number_density

Dependencies

These helpers require h5py for HDF5 output. They are intended for the local DEGRACE data layout used in this repository, but the root directories can be overridden with source_root= and output_root=.