Esempio n. 1
0
 def read_regfile(self, regfile):
     cra, cdec = get_centpos()
     self.r = RegPoly(regfile, cra, cdec)
     self.polys = self.r.oclist
     self.labels = self.r.ollist
     self.plab = self.r.plab
     self.pli = self.r.plab_int
Esempio n. 2
0
 def read_regfile(self,regfile):
     cra,cdec=get_centpos()
     self.r=RegPoly(regfile,cra,cdec)
     self.polys=self.r.oclist
     self.labels=self.r.ollist
     self.plab=self.r.plab
     self.pli=self.r.plab_int
def do_plot_facet_offsets(t,regfile,savefig=None):
    ''' convenience function to plot offsets '''
    if savefig is not None and os.path.isfile(savefig):
        warn('Figure file %s exists, not re-making it' % savefig)
    else:
        cra,cdec=get_centpos()
        r=RegPoly(regfile,cra,cdec)
        if isinstance(t,str):
            t=Table.read(t)
        if 'Facet' not in t.columns:
            r.add_facet_labels(t)
        plot_offsets(t,r.clist,'red')
        if savefig is not None:
            plt.savefig(savefig)
Esempio n. 4
0
def do_plot_facet_offsets(t, regfile, savefig=None):
    ''' convenience function to plot offsets '''
    if savefig is not None and os.path.isfile(savefig):
        warn('Figure file %s exists, not re-making it' % savefig)
    else:
        cra, cdec = get_centpos()
        r = RegPoly(regfile, cra, cdec)
        if isinstance(t, str):
            t = Table.read(t)
        if 'Facet' not in t.columns:
            r.add_facet_labels(t)
        plot_offsets(t, r.clist, 'red')
        if savefig is not None:
            plt.savefig(savefig)
            try:
                o[cat+'_fluxfactor']=o['fluxfactor'][i]
            except:
                pass
        
    if "DDF_PIPELINE_CATALOGS" in os.environ.keys():
        o['catdir']=os.environ["DDF_PIPELINE_CATALOGS"]

    if o['logging'] is not None and not os.path.isdir(o['logging']):
        os.mkdir(o['logging'])
        
    # pybdsm source finding
    sfind_image(o['catprefix'],o['pbimage'],o['nonpbimage'],o['sfind_pixel_fraction'])

    # facet labels -- do this now for generality
    cra,cdec=get_centpos()
    t=Table.read(o['catprefix'] + '.cat.fits')
    tesselfile=o['catprefix']+'.tessel.reg'
    if 'Facet' not in t.columns:
        t=label_table(t,tesselfile,cra,cdec)
        t.write(o['catprefix'] + '.cat.fits',overwrite=True)

    catsources=len(t)
    
    # matching with catalogs
    removelist=[]
    for cat in o['list']:
        print 'Doing catalogue',cat
        if crossmatch_image(o['catprefix'] + '.cat.fits',cat,catdir=o['catdir'])>10:
            filter_catalog(o['catprefix'] + '.cat.fits',o['catprefix']+'.cat.fits_'+cat+'_match.fits',o['pbimage'],o['catprefix']+'.cat.fits_'+cat+'_match_filtered.fits',cat,options=o)
        else:
Esempio n. 6
0
                o[cat + '_fluxfactor'] = o['fluxfactor'][i]
            except:
                pass

    if "DDF_PIPELINE_CATALOGS" in os.environ.keys():
        o['catdir'] = os.environ["DDF_PIPELINE_CATALOGS"]

    if o['logging'] is not None and not os.path.isdir(o['logging']):
        os.mkdir(o['logging'])

    # pybdsm source finding
    sfind_image(o['catprefix'], o['pbimage'], o['nonpbimage'],
                o['sfind_pixel_fraction'])

    # facet labels -- do this now for generality
    cra, cdec = get_centpos()
    t = Table.read(o['catprefix'] + '.cat.fits')
    tesselfile = o['catprefix'] + '.tessel.reg'
    if 'Facet' not in t.columns:
        t = label_table(t, tesselfile, cra, cdec)
        t.write(o['catprefix'] + '.cat.fits', overwrite=True)

    catsources = len(t)

    # matching with catalogs
    removelist = []
    for cat in o['list']:
        print 'Doing catalogue', cat
        if crossmatch_image(o['catprefix'] + '.cat.fits',
                            cat,
                            catdir=o['catdir']):
Esempio n. 7
0
def do_offsets(o):
    # o is the options file

    if o['mode'] != 'normal' and o['mode'] != 'test':
        raise NotImplementedError('Offsets called with mode ' + o['mode'])

    image_root = 'image_full_ampphase_di_m.NS'

    method = o['method']

    report('Determining astrometric offsets with method ' + method +
           ' in mode ' + o['mode'])
    report('Merging downloaded catalogues')
    if os.path.isfile(method + '.fits'):
        warn('Merged file exists, reading from disk instead')
        data = Table.read(method + '.fits')
    else:
        if method == 'pslocal':
            data = Table.read(method + '/' + method + '.txt', format='ascii')
            data['RA'].name = 'ra'
            data['DEC'].name = 'dec'
            data.write(method + '.fits')
        else:
            kwargs = {}
            if 'panstarrs' in method:
                kwargs['rastr'] = 'ramean'
                kwargs['decstr'] = 'decmean'
            data = merge_cat(method, **kwargs)

    if o['mode'] == 'test':
        image_root += '_shift'
        method += '-test'

    report('Running PyBDSM on LOFAR image, please wait...')
    catfile = image_root + '.offset_cat.fits'
    gaulfile = catfile.replace('cat', 'gaul')
    if os.path.isfile(catfile):
        warn('Catalogue already exists, skipping pybdsf run')
    else:
        if o['mode'] == 'test':
            suffix = 'facetRestored'
        else:
            suffix = 'restored'
        pbimage = image_root + '.int.' + suffix + '.fits'
        nonpbimage = image_root + '.app.' + suffix + '.fits'
        img = bdsm.process_image(pbimage,
                                 detection_image=nonpbimage,
                                 thresh_isl=4.0,
                                 thresh_pix=5.0,
                                 rms_box=(150, 15),
                                 rms_map=True,
                                 mean_map='zero',
                                 ini_method='intensity',
                                 adaptive_rms_box=True,
                                 adaptive_thresh=150,
                                 rms_box_bright=(60, 15),
                                 group_by_isl=False,
                                 group_tol=10.0,
                                 output_opts=True,
                                 output_all=True,
                                 atrous_do=False,
                                 flagging_opts=True,
                                 flag_maxsize_fwhm=0.5,
                                 advanced_opts=True,
                                 blank_limit=None)
        img.write_catalog(outfile=catfile,
                          catalog_type='srl',
                          format='fits',
                          correct_proj='True')
        img.write_catalog(outfile=gaulfile,
                          catalog_type='gaul',
                          format='fits',
                          correct_proj='True')

    lofar = Table.read(catfile)
    print len(lofar), 'LOFAR sources before filtering'
    filter = (lofar['E_RA'] * 3600.0) < 2.0
    filter &= (lofar['E_DEC'] * 3600.0) < 2.0
    filter &= (lofar['Maj'] * 3600.0) < 10
    lofar = lofar[filter]
    print len(lofar), 'LOFAR sources after filtering'
    regfile = image_root + '.tessel.reg'
    cra, cdec = get_centpos()
    report('Set up structure')

    NDir = np.load("image_dirin_SSD_m.npy.ClusterCat.npy").shape[0]
    oo = Offsets(method,
                 n=NDir,
                 imroot=image_root,
                 cellsize=o['cellsize'],
                 fitmethod=o['fit'])
    report('Label table')
    lofar_l = oo.r.add_facet_labels(lofar)
    report('Finding offsets')
    oo.find_offsets(lofar_l, data)
    report('Fitting offsets')
    oo.fit_offsets()
    report('Making plots and saving output')
    #oo.plot_fits(method+'-fits.pdf')
    oo.save_fits()
    oo.plot_offsets()
    if 'test' not in o['mode']:
        oo.save(method + '-fit_state.pickle')
        report('Making astrometry error map, please wait')
        oo.make_astrometry_map('astromap.fits', 20)
        oo.offsets_to_facetshift('facet-offset.txt')
Esempio n. 8
0
def do_offsets(o):
    # o is the options file

    if o['mode']!='normal' and  o['mode']!='test':
        raise NotImplementedError('Offsets called with mode '+o['mode'])

    image_root='image_full_ampphase_di_m.NS'

    method=o['method']

    report('Determining astrometric offsets with method '+method+' in mode '+o['mode'])
    report('Merging downloaded catalogues')
    if os.path.isfile(method+'.fits'):
        warn('Merged file exists, reading from disk instead')
        data=Table.read(method+'.fits')
    else:
        if method=='pslocal':
            data=Table.read(method+'/'+method+'.txt',format='ascii')
            data['RA'].name='ra'
            data['DEC'].name='dec'
            data.write(method+'.fits')
        else:    
            kwargs={}
            if 'panstarrs' in method:
                kwargs['rastr']='ramean'
                kwargs['decstr']='decmean'
            data=merge_cat(method,**kwargs)

    if o['mode']=='test':
        image_root+='_shift'
        method+='-test'

    report('Running PyBDSM on LOFAR image, please wait...')
    catfile=image_root+'.offset_cat.fits'
    gaulfile=catfile.replace('cat','gaul')
    if os.path.isfile(catfile):
        warn('Catalogue already exists, skipping pybdsf run')
    else:
        if o['mode']=='test':
            suffix='facetRestored'
        else:
            suffix='restored'
        pbimage=image_root+'.int.'+suffix+'.fits'
        nonpbimage=image_root+'.app.'+suffix+'.fits'
        img = bdsm.process_image(pbimage, detection_image=nonpbimage, thresh_isl=4.0, thresh_pix=5.0, rms_box=(150,15), rms_map=True, mean_map='zero', ini_method='intensity', adaptive_rms_box=True, adaptive_thresh=150, rms_box_bright=(60,15), group_by_isl=False, group_tol=10.0,output_opts=True, output_all=True, atrous_do=False, flagging_opts=True, flag_maxsize_fwhm=0.5,advanced_opts=True, blank_limit=None)
        img.write_catalog(outfile=catfile,catalog_type='srl',format='fits',correct_proj='True')
        img.write_catalog(outfile=gaulfile,catalog_type='gaul',format='fits',correct_proj='True')

    lofar=Table.read(catfile)
    print len(lofar),'LOFAR sources before filtering'
    filter=(lofar['E_RA']*3600.0)<2.0
    filter&=(lofar['E_DEC']*3600.0)<2.0
    filter&=(lofar['Maj']*3600.0)<10
    lofar=lofar[filter]
    print len(lofar),'LOFAR sources after filtering'
    regfile=image_root+'.tessel.reg'
    cra,cdec=get_centpos()
    report('Set up structure')

    NDir=np.load("image_dirin_SSD_m.npy.ClusterCat.npy").shape[0]
    oo=Offsets(method,n=NDir,imroot=image_root,cellsize=o['cellsize'],fitmethod=o['fit'])
    report('Label table')
    lofar_l=oo.r.add_facet_labels(lofar)
    report('Finding offsets')
    oo.find_offsets(lofar_l,data)
    report('Fitting offsets')
    oo.fit_offsets()
    report('Making plots and saving output')
    #oo.plot_fits(method+'-fits.pdf')
    oo.save_fits()
    oo.plot_offsets()
    if 'test' not in o['mode']:
        oo.save(method+'-fit_state.pickle')
        report('Making astrometry error map, please wait')
        oo.make_astrometry_map('astromap.fits',20)
        oo.offsets_to_facetshift('facet-offset.txt')