示例#1
0
def test_get_peakflux():
    stats = et.get_flux(fitsfile, 74.26237654, -52.0209015)
    nt.assert_almost_equal(stats['pflux'], 0.75)
    stats = et.get_flux(fitsfile, 41.91116875, -43.2292595)
    nt.assert_almost_equal(stats['pflux'], 0.5)
    stats = et.get_flux(fitsfile, 356.26, -0.37)
    nt.assert_almost_equal(stats['pflux'], 0.6)
    nt.assert_almost_equal(stats['gauss_pflux'], 0.6, 1)
示例#2
0
 def subtract_sources(self, ra, dec, pflux, imagename, fitsname=None, niter=0, antenna='', start=200, stop=900, npix=30, gain=0.3, maxiter=10, return_val=False, ms_ext='ms'):
     if fitsname is None:
         fitsname = imagename + '.fits'
     phasecenter = self.const_phase_center(ra, dec)
     self.generate_image(imagename, antenna=antenna, niter=niter, start=start, stop=stop, npix=npix, phasecenter=phasecenter)
     mod_fitsname = imagename + '.mod.fits'
     self.to_fits(imagename + '.model', mod_fitsname, overwrite=True)
     self.remove_image(imagename, del_img=True)
     moddata = ft.get_fitsinfo(mod_fitsname)['data']
     #self.generate_image(imagename, antenna=antenna, niter=0, start=start, stop=stop)
     self.generate_image(imagename, antenna=antenna, niter=0, start=start, stop=stop, npix=npix, phasecenter=phasecenter)
     self.to_fits(imagename + '.image', fitsname, overwrite=True)
     stats = et.get_flux(fitsname, ra, dec)
     resflux = stats['gauss_tflux']
     flux0 = resflux
     resdata = moddata
     iter_num = 1 
     res_ms = self.ms.replace('.{}'.format(ms_ext), '.optsub.{}'.format(ms_ext))
     print ('Iteration {}: {} Jy -- {}% of observed flux'.format(iter_num, resflux, round(abs(resflux * 100 / np.abs(pflux))), 2))
     while (np.abs(resflux) > 1 / 10. * np.abs(pflux) and np.abs(resflux) <= np.abs(flux0) and iter_num < maxiter):
         pmod_fitsname = imagename + '.pmod.fits'
         ft.write_fits(mod_fitsname, gain * resdata, pmod_fitsname, overwrite=True)
         resdata -= gain * resdata
         mod_imagename = mod_fitsname.replace('.fits', '.image')
         ct.importfits(mod_fitsname, mod_imagename, overwrite=True)
         ct.ft(self.ms, model = mod_imagename)
         if os.path.exists(res_ms): os.system('rm -rf {}'.format(res_ms))
         os.system('cp -rf {} {}'.format(self.ms, res_ms))
         ct.subtract_model_ant(self.ms, antenna)
         self.remove_image(imagename, del_img=True)
         self.generate_image(imagename, antenna=antenna, niter=niter, start=start, stop=stop, npix=npix, phasecenter=phasecenter)
         self.to_fits(imagename + '.image', fitsname, overwrite=True)
         stats = et.get_flux(fitsname, ra, dec)
         flux0 = resflux
         resflux = stats['gauss_tflux']
         iter_num += 1
         print ('Iteration {}: {} Jy -- {}% of observed flux'.format(iter_num, resflux, round(abs(resflux * 100 / np.abs(pflux))), 2))
     if return_val:
         return np.abs(flux0) * 100 / np.abs(pflux)
示例#3
0
 def _generate_srcdict(self, ras, decs, fitsfiles, flux_type):
     """
     Extracts flux measurements at specified right ascension and declination values from the fitsfiles
     and return dictionary containing the data and necessary metadata for single polarization.
     polarization. 
     Parameters
     ---------
     ras : list of float
         List of right ascension values in degrees.
     decs : list of floats
         List of declination values in degrees.
     fitsfiles : list of str
         List of of xx or yy fitsfiles that will be used to extract the flux values.
     flux_type : str
         Flux type to extract, options: 
             'pflux'       : peak value from the data
             'gauss_pflux' : peak value of the 2d gaussian fit of the data
             'gauss_tflux' : total integrated value of the 2d gaussian fit of the data                        """
     # selecting unique ras and decs
     nsrcs = len(ras)
     nfits = len(fitsfiles)
     srcdict = OrderedDict()
     ha_array = np.zeros((nsrcs, nfits))
     error_array = np.zeros((nsrcs, nfits))
     data_array = np.zeros((nsrcs, nfits))
     azalt_array = np.zeros((2, nsrcs, nfits))
     jds = self._get_jds(fitsfiles)
     srcdict['jds'] = jds
     for i, ra in enumerate(ras):
         key = (round(ra, 2), round(decs[i], 2))
         if not key in srcdict: srcdict[key] = {}
         for j, fn in enumerate(fitsfiles):
             srcstats = et.get_flux(fn, ra, decs[i])
             lst, ha = self._get_lstha(jds[j], ra)
             az, alt = self._get_azalt(decs[i], ha)
             ha_array[i, j] = ha
             error_array[i, j] = srcstats['error']
             data_array[i, j] = srcstats[flux_type]
             azalt_array[0, i, j] = az
             azalt_array[1, i, j] = alt
             # saving to dictionary
         srcdict[key]['data'] = data_array[i, :]
         srcdict[key]['error'] = error_array[i, :]
         srcdict[key]['ha'] = ha_array[i, :]
         srcdict[key]['azalt'] = azalt_array[:, i, :]
     return srcdict
示例#4
0
 def extract_flux(self, fitsname, ras, decs):
     return [et.get_flux(fitsname, ras[i], decs[i])['gauss_pflux'] for i in range(len(ras))]
示例#5
0
def test_boundaries():
    stats = et.get_flux(fitsfile, 74.26237654, -9.0)
    nt.assert_true(np.isnan(stats['pflux']))