Esempio n. 1
0
 def setUp(self):
     # Make a positive definite noise matrix, clean map, and dirty_map.
     self.nra = 10
     self.ndec = 5
     self.nf = 20
     self.shape = (self.nf, self.nra, self.ndec)
     self.size = self.nra * self.ndec * self.nf
     # Clean map.
     clean_map = sp.empty(self.shape, dtype=float)
     clean_map = al.make_vect(clean_map, axis_names=('freq', 'ra', 'dec'))
     clean_map[...] = sp.sin(sp.arange(self.nf))[:,None,None]
     clean_map *= sp.cos(sp.arange(self.nra))[:,None]
     clean_map *= sp.cos(sp.arange(self.ndec))
     # Noise inverse matrix.
     noise_inv = sp.empty(self.shape * 2, dtype=float)
     noise_inv = al.make_mat(noise_inv, axis_names=('freq', 'ra', 'dec')*2,
                             row_axes=(0, 1, 2), col_axes=(3, 4, 5))
     rand_mat = rand.randn(*((self.size,) * 2))
     information_factor = 1.e6  # K**-2
     rand_mat = sp.dot(rand_mat, rand_mat.transpose()) * information_factor
     noise_inv.flat[...] = rand_mat.flat
     # Dirty map.
     dirty_map = al.partial_dot(noise_inv, clean_map)
     # Store in self.
     self.clean_map = clean_map
     self.noise_inv = noise_inv
     self.dirty_map = dirty_map
Esempio n. 2
0
 def setUp(self):
     # Make a positive definite noise matrix, clean map, and dirty_map.
     self.nra = 10
     self.ndec = 5
     self.nf = 20
     self.shape = (self.nf, self.nra, self.ndec)
     self.size = self.nra * self.ndec * self.nf
     # Clean map.
     clean_map = sp.empty(self.shape, dtype=float)
     clean_map = al.make_vect(clean_map, axis_names=('freq', 'ra', 'dec'))
     clean_map[...] = sp.sin(sp.arange(self.nf))[:, None, None]
     clean_map *= sp.cos(sp.arange(self.nra))[:, None]
     clean_map *= sp.cos(sp.arange(self.ndec))
     # Noise inverse matrix.
     noise_inv = sp.empty(self.shape * 2, dtype=float)
     noise_inv = al.make_mat(noise_inv,
                             axis_names=('freq', 'ra', 'dec') * 2,
                             row_axes=(0, 1, 2),
                             col_axes=(3, 4, 5))
     rand_mat = rand.randn(*((self.size, ) * 2))
     information_factor = 1.e6  # K**-2
     rand_mat = sp.dot(rand_mat, rand_mat.transpose()) * information_factor
     noise_inv.flat[...] = rand_mat.flat
     # Dirty map.
     dirty_map = al.partial_dot(noise_inv, clean_map)
     # Store in self.
     self.clean_map = clean_map
     self.noise_inv = noise_inv
     self.dirty_map = dirty_map
Esempio n. 3
0
 def test_apply_time_axis(self):
     # The function that this is testing hasn't been implemented. Test
     # disabled.
     time_stream, ra, dec, az, el, time, mask_inds = \
             self.DM.get_all_trimmed()
     P = dirty_map.Pointing(('ra', 'dec'), (ra, dec), self.map, 'linear')
     pointing_matrix = P.get_matrix()
     gridded_data_mult = al.partial_dot(time_stream, pointing_matrix)
     gridded_data_fast = P.apply_to_time_axis(time_stream)
     self.assertTrue(sp.allclose(gridded_data_mult, gridded_data_fast))
Esempio n. 4
0
 def test_apply_time_axis(self):
     # The function that this is testing hasn't been implemented. Test
     # disabled.
     time_stream, ra, dec, az, el, time, mask_inds = \
             self.DM.get_all_trimmed()
     P = dirty_map.Pointing(('ra', 'dec'), (ra, dec), self.map, 'linear')
     pointing_matrix = P.get_matrix()
     gridded_data_mult = al.partial_dot(time_stream,
                                        pointing_matrix)
     gridded_data_fast = P.apply_to_time_axis(time_stream)
     self.assertTrue(sp.allclose(gridded_data_mult, gridded_data_fast))
Esempio n. 5
0
 def test_solve_eig_bad_ind(self):
     # Set all the information in one pixel to nil.
     self.noise_inv[17,3,1,...] = 0
     self.noise_inv[...,17,3,1] = 0
     self.dirty_map = al.partial_dot(self.noise_inv, self.clean_map)
     self.eig()
     new_clean_map, noise_diag = clean_map.solve_from_eig(
         self.noise_evalsinv, self.noise_evects, self.dirty_map, True,
         feedback=0)
     self.clean_map[17,3,1] = 0
     self.assertTrue(sp.allclose(new_clean_map, self.clean_map))
Esempio n. 6
0
 def test_solve_eig_bad_ind(self):
     # Set all the information in one pixel to nil.
     self.noise_inv[17, 3, 1, ...] = 0
     self.noise_inv[..., 17, 3, 1] = 0
     self.dirty_map = al.partial_dot(self.noise_inv, self.clean_map)
     self.eig()
     new_clean_map, noise_diag = clean_map.solve_from_eig(
         self.noise_evalsinv,
         self.noise_evects,
         self.dirty_map,
         True,
         feedback=0)
     self.clean_map[17, 3, 1] = 0
     self.assertTrue(sp.allclose(new_clean_map, self.clean_map))
Esempio n. 7
0
 def test_build_noise(self):
     map = self.map
     time_stream, ra, dec, az, el, time, mask_inds = \
                                            self.DM.get_all_trimmed()
     nt = len(time)
     Noise = dirty_map.Noise(time_stream, time)
     thermal_noise_levels = sp.zeros((nf_d)) + 0.04  # Kelvin**2
     Noise.add_thermal(thermal_noise_levels)
     Noise.add_mask(mask_inds)
     self.assertTrue(sp.alltrue(Noise.diagonal[mask_inds] > 10))
     Noise.deweight_time_mean()
     Noise.deweight_time_slope()
     Noise.add_correlated_over_f(0.01, -1.2, 0.1)
     Noise.finalize()
     #### Test the full inverse.
     # Frist get a full representation of the noise matrix
     #tmp_mat = sp.zeros((nf_d, nt, nf_d, nt))
     #tmp_mat.flat[::nt*nf_d + 1] += Noise.diagonal.flat
     #for jj in xrange(Noise.time_modes.shape[0]):
     #    tmp_mat += (Noise.time_mode_noise[jj,:,None,:,None]
     #                * Noise.time_modes[jj,None,:,None,None]
     #                * Noise.time_modes[jj,None,None,None,:])
     #for jj in xrange(Noise.freq_modes.shape[0]):
     #    tmp_mat +=  (Noise.freq_mode_noise[jj,None,:,None,:]
     #                 * Noise.freq_modes[jj,:,None,None,None]
     #                 * Noise.freq_modes[jj,None,None,:,None])
     tmp_mat = Noise.get_mat()
     tmp_mat.shape = (nt*nf_d, nt*nf_d)
     # Check that the matrix I built for testing is indeed symetric.
     self.assertTrue(sp.allclose(tmp_mat, tmp_mat.transpose()))
     noise_inv = Noise.get_inverse()
     noise_inv.shape = (nt*nf_d, nt*nf_d)
     # Check that the production matrix is symetric.
     self.assertTrue(sp.allclose(noise_inv, noise_inv.transpose()))
     tmp_eye = sp.dot(tmp_mat, noise_inv)
     #print tmp_eye
     noise_inv.shape = (nf_d, nt, nf_d, nt)
     self.assertTrue(sp.allclose(tmp_eye, sp.identity(nt*nf_d)))
     # Check that the calculation of the diagonal is correct.
     noise_inv_diag = Noise.get_inverse_diagonal()
     self.assertTrue(sp.allclose(noise_inv_diag.flat, 
                                 noise_inv.flat[::nf_d*nt + 1]))
     #### Test the noise weighting of the data.
     noise_weighted_data = Noise.weight_time_stream(time_stream)
     self.assertTrue(sp.allclose(noise_weighted_data, al.dot(noise_inv,
                                                             time_stream)))
     #### Test making noise in map space.
     # First make the noise matrix by brute force.
     P = dirty_map.Pointing(("ra", "dec"), (ra, dec), map, 'nearest')
     P_mat = P.get_matrix()
     tmp_map_noise_inv = al.partial_dot(noise_inv,
                                        P_mat)
     tmp_map_noise_inv = al.partial_dot(P_mat.mat_transpose(), 
                                        tmp_map_noise_inv)
     # I mess up the meta data by doing this, but rotate the axes so they
     # are in the desired order.
     tmp_map_noise_inv = sp.rollaxis(tmp_map_noise_inv, 2, 0)
     # Now use fast methods.
     map_noise_inv = sp.zeros((nf_d, nra_d, ndec_d, nf_d, nra_d, ndec_d),
                              dtype=float)
     map_noise_inv = al.make_mat(map_noise_inv, axis_names=('freq', 'ra', 
         'dec', 'freq', 'ra', 'dec'), row_axes=(0, 1, 2), 
         col_axes=(3, 4, 5))
     start = time_module.clock()
     for ii in xrange(nf_d):
         for jj in xrange(nra_d):
             P.noise_to_map_domain(Noise, ii, jj,
                                   map_noise_inv[ii,jj,:,:,:,:])
     stop = time_module.clock()
     #print "Constructing map noise took %5.2f seconds." % (stop - start)
     self.assertTrue(sp.allclose(map_noise_inv, tmp_map_noise_inv))
Esempio n. 8
0
 def test_build_noise(self):
     map = self.map
     time_stream, ra, dec, az, el, time, mask_inds = \
                                            self.DM.get_all_trimmed()
     nt = len(time)
     Noise = dirty_map.Noise(time_stream, time)
     thermal_noise_levels = sp.zeros((nf_d)) + 0.04  # Kelvin**2
     Noise.add_thermal(thermal_noise_levels)
     Noise.add_mask(mask_inds)
     self.assertTrue(sp.alltrue(Noise.diagonal[mask_inds] > 10))
     Noise.deweight_time_mean()
     Noise.deweight_time_slope()
     Noise.add_correlated_over_f(0.01, -1.2, 0.1)
     Noise.finalize()
     #### Test the full inverse.
     # Frist get a full representation of the noise matrix
     #tmp_mat = sp.zeros((nf_d, nt, nf_d, nt))
     #tmp_mat.flat[::nt*nf_d + 1] += Noise.diagonal.flat
     #for jj in xrange(Noise.time_modes.shape[0]):
     #    tmp_mat += (Noise.time_mode_noise[jj,:,None,:,None]
     #                * Noise.time_modes[jj,None,:,None,None]
     #                * Noise.time_modes[jj,None,None,None,:])
     #for jj in xrange(Noise.freq_modes.shape[0]):
     #    tmp_mat +=  (Noise.freq_mode_noise[jj,None,:,None,:]
     #                 * Noise.freq_modes[jj,:,None,None,None]
     #                 * Noise.freq_modes[jj,None,None,:,None])
     tmp_mat = Noise.get_mat()
     tmp_mat.shape = (nt * nf_d, nt * nf_d)
     # Check that the matrix I built for testing is indeed symetric.
     self.assertTrue(sp.allclose(tmp_mat, tmp_mat.transpose()))
     noise_inv = Noise.get_inverse()
     noise_inv.shape = (nt * nf_d, nt * nf_d)
     # Check that the production matrix is symetric.
     self.assertTrue(sp.allclose(noise_inv, noise_inv.transpose()))
     tmp_eye = sp.dot(tmp_mat, noise_inv)
     #print tmp_eye
     noise_inv.shape = (nf_d, nt, nf_d, nt)
     self.assertTrue(sp.allclose(tmp_eye, sp.identity(nt * nf_d)))
     # Check that the calculation of the diagonal is correct.
     noise_inv_diag = Noise.get_inverse_diagonal()
     self.assertTrue(
         sp.allclose(noise_inv_diag.flat, noise_inv.flat[::nf_d * nt + 1]))
     #### Test the noise weighting of the data.
     noise_weighted_data = Noise.weight_time_stream(time_stream)
     self.assertTrue(
         sp.allclose(noise_weighted_data, al.dot(noise_inv, time_stream)))
     #### Test making noise in map space.
     # First make the noise matrix by brute force.
     P = dirty_map.Pointing(("ra", "dec"), (ra, dec), map, 'nearest')
     P_mat = P.get_matrix()
     tmp_map_noise_inv = al.partial_dot(noise_inv, P_mat)
     tmp_map_noise_inv = al.partial_dot(P_mat.mat_transpose(),
                                        tmp_map_noise_inv)
     # I mess up the meta data by doing this, but rotate the axes so they
     # are in the desired order.
     tmp_map_noise_inv = sp.rollaxis(tmp_map_noise_inv, 2, 0)
     # Now use fast methods.
     map_noise_inv = sp.zeros((nf_d, nra_d, ndec_d, nf_d, nra_d, ndec_d),
                              dtype=float)
     map_noise_inv = al.make_mat(map_noise_inv,
                                 axis_names=('freq', 'ra', 'dec', 'freq',
                                             'ra', 'dec'),
                                 row_axes=(0, 1, 2),
                                 col_axes=(3, 4, 5))
     start = time_module.clock()
     for ii in xrange(nf_d):
         for jj in xrange(nra_d):
             P.noise_to_map_domain(Noise, ii, jj,
                                   map_noise_inv[ii, jj, :, :, :, :])
     stop = time_module.clock()
     #print "Constructing map noise took %5.2f seconds." % (stop - start)
     self.assertTrue(sp.allclose(map_noise_inv, tmp_map_noise_inv))