Example #1
0
def zeropoint(twomassfile, iap, band, image, sexfile, outfile=None, center=(None,None),
              size=(None,None)):

    # read in catalogue of unsaturated stars
    photfile = phot_curves.remove_saturated(image, sexfile)

    # Removed reddened stars from zeropoint calculation
    if center[0] is not None:
        idx_reddened = id_region(photfile['X_IMAGE'], photfile['Y_IMAGE'], center, size)  # Find reddened
        unreddened = photfile[~idx_reddened]
    else:
        unreddened = photfile

    # Remove objects which are not stars by PSF
    idx_stars = phot_curves.half_light(unreddened['MAG_APER_{}'.format(iap)], unreddened['FLUX_RADIUS'], toplot=False)
    stars = unreddened[idx_stars]

    # Compare magnitudes with same in 2Mass catalogue
    twomass, stars_tm = parse_2mass(twomassfile, stars)
    offset = compare_magnitudes(stars_tm['MAG_APER_{}'.format(iap)], twomass['{}_m'.format(band)],
                                stars_tm['MAGERR_APER_{}'.format(iap)], outfile)
Example #2
0
def main():
    parser = argparse.ArgumentParser(
        description='For photometry output from sextractor for 3 bands, compile magnitude arrays into singe file')
    parser.add_argument("--sexfiles", '-sfs',
                        nargs='*',
                        action='store',
                        default=None,
                        help='Source extractor files for J,H,Ks bands.')
    parser.add_argument("--maxsep", '-ms',
                        action='store',
                        default=0.0001,
                        help='Maximum angular separation for nearest neighbour search.')
    parser.add_argument("--outfile", '-ofile',
                        action='store',
                        default=None,
                        help='Output file.')
    parser.add_argument("--outfig", '-ofig',
                        action='store',
                        default=None,
                        help='Output figure.')
    parser.add_argument("--images", '-is',
                        nargs='*',
                        action='store',
                        default=None,
                        help='Fits images for J,H,Ks bands.')
    parser.add_argument("--toplot",
                        action='store',
                        default=False,
                        help='Plot figures.')
    args = parser.parse_args()


    if args.outfig is None:
        print 'Warning: No output figure specified'

    if not os.path.exists(str(args.outfile)):
        if args.sexfiles is None:
            raise Exception, 'No source extractor files given'
        if args.images is None:
            raise Exception, 'No image files given'
        if args.outfile is None:
            print 'Warning: No output file specified'

        sexfile_j, sexfile_ks, sexfile_h = args.sexfiles
        fits_j, fits_ks, fits_h = args.images

        print '** Removing saturated stars'
        # remove stars saturated in the fits images, marked with 0 center
        phot_j_unsat = phot_curves.remove_saturated(fits_j, sexfile_j)
        phot_ks_unsat = phot_curves.remove_saturated(fits_ks, sexfile_ks)
        phot_h_unsat = phot_curves.remove_saturated(fits_h, sexfile_h)

        phot_j = phot_j_unsat[np.where(phot_j_unsat['MAG_APER'] < 50.)]
        phot_ks = phot_ks_unsat[np.where(phot_ks_unsat['MAG_APER'] < 50.)]
        phot_h = phot_h_unsat[np.where(phot_h_unsat['MAG_APER'] < 50.)]

        print '** Removing objcts with nonstellar PSFs'
        i_j = phot_curves.half_light(phot_j['MAG_APER'], phot_j['FLUX_RADIUS'], toplot=False)
        phot_j = phot_j[i_j]
        i_k = phot_curves.half_light(phot_ks['MAG_APER'], phot_ks['FLUX_RADIUS'], toplot=False)
        phot_ks = phot_ks[i_k]
        i_h = phot_curves.half_light(phot_h['MAG_APER'], phot_h['FLUX_RADIUS'], toplot=False)
        phot_h = phot_h[i_h]

        print '** Matching stars in J,H,K catalogues, please wait'
        # match the stars in each source extractor file by nearest neighbour
        mags = sort_by_coords_tree(phot_j, phot_ks, phot_h, float(args.maxsep), args.toplot)
        mags.to_csv(args.outfile, index=False, delimater=' ')


    print 'Reading magnitude table from file {}'.format(args.outfile)
    mags = ascii.read(args.outfile)

    outfig_cc = args.outfig.split('.')[0] + '_cc.png'
    mags_colours = [mags['mag_aper_J'].data, mags['mag_aper_H'].data, mags['mag_aper_Ks'].data]
    magerrs_colours = [mags['magerr_aper_J'].data, mags['magerr_aper_H'].data, mags['magerr_aper_Ks'].data]
    plot_cmd(mags_colours, magerrs_colours, args.outfig)
    plot_colourcolour(mags_colours, outfig_cc)