Skip to content

HealPixMapPriorDist Redundancy Fix

Isaac McMahon requested to merge isaac.mcmahon/healpix-redundancy:master into master

When using a Healpix Map as a prior, there is a significant amount of resources and walltime dedicated to redundant normalization of the probability skymap. In the _sample method in HealPixMapPriorDist in bilby/gw/prior.py, the first three lines are dedicated to creating an array of indices, normalizing the skymap, and sampling from the skymap using np.random.choice:

pixel_choices = np.arange(self.npix)
pixel_probs = self._check_norm(self.prob)
sample_pix = np.random.choice(pixel_choices, size=size, p=pixel_probs, replace=True)

The first two lines of _sample are redundant, because the skymap should be read-only and normalization only needs to be done once, not before every sample. Here the class is rewritten so that self._check_norm is called on self.prob when the skymap is read from file during initialization and the array of indices pixel_choices is declared as an object-level element.

Merge request reports