API reference

galtab

class galtab.GalaxyTabulator(halocat, fiducial_model, n_mc=10, min_quant=0.0001, max_weight=0.05, sample_fraction=1.0, num_ptcl_requirement=None, seed=None, cosmo=None, sat_quant_instead_of_max_weight=False)[source]

This object populates placeholder galaxies according to a fiducial halo occupation model. Then, given any occupation model, each placeholder which will be assigned a “weight” according to the mean occupation of

__init__(halocat, fiducial_model, n_mc=10, min_quant=0.0001, max_weight=0.05, sample_fraction=1.0, num_ptcl_requirement=None, seed=None, cosmo=None, sat_quant_instead_of_max_weight=False)[source]
Parameters:
  • halocat (htsm.CachedHaloCatalog) – Catalog containing the halos to populate galaxies on top of

  • fiducial_model (htem.ModelFactory) – Used to calculate the number of placeholder galaxies per halo

  • n_mc (int (default = 10)) – Number of Monte-Carlo realizations to combine

  • min_quant (float (default = 0.001)) – The minimum quantile of galaxies as a function of the model’s prim_haloprop to populate at least one placeholder in such a halo

  • max_weight (float (default = 0.01)) – The quantile of the Poisson distribution centered around <N_sat> to use as the number of satellite placeholders per halo

  • sample_fraction (float (default = 1.0)) – The fraction of galaxies to keep - useful for modeling surveys whose targeting fraction is <100%, but not spatially correlated

  • num_ptcl_requirement (Optional[int]) – Passed to the initial call of model.populate_mock()

  • seed (Optional[int]) – Monte-Carlo realization seeds; also passed to model.populate_mock()

  • cosmo (Optional[astropy.Cosmology object]) – Used for redshift-space distortions; default taken from halocat

  • sat_quant_instead_of_max_weight (Optional[bool]) – If true, max_weight is interpretted as 1 - sat_quant, where sat_quant specifies the number of placeholder satellites by the quantile of the (Poisson) occupation distribution of each halo

Examples

Choose HOD model and load halos

>>> hod = halotools.empirical_models.PrebuiltHodModelFactory("zheng07")
>>> halocat = halotools.sim_manager.CachedHaloCatalog(simname="bolplanck")

Instantiate the tabulators

>>> gtab = GalaxyTabulator(halocat, hod)
>>> cictab = CICTabulator(
...     gtab, proj_search_radius=2.0,
...     cylinder_half_length=10.0, bin_edges=np.arange(-0.5, 16))

Update HOD parameters to your liking and perform CiC prediction

>>> hod.param_dict.update({})
>>> cictab.predict(hod)
tabulate_cic(**kwargs)[source]

Initialize a CICTabulator

This object tabulates the cylinder counts of each placeholder galaxy to quickly, deterministically, and differentiably predict dP(N_CIC)/dN_CIC for any given occupation model.

Parameters:
  • galtabulator (GalaxyTabulator) – Object containing the tabulated placeholder galaxies

  • proj_search_radius (float) – Perpendicular radius of circle in which to count pairs

  • cylinder_half_length (float) – Half length of cylinder in which to count pairs

  • k_vals (Optional[np.ndarray]) – Array of moment numbers (i.e. [1, 2] for mean, std)

  • bin_edges (Optional[np.ndarray]) – Bin edges of P(Ncic); ignored if k_vals are provided

  • sample1_selector (Optional[callable]) – Not implemented

  • sample2_selector (Optional[callable]) – Not implemented

  • analytic_moments (Optional[bool]) – Less noisy than Monte-Carlo approximation and quicker if only calculating a few k_vals

  • sort_tabulated_indices (Optional[bool]) – This will cause longer tabulation time, but shorter subsequent prediction calls

  • max_ncic (Optional[int]) – If any galaxies have more Ncic than this, return Ncic=0

  • seed (Optional[int]) – Random seed to produce reproducible results, even if not using analytic_moments=True

  • Note (Remaining keyword arguments are passed to halotools' counts-in-)

  • function. (cylinders)

class galtab.CICTabulator(galtabulator, proj_search_radius, cylinder_half_length, k_vals=None, bin_edges=None, sample1_selector=None, sample2_selector=None, analytic_moments=True, sort_tabulated_indices=False, max_ncic=100000, seed=None, **kwargs)[source]
__init__(galtabulator, proj_search_radius, cylinder_half_length, k_vals=None, bin_edges=None, sample1_selector=None, sample2_selector=None, analytic_moments=True, sort_tabulated_indices=False, max_ncic=100000, seed=None, **kwargs)[source]

Initialize a CICTabulator

This object tabulates the cylinder counts of each placeholder galaxy to quickly, deterministically, and differentiably predict dP(N_CIC)/dN_CIC for any given occupation model.

Parameters:
  • galtabulator (GalaxyTabulator) – Object containing the tabulated placeholder galaxies

  • proj_search_radius (float) – Perpendicular radius of circle in which to count pairs

  • cylinder_half_length (float) – Half length of cylinder in which to count pairs

  • k_vals (Optional[np.ndarray]) – Array of moment numbers (i.e. [1, 2] for mean, std)

  • bin_edges (Optional[np.ndarray]) – Bin edges of P(Ncic); ignored if k_vals are provided

  • sample1_selector (Optional[callable]) – Not implemented

  • sample2_selector (Optional[callable]) – Not implemented

  • analytic_moments (Optional[bool]) – Less noisy than Monte-Carlo approximation and quicker if only calculating a few k_vals

  • sort_tabulated_indices (Optional[bool]) – This will cause longer tabulation time, but shorter subsequent prediction calls

  • max_ncic (Optional[int]) – If any galaxies have more Ncic than this, return Ncic=0

  • seed (Optional[int]) – Random seed to produce reproducible results, even if not using analytic_moments=True

  • Note (Remaining keyword arguments are passed to halotools' counts-in-)

  • function. (cylinders)

predict(model, return_number_densities=False, n_mc=None, reseed_mc=False, warn_p_over_1=True)[source]

Perform tabulation-accelerated prediction

Parameters:
  • model (halotools.empirical_models.ModelFactory) – Halotools model we want to evaluate CiC for

  • return_number_densities (bool [Optional]) – Return number densities of both samples n1 and n2

  • n_mc (int [Optional]) – Number of Monte-Carlo realizations (ignored in analytic moments)

  • reseed_mc (bool [Optional]) – Reseed the CICTabulator’s Monte Carlo realization generator

  • warn_p_over_1 (bool | str [Optional]) – If true (default), print a warning if any placeholder weights > 1 If string starting with “return”, return warn_status, don’t print

Returns:

  • cic (np.ndarray) – Values of P(Ncic) or moments specified by k_vals

  • [n1] (float) – Number density of sample1. Only returned if return_number_densities

  • [n2] (float) – n2 always = n1 for now. Only returned if return_number_densities

  • [warn_status] (dict) – Dictionary specifying the warning status. Only returned if warn_p_over_1 is a string starting with “return”

galtab.obs

Note: this package must be loaded separately with import galtab.obs

galtab.obs.cic_obs_data(centers, companions, r_cyl, cyl_half_length, cosmo=None, weigh_companions=False, return_indices=False, companion_weights=None, weigh_counts=False, count_weights=None, progress=False, infinite_distance=False, search_angle_at_near_end_of_cylinder=False, perform_additional_angle_selection_at_companion_dist=False, num_threads=1, tqdm_kwargs=None)[source]

Calculate counts-in-cylinders from observed celestial data Based off Kuan Wang’s Ncic function

Notes: All units must be in degrees and Mpc/h

Self-counting is not removed, so make sure to subtract by 1 (or by the count_weights array) if desired

centers and companions must be (N, 3) arrays with columns [ra, dec, redshift] if cosmo is specified. Otherwise, columns are [ra, dec, comoving_dist].

r_cyl and cyl_half_length are comoving distances to search in the transverse and line-of-sight directions.

cosmo is an astropy.cosmology.Cosmology object for converting redshift to distance.

galtab.obs.get_search_angle(r_cyl, cyl_half_length, point_dist)[source]

Calculate the search angle in radians

galtab.obs.fuzzy_histogram(x, centroids, weights=None)[source]

galtab.moments

galtab.moments.jit_sum_at(arr_in, ind_in, ind_out, len_out=None, ind_out_is_sorted=False)[source]
galtab.moments.moments_from_samples(samples, k_vals, weights=None)[source]

Calculate up to the kth moment of a given sample. 1st moment is the mean, 2nd moment is the standard deviation, and for k=3+ we compute standardized moments, e.g. skewness, kurtosis, etc.

Parameters:
  • samples (array-like) – Sampled values from which to calculate moments

  • k_vals (list[int]) – Moments to be calculated

  • weights (array-like, optional) – Weights for each sample. If None, all samples are equally weighted.

Returns:

Calculated moments

Return type:

jnp.array

galtab.moments.moments_from_binned_pmf(bin_edges, pmf, k_vals)[source]
class galtab.moments.BernoulliCumulantGenerator[source]

galtab.jaxhalotools

class galtab.jaxhalotools.JaxZheng07Cens(threshold=-20, prim_haloprop_key='halo_mvir', **kwargs)[source]
class galtab.jaxhalotools.JaxZheng07Sats(threshold=-20, prim_haloprop_key='halo_mvir', modulate_with_cenocc=False, cenocc_model=None, **kwargs)[source]
galtab.jaxhalotools.vectorized_cond(pred, true_fun, false_fun, operand, safe_operand_value=0)[source]