Пример #1
0
 def setUp(self):
     Reader = fitsGBT.Reader("./testdata/testfile_guppi_combined.fits",
                             feedback=0)
     self.Blocks = Reader.read((), 1)
     Data = self.Blocks[0]
     Data.calc_freq()
     params = {'dm_deweight_time_slope': True}
     Maker = dirty_map.DirtyMapMaker(params, feedback=0)
     n_chan = Data.dims[-1]
     Maker.n_chan = n_chan
     Maker.pols = (1, 2, 3, 4)
     Maker.pol_ind = 0
     Maker.band_centres = (Data.freq[Data.dims[-1] // 2], )
     Maker.band_ind = 0
     map = sp.zeros((Data.dims[-1], 32, 15))
     map = al.make_vect(map, ('freq', 'ra', 'dec'))
     map.set_axis_info('freq', Data.freq[Data.dims[-1] // 2],
                       Data.field['CRVAL1'])
     map.set_axis_info('ra', 218, 0.075)
     map.set_axis_info('dec', 2, 0.075)
     Maker.map = map
     self.Maker = Maker
     # The variances of each channel.
     self.norms = (sp.arange(1., 2., 0.25)[:, None] *
                   (sp.arange(1., 2., 1. / n_chan)[None, :]))
     for Data in self.Blocks:
         Data.data[...] = random.randn(*Data.data.shape)
         Data.data *= sp.sqrt(self.norms[:, None, :])
         Data.data += 50.
Пример #2
0
 def test_normal(self):
     params = self.params
     dirty_map.DirtyMapMaker(params, feedback=0).execute(4)
     files = glob.glob('*testout*')
     # 17 files = 2 pols * 2 bands * 2 (map and noise) * 2 (.npy and
     # .npy.meta) + 1 (parameter file)
     self.assertTrue(len(files) == 9)
Пример #3
0
 def test_independant_channels(self):
     params = self.params
     params["dm_frequency_correlations"] = "None"
     dirty_map.DirtyMapMaker(params, feedback=0).execute(4)
     files = glob.glob('*testout*')
     # 17 files = 2 pols * 2 bands * 2 (map and noise) * 2 (.npy and
     # .npy.meta) + 1 (parameter file)
     self.assertTrue(len(files) == 9)
Пример #4
0
 def test_separate_scans(self):
     params = self.params
     params['dm_time_block'] = 'scan'
     dirty_map.DirtyMapMaker(params, feedback=0).execute(4)
     files = glob.glob('*testout*')
     # 17 files = 2 pols * 2 bands * 2 (map and noise) * 2 (.npy and
     # .npy.meta) + 1 (parameter file)
     self.assertTrue(len(files) == 9)
Пример #5
0
    def make_map(self,
                 Data,
                 n_data=10,
                 time=False,
                 thermal=None,
                 over_f=None,
                 over_f_modes=None,
                 all_channel=None):
        """This does all the map making for the input parameters.  Contains no
        tests."""

        nf = Data.nf
        nra = Data.nra
        ndec = Data.ndec
        map_size = Data.map_size
        scan_size = Data.scan_size
        # Figure out the thermal values.
        if thermal is None:
            thermal_var = Data.thermal
        else:
            thermal_var = thermal
        # Figure out what the noise frequeny modes are.
        if over_f is None:
            over_f_pars = Data.correlated_noise
        else:
            over_f_pars = over_f
        if over_f_modes is None:
            over_f_mode_pars = Data.freq_mode_noise
        else:
            over_f_mode_pars = over_f_modes
        # Figure out what to use all the all channel noise.
        if all_channel is None:
            all_channel_pars = Data.universal_over_f
        else:
            all_channel_pars = all_channel
        # Figure out what noise model will be used.
        if (not over_f is None) or (over_f_modes is None
                                    and not Data.correlated_noise is None):
            n_modes = 0
            noise_model = 'mean'
        else:
            n_modes = len(over_f_mode_pars)
            noise_model = 'measured'

        params = {
            'dm_file_middles': ['a'] * n_data,
            'dm_map_shape': (nra, ndec),
            'dm_field_centre': (21., 0.),
            'dm_pixel_spacing': map_size / nra,
            'dm_time_block': 'file',
            'dm_frequency_correlations': noise_model,
            'dm_number_frequency_modes': n_modes,
            'dm_deweight_time_mean': True,
            'dm_deweight_time_slope': True
        }
        Maker = dirty_map.DirtyMapMaker(params, feedback=0)
        Maker.pol = 0
        Maker.band = 0

        # Replace the data reader with mock data generator.
        def iterate_data(file_middles):
            for ii in xrange(n_data):
                yield Data.get_all_trimmed(ii)

        Maker.iterate_data = iterate_data

        # Replace the noise parameter reader.
        def get_noise_parameter(MakerClass, parameter_name):
            if parameter_name == "thermal":
                thermal = sp.empty(nf)
                thermal[...] = thermal_var
                return thermal
            elif parameter_name == "mean_over_f":
                return over_f_pars
            elif parameter_name[:12] == "over_f_mode_":
                mode_number = int(parameter_name[12:])
                mode = make_frequency_mode(mode_number, nf)
                return over_f_mode_pars[mode_number] + (mode, )
            elif parameter_name == "all_channel":
                thermal = sp.empty(nf)
                thermal[...] = thermal_var / BW_d / 2.
                return (thermal_var, ) + all_channel_pars
            else:
                raise ValueError()

        Maker.get_noise_parameter = lambda p_name: get_noise_parameter(
            Maker, p_name)
        Maker.uncorrelated_channels = False
        Maker.n_chan = nf
        Maker.n_ra = nra
        Maker.n_dec = ndec
        Maker.n_processes = 8
        # Initialize the map maker's map and inverse covariance.
        map = Data.get_map()
        Maker.map = map
        # I use ones instead of zeros to make sure it gets overwritten.
        cov_inv = sp.ones((nf, nra, ndec, nf, nra, ndec), dtype=float)
        cov_inv = al.make_mat(cov_inv,
                              axis_names=('freq', 'ra', 'dec', 'freq', 'ra',
                                          'dec'),
                              row_axes=(0, 1, 2),
                              col_axes=(3, 4, 5))
        cov_inv[...] = 0
        Maker.cov_inv = cov_inv
        # Run the engine of the map maker.
        start = time_module.clock()
        real_start = time_module.time()
        Maker.make_map()
        t = time_module.clock() - start
        t2 = time_module.time() - real_start
        if time:
            return t, t2
        # Clean the map.
        cov_inv_m = cov_inv.view()
        cov_inv_m.shape = (nf * nra * ndec, nf * nra * ndec)
        map_v = map.view()
        map_v.shape = (nf * nra * ndec, )
        v, U = linalg.eigh(cov_inv_m)
        self.assertTrue(sp.all(v > 0))
        new_map = sp.dot(U.T, map_v)
        new_map /= v
        new_map = sp.dot(U, new_map)
        new_map.shape = (nf, nra, ndec)
        # Get the expected map.
        map_ra = map.get_axis('ra')[:, None]
        map_dec = map.get_axis('dec')[None, :]
        expected_map = Data.sky_ra_dec(map_ra, map_dec)
        # Figure out the differences (that aren't in the slice mean mode).
        map_diffs = new_map - expected_map
        diff_v = map_diffs.view()
        diff_v.shape = (nf * nra * ndec, )
        chi_sq = sp.dot(sp.dot(diff_v, cov_inv_m), diff_v)
        n_deg_f = nf * nra * ndec
        # Transformation to make it normally distributed.
        nor = (chi_sq / n_deg_f)**(1.0 / 3) - (1.0 - 2.0 / 9 / n_deg_f)
        nor /= sp.sqrt(2.0 / 9.0 / n_deg_f)
        return new_map, map_diffs, nor