示例#1
0
    def test_calibrate_image_junk_unit_fails(self):
        scanset = ScanSet('test.hdf5')

        scanset.calculate_images()
        with pytest.raises(ValueError) as excinfo:
            images = scanset.calculate_images(calibration=self.calfile,
                                              map_unit="junk")
            assert "Unit for calibration not recognized" in str(excinfo.value)
示例#2
0
    def test_calibrate_image_beam(self):
        scanset = ScanSet('test.hdf5')

        scanset.calculate_images()
        images = scanset.calculate_images(calibration=self.calfile,
                                          map_unit="Jy/beam")

        assert np.allclose(np.max(images['Feed0_RCP']), self.simulated_flux,
                           atol=0.1)
示例#3
0
 def test_calibrate_scanset_pixel(self):
     scanset = ScanSet('test.hdf5')
     images_standard = scanset.calculate_images(calibration=self.calfile,
                                                map_unit="Jy/pixel")
     images = scanset.calculate_images(calibration=self.calfile,
                                       map_unit="Jy/pixel",
                                       calibrate_scans=True)
     assert np.allclose(images['Feed0_RCP'], images_standard['Feed0_RCP'],
                        rtol=0.05)
示例#4
0
    def test_calibrate_image_sr(self):
        scanset = ScanSet('test.hdf5')

        scanset.calculate_images()
        images = scanset.calculate_images(calibration=self.calfile,
                                          map_unit="Jy/sr")

        images_pix = scanset.calculate_images(calibration=self.calfile,
                                              map_unit="Jy/pixel")

        pixel_area = scanset.meta['pixel_size'] ** 2
        assert np.allclose(images['Feed0_RCP'],
                           images_pix['Feed0_RCP'] / pixel_area.to(u.sr).value,
                           rtol=0.05)
示例#5
0
    def test_global_fit_image(self):
        '''Test image production.'''
        scanset = ScanSet('test.hdf5')
        # It works with no parameters, before calculating images,
        # with no_offsets
        scanset.fit_full_images(no_offsets=True)
        # It works after calculating images
        images = scanset.calculate_images()
        nx, ny = images['Feed0_RCP'].shape
        excluded = [[nx // 2, ny // 2, nx // 4]]
        scanset.fit_full_images(excluded=excluded, chans='Feed0_RCP')
        os.path.exists("out_iter_Feed0_RCP_002.txt")
        scanset.fit_full_images(excluded=excluded, chans='Feed0_LCP')
        os.path.exists("out_iter_Feed0_LCP_000.txt")

        if not HAS_MPL:
            with pytest.raises(ImportError) as excinfo:
                display_intermediate(scanset, chan="Feed0_RCP",
                                     excluded=excluded,
                                     parfile="out_iter_Feed0_RCP_002.txt")

            assert "display_intermediate: matplotlib" in str(excinfo.value)
        else:
            display_intermediate(scanset, chan="Feed0_RCP",
                                 excluded=excluded,
                                 parfile="out_iter_Feed0_RCP_002.txt")
            os.path.exists("out_iter_Feed0_LCP_002.png")
示例#6
0
    def test_update_scan_zap(self):
        scanset = ScanSet('test.hdf5')

        images = scanset.calculate_images()
        ysize, xsize = images['Feed0_RCP'].shape
        ra_xs, ra_ys, dec_xs, dec_ys, scan_ids, ra_masks, dec_masks, coord = \
            scanset.find_scans_through_pixel(xsize//2, 0, test=True)

        sname = sorted(list(dec_xs.keys()))[0]
        s = Scan(sname)

        info = {sname: copy.copy(self.stdinfo)}
        info[sname]['zap'].xs = [np.float(s['dec'][0]), np.float(s['dec'][10])]
        sid = scan_ids[sname]
        mask = scanset['Scan_id'] == sid
        before = scanset['Feed0_RCP-filt'][mask]
        scanset.update_scan(sname, scan_ids[sname], coord[sname],
                            info[sname]['zap'],
                            info[sname]['fitpars'], info[sname]['FLAG'],
                            test=True)
        after = scanset['Feed0_RCP-filt'][mask]

        assert np.all(before[:10] != after[:10])
        s = Scan(sname)

        assert np.all(np.array(after, dtype=bool) ==
                      np.array(s['Feed0_RCP-filt'], dtype=bool))
示例#7
0
    def test_ver_images(self):
        '''Test image production.'''

        scanset = ScanSet('test.hdf5')
        scanset.remove_column('Feed0_RCP-filt')
        images = scanset.calculate_images(no_offsets=True, direction=1)

        img = images['Feed0_RCP']
示例#8
0
    def test_find_scan_through_invalid_pixel(self):
        scanset = ScanSet('test.hdf5')

        images = scanset.calculate_images()
        ysize, xsize = images['Feed0_RCP'].shape
        _, _, _, _, _, _, _, coord = \
            scanset.find_scans_through_pixel(xsize//2, -2, test=True)
        assert coord == {}
        _, _, _, _, _, _, _, coord = \
            scanset.find_scans_through_pixel(xsize//2, ysize + 2, test=True)
        assert coord == {}
示例#9
0
    def test_global_fit_image_using_ds9_region(self):
        scanset = ScanSet('test.hdf5')
        # It works after calculating images
        images = scanset.calculate_images()
        nx, ny = images['Feed0_RCP'].shape

        regstr = 'image;circle({},{},{})'.format(nx // 2, ny // 2, nx // 4)
        with open('region.reg', 'w') as fobj:
            print(regstr, file=fobj)

        main_imager('test.hdf5 -g --exclude region.reg'.split())
        os.unlink('region.reg')
示例#10
0
    def test_imager_global_fit_valid(self):
        '''Test image production.'''
        # Get information on images
        scanset = ScanSet('test.hdf5')
        scanset.fit_full_images(no_offsets=True)
        # It works after calculating images
        images = scanset.calculate_images()
        nx, ny = images['Feed0_RCP'].shape
        excluded = [[nx//2, ny//2, nx//4]]

        main_imager('test.hdf5 -g '
                    '-e {} {} {}'.format(*(excluded[0])).split(' '))
示例#11
0
    def test_find_scan_through_pixel_bad_scan(self, logger, caplog):
        scanset = ScanSet('test.hdf5')
        images = scanset.calculate_images()
        ysize, xsize = images['Feed0_RCP'].shape
        x, y = xsize // 2, 0
        good_entries = np.logical_and(
                np.abs(scanset['x'][:, 0] - x) < 1,
                np.abs(scanset['y'][:, 0] - y) < 1)

        sids = list(set(scanset['Scan_id'][good_entries]))
        scanset.scan_list[sids[0]] = 'skd'
        scanset.find_scans_through_pixel(x, y, test=True)
        assert "Errors while opening scan skd" in caplog.text
示例#12
0
    def test_rough_image_nooffsets_nofilt(self):
        '''Test image production.'''

        scanset = ScanSet('test.hdf5')
        scanset.remove_column('Feed0_RCP-filt')
        images = scanset.calculate_images(no_offsets=True)

        img = images['Feed0_RCP']
        if HAS_MPL:
            fig = plt.figure('img')
            plt.imshow(img, origin='lower')
            plt.colorbar()
            plt.savefig('img_nooff_nofilt.png')
            plt.close(fig)
示例#13
0
    def test_rough_image(self):
        '''Test image production.'''

        scanset = ScanSet('test.hdf5')

        images = scanset.calculate_images()

        img = images['Feed0_RCP']

        if HAS_MPL:
            fig = plt.figure('img')
            plt.imshow(img, origin='lower')
            plt.colorbar()
            plt.savefig('img.png')
            plt.close(fig)
示例#14
0
    def test_rough_image_altaz(self):
        '''Test image production.'''
        scanset = ScanSet('test.hdf5')

        images = scanset.calculate_images(altaz=True)

        img = images['Feed0_RCP']

        if HAS_MPL:
            fig = plt.figure('img_altaz')
            plt.imshow(img, origin='lower')
            plt.colorbar()
            plt.savefig('img_altaz.png')
            scanset.save_ds9_images(save_sdev=True, altaz=True)
            plt.close(fig)
示例#15
0
    def test_image_stdev(self):
        '''Test image production.'''

        scanset = ScanSet('test.hdf5')

        images = scanset.calculate_images()

        img = images['Feed0_RCP-Sdev']
        if HAS_MPL:
            fig = plt.figure('log(img-Sdev)')
            plt.imshow(np.log10(img), origin='lower')
            plt.colorbar()
            plt.ioff()
            plt.savefig('img_sdev.png')
            plt.close(fig)
示例#16
0
    def test_image_scrunch(self):
        '''Test image production.'''

        scanset = ScanSet('test.hdf5')

        scanset.calculate_images()
        images = scanset.scrunch_images()

        img = images['TOTAL']

        if HAS_MPL:
            fig = plt.figure('img - scrunched')
            plt.imshow(img, origin='lower')
            plt.colorbar()
            img = images['TOTAL-Sdev']
            plt.savefig('img_scrunch.png')
            plt.close(fig)

            fig = plt.figure('img - scrunched - sdev')
            plt.imshow(img, origin='lower')
            plt.colorbar()
            plt.ioff()
            plt.savefig('img_scrunch_sdev.png')
            plt.close(fig)
示例#17
0
    def test_calibrate_image_pixel(self):
        scanset = ScanSet('test.hdf5')

        images = scanset.calculate_images(calibration=self.calfile,
                                          map_unit="Jy/pixel")

        img = images['Feed0_RCP']
        center = img.shape[0] // 2, img.shape[1] // 2
        shortest_side = np.min(img.shape)
        X, Y = np.meshgrid(np.arange(img.shape[1]), np.arange(img.shape[0]))
        good = (X-center[1])**2 + (Y-center[0])**2 <= (shortest_side//4)**2
        rtol = 0.1 if HAS_STATSM else 0.15

        assert np.isclose(np.sum(images['Feed0_RCP'][good]),
                          self.simulated_flux, rtol=rtol)
示例#18
0
    def test_find_scan_through_pixel0(self):
        scanset = ScanSet('test.hdf5')

        images = scanset.calculate_images()
        ysize, xsize = images['Feed0_RCP'].shape
        _, _, _, _, _, _, _, coord = \
            scanset.find_scans_through_pixel(xsize//2, ysize-1, test=True)

        dec_scan = os.path.join(self.obsdir_dec,
                                self.dec_scans[self.n_dec_scans // 2])
        assert dec_scan in coord
        assert coord[dec_scan] == 'dec'
        ra_scan = os.path.join(self.obsdir_ra,
                               self.ra_scans[self.n_ra_scans - 1])
        assert ra_scan in coord
        assert coord[ra_scan] == 'ra'
示例#19
0
    def test_find_scan_through_pixel1(self):
        scanset = ScanSet('test.hdf5')
        for i in scanset.chan_columns:
            scanset.remove_column(i + '-filt')

        images = scanset.calculate_images()
        ysize, xsize = images['Feed0_RCP'].shape
        _, _, _, _, _, _, _, coord = \
            scanset.find_scans_through_pixel(xsize//2, 0, test=True)

        dec_scan = os.path.join(self.obsdir_dec,
                                self.dec_scans[self.n_dec_scans // 2])
        assert dec_scan in coord
        assert coord[dec_scan] == 'dec'
        ra_scan = os.path.join(self.obsdir_ra, 'Ra0.fits')
        assert ra_scan in coord
        assert coord[ra_scan] == 'ra'
示例#20
0
    def test_update_scan_invalid(self):
        scanset = ScanSet('test.hdf5')

        images = scanset.calculate_images()
        ysize, xsize = images['Feed0_RCP'].shape
        ra_xs, ra_ys, dec_xs, dec_ys, scan_ids, ra_masks, dec_masks, coord = \
            scanset.find_scans_through_pixel(xsize//2, 0, test=True)

        sname = 'xkd'
        coord['xkd'] = None
        scan_ids['xkd'] = None

        info = {sname: copy.copy(self.stdinfo)}
        info[sname]['FLAG'] = True
        with pytest.warns(UserWarning):
            scanset.update_scan(sname, scan_ids[sname], coord[sname],
                                info[sname]['zap'],
                                info[sname]['fitpars'], info[sname]['FLAG'],
                                test=True)
示例#21
0
    def test_update_scan_fit(self):
        scanset = ScanSet('test.hdf5')

        images = scanset.calculate_images()
        ysize, xsize = images['Feed0_RCP'].shape
        ra_xs, ra_ys, dec_xs, dec_ys, scan_ids, ra_masks, dec_masks, coord = \
            scanset.find_scans_through_pixel(xsize//2, 0, test=True)

        sname = list(scan_ids.keys())[0]

        info = {sname: copy.copy(self.stdinfo)}
        info[sname]['fitpars'] = np.array([0.1, 0.3])
        sid = scan_ids[sname]
        mask = scanset['Scan_id'] == sid
        before = scanset['Feed0_RCP'][mask]
        scanset.update_scan(sname, scan_ids[sname], coord[sname],
                            info[sname]['zap'],
                            info[sname]['fitpars'], info[sname]['FLAG'],
                            test=True)
        after = scanset['Feed0_RCP'][mask]
        assert np.all(before != after)
        s = Scan(sname)
        assert np.all(after == s['Feed0_RCP'])