halocat.xi_AB_io¶
xi_AB_io
¶
On-disk storage for the cumulative-threshold ξ_AB cube.
Each per-realisation file holds one (gravity, redshift, imodel,
ibox) measurement of
xi_AB[N_r, N_t, N_t] = xi_hh(r | n_h(>=t_i), n_h(>=t_j))
on a fixed mass-threshold grid plus the halo counts n_h_cum[N_t]
above each threshold. The schema is dense and symmetric in the last
two axes — emulator inputs read the cube directly without any
pair-sparse densification.
Atomic writes via tempfile + os.replace give a corruption
guarantee on POSIX-rename-atomic filesystems (Lustre, GPFS).
Cache invalidation hashes a spec tuple (not raw array bytes) over
the parameters that actually affect the measurement.
XiABRecord
dataclass
¶
XiABRecord(r_edges: ndarray, r: ndarray, thresholds: ndarray, xi_AB: ndarray, n_h_cum: ndarray, n_pairs: ndarray | None, box_size: float, attrs: dict = dict())
In-memory view of one xi_AB_thresh.hdf5 file.
Attributes:
| Name | Type | Description |
|---|---|---|
r_edges |
(N_r+1,) float64
|
Separation bin edges (Mpc/h). |
r |
(N_r,) float64
|
Arithmetic mean of |
thresholds |
(N_t,) float64
|
Sorted log10(M / [Msun/h]) thresholds. |
xi_AB |
(N_r, N_t, N_t) float64
|
Bin-averaged correlation cube. Symmetric in the last two axes. |
n_h_cum |
(N_t,) int64
|
Halo counts above each threshold (raw count in the simulation
box, not density). Convert to density via
|
n_pairs |
(N_t, N_t) int64 or None
|
Optional diagnostic: pair counts per threshold pair, for
shot-noise estimates. |
box_size |
float
|
Periodic box side length (Mpc/h). |
attrs |
dict
|
Top-level HDF5 attributes — see :func: |
xi_AB_path
¶
xi_AB_path(gravity: str, redshift: float, imodel: int, ibox: int, *, root: str | None = None) -> str
Path to the per-realisation xi_AB_thresh.hdf5.
Mirrors the layout of xi_hh.hdf5 / hmf.hdf5 —
<OUTPUT_ROOT>/gravity_<g>/z_<z:.2f>/imodel_<m>/box_<b>/xi_AB_thresh.hdf5.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
str
|
Override :data: |
None
|
Source code in halocat/xi_AB_io.py
xi_AB_cache_key
¶
xi_AB_cache_key(*, thresholds, r_edges, mass_definition: str, code_version: str, source_dat: str) -> str
blake2b-128 hex digest of the canonicalised measurement spec.
Encodes everything that changes the measurement:
- r-binning summary (_r_spec);
- thresholds (sorted, rounded to 6 dp);
- mass column ("Mtot");
- halocat code version (cache invalidates on releases that
change the measurement code path);
- the source_dat path from halo.hdf5 (the upstream
catalogue identity — invalidates if the user re-runs against
a different DAT under the same realisation slot).
Source code in halocat/xi_AB_io.py
write_xi_AB
¶
Write record to path.
With atomic=True (default), the writer first dumps to
<path>.tmp.<host>.<pid> then os.replace(...) — a
POSIX-atomic rename on Lustre / GPFS, so concurrent writers
cannot corrupt the destination. A soft warning is logged if
sibling tmp files already exist (likely concurrent writer).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
record
|
XiABRecord
|
|
required |
path
|
str
|
|
required |
atomic
|
bool
|
Default True. Set False for in-place writes (faster, but not crash-safe). |
True
|
Source code in halocat/xi_AB_io.py
read_xi_AB
¶
Read one xi_AB_thresh.hdf5 file into an :class:XiABRecord.
r is recomputed as the arithmetic mean of r_edges — never
read from disk, mirroring the project-wide rule.
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in halocat/xi_AB_io.py
is_cache_valid
¶
True iff path exists, schema matches, and cache_key agrees.
Reads only attrs (no datasets) — ~ms per file even on cold Lustre.
Source code in halocat/xi_AB_io.py
to_xi_hh_record
¶
Convert an :class:XiABRecord to a threshold-style XiHHRecord.
The dense (N_r, N_t, N_t) cube is repacked into the pair-sparse
upper-triangular layout that
:func:halocat.xi_hh_rebin.rebin_xi_hh_record expects, with
mass_bins[:, 0] = thresholds and mass_bins[:, 1] = +inf.
Halo counts n1 / n2 are filled per pair from
n_h_cum.
Returns:
| Type | Description |
|---|---|
XiHHRecord
|
A new in-memory record; not written to disk. |
Source code in halocat/xi_AB_io.py
make_attrs
¶
make_attrs(*, gravity: str, redshift: float, imodel: int, ibox: int, snapnum: int, cache_key: str, code_version: str, source_dat: str, halo_file: str, mass_definition: str = C.MASS_COLUMN, estimator: str = 'natural', pycorr_version: str = '', corrfunc_version: str = '') -> dict
Build the canonical attrs dict for a fresh :class:XiABRecord.
The writer adds schema_version and box_size itself; everything
else lives here.