def test_02a_rand_vec_in_pix(self): pix = np.random.randint(0, self.npix, self.stat) vecs = hpt.rand_vec_in_pix(self.nside, pix) pix_check = hpt.vec2pix(self.nside, *vecs) vecs_check = hpt.pix2vec(self.nside, pix) self.assertTrue((vecs != vecs_check).all() and (pix == pix_check).all())
def test_02c_rand_exposure_vec_in_pix(self): nside = 8 stat = 100000 pix = hpt.rand_pix_from_map(hpt.exposure_pdf(nside), n=stat) v1 = hpt.rand_vec_in_pix(nside, pix) # there should be a problem with some few vetors that have exposure zero self.assertTrue(not (coord.get_exposure(v1) > 0).all()) # here the problem is resolved (function is slower though) v2 = hpt.rand_exposure_vec_in_pix(nside, pix) self.assertTrue((coord.get_exposure(v2) > 0).all())
def test_03_iso(self): nside = 256 roi_size = 0.25 pix, _ = setup_roi(nside=nside, roi_size=roi_size) p = hpt.rand_vec_in_pix(nside, pix) T, N = obs.thrust(p, weights=None) self.assertTrue(np.abs(T[1] - 4. / (3. * np.pi) * roi_size) < 1e-2) self.assertTrue(T[2] < T[1]) self.assertTrue(np.abs(T[2] - T[1]) < 1e-2)
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))
# distributions on the sphere (dipole, fisher, experiment exposure). ncrs = 3000 # number of cosmic rays log10e_min = 18.5 # minimum energy in log10(E / eV) nside = 64 # resolution of the HEALPix map (default: 64) npix = hpt.nside2npix(nside) # Create a dipole distribution for a healpy map lon, lat = np.radians(45), np.radians(60) # Position of the maximum of the dipole (healpy and astrotools definition) vec_max = hpt.ang2vec(lat, lon) # Convert this to a vector amplitude = 0.5 # amplitude of dipole dipole = hpt.dipole_pdf(nside, amplitude, vec_max, pdf=False) skymap.heatmap(dipole, opath='dipole.png') # Draw random events from this distribution pixel = hpt.rand_pix_from_map(dipole, n=ncrs) # returns 3000 random pixel from this map vecs = hpt.rand_vec_in_pix(nside, pixel) # Random vectors within the drawn pixel skymap.scatter(vecs, c=auger.rand_energy_from_auger(ncrs, log10e_min), opath='dipole_events.png') # Create a healpy map that follows the exposure of an observatory at latitude # a0 = -35.25 (Pierre Auger Observatory) and maximum zenith angle of 60 degree exposure = hpt.exposure_pdf(nside, a0=-35.25, zmax=60) skymap.heatmap(exposure, opath='exposure.png') # Note, if you want to sample from the exposure healpy map random vectors you # have to be careful with the above method hpt.rand_vec_in_pix, # as the exposure healpy map reads out the exposure value in the pixel centers, # whereas hpt.rand_vec_in_pix might sample some directions where # the exposure already dropped to zero. If you want to sample only isoptropic # arrival directions it is instead recommended to use # coord.rand_exposure_vec(), or if you can not avoid healpy # pixelization use <code> hpt.rand_exposure_vec_in_pix </code>.
def test_02b_rand_exposure_vec_in_pix(self): pix = hpt.rand_pix_from_map(hpt.exposure_pdf(self.nside), n=self.stat) v1 = hpt.rand_vec_in_pix(self.nside, pix) v2 = hpt.rand_exposure_vec_in_pix(self.nside, pix) self.assertTrue( (coord.angle(v1, v2) < 2 * hpt.max_pixrad(self.nside)).all())
def setUp(self): self.nside, self.stat, self.nbins = 64, 1000, 180 self.npix = hpt.nside2npix(self.nside) self.vecs = hpt.rand_vec_in_pix(self.nside, np.random.choice(self.npix, self.stat))