Exemplo n.º 1
0
def transFLCfilt(targname,dir='./',matchtol=1):
    """
    Replace F606W and F814W (and 606 and 814) throughout this if using
    different filters
    """

    x = os.listdir(dir)
    for ii in x:
        if ii.endswith('cut_F606W.dat'):
            f606w_file = ii
        elif ii.endswith('cut_F814W.dat'):
            f814w_file = ii

    f606wN = np.genfromtxt(dir+f606w_file,names=True)
    f606w = np.genfromtxt(dir+f606w_file)

    f814wN = np.genfromtxt(dir+f814w_file,names=True)
    f814w = np.genfromtxt(dir+f814w_file)

    col606 = np.array(f606wN.dtype.names)
    # col814 = np.array(f814wN.dtype.names)  # names will be the same between
    # filters

    # Getting indices of columns

    # Will be the same for both filters
    x = np.int(np.where(col606=='xDRC1')[0])
    y = np.int(np.where(col606=='yDRC1')[0])

    idCol = len(col606)
    newCol = np.zeros((len(f606w),1),dtype=int)
    newCol[:,0] = np.arange(0,len(f606w),1)

    f606w_id = np.hstack((f606w,newCol))

    newCol = np.zeros((len(f814w),1),dtype=int)
    newCol[:,0] = np.arange(0,len(f814w),1)
    f814w_id = np.hstack((f814w,newCol))

    # Sorting to get the 50 brightest stars
    v50 = np.argsort(f606wN['mean'])[:50]  # using v abbreviation because
    # F606W is a broad V-band
    f606w_50 = f606w_id[v50]

    i50 = np.argsort(f814wN['mean'])[:50]  # using i abbrev. b/c F814W is
    # broad I-band
    f814w_50 = f814w_id[i50]

    master_in = f606w_50[:,[idCol,x,y]]  # selecting the columns I need
    idV,xv,yv= 0,1,2  # associating short vars with indices

    cat = f814w_50  # this has ALL of the columns from F814W catalog

    nF_out = True

    while nF_out:

        master, matchids = matchlistID(master_in,cat,matchtol,xv,yv,x,y,idCol)

        if len(master)>=int(6):  # because it's a 6D transformation
            nF_out = False
            print('Minimum Number Reached:{0:d}'.format(len(master)),targname)
        else:
            print('Need More Stars')
            master_in = f606w_50[:,[idCol,x,y]]  # resetting, just in case
            matchtol += 1

    master = np.hstack((master,matchids))

    idV, xv, yv, idI = 0, 1, 2, 3, 4  # index columns of master

    newCols = np.zeros((len(master),2))

    idxCol = master[:,idI]
    idxI = np.asarray(idxCol,int)
    regI = f814w[idxI]

    newCols[:,0] = regI[:,x]
    newCols[:,1] = regI[:,y]

    tempArr = np.hstack((master,newCols))

    idV, xv, yv, idI, xi, yi = 0, 1, 2, 3, 4, 5

    # Linear Transform Part

    match_arr = np.zeros((len(tempArr),2))
    match_arr[:,0] = tempArr[:,xi]  # the x in F814W that is going to F606W
    match_arr[:,1] = tempArr[:,yi]  # the y in F814W that is going to F606W

    master_arr = np.zeros((len(tempArr),2))
    master_arr[:,0] = tempArr[:,xv]  # the x ref F606W
    master_arr[:,1] = tempArr[:,yv]  # the y ref F606W

    weights = np.ones(len(master_arr))

    all_arr = np.zeros((len(f814w),2))
    all_arr[:,0] = f814w_id[:,x]
    all_arr[:,1] = f814w_id[:,y]

    print('Transforming ',targname)
    new_match, new_all = test_linear(match_arr[:,0],match_arr[:,1],
                                     master_arr[:,0],master_arr[:,1],weights,
                                     weights, all_arr[:,0],all_arr[:,1])

    outArr = np.hstack((f814w,new_all))
    s0 = ' '
    header = s0.join(col606)
    header += ' x_f606wTrans y_f606wTrans'

    outName = dir + 'flcFiltTrans_' + targname

    np.savetxt(outName + '.dat',outArr,header=header)

    makePlot(targname,match_arr[:,0],match_arr[:,1],master_arr[:,0],
             master_arr[:,1],new_match[:,0],new_match[:,1],
             label_1='Original in F814W',label_2='Original in F606W',
             label_3='New in F814W 2 F606W',outname=outName+'_matchCheck')

    return None
Exemplo n.º 2
0
def linTransSEpu(targname,
                 refFile='None.dat',
                 allFile='None.dat',
                 saveDir='./'):

    # Going from photutils to source extractor; although it shouldn't
    # really matter which direction I go as long as the eventual
    # matching code knows what I'm doing here

    # Loading the reference file and putting the names in an array;
    # the "col" randomly refers to column.
    # The -N suffix means that array was loaded with Names,
    # and is therefore not has a form (n,)
    mFileN = np.genfromtxt(refFile, names=True)
    mFile = np.genfromtxt(refFile)
    colMs = np.array(mFileN.dtype.names)

    # Loading the file with source positions to be transformed;
    # calling this the all file because it has all the points,
    # not just the few reference points
    aFileN = np.genfromtxt(allFile, names=True)
    aFile = np.genfromtxt(allFile)
    colAs = np.array(aFileN.dtype.names)

    # Putting the photutils positions into the match array
    # to be used as references
    match_arr = np.zeros((len(mFile), 2))
    xtrans = np.int(np.where(colMs == 'xPU')[0])
    ytrans = np.int(np.where(colMs == 'yPU')[0])

    match_arr[:, 0] = mFile[:, xtrans]
    match_arr[:, 1] = mFile[:, ytrans]

    # Putting the source extractor positions into the master array
    master_arr = np.zeros((len(mFile), 2))
    x1 = np.int(np.where(colMs == 'xSE')[0])
    y1 = np.int(np.where(colMs == 'ySE')[0])

    master_arr[:, 0] = mFile[:, x1]
    master_arr[:, 1] = mFile[:, y1]

    # Weights are needed for the 6D code, but we've
    # never really taken them into account
    weights = np.zeros((len(master_arr)))
    weights.fill(1.0)

    # Filling the array that will have the values that need
    # to be transformed; in this case, they are going from PU to SE;
    # variable names with _bt refer to "before tranform"
    all_arr = np.zeros((len(aFile), 2))
    x_bt = np.int(np.where(colAs == 'xcenter_f606w')[0])
    y_bt = np.int(np.where(colAs == 'ycenter_f606w')[0])

    all_arr[:, 0] = aFile[:, x_bt]
    all_arr[:, 1] = aFile[:, y_bt]

    s0 = ' '
    header = s0.join(colAs)  # "pulling" the header from the original file
    header += ' xSEf606w ySEf606w'  # adding new column names; make sure
    # there's a SPACE at the beginning, so the names don't run together

    outName = saveDir + 'puWtrans'

    # Call to the 6D code. More info in that script on the inputs;
    # the above portion of code put together the necessary arrays;
    # new_match is the positions of the original reference stars
    # transformed into the new frame
    # new_all is the list of all the transformed positions
    new_match, new_all = test_linear(match_arr[:, 0], match_arr[:, 1],
                                     master_arr[:, 0], master_arr[:,
                                                                  1], weights,
                                     weights, all_arr[:, 0], all_arr[:, 1])

    # Tacking the columns onto the original array
    outArr = np.hstack((aFile, new_all))

    np.savetxt(outName + '.dat', outArr, header=header)

    # Making a plot of the transformed reference stars to see
    # if anything went wrong
    makePlot(targname,
             match_arr[:, 0],
             match_arr[:, 1],
             new_match[:, 0],
             new_match[:, 1],
             master_arr[:, 0],
             master_arr[:, 1],
             label_1='Original in PU',
             label_2='New in PU 2 SE',
             label_3='Original in SE',
             outname=outName)

    return None
Exemplo n.º 3
0
def transFLCdrc(targname, flcFile, drcFile, dir='./', matchtol=1):

    flcN = np.genfromtxt(dir + flcFile, names=True)
    flc = np.genfromtxt(dir + flcFile)

    drcN = np.genfromtxt(dir + drcFile, names=True)
    drc = np.genfromtxt(dir + drcFile)

    colFs = np.array(flcN.dtype.names)
    colDs = np.array(drcN.dtype.names)

    xF = np.int(np.where(colFs == 'xDRC1_f606w')[0])
    yF = np.int(np.where(colFs == 'yDRC1_f606w')[0])

    xD = np.int(np.where(colDs == 'xcenter_f606w')[0])
    yD = np.int(np.where(colDs == 'ycenter_f606w')[0])

    idColF = len(colFs)
    newCol = np.zeros((len(flc), 1), dtype=int)
    newCol[:, 0] = np.arange(0, len(flc), 1)

    flc_id = np.hstack((flc, newCol))

    idColD = len(colDs)
    newCol = np.zeros((len(drc), 1), dtype=int)
    newCol[:, 0] = np.arange(0, len(drc), 1)
    drc_id = np.hstack((drc, newCol))

    f50 = np.argsort(flcN['mean_f606w'])[:50]
    flc_50 = flc_id[f50]

    d50 = np.argsort(drcN['magr_f606w'])[:50]
    drc_50 = drc_id[d50]

    master_in = drc_50[:, [idColD, xD, yD]]

    idD, xd, yd = 0, 1, 2

    cat = flc_50

    nF_out = True

    while nF_out:
        master, matchids = matchlistID(master_in, cat, matchtol, xd, yd, xF,
                                       yF, idColF)

        if len(master) >= int(6):  # because it's a 6D transformation
            nF_out = False
            print('Minimum Number Reached:{0:d}'.format(len(master)), targname)
        else:
            print('Need More Stars')
            master_in = drc_50[:, [idColD, xD, yD]]  # resetting, just in case
            matchtol += 1

    master = np.hstack((master, matchids))
    idD, xd, yd, idF = 0, 1, 2, 3

    newCols = np.zeros((len(master), 2))
    idxCol = master[:, idF]
    idxF = np.asarray(idxCol, int)
    regF = flc[idxF]

    newCols[:, 0] = regF[:, xF]
    newCols[:, 1] = regF[:, yF]

    tempArr = np.hstack((master, newCols))

    idD, xd, yd, idF, xf, yf = 0, 1, 2, 3, 4, 5

    # Linear Transform Part

    match_arr = np.zeros((len(tempArr), 2))
    match_arr[:, 0] = tempArr[:, xf]  # the x in FLC that is going to DRC
    match_arr[:, 1] = tempArr[:, yf]  # the y in FLC that is going to DRC

    master_arr = np.zeros((len(tempArr), 2))
    master_arr[:, 0] = tempArr[:, xd]  # the x ref DRC
    master_arr[:, 1] = tempArr[:, yd]  # the y ref DRC

    weights = np.ones(len(master_arr))

    all_arr = np.zeros((len(flc), 2))
    all_arr[:, 0] = flc_id[:, xF]
    all_arr[:, 1] = flc_id[:, yF]

    print('Transforming ', targname)
    new_match, new_all = test_linear(match_arr[:, 0], match_arr[:, 1],
                                     master_arr[:, 0], master_arr[:,
                                                                  1], weights,
                                     weights, all_arr[:, 0], all_arr[:, 1])

    outArr = np.hstack((flc, new_all))
    s0 = ' '
    header = s0.join(colFs)
    header += ' x_DRCtrans y_DRCtrans'

    outName = dir + 'flcDRCtrans_' + targname

    np.savetxt(outName + '.dat', outArr, header=header)

    makePlot(targname,
             match_arr[:, 0],
             match_arr[:, 1],
             master_arr[:, 0],
             master_arr[:, 1],
             new_match[:, 0],
             new_match[:, 1],
             label_1='Original in FLC',
             label_2='Original in DRC',
             label_3='New in FLC 2 DRC',
             outname=outName + '_matchCheck')

    return None
Exemplo n.º 4
0
def drcFiltLinTrans(targname, dir='./', suffix='_pu.dat'):

    # Will need to replace filter names with appropriate
    # ones for your use.
    x = os.listdir(dir)
    for ii in x:
        if ii.endswith('_F606W' + suffix):
            f606w_file = ii
        elif ii.endswith('_F814W' + suffix):
            f814w_file = ii

    # Going from F814W to F606W
    refN = np.genfromtxt(dir + 'drcFiltRef_' + targname + '.dat', names=True)
    ref = np.genfromtxt(dir + 'drcFiltRef_' + targname + '.dat')
    colRs = np.array(refN.dtype.names)

    allN = np.genfromtxt(dir + f814w_file, names=True)
    all = np.genfromtxt(dir + f814w_file)
    colAs = np.array(allN.dtype.names)

    # Putting the F814W positions into the match array
    # to be used as references.
    match_arr = np.zeros((len(ref), 2))
    xi2v = np.int(np.where(colRs == 'x_f814w')[0])
    yi2v = np.int(np.where(colRs == 'y_f814w')[0])

    match_arr[:, 0] = ref[:, xi2v]
    match_arr[:, 1] = ref[:, yi2v]

    # Putting the F606W positions into the master array
    master_arr = np.zeros((len(ref), 2))
    xv = np.int(np.where(colRs == 'x_f606w')[0])
    yv = np.int(np.where(colRs == 'y_f606w')[0])

    master_arr[:, 0] = ref[:, xv]
    master_arr[:, 1] = ref[:, yv]

    # Weights required for the 6D transformation function
    # We haven't assigned useful values to them.
    weights = np.ones(len(master_arr))

    # Creating an array that will hold the original and transformed values
    all_arr = np.zeros((len(all), 2))

    # bt stands for before transform
    x_bt = np.int(np.where(colAs == 'xcenter')[0])
    y_bt = np.int(np.where(colAs == 'ycenter')[0])

    all_arr[:, 0] = all[:, x_bt]
    all_arr[:, 1] = all[:, y_bt]

    outName = dir + 'drcFiltTrans_' + targname
    print('Transforming ', targname)
    # This takes the xy positions from the points you have matched
    # to the master, the xy positions of the corresponding points in
    # the master, weights, and the xy points in the match_arr frame
    # that will be transformed into the master_arr frame.
    new_match, new_all = test_linear(match_arr[:, 0], match_arr[:, 1],
                                     master_arr[:, 0], master_arr[:,
                                                                  1], weights,
                                     weights, all_arr[:, 0], all_arr[:, 1])

    outArr = np.hstack((all, new_all))  # attaching the transformed positions
    # to the original (F814W) catalog

    s0 = ' '
    header = s0.join(colAs)
    header += ' x_f606wTrans y_f606wTrans'

    np.savetxt(outName + '.dat', outArr, header=header)

    makePlot(targname,
             match_arr[:, 0],
             match_arr[:, 1],
             master_arr[:, 0],
             master_arr[:, 1],
             new_match[:, 0],
             new_match[:, 1],
             label_1='Original in F814W',
             label_2='Original in F606W',
             label_3='New in F814W 2 F606W',
             outname=outName + '_matchCheck')

    return None