Ejemplo n.º 1
0
 def test_01b_load_saved(self):
     """ Test raw mldat matrices with simple load function"""
     for bin_t in test_bins:
         toy_lens_path = path + '/toy-lens/pt11-bss-%d.mldat' % bin_t
         lp = gamale.load_lens_part(toy_lens_path)
         lp_mldat = gamale.load_lens_part(
             toy_lens_path.replace('.mldat', '-save.mldat'))
         lp_npz = gamale.load_lens_part(
             toy_lens_path.replace('.mldat', '-save.npz'))
         # Sparse matrix that maps npix_extragalactic to npix_observed:
         self.assertTrue(lp.shape == lp_mldat.shape)
         self.assertTrue(lp_mldat.shape == lp_npz.shape)
Ejemplo n.º 2
0
 def test_07_flux_map(self):
     """ Test flux function """
     for bin_t in test_bins:
         lenspart_path = path + '/toy-lens/pt11-bss-%d.mldat' % bin_t
         lp = gamale.load_lens_part(lenspart_path)
         flux_map = gamale.flux_map(lp)
         self.assertTrue(flux_map.sum() == stat * npix)
         self.assertTrue((flux_map >= 0).all())
Ejemplo n.º 3
0
 def test_05_mean_deflection(self):
     """ Test for higher deflections in lower energy bins """
     old_def = None
     for bin_t in test_bins:
         lenspart_path = path + '/toy-lens/pt11-bss-%d.mldat' % bin_t
         lp = gamale.load_lens_part(lenspart_path)
         deflection = gamale.mean_deflection(lp)
         self.assertTrue(deflection >= 0)
         self.assertTrue(deflection < np.pi)
         if bin_t > test_bins[0]:
             self.assertTrue(deflection < old_def)
         old_def = deflection
Ejemplo n.º 4
0
 def test_06_galactic_extragalactic(self):
     """ Test galactic and extragalactic vectors """
     for bin_t in test_bins:
         lenspart_path = path + '/toy-lens/pt11-bss-%d.mldat' % bin_t
         lp = gamale.load_lens_part(lenspart_path)
         observed = 0
         for i in range(npix):
             eg_vec = gamale.extragalactic_vector(lp, i)
             self.assertTrue(eg_vec.sum() == float(stat))
             self.assertTrue(isinstance(eg_vec[0], (float)))
             obs_vec = gamale.observed_vector(lp, i)
             self.assertTrue(isinstance(obs_vec[0], (float)))
             observed += obs_vec.sum()
             self.assertTrue(obs_vec.sum() >= 0)
             self.assertTrue(obs_vec.sum() < stat * npix)
         self.assertTrue(observed == stat * npix)
Ejemplo n.º 5
0
 def test_01_load_and_dimensions(self):
     """ Test raw mldat matrices with simple load function"""
     old_mcs = None
     for bin_t in test_bins:
         lenspart_path = path + '/toy-lens/jf12-regular-%d.npz' % bin_t
         lp = gamale.load_lens_part(lenspart_path)
         # Sparse matrix that maps npix_extragalactic to npix_observed:
         self.assertTrue(lp.shape == (npix, npix))
         mrs = lp.sum(axis=1).max()
         mcs = lp.sum(axis=0).max()
         self.assertTrue(int(mrs) == stat)
         self.assertTrue(mcs >= mrs)
         # Lower energy bins have higher flux differences
         # (see e.g. arXiv:1607.01645), thus:
         if bin_t > test_bins[0]:
             self.assertTrue(mcs < old_mcs)
         old_mcs = mcs
Ejemplo n.º 6
0
# the simulation and the rigidity range of the lens parts.

# If you have a galactic field lens on your computer, you can execute the following code:
lens_path = '/path/to/config/file.cfg'
if os.path.exists(lens_path):
    # Loading a lens
    lens = gamale.Lens(lens_path)

    # Loading the lens part corresponding to a particle of energy log10e and charge z
    log10e = 19  # Make sure that the rigidity is covered in your lens
    z = 1
    lens_part = lens.get_lens_part(log10e=log10e, z=z)

    # Alternatively, a lens part can be loaded directly
    lens_part_path = '/path/to/lens/part.npz'
    lens_part = gamale.load_lens_part(lens_part_path)

    nside = gamale.mat2nside(lens_part)  # calculating nside from lens part
    npix = hpt.nside2npix(nside)

    # Compute the observed directions of cosmic rays that arrives from direction of the
    # extragalactic pixel eg_pix after backpropagation from earth. The amount of
    # backpropagated cosmic rays per pixel is found as "Stat" in the .cfg-file.
    eg_pix = np.random.randint(0, npix)
    obs_dist = gamale.observed_vector(lens_part, eg_pix)  # Distribution of shape (Nside,)
    print("A cosmic ray originating from pixel %i is most likely observed in pixel %i." % (eg_pix, np.argmax(obs_dist)))

    # The other direction is also possible. Calculate the distribution of extragalactic
    # directions for cosmic rays arriving in the observed direction 'obs_pix'.
    obs_pix = np.random.randint(0, npix)
    eg_dist = gamale.extragalactic_vector(lens_part, obs_pix)  # Distribution of shape (Nside,)