Exemplo n.º 1
0
        
    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:
            print 'Insufficient matches, abandoning catalogue'
            removelist.append(cat)
    for cat in removelist:
        o['list'].remove(cat)
Exemplo n.º 2
0
        try:
            o[cat + '_fluxfactor'] = o['fluxfactor'][i]
        except:
            pass

    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
    t = Table.read(o['catprefix'] + '.cat.fits')
    if 'Facet' not in t.columns:
        t = label_table(t, 'image_full_ampphase1m.tessel.reg')
        t.write(o['catprefix'] + '.cat.fits', overwrite=True)

    # matching with catalogs
    for cat in o['list']:
        print 'Doing catalogue', cat
        crossmatch_image(o['catprefix'] + '.cat.fits', cat)
        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)

    # Filter catalogs (only keep isolated compact sources within 3deg of pointing centre)
Exemplo n.º 3
0
    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']):
            filter_catalog(o['catprefix'] + '.cat.fits',
                           o['catprefix'] + '.cat.fits_' + cat + '_match.fits',
                           o['pbimage'],
                           o['catprefix'] + '.cat.fits_' + cat +
Exemplo n.º 4
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'])

    if o['second_selfcal']:
        image_root = 'image_full_ampphase2'
    else:
        image_root = 'image_full_ampphase1m'

    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:
        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'
    if os.path.isfile(catfile):
        warn('Catalogue already exists')
    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')

    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'
    lofar_l = label_table(lofar, regfile)

    oo = Offsets(method,
                 n=o['ndir'],
                 imroot=image_root,
                 cellsize=o['cellsize'],
                 fitmethod=o['fit'])
    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')