Counting and one-point PDFs#
Counting filters an SFCField with one optional window and evaluates the
continuous result at uniformly sampled box positions. The returned values can
be used for count-in-cell PDFs, moments, environmental marks, and filtered-field
diagnostics.
The complete Counting notebook compares the task and low-level interfaces and visualises the resulting one-point PDFs.
Minimal YAML#
Counting:
sfc_field: ./output/quijote8000_snap004_sfc.pkl
random_count: 10000000
seed: 42
weight_normalization: catalog
window:
type: sphere
len_args: {R: 20.0}
threads: 8
fout_path: ./output/quijote8000_snap004_counting_sph20.pkl
Run it from examples/:
python scripts/run_counting.py configs/param_counting.yaml
The result#
import numpy as np
from pyhermes.io import CountingData
counts = CountingData(
data_path="./output/quijote8000_snap004_counting_sph20.pkl"
)
print(counts.nx.shape)
print(np.mean(counts.nx), np.std(counts.nx))
CountingData.nx contains physical-unit field densities at the sampled
positions. counting_info records the seed, sample count, window, input
field, and normalisation. The random positions themselves are deterministic
from those settings and are not stored separately.
Python task interface#
from pyhermes.theory.counting import Counting
task = Counting()
task.sfc_field = "./output/quijote8000_snap004_sfc.pkl"
task.random_count = 300000
task.seed = 7
task.window = {"type": "gaussian", "len_args": {"R": 10.0}}
task.threads = 8
task.fout_path = "./output/counting_gaussian_R10.pkl"
result = task.run()
Low-level equivalent#
When positions are scientifically meaningful rather than random, evaluate the field directly:
from pyhermes.io import SFCField, WindowFunc
D = SFCField(data_path="./output/quijote8000_snap004_sfc.pkl", threads=8)
W = WindowFunc(
{"type": "sphere", "len_args": {"R": 20.0}},
D.sfc_info,
threads=8,
)
local_density = (D @ W).field_density_at_pos(
halo_positions,
value_unit="physical",
)
This is the route used to evaluate a local environment at each halo before constructing a marked field.
Choose the window deliberately#
sphereLiteral count-in-sphere or top-hat-smoothed density.
gaussianSmooth low-pass field without a hard boundary.
cubicorcylinderAnisotropic finite-volume average.
cw,cws,gdwZero-mean localised fluctuation rather than a count density.
For a sphere of radius \(R\), a raw number field can be converted to an expected count by multiplying density by \(4\pi R^3/3\). With catalogue normalisation, remember that the field integrates to one; use its metadata and mean density rather than assuming a raw particle count.
MPI distribution#
The filtered field is broadcast to all ranks. Each rank samples a disjoint
deterministic subset of positions and rank 0 gathers the values. random_count
is padded internally only when needed for an even rank distribution; the
returned array is trimmed to the requested size.
Public tutorial#
The rendered notebook compares task and low-level interfaces, constructs one-point PDFs, and contrasts low-pass and high-pass responses.