Example #1
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']
Example #2
0
    def test_image_fail_mixup_feeds(self):
        '''Test image production.'''

        scanset = ScanSet('test.hdf5')
        scanset['Ch0_feed'] = np.random.randint(0, 3, len(scanset['Ch0_feed']))
        with pytest.raises(ValueError) as excinfo:
            images = scanset.calculate_images()
        assert "Feeds are mixed up" in str(excinfo)
Example #3
0
    def test_hor_images(self):
        '''Test image production.'''

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

        img = images['Ch0']
Example #4
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)
Example #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')
Example #6
0
    def test_calibrate_scanset_beam(self):
        scanset = ScanSet('test.hdf5')
        images_standard = scanset.calculate_images(calibration=self.calfile,
                                                   map_unit="Jy/beam")
        images = scanset.calculate_images(calibration=self.calfile,
                                          map_unit="Jy/beam",
                                          calibrate_scans=True)

        assert np.allclose(images['Ch0'], images_standard['Ch0'])
Example #7
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)
Example #8
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['Ch0']),
                           self.simulated_flux,
                           atol=0.1)
Example #9
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)
        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")
Example #10
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)
     print(images['Feed0_RCP'], images_standard['Feed0_RCP'])
     assert np.allclose(images['Feed0_RCP'],
                        images_standard['Feed0_RCP'],
                        rtol=0.05)
Example #11
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 == {}
Example #12
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(' '))
Example #13
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'])
Example #14
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')
Example #15
0
    def test_calibrate_scanset_sr(self):
        scanset = ScanSet('test.hdf5')
        images_standard = scanset.calculate_images(calibration=self.calfile,
                                                   map_unit="Jy/sr")
        images = scanset.calculate_images(calibration=self.calfile,
                                          map_unit="Jy/sr",
                                          calibrate_scans=True)

        good = images['Ch0'] > 1

        assert np.allclose(images['Ch0'][good],
                           images_standard['Ch0'][good],
                           rtol=1e-4)
Example #16
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)
Example #17
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)
Example #18
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)
Example #19
0
    def test_find_scan_through_pixel0(self):
        scanset = ScanSet('test.hdf5')

        images = scanset.calculate_images()
        ysize, xsize = images['Ch0'].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])
        assert ra_scan in coord
        assert coord[ra_scan] == 'ra'
Example #20
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)
Example #21
0
    def test_calc_and_calibrate_image_pixel(self):
        scanset = ScanSet('test.hdf5')

        scanset.calibrate_images(calibration=self.calfile, map_unit="Jy/pixel")
        images = scanset.images
        img = images['Ch0']
        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['Ch0'][good]),
                          self.simulated_flux,
                          rtol=rtol)
Example #22
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['Ch0']
        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['Ch0'][good]),
                          self.simulated_flux,
                          rtol=0.1)
Example #23
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'])))
Example #24
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)
Example #25
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))
        os.unlink(sname.replace('fits', 'hdf5'))
Example #26
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'])
        os.unlink(sname.replace('fits', 'hdf5'))
Example #27
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)
Example #28
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
Example #29
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['Ch0'],
                           images_pix['Ch0'] / pixel_area.to(u.sr).value,
                           rtol=0.05)
Example #30
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'