Exemple #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)
Exemple #2
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']
Exemple #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)
Exemple #4
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)
Exemple #5
0
    def test_interactive_quit(self):
        scanset = ScanSet('test.hdf5')
        imgsel = scanset.interactive_display('Feed0_RCP', test=True)
        fake_event = type('event', (), {})()
        fake_event.key = 'q'
        fake_event.xdata, fake_event.ydata = (130, 30)

        retval = imgsel.on_key(fake_event)
        assert retval == (130, 30, 'q')
Exemple #6
0
    def test_barycenter_times(self):
        '''Test image production.'''

        scanset = ScanSet('test.hdf5')

        scanset.barycenter_times()

        assert 'barytime' in scanset.colnames
        assert np.all(np.abs(scanset['barytime'] -
                             scanset['time']) < 9 * 60 / 86400)
Exemple #7
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")
Exemple #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 == {}
Exemple #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')
Exemple #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(' '))
Exemple #11
0
    def test_apply_user_filt(self):
        '''Test apply user filts.'''

        def user_fun(scanset):
            return scanset['barytime'] - np.floor(scanset['barytime'])

        scanset = ScanSet('test.hdf5')
        scanset.barycenter_times()
        phase_in_sec = scanset.apply_user_filter(user_fun, 'Phase_in_sec')

        assert np.min(phase_in_sec) >= 0
        assert np.max(phase_in_sec) <= 1
        assert np.all(phase_in_sec == scanset['Phase_in_sec'])
Exemple #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)
Exemple #13
0
    def test_destripe(self):
        '''Test image production.'''

        scanset = ScanSet('test.hdf5')

        scanset.destripe_images(calibration=self.calfile,
                                map_unit="Jy/pixel", npix_tol=10)
        images = scanset.images
        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
        assert np.isclose(np.sum(images['Feed0_RCP'][good]),
                          self.simulated_flux, rtol=0.1)
Exemple #14
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)
Exemple #15
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)
Exemple #16
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)
Exemple #17
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)
Exemple #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'
Exemple #19
0
 def test_meta_saved_and_loaded_correctly(self):
     scanset = ScanSet('test.hdf5')
     for k in scanset.meta.keys():
         assert np.all(scanset.meta[k] == self.scanset.meta[k])
     assert sorted(scanset.meta.keys()) == sorted(self.scanset.meta.keys())
     assert scanset.scan_list == self.scanset.scan_list
     assert sorted(scanset.meta['calibrator_directories']) == \
         sorted(list(set(scanset.meta['calibrator_directories'])))
     assert sorted(scanset.meta['list_of_directories']) == \
         sorted(list(set(scanset.meta['list_of_directories'])))
Exemple #20
0
    def test_interactive_scans_all_calibrated_channels(self, capsys):
        scanset = ScanSet('test.hdf5')
        scanset.calibrate_images(calibration=self.calfile)
        images = scanset.images
        ysize, xsize = images['Feed0_RCP'].shape

        imgsel = scanset.interactive_display(test=True)
        fake_event = type('event', (), {})()
        fake_event.key = 'a'
        fake_event.xdata, fake_event.ydata = (xsize//2, ysize-1)

        imgsel.on_key(fake_event)
        fake_event.key = 'h'
        fake_event.xdata, fake_event.ydata = (xsize//2, ysize-1)
        out, err = capsys.readouterr()
        assert "a    open a window to filter all" in out

        imgsel.on_key(fake_event)
        fake_event.key = 'v'
        fake_event.xdata, fake_event.ydata = (xsize//2, ysize-1)
        imgsel.on_key(fake_event)
Exemple #21
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))
Exemple #22
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)
Exemple #23
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
Exemple #24
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)
Exemple #25
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'
Exemple #26
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)
Exemple #27
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'])
Exemple #28
0
def test_import_scanset():
    from srttools.imager import ScanSet
    s = ScanSet()
    assert isinstance(s, Table)
Exemple #29
0
    def test_ds9_image_not_save_sdev(self):
        '''Test image production.'''

        scanset = ScanSet('test.hdf5')

        scanset.save_ds9_images(save_sdev=False)
Exemple #30
0
    def test_ds9_image_destripe(self):
        '''Test image production.'''

        scanset = ScanSet('test.hdf5')

        scanset.save_ds9_images(destripe=True)