def test_01_pix2ang(self): pix = np.random.randint(0, self.npix, self.stat) phi, theta = hpt.pix2ang(self.nside, pix) phi_range = (phi >= -np.pi).all() and (phi <= np.pi).all() theta_range = (theta >= -np.pi / 2.).all() and (theta <= np.pi / 2.).all() self.assertTrue(phi_range and theta_range)
def test_ang2pix_ring(self): # ensure nside = 1 << 23 is correctly calculated # by comparing the original theta phi are restored. # NOTE: nside needs to be sufficiently large! id = hpt.ang2pix(1048576 * 8, self.phi0, self.theta0, nest=False) phi1, theta1 = hpt.pix2ang(1048576 * 8, id, nest=False) np.testing.assert_array_almost_equal(theta1, self.theta0, decimal=5) np.testing.assert_array_almost_equal(phi1, self.phi0, decimal=5)
def test_ang2pix_nest(self): # ensure nside = 1 << 23 is correctly calculated # by comparing the original theta phi are restored. # NOTE: nside needs to be sufficiently large! # NOTE: with Healpy_Base this will fail because nside # is limited to 1 << 13 with Healpy_Base. id = hpt.ang2pix(1048576 * 8, self.phi0, self.theta0, nest=True) phi1, theta1 = hpt.pix2ang(1048576 * 8, id, nest=True) np.testing.assert_array_almost_equal(theta1, self.theta0) np.testing.assert_array_almost_equal(phi1, self.phi0)
def _direction_transformation(self, similar_key, orig_key): """ Helper function to get values stored under a different physical key in the correctly transformed way specifically only for directions """ nside = self.general_object_store['nside'] if 'nside' in self.keys() else 64 store = self.shape_array if similar_key in list(self.shape_array.dtype.names) else self.general_object_store if orig_key == 'vecs': if ('lon' in similar_key) or ('lat' in similar_key): return hpt.ang2vec(store['lon'], store['lat']) return hpt.pix2vec(nside, store[similar_key]) if ('pix' in orig_key): if 'pix' in similar_key: return store[similar_key] if similar_key == 'vecs': return hpt.vec2pix(nside, store['vecs']) return hpt.ang2pix(nside, store['lon'], store['lat']) if similar_key == 'vecs': lon, lat = hpt.vec2ang(store['vecs']) else: lon, lat = hpt.pix2ang(nside, store[similar_key]) return lon if orig_key == 'lon' else lat
print("Test: module cosmic_rays.py") # This module provides a data container for cosmic ray observables and can be used # to simply visualize, share, save and load data in an efficient way. There are # two classes, the CosmicRaysBase and the CosmicRaysSets. # If you just have a single cosmic ray set you want to use the ComicRaysBase. You can # set arbitrary content in the container. Objects with shape (self.crs) will be # stored in an internal array called 'shape_array', all other data in a # dictionary called 'general_object_store'. nside = 64 npix = hpt.nside2npix(nside) ncrs = 5000 exposure = hpt.exposure_pdf(nside) lon, lat = hpt.pix2ang(nside, hpt.rand_pix_from_map(exposure, n=ncrs)) crs = cosmic_rays.CosmicRaysBase(ncrs) # Initialize cosmic ray container # you can set arbitrary content in the container. Objects with different shape # than (ncrs) will be stored in an internal dictionary called 'general_object_store' crs['lon'], crs['lat'] = lon, lat crs['date'] = 'today' crs['log10e'] = auger.rand_energy_from_auger(log10e_min=19, n=ncrs) crs.set('vecs', coord.ang2vec(lon, lat)) # another possibility to set content crs.keys() # will print the keys that are existing # Save, load and plot cosmic ray base container opath = 'cr_base_container.npz' crs.save(opath) crs_load = cosmic_rays.CosmicRaysBase(opath) crs_load.plot_heatmap(opath='cr_base_healpy.png') crs_load.plot_eventmap(opath='cr_base_eventmap.png')