def sensitivity_2pt(self, set_idx=None, niso=1000, bins=180, **kwargs): """ Function to calculate the sensitivity by the 2pt-auto-correlation over a scrambling of the right ascension coordinates. :param set_idx: If set, only this set number will be evaluated :param niso: Number of isotropic sets to calculate :param bins: Number of angular bins, 180 correspond to 1 degree binning (np.linspace(0, np.pi, bins+1). :param kwargs: additional named arguments passed to obs.two_pt_auto() :return: pvalues in the shape (self.nsets, bins) """ kwargs.setdefault('cumulative', True) vec_crs = self.get('vecs') _, dec = coord.vec2ang(coord.gal2eq(np.reshape(vec_crs, (3, -1)))) # calculate auto correlation for isotropic scrambled data _ac_iso = np.zeros((niso, bins)) for i in range(niso): _vecs = coord.ang2vec(coord.rand_phi(self.ncrs), np.random.choice(dec, size=self.ncrs)) _ac_iso[i] = obs.two_pt_auto(_vecs, bins, **kwargs) # calculate p-value by comparing the true sets with the isotropic ones set_idx = np.arange(self.nsets) if set_idx is None else [set_idx] pvals = np.zeros((len(set_idx), bins)) for i, idx in enumerate(set_idx): _ac_crs = obs.two_pt_auto(vec_crs[:, idx], bins, **kwargs) pvals[i] = np.sum(_ac_iso >= _ac_crs[np.newaxis], axis=0) / float(niso) return pvals
def test_05_inariant_rotation(self): ac = obs.two_pt_auto(self.vecs, bins=self.nbins, cumulative=True, normalized=True) vecs_rotated = coord.gal2eq(self.vecs) self.assertTrue(np.mean(coord.angle(self.vecs, vecs_rotated)) > 0.1) ac_rotated = obs.two_pt_auto(vecs_rotated, bins=self.nbins, cumulative=True, normalized=True) self.assertTrue(np.allclose(ac, ac_rotated))
def test_02_isotropy_peak_90(self): ac = obs.two_pt_auto(self.vecs, bins=self.nbins, cumulative=False, normalized=True) # Check if isotropy peaks at 90 degree self.assertTrue(np.abs(np.argmax(ac) - 90) < 20)
def test_03_isotropy_in_omega(self): ac = obs.two_pt_auto(self.vecs, bins=self.nbins, cumulative=True, normalized=True) theta_bins = np.linspace(0, np.pi, self.nbins + 1) expectation = np.sin(theta_bins / 2)**2 # Check if number of events within opening angle scales with expectation # as only 1000 cosmic rays: exclude first 15 bins (starting at 15 deg) self.assertTrue(np.allclose(ac[15:], expectation[16:], rtol=5e-2))
def sensitivity_2pt(self, niso=1000, bins=180, **kwargs): """ Function to calculate the sensitivity by the 2pt-auto-correlation over a scrambling of the right ascension coordinates. :param niso: Number of isotropic sets to calculate. :param bins: Number of angular bins, 180 correspond to 1 degree binning (np.linspace(0, np.pi, bins+1). :param kwargs: additional named arguments passed to obs.two_pt_auto() :return: pvalues in the shape (bins) """ kwargs.setdefault('cumulative', True) vec_crs = self.get('vecs') _, dec = coord.vec2ang(coord.gal2eq(vec_crs)) # calculate auto correlation for isotropic scrambled data _ac_iso = np.zeros((niso, bins)) for i in range(niso): _vecs = coord.ang2vec(coord.rand_phi(self.ncrs), dec) _ac_iso[i] = obs.two_pt_auto(_vecs, bins, **kwargs) # calculate p-value by comparing the true sets with the isotropic ones _ac_crs = obs.two_pt_auto(vec_crs, bins, **kwargs) pvals = np.sum(_ac_iso >= _ac_crs[np.newaxis], axis=0) / float(niso) return pvals
def test_04_clustering(self): radius = 0.1 pix_choice = hpt.query_disc(self.nside, np.array([0, 0, 1]), radius) vecs = hpt.rand_vec_in_pix(self.nside, np.random.choice(pix_choice, self.stat)) ac = obs.two_pt_auto(vecs, bins=self.nbins, cumulative=False) theta_bins = np.linspace(0, np.pi, self.nbins + 1) # no event with correlation higher than 2 * radius self.assertTrue(np.sum(ac[theta_bins[1:] > 2.1 * radius]) == 0) # all events within 2 * radius self.assertTrue( np.sum(ac[theta_bins[1:] < 2.1 * radius]) == np.sum(ac)) # check if maximum is close to radius self.assertTrue( ac[np.argmin(np.abs(theta_bins[1:] - radius))] > 0.9 * max(ac))
def test_01_number_correlations(self): ac = obs.two_pt_auto(self.vecs, bins=self.nbins, cumulative=True) # Check if cumulative value is in upper triangle matrix (100 x 100) without diagonal self.assertEqual(ac[-1], int(int(self.stat**2 - self.stat) / 2))