def test_01d_rand_fisher_vecs_shape(self): shape = (5, 10) v0 = coord.rand_vec(shape) sigma = 0.1 * np.random.random(shape) vecs = coord.rand_fisher_vec(v0, kappa=1. / sigma**2) self.assertTrue(vecs.shape == (v0.shape)) self.assertTrue((coord.angle(vecs, v0) < 5 * sigma).all())
def test_09c_rotate_zaxis_to_x(self): v = np.array([np.zeros(stat), np.zeros(stat), np.ones(stat)]) angle = np.deg2rad(5) v_fisher = coord.rand_fisher_vec(v, kappa=1 / angle**2) self.assertTrue(v_fisher.shape == (3, stat)) self.assertTrue( np.abs(np.mean(coord.angle(v, v_fisher)) - angle) / angle < 0.5)
def test_01c_rand_fisher_vecs(self): v0 = coord.rand_vec(stat) sigma = 0.1 vecs = coord.rand_fisher_vec(v0, kappa=1. / sigma**2, n=stat) angles = coord.angle(vecs, v0) self.assertTrue((angles >= 0).all()) self.assertTrue((np.mean(angles) > 0.5 * sigma) & (np.mean(angles) < 2. * sigma)) self.assertTrue((angles < 5 * sigma).all())
def test_01b_rand_fisher_vec(self): vmean = np.array([0, 0, 1]) sigma = 0.25 vecs = coord.rand_fisher_vec(vmean, kappa=1. / sigma**2, n=stat) angles = coord.angle(vecs, vmean) self.assertTrue((angles >= 0).all()) self.assertTrue((np.mean(angles) > 0.5 * sigma) & (np.mean(angles) < 2. * sigma)) self.assertTrue((angles < 5 * sigma).all())
def test_09a_rotate_zaxis_to_x(self): zaxis = np.array([[0], [0], [1]]) v = coord.rand_fisher_vec(zaxis, kappa=1 / np.deg2rad(10)**2, n=100) _scalar = np.sum(v * zaxis, axis=0) # rotate to z-axis (no change) x1 = zaxis v1 = coord.rotate_zaxis_to_x(v, x1) self.assertTrue(np.allclose(v, v1)) self.assertTrue(np.allclose(_scalar, np.sum(v1 * x1, axis=0))) # rotate to negative z-axis x2 = -zaxis v2 = coord.rotate_zaxis_to_x(v, x2) self.assertTrue(np.allclose(_scalar, np.sum(v2 * x2, axis=0))) # rotate to arbitrary point on sphere x3 = np.array([[1], [1], [1]]) / np.sqrt(3) v3 = coord.rotate_zaxis_to_x(v, x3) self.assertTrue(np.allclose(_scalar, np.sum(v3 * x3, axis=0)))
ncrs = 3000 # number of cosmic rays log10e_min = 18.5 # minimum energy in log10(E / eV) lons = coord.rand_phi(ncrs) # isotropic in phi (~Uniform(-pi, pi)) lats = coord.rand_theta(ncrs) # isotropic in theta (Uniform in cos(theta)) vecs = coord.ang2vec(lons, lats) log10e = auger.rand_energy_from_auger(n=ncrs, log10e_min=log10e_min) # Plot an example map with sampled energies. If you specify the opath keyword in # the skymap function, the plot will be automatically saved and closed skymap.scatter(vecs, c=log10e, opath='isotropic_sky.png') # Creates an arrival map with a source located at v_src=(1, 0, 0) and apply a # fisher distribution around it with gaussian spread sigma=10 degree v_src = np.array([1, 0, 0]) kappa = 1. / np.radians(10.)**2 vecs = coord.rand_fisher_vec(v_src, kappa=kappa, n=ncrs) # if you dont specify the opath you can use (fig, ax) to plot more stuff fig, ax = skymap.scatter(vecs, c=log10e) plt.scatter(0, 0, s=100, c='red', marker='*') # plot source in the center plt.savefig('fisher_single_source_10deg.png', bbox_inches='tight') plt.close() # We can also use the coord.rand_fisher_vec() function to apply an angular uncertainty # on simulated arrival directions by feeding a higher dimensional v_src in shape (3, ncrs). # Each cosmic ray can also have a separate smearing angle, in the following code snippet # increasing with the longitude. lats = np.radians(np.array([-60, -30, -15, 0, 15, 30, 60])) lons = np.radians(np.arange(-180, 180, 30)) lons, lats = np.meshgrid(lons, lats) # vectors on this defined grid: vecs = coord.ang2vec(lons.flatten(), lats.flatten())