Пример #1
0
def match_optical(target,
                  channel,
                  data_dir='',
                  optical_dir='/Volumes/Annie/CRRP/OpticalCatalogs/',
                  dao_dir='/usr/local/phot/'):

    deep_mosaic_fits = target + '_' + channel + '_deep.fits'

    curr_dir = os.getcwd()
    os.chdir(data_dir + 'DeepMosaic')
    ids, catalog_x, catalog_y, catalog_ra, catalog_dec = optical.read_optical_fnl(
        optical_dir, target)

    als_file = re.sub('.fits', '_dn.als', deep_mosaic_fits)
    dtype1 = np.dtype([('x', float), ('y', float)])
    data = np.loadtxt(als_file, dtype=dtype1, skiprows=3, usecols=(1, 2))
    xmin = np.min(data['x'])
    xmax = np.max(data['x'])
    ymin = np.min(data['y'])
    ymax = np.max(data['y'])

    print "Calculating optical boundaries..."
    print xmin, xmax, ymin, ymax
    ra1, ra2, dec1, dec2 = coordinates.find_coord_window_mosaic(
        deep_mosaic_fits, xmin, xmax, ymin, ymax)
    print ra1, ra2, dec1, dec2
    min_x, min_y = coordinates.radec2catalogpix(ra1, dec1, catalog_x,
                                                catalog_y, catalog_ra,
                                                catalog_dec)
    max_x, max_y = coordinates.radec2catalogpix(ra2, dec2, catalog_x,
                                                catalog_y, catalog_ra,
                                                catalog_dec)
    #		c1, c2, c3, c4 = coordinates.radec2pix(target, x1, x2, y1, y2, xcat, ycat, ra, dec)
    print "Xmin, Xmax, Ymin, Ymax for optical catalog:"
    print min_x, max_x, min_y, max_y

    xmin = [min_x]
    xmax = [max_x]
    ymin = [min_y]
    ymax = [max_y]
    f = ['Deep']

    # Save boundary window for each field into a text file (e.g. I1-catalog-cuts.txt)
    data_save = np.array(zip(f, xmin, xmax, ymin, ymax),
                         dtype=[('c1', 'S8'), ('c2', float), ('c3', float),
                                ('c4', float), ('c5', float)])
    np.savetxt(channel + '-deep-cuts.txt',
               data_save,
               comments='',
               fmt='%s %0.3f %0.3f %0.3f %0.3f')

    limits = str(min_x) + ',' + str(max_x) + ',' + str(min_y) + ',' + str(
        max_y)
    image_list = ['optical:' + target + '-I.mag', als_file]
    mch_file = 'op-' + channel + '.mch'
    daomatch.daomatch(image_list, mch_file, dao_dir=dao_dir, xy_limits=limits)
    daomaster.daomaster(mch_file, dao_dir=dao_dir, frame_num='1,0.5,1')
    os.chdir(curr_dir)
Пример #2
0
def check_match(target,
                channel,
                optical_dir='/Volumes/Annie/CRRP/OpticalCatalogs/',
                data_dir=''):

    fig = mp.figure(figsize=(8, 8))
    ax1 = fig.add_subplot(111)

    # read optical catalog and add to plots
    ids, xcat, ycat, ra, dec = optical.read_optical_fnl(optical_dir, target)
    ax1.plot(xcat, ycat, '.', color='0.25', markersize=0.75)

    # read boundaries of IRAC data
    dtype1 = np.dtype([('xmin', float), ('xmax', float), ('ymin', float),
                       ('ymax', float)])
    cuts = np.loadtxt(data_dir + 'DeepMosaic/' + channel + '-deep-cuts.txt',
                      dtype=dtype1,
                      usecols=(1, 2, 3, 4))

    ax1.plot([cuts['xmin'], cuts['xmax']], [cuts['ymin'], cuts['ymin']],
             '-',
             color='r',
             linewidth=2)
    ax1.plot([cuts['xmin'], cuts['xmax']], [cuts['ymax'], cuts['ymax']],
             '-',
             color='r',
             linewidth=2)
    ax1.plot([cuts['xmin'], cuts['xmin']], [cuts['ymin'], cuts['ymax']],
             '-',
             color='r',
             linewidth=2)
    ax1.plot([cuts['xmax'], cuts['xmax']], [cuts['ymin'], cuts['ymax']],
             '-',
             color='r',
             linewidth=2)
    ax1.set_xlabel('X (pixels)')
    ax1.set_ylabel('Y (pixels)')

    # Add transformed catalogs
    data = read_dao.read_alf(data_dir + 'DeepMosaic/' + target + '_' +
                             channel + '_deep_dn.als')
    x = data['x']
    y = data['y']

    files, x_off, y_off, transform, dof = read_dao.read_mch(data_dir +
                                                            'DeepMosaic/op-' +
                                                            channel + '.mch')

    x_new = float(
        x_off[1]) + float(transform[1][0]) * x + float(transform[1][1]) * y
    y_new = float(
        y_off[1]) + float(transform[1][2]) * x + float(transform[1][3]) * y

    ax1.plot(x_new, y_new, '.', markersize=1.8, color='r')
    mp.show()
Пример #3
0
def find_variables_by_coord_mosaic(optical_folder, target):

    # read in list of Clement variables
    dtype1 = np.dtype([('id', 'S8'), ('ra', 'S10'), ('dec', 'S11'),
                       ('period', float), ('var_type', 'S8')])
    data = np.loadtxt(target + '-clement.txt', dtype=dtype1)

    RRc = data[:][data['var_type'] == 'RR1']
    RRab = data[:][data['var_type'] == 'RR0']

    ra_variables, dec_variables = coordinates.radec_string2deg(
        data['ra'], data['dec'])

    ids, xcat, ycat, ra, dec = optical.read_optical_fnl(optical_folder, target)
    # Limit search to horizontal branch
    #    ids, xcat, ycat, ra, dec = optical.read_optical_catalog(optical_folder, target+'-HB')

    ra1 = np.radians(ra)
    dec1 = np.radians(dec)
    id_match = []
    ra_match = []
    dec_match = []
    num_neighbors = []

    for obj in range(0, len(ra_variables)):

        ra2 = np.radians(ra_variables[obj])
        dec2 = np.radians(dec_variables[obj])
        x1 = np.cos(dec1) * np.cos(ra1)
        y1 = np.cos(dec1) * np.sin(ra1)
        z1 = np.sin(dec1)
        x2 = np.cos(dec2) * np.cos(ra2)
        y2 = np.cos(dec2) * np.sin(ra2)
        z2 = np.sin(dec2)

        dist = np.sqrt((x2 - x1)**2 + (y2 - y1)**2 + (z2 - z1)**2)
        dist = np.degrees(dist) * 3600.

        matches = ids[dist < 3]
        code = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l']
        print 'V' + data['id'][obj] + ' - ' + str(len(matches)) + ' matches'
        for ind, star in enumerate(matches):
            if ind == 0:
                variable_star = 'V' + data['id'][obj]
                lightcurves.make_mosaic_lcv(['I1'], [variable_star], [star])
            if ind <= 12 and ind > 0:
                variable_star = 'V' + data['id'][obj] + code[ind - 1]
                lightcurves.make_mosaic_lcv(['I1'], [variable_star], [star])
        #    lightcurves.phase_lcv('lcvs/'+variable_star+'.lcv', data['period'][obj], 50000, bin=0)
            lightcurves.plot_raw_mosaic_lcv(
                'mosaic_lcvs/' + variable_star + '.lcv', star)
Пример #4
0
    mp.plot([ra2, ra3], [dec2, dec3], '-', color='0.5')
    mp.plot([ra3, ra4], [dec3, dec4], '-', color='0.5')
    mp.plot([ra4, ra1], [dec4, dec1], '-', color='0.5')
mp.xlabel('RA')
mp.ylabel('Dec')

x_formatter = ScalarFormatter(useOffset=False)
mp.gca().xaxis.set_major_formatter(x_formatter)
mp.savefig('aor-footprint.eps', format='eps')
mp.gcf().clear()

# Map of source catalog with field boundaries shown

optical_folder = '/Users/jrneeley/CRRP/OpticalCatalogs/'

ids, xcat, ycat, ra, dec = optical.read_optical_fnl(optical_folder, target)

dtype1 = np.dtype([('xmin', float), ('xmax', float), ('ymin', float), ('ymax', float)])
cuts = np.loadtxt(channel+'-catalog-cuts.txt', dtype=dtype1, usecols=(1,2,3,4))

mp.plot(xcat, ycat, '.', color='0.25', markersize=0.75)
colors=['r', 'b', 'g', 'c', 'm', 'k']
for ind in range(len(cuts['xmin'])):
    mp.plot([cuts['xmin'][ind], cuts['xmax'][ind]], [cuts['ymin'][ind], cuts['ymin'][ind]],
        '-', color=colors[ind], linewidth=2)
    mp.plot([cuts['xmin'][ind], cuts['xmax'][ind]], [cuts['ymax'][ind], cuts['ymax'][ind]],
        '-', color=colors[ind], linewidth=2)
    mp.plot([cuts['xmin'][ind], cuts['xmin'][ind]], [cuts['ymin'][ind], cuts['ymax'][ind]],
        '-', color=colors[ind], linewidth=2)
    mp.plot([cuts['xmax'][ind], cuts['xmax'][ind]], [cuts['ymin'][ind], cuts['ymax'][ind]],
        '-', color=colors[ind], linewidth=2)
Пример #5
0
def find_stars_in_cat(optical_dir, target, channel, data_dir=''):

    cat_ids, x, y, ra, dec = optical.read_optical_fnl(optical_dir, target)

    reg_file = open(data_dir + channel + '.reg').read().replace(':', ' ')
    dtype1 = np.dtype([('ra_h', int), ('ra_m', int), ('ra_s', float),
                       ('dec_d', int), ('dec_m', int), ('dec_s', float)])
    data = np.loadtxt(StringIO.StringIO(reg_file), dtype=dtype1)
    ra_h = data['ra_h']
    ra_m = data['ra_m']
    ra_s = data['ra_s']
    dec_d = data['dec_d']
    dec_m = data['dec_m']
    dec_s = data['dec_s']

    cal_ra, cal_dec = coordinates.hms2deg(ra_h, ra_m, ra_s, dec_d, dec_m,
                                          dec_s)

    alf_list = glob.glob(data_dir + 'data/' + channel + '*.alf')

    phot_data = np.zeros(len(cal_ra),
                         dtype=[('id', 'S8'), ('ra', float), ('dec', float),
                                ('neigh', int), ('aor', int, len(alf_list)),
                                ('f_num', int, len(alf_list)),
                                ('x', float, len(alf_list)),
                                ('y', float, len(alf_list)),
                                ('psf_mag', float, len(alf_list)),
                                ('psf_err', float, len(alf_list))])
    neighbors = np.zeros(len(cal_ra), dtype=object)

    # Find id numbers of selected stars in optical catalog - and all stars within 6 arcsec
    for obj in range(0, len(cal_ra)):

        dist = coordinates.radial_dist(cal_ra[obj], cal_dec[obj], ra, dec)

        cat_match = np.argmin(dist)
        nei_match = np.argwhere(dist < 6.0)
        num_neighbors = len(nei_match)

        phot_data['id'][obj] = cat_ids[cat_match]
        phot_data['ra'][obj] = ra[cat_match]
        phot_data['dec'][obj] = dec[cat_match]
        phot_data['neigh'][obj] = num_neighbors
        neighbors[obj] = cat_ids[nei_match]


# Find the selected stars in the individual alf files
    for ind in range(0, len(alf_list)):

        alf_id, x, y, alf_mag, alf_err = read_dao.read_alf(alf_list[ind])

        for ind2 in range(0, len(cal_ra)):
            alf_match = np.argwhere(alf_id == int(phot_data['id'][ind2]))
            alf_nei_match = np.argwhere(alf_id == neighbors[ind2])
            trash1, aor_num, frame_num, trash2 = alf_list[ind].split('_')
            phot_data['aor'][ind2, ind] = int(aor_num)
            phot_data['f_num'][ind2, ind] = int(frame_num)

            if len(alf_match):
                phot_data['x'][ind2, ind] = x[alf_match]
                phot_data['y'][ind2, ind] = y[alf_match]
                phot_data['psf_mag'][ind2, ind] = alf_mag[alf_match]
                phot_data['psf_err'][ind2, ind] = alf_err[alf_match]
            else:
                phot_data['x'][ind2, ind] = float('NaN')
                phot_data['y'][ind2, ind] = float('NaN')
                phot_data['psf_mag'][ind2, ind] = float('NaN')
                phot_data['psf_err'][ind2, ind] = float('NaN')

    print 'Writing files...'
    #    print phot_data['x'][1]
    for ind in range(0, len(cal_ra)):
        if np.all(np.isnan(phot_data['psf_mag'][ind])):
            continue

        np.savetxt(data_dir + 'cal_stars/' + channel + '_' +
                   phot_data['id'][ind] + '.coo',
                   np.c_[phot_data['aor'][ind], phot_data['f_num'][ind],
                         phot_data['x'][ind], phot_data['y'][ind],
                         phot_data['psf_mag'][ind], phot_data['psf_err'][ind]],
                   header=str(phot_data['id'][ind]) + ' ' +
                   str(phot_data['ra'][ind]) + ' ' +
                   str(phot_data['dec'][ind]) + ' ' +
                   str(phot_data['neigh'][ind]) + '\n',
                   comments='',
                   fmt='%8i %2i %7.3f %7.3f %6.3f %6.4f')
Пример #6
0
    daomaster.daomaster_mosaic(dao_dir, channel + "_mosaic.mch")

## Find appropriate window in source catalog
if (start <= 5):

    dtype1 = np.dtype([('x', float), ('y', float)])
    data = np.loadtxt(channel + '_mosaic.mag',
                      dtype=dtype1,
                      skiprows=3,
                      usecols=(1, 2))
    xmin = np.min(data['x'])
    xmax = np.max(data['x'])
    ymin = np.min(data['y'])
    ymax = np.max(data['y'])

    ids, catalog_x, catalog_y, catalog_ra, catalog_dec = optical.read_optical_fnl(
        optical_dir, target)

    print "Calculating field boundaries..."
    ra1, ra2, dec1, dec2 = coordinates.find_coord_window_mosaic(
        dn_list[0], xmin, xmax, ymin, ymax)
    print ra1, ra2, dec1, dec2
    min_x, min_y = coordinates.radec2catalogpix(ra1, dec1, catalog_x,
                                                catalog_y, catalog_ra,
                                                catalog_dec)
    max_x, max_y = coordinates.radec2catalogpix(ra2, dec2, catalog_x,
                                                catalog_y, catalog_ra,
                                                catalog_dec)
    #		c1, c2, c3, c4 = coordinates.radec2pix(target, x1, x2, y1, y2, xcat, ycat, ra, dec)
    print "Xmin, Xmax, Ymin, Ymax for optical catalog:"
    print min_x, max_x, min_y, max_y