def test_scan(self): '''Test that data are read.''' scan = Scan(self.fname) scan.write('scan.hdf5', overwrite=True) scan2 = Scan('scan.hdf5') assert scan.meta == scan2.meta
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))
def test_conversion(self): convert_to_complete_fitszilla(self.fname, 'converted') scan0 = Scan(self.fname, norefilt=False) scan1 = Scan('converted.fits', norefilt=False) for col in ['ra', 'el', 'az', 'dec']: assert np.allclose(scan0[col], scan1[col]) os.unlink('converted.fits')
def test_scan_clean_and_splat(self): '''Test that data are read.''' scan = Scan(self.fname, debug=True) scan.meta['filtering_factor'] = 0.7 with pytest.warns(UserWarning) as record: scan.clean_and_splat() assert np.any([ "Don't use filtering factors > 0.5" in r.message.args[0] for r in record ])
def test_scan_from_table(self): '''Test that data are read.''' from astropy.table import Table scan = Scan(self.fname) scan.write('scan.hdf5', overwrite=True) table = Table.read('scan.hdf5', path='scan') scan_from_table = Scan(table) for c in scan.columns: assert np.all(scan_from_table[c] == scan[c]) for m in scan_from_table.meta.keys(): assert scan_from_table.meta[m] == scan.meta[m]
def test_simple_in_stokes(self): with pytest.warns(UserWarning) as record: scan = Scan(os.path.join(self.datadir, 'srt_pol_bad.fits')) assert np.any([ "contain polarization information" in r.message.args[0] for r in record ])
def test_scan_write_other_than_hdf5_raises(self): '''Test that data are read.''' scan = Scan(self.fname, debug=True) with pytest.raises(TypeError): scan.write('scan.fits', overwrite=True) with pytest.raises(TypeError): scan.write('scan.json', overwrite=True) with pytest.raises(TypeError): scan.write('scan.csv', overwrite=True)
def test_coordinate_conversion_works(self, fname): scan = Scan(os.path.join(self.datadir, 'spectrum', fname), norefilt=False, debug=True) obstimes = Time(scan['time'] * u.day, format='mjd', scale='utc') idx = 1 if '_multif' in fname else 0 # Tolerance: +- 1 second of observation, or sample time, whichever is # larger sampletime = np.max( [scan[ch].meta['sample_time'].value for ch in scan.chan_columns()]) sampletime = np.max([sampletime, 1]) * u.s ref_coords0 = SkyCoord(ra=scan['ra'][:, idx], dec=scan['dec'][:, idx], obstime=obstimes - sampletime, location=locations[scan.meta['site']]) ref_coords1 = SkyCoord(ra=scan['ra'][:, idx], dec=scan['dec'][:, idx], obstime=obstimes + sampletime, location=locations[scan.meta['site']]) altaz0 = ref_coords0.altaz altaz1 = ref_coords1.altaz az0, az1 = altaz0.az.to(u.rad).value, altaz1.az.to(u.rad).value tol = (30 * u.arcsec).to(u.rad).value good0 = (scan['az'][:, idx] >= az0 - tol) & (scan['az'][:, idx] <= az1 + tol) good1 = (scan['az'][:, idx] <= az1 + tol) & (scan['az'][:, idx] >= az0 - tol) assert np.all(good0 | good1) el0, el1 = altaz0.alt.to(u.rad).value, altaz1.alt.to(u.rad).value tol = (30 * u.arcsec).to(u.rad).value good0 = (scan['el'][:, idx] >= el0 - tol) & (scan['el'][:, idx] <= el1 + tol) good1 = (scan['el'][:, idx] <= el1 + tol) & (scan['el'][:, idx] >= el0 - tol) assert np.all(good0 | good1)
def test_scan_baseline_unknown(self): '''Test that data are read.''' scan = Scan(self.fname, debug=True) scan.write('scan.hdf5', overwrite=True) with pytest.raises(ValueError): scan.baseline_subtract('asdfgh', plot=True)
def test_scan(self): '''Test that data are read.''' scan = Scan(self.fname, debug=True) scan.write('scan.hdf5', overwrite=True) scan.baseline_subtract('rough', plot=True)
def test_coordinate_conversion_works(self, fname): scan = Scan(os.path.join(self.datadir, fname)) obstimes = Time(scan['time'] * u.day, format='mjd', scale='utc') idx = 1 if '_multif' in fname else 0 ref_coords = SkyCoord(ra=scan['ra'][:, idx], dec=scan['dec'][:, idx], obstime=obstimes, location=locations[scan.meta['site']]) altaz = ref_coords.altaz diff = np.abs( (altaz.az.to(u.rad) - scan['az'][:, idx]).to(u.arcsec).value) assert np.all(diff < 1) diff = np.abs( (altaz.alt.to(u.rad) - scan['el'][:, idx]).to(u.arcsec).value) assert np.all(diff < 1)
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'])
def test_interactive(self): scan = Scan(self.fname) scan.interactive_filter('Ch0', test=True)
def test_bad_nchan_detected(self): with pytest.raises(Exception) as excinfo: scan = Scan(os.path.join(self.datadir, 'srt_chans_bad.fits')) assert "with channel subdivision:" in str(excinfo)
def test_scan_nofilt_executes(self): '''Test that data are read.''' scan = Scan(self.fname, nofilt=True)
def test_scan_loading(self, fname): '''Test that data are read.''' Scan(os.path.join(self.datadir, 'spectrum', fname), debug=True)
def test_print(self, capsys): scan = Scan(self.fname) print(scan) out, err = capsys.readouterr() assert 'scan from file' not in out.lower()
def test_repr(self): scan = Scan(self.fname) out = repr(scan) assert 'scan from file' in out.lower()
def test_import_scan(): from srttools.scan import Scan s = Scan() assert isinstance(s, Table)
def test_interactive(self): scan = Scan(self.fname) scan.interactive_filter('Feed0_RCP', test=True)