def georun_sky(clustname, lims):

    #run geomap and geoxytran.  I have to run this within this module
    #as geomap crashes when run from an external module.

    #in this version

    catpath = '.'
    geomap_infile = catpath + '/geomap_coords_sky.' + clustname + '.in'
    dbfile = catpath + '/' + clustname + '_geomap_sky.db'
    iraf.geomap.xmin = lims['ramin']
    iraf.geomap.xmax = lims['ramax']
    iraf.geomap.ymin = lims['decmin']
    iraf.geomap.ymax = lims['decmax']
    iraf.geomap.maxiter = 3
    iraf.geomap.reject = 3.0
    iraf.geomap.fitgeometry = 'rxyscale'

    iraf.geomap(geomap_infile, dbfile)

    geotran_outfile = catpath + '/geomap_coords_sky.' + clustname + '.out'

    #remove geotran output file if it already exists
    if os.path.isfile(geotran_outfile) is True:
        cmdstr = 'rm ' + geotran_outfile
        os.system(cmdstr)

    #transform the input coordinates in the geomap input file.
    iraf.geoxytran(geomap_infile,
                   geotran_outfile,
                   dbfile,
                   geomap_infile,
                   direction="backward",
                   xcolumn=3,
                   ycolumn=4)

    #read in the geomap input catalog that was transformed using geoxytran.
    trans_ggdat = ascii.read(geotran_outfile)
    ratrans = trans_ggdat['rain']
    dectrans = trans_ggdat['decin']
    raref = trans_ggdat['raref']
    decref = trans_ggdat['decref']

    #make a plot of the new residuals
    posttrans_plotfile = catpath + '/posttrans.' + clustname + '_coordiff_sky.pdf'
    cmts.match_diff_sky_plot(raref,
                             decref,
                             ratrans,
                             dectrans,
                             plotfile=posttrans_plotfile)

    return dbfile, geomap_infile
Example #2
0
def mosfire_geoxytrans(x_kfp,
                       y_kfp,
                       transform="final.pix2mm.4.972.120k",
                       database="ale/10March2011.4.972.db",
                       direction="forward"):
    '''Conveninece wrapper around IRAF geoxytran'''
    iraf.images()
    path = os.path.join(os.environ["MOSPATH"], "platescale",
                        "10March2011.4.972.db")
    database = path
    pars = iraf.geoxytran.getParList()
    iraf.geoxytran.unlearn()
    ins = []
    for i in range(len(x_kfp)):
        ins.append("%f %f" % (x_kfp[i], y_kfp[i]))
    results = iraf.geoxytran("STDIN",
                             "STDOUT",
                             Stdin=ins,
                             Stdout=1,
                             database=database,
                             transform=transform,
                             direction=direction)

    iraf.geoxytran.setParList(pars)

    poss = []
    for result in results:
        poss.append(np.array(result.split(), dtype=np.float64))

    return np.array(poss)
Example #3
0
def mosfire_geoxytran(x_kfp,
                      y_kfp,
                      transform="final.pix2mm.4.972.120k",
                      database="/platescale/10March2011.4.972.db",
                      direction="forward"):
    '''Conveninece wrapper around IRAF geoxytran'''
    iraf.images()

    path = os.path.join(os.environ["MOSPATH"], "platescale",
                        "10March2011.4.972.db")
    database = path
    pars = iraf.geoxytran.getParList()
    iraf.geoxytran.unlearn()
    t = iraf.geoxytran("STDIN",
                       "STDOUT",
                       Stdin=["%f %f" % (x_kfp, y_kfp)],
                       Stdout=1,
                       database=database,
                       transform=transform,
                       direction=direction)

    iraf.geoxytran.setParList(pars)
    (x, y) = np.array(t[0].split(), dtype=np.float64)

    return (x, y)
def mosfire_geoxytran(x_kfp, y_kfp, transform="final.pix2mm.4.972.120k",
        database="/platescale/10March2011.4.972.db", direction="forward"):
    '''Conveninece wrapper around IRAF geoxytran'''
    iraf.images()


    path = os.path.join(os.environ["MOSPATH"], "platescale", 
            "10March2011.4.972.db")
    database = path
    pars = iraf.geoxytran.getParList()
    iraf.geoxytran.unlearn()
    t = iraf.geoxytran("STDIN", "STDOUT", Stdin=["%f %f" % (x_kfp, y_kfp)], Stdout=1,
            database=database,
            transform=transform,
            direction=direction)

    iraf.geoxytran.setParList(pars) 
    (x,y) = np.array(t[0].split(), dtype=np.float64)

    return (x,y)
Example #5
0
def mosfire_geoxytrans(
    x_kfp, y_kfp, transform="final.pix2mm.4.972.120k", database="ale/10March2011.4.972.db", direction="forward"
):
    """Conveninece wrapper around IRAF geoxytran"""
    iraf.images()
    path = os.path.join(os.environ["MOSPATH"], "platescale", "10March2011.4.972.db")
    database = path
    pars = iraf.geoxytran.getParList()
    iraf.geoxytran.unlearn()
    ins = []
    for i in range(len(x_kfp)):
        ins.append("%f %f" % (x_kfp[i], y_kfp[i]))
    results = iraf.geoxytran(
        "STDIN", "STDOUT", Stdin=ins, Stdout=1, database=database, transform=transform, direction=direction
    )

    iraf.geoxytran.setParList(pars)

    poss = []
    for result in results:
        poss.append(np.array(result.split(), dtype=np.float64))

    return np.array(poss)
def speczcat_trans_sky(incat, dbfile, geomap_infile, refcat, clustname, septol,
                       **kwargs):
    '''This routine reads in a FITS catalog, writes a temporary output
    ASCII catalog, then transforms this catalog using geoxytran.  It
    then writes a new catalog with  old coordinates replaced by the new ones.

    INPUT

    incat: the input fits catalog

    dbfile: the geomap database file

    geomap_infile: used as the database record

    refcat: the original astrometric reference catalog

    clustname: the name of the cluster

    septol: the maximum separation allowed for a match in arcseconds

    OPTIONAL KEYWORDS

    ramin, ramax, decmin, decmax.  These are the limits over which the
    transform was originally computed.  If these are given then it
    uses those limits to color the points in the ra and decdiff plots.
    If one is given, all must be given.

    '''

    #read in the spectroscopic redshift catalog
    cat_hdul = fits.open(incat)
    cat_dat = cat_hdul["MDF"].data

    #read in original astrometric catalog
    ref_dat = ascii.read(refcat)
    raref = np.array(ref_dat['ALPHA_SKY'])
    decref = np.array(ref_dat['DELTA_SKY'])

    #tmp coordinate files for geoxytran
    tmpin = 'tmp_geoxytran_sky_in'
    tmpout = 'tmp_geoxytran_sky_out'

    #remove the existing transformed file
    newcat = incat.replace('.fits', '.trans.fits')

    if os.path.isfile(tmpout) is True:
        cmdstr = 'rm ' + tmpout
        os.system(cmdstr)
        cmdstr = 'rm ' + newcat
        os.system(cmdstr)

    #output temporary ASCII file with coordinates
    fo = open(tmpin, "w")
    fo.write("# ra dec\n")
    for i, val in enumerate(cat_dat['RA']):
        #convert speczcat RA to degrees when writing out
        fo.write('{} {}\n'.format(cat_dat['RA'][i] * 15.0, cat_dat['DEC'][i]))
    fo.close()

    iraf.geoxytran(tmpin, tmpout, dbfile, geomap_infile, direction="backward",\
                   xcolumn=1, ycolumn = 2)

    #read in ascii output file
    trans_dat = ascii.read(tmpout)
    ratrans = np.array(trans_dat['ra'])
    dectrans = np.array(trans_dat['dec'])

    #replace the old RAs and DECs with new RAs and DECs in place
    tcat_hdul = cat_hdul
    #convert RA back to hours for output
    tcat_hdul["MDF"].data['RA'] = ratrans / 15.0
    tcat_hdul["MDF"].data['DEC'] = dectrans

    #write the new fits file
    tcat_hdul.writeto(newcat)

    #match new catalog against original catalog
    mfile = "speczcat_sky_match.txt"
    (rarefm,decrefm,ratransm,dectransm, translims) = cmts.cat_sky_match(raref, decref, \
                                                                       ratrans, dectrans, septol, \
                                                                       matchfile = mfile)

    #make a plot of the residuals
    allcattrans_plotfile = 'speczcat_trans.' + clustname + '_coordiff_sky.pdf'
    #passes ra and dec limits if they are defined to find source
    #outside of ra and dec lims.  Assumes that if one keyword is given
    #that all are given
    if 'ramin' in kwargs.keys():
        cmts.match_diff_sky_plot(rarefm,decrefm,ratransm,dectransm, plotfile = allcattrans_plotfile, \
                            ramin = kwargs['ramin'], ramax = kwargs['ramax'], \
                            decmin = kwargs['decmin'], decmax = kwargs['decmax'])
    else:
        cmts.match_diff_sky_plot(rarefm,
                                 decrefm,
                                 ratransm,
                                 dectransm,
                                 plotfile=allcattrans_plotfile)
def cat_trans_im(incat, dbfile, geomap_infile, refcat, clustname, septol,  **kwargs):

    '''This routine reads in a FITS catalog, writes a temporary output
    ASCII catalog, then transforms this catalog using geoxytran.  It
    then appends these new coordinates as new columns to the original catalog.

    It is usually run by hand after the geomap solution has been derived.

    INPUT

    incat: the input SExtractor catalog

    dbfile: the geomap database file

    geomap_infile: used as the database record

    refcat: the original astrometric reference catalog

    clustname: the name of the cluster

    septol: the maximum separation allowed for a match in pixels

    OPTIONAL KEYWORDS

    xmin, xmax, ymin, ymax.  These are the limits over which the
    transform was originally computed.  If these are given then it
    uses those limits to color the points in the ra and decdiff plots.
    If one is given, all must be given.

    '''

    #read in GMOS sextractor photometry catalog with (x,y) coordinates
    cat_dat = ascii.read(incat)

    #read in original astrometric catalog
    ref_dat = ascii.read(refcat)
    xref = np.array(ref_dat['X_IMAGE'])
    yref = np.array(ref_dat['Y_IMAGE'])

    #tmp coordinate files for geoxytran
    tmpin = 'tmp_geoxytran_im_in'
    tmpout = 'tmp_geoxytran_im_out'

    #make a new name for the transformed file
    newcat = incat.replace('.sexcat','.trans.cat')

    if os.path.isfile(tmpout) is True:
        cmdstr = 'rm ' + tmpout
        os.system(cmdstr)
        cmdstr = 'rm ' + newcat
        os.system(cmdstr)

    #output temporary ASCII file with coordinates
    fo = open(tmpin, "w")
    fo.write("# x y\n")
    for i,val in enumerate(cat_dat['X_IMAGE']):
        fo.write('{} {}\n'.format(cat_dat['X_IMAGE'][i],cat_dat['Y_IMAGE'][i]))
    fo.close()

    iraf.geoxytran(tmpin, tmpout, dbfile, geomap_infile, direction="backward",\
                   xcolumn=1, ycolumn = 2)

    #read in ascii output file
    trans_dat = ascii.read(tmpout)
    xtrans = np.array(trans_dat['x'])
    ytrans = np.array(trans_dat['y'])

    #replace the old RAs and DECs with new RAs and DECs in place    
    tcat_dat = cat_dat
    tcat_dat['X_IMAGE'] = xtrans
    tcat_dat['Y_IMAGE'] = ytrans

    #write the new catalog file with the transformed coordinates
    ascii.write(tcat_dat, newcat, format='commented_header')
    
    #match new catalog against original catalog
    mfile = "allcat_im_match.txt"
    (xrefm,yrefm,xtransm,ytransm, translims) = cmti.cat_im_match(xref, yref, \
                                                                 xtrans, ytrans, septol, \
                                                                 matchfile = mfile)

    #make a plot of the residuals
    allcattrans_plotfile = 'allcat_trans.' + clustname + '_coordiff_im.pdf'
    #passes ra and dec limits if they are defined to find source
    #outside of ra and dec lims.  Assumes that if one keyword is givenSPT0205_GMOS_z.v0.sexcat'
    #that all are given
    
    if 'xmin' in kwargs.keys():
        cmti.match_diff_im_plot(xrefm,yrefm,xtransm,ytransm, plotfile = allcattrans_plotfile, \
                            xmin = kwargs['xmin'], xmax = kwargs['xmax'], \
                            ymin = kwargs['ymin'], ymax = kwargs['ymax'])
    else:
        cmti.match_diff_im_plot(xrefm,yrefm,xtransm,ytransm, plotfile = allcattrans_plotfile)
def speczcat_trans_sky(incat, dbfile, geomap_infile, refcat, clustname, septol,
                       **kwargs):
    '''This routine reads in a FITS catalog, writes a temporary output
    ASCII catalog, then transforms this catalog using geoxytran.  It
    then writes a new catalog with  old coordinates replaced by the new ones.

    INPUT

    incat: the input fits catalog

    dbfile: the geomap database file

    geomap_infile: used as the database record

    refcat: the original astrometric reference catalog

    clustname: the name of the cluster

    septol: the maximum separation allowed for a match in arcseconds

    OPTIONAL KEYWORDS

    ramin, ramax, decmin, decmax.  These are the limits over which the
    transform was originally computed.  If these are given then it
    uses those limits to color the points in the ra and decdiff plots.
    If one is given, all must be given.

    '''

    #read in the spectroscopic redshift catalog
    cat_hdul = fits.open(incat)
    cat_dat = cat_hdul["MDF"].data

    #read in original astrometric catalog
    #assume that this is a GAIA VOTable
    votable = parse(refcat)
    table = votable.get_first_table()
    ref_dat = table.array
    #convert masked arrays to normal arrays
    raref = np.array(ref_dat['RA_ICRS'])
    decref = np.array(ref_dat['DE_ICRS'])

    #ref_dat = ascii.read(refcat)
    #raref = np.array(ref_dat['ALPHA_SKY'])
    #decref = np.array(ref_dat['DELTA_SKY'])

    #tmp coordinate files for geoxytran
    tmpin = 'tmp_geoxytran_sky_in'
    tmpout = 'tmp_geoxytran_sky_out'

    #remove the existing transformed file
    newcat = incat.replace('.fits', '.trans.fits')

    if os.path.isfile(tmpout) is True:
        cmdstr = 'rm ' + tmpout
        os.system(cmdstr)
        cmdstr = 'rm ' + newcat
        os.system(cmdstr)

    #output temporary ASCII file with coordinates
    fo = open(tmpin, "w")
    fo.write("# ra dec\n")
    for i, val in enumerate(cat_dat['RA']):
        #convert speczcat RA to degrees when writing out
        fo.write('{} {}\n'.format(cat_dat['RA'][i] * 15.0, cat_dat['DEC'][i]))
    fo.close()

    iraf.geoxytran(tmpin, tmpout, dbfile, geomap_infile, direction="backward",\
                   xcolumn=1, ycolumn = 2)

    #read in ascii output file
    trans_dat = ascii.read(tmpout)
    ratrans = np.array(trans_dat['ra'])
    dectrans = np.array(trans_dat['dec'])

    #replace the old RAs and DECs with new RAs and DECs in place
    tcat_hdul = cat_hdul
    #convert RA back to hours for output
    tcat_hdul["MDF"].data['RA'] = ratrans / 15.0
    tcat_hdul["MDF"].data['DEC'] = dectrans

    #write the new fits file
    tcat_hdul.writeto(newcat)
Example #9
0
def transformcoords(im1, im2):
    checkxy = 1
    infile = '/Users/rfinn/clusters/spitzer/Mastertables/' + prefix + 'mastertable24.dat'
    input = open(infile, 'r')
    i = 0
    k = 0
    era = []  #ediscs ra
    edec = []  #ediscs dec
    excorr = []  #ediscs x pixel position
    eycorr = []  #ediscs y pixel position
    for line in input:
        if line.find('#') > -1:  #skip lines with '#' in them
            continue
        if line.find('\\') > -1:  #skip lines with '#' in them
            continue
        if line.find('|') > -1:  #skip lines with '#' in them
            continue
        t = line.split()  #break up columns & save ra and dec
        era.append(float(t[1]))
        edec.append(float(t[2]))
        excorr.append(float(t[3]))
        eycorr.append(float(t[4]))
    input.close()
    era = N.array(era, 'd')
    edec = N.array(edec, 'd')
    excorr = N.array(excorr, 'd')
    eycorr = N.array(eycorr, 'd')
    output = prefix + 'radec.dat'
    out1 = open(output, 'w')
    for i in range(len(era)):
        s = "%14.10f %14.10f \n" % (era[i], edec[i])
        out1.write(s)
    out1.close()
    output = prefix + '-ediscsxy.dat'  #now contains xcorr, ycorr
    out1 = open(output, 'w')
    for i in range(len(era)):
        s = "%14.10f %14.10f \n" % (excorr[i], eycorr[i])
        out1.write(s)
    out1.close()

    #transform ra and dec to x and y coords on ediscs image using ediscs i band image
    #write era and edec to a file
    outfile = output
    #outfile=prefix+'-ediscsxy.dat'#file containing x and y pixels values on ediscs iband image
    #iraf.wcsctran(output,outfile,image=im2,inwcs='world',outwcs='physical',columns='1 2', verbose='no')

    if checkxy > 0:
        iraf.display(im2, 1, fill='yes')
        iraf.tvmark(1, outfile, color=204, radii=15)
        #iraf.tvmark(1,output,color=204,radii=15)#plot xcorr and ycorr instead of transformed coordinates
        flag = raw_input("Enter 0 to terminate now or 1 to continue \n")
        if flag < 0.1:
            return

    dbase = prefix + '-match-geomap'
    outfile2 = prefix + '-GMOSxy.dat'  #file containing x and y pixels values on gmos image
    iraf.geoxytran(outfile,
                   output=outfile2,
                   database=dbase,
                   transform='gmos',
                   direction='backward')

    if checkxy > 0:
        iraf.display(im1, 2, fill='yes')
        iraf.tvmark(2, outfile2, color=204, radii=15)
        im3 = 'g' + im2
        iraf.display(im3, 3, fill='yes')
        iraf.tvmark(3, outfile2, color=204, radii=15)
        flag = raw_input("Enter anything to continue \n")