コード例 #1
0
ファイル: make_transit_file.py プロジェクト: jacob975/TATIRP
def take_data_within(name, start_date, end_date):
    #----------------------------------------
    # Convert date to JD
    times = [
        '{0}-{1}-{2}T12:00:00'.format(start_date[:4], start_date[4:6],
                                      start_date[6:]),
        '{0}-{1}-{2}T12:00:00'.format(end_date[:4], end_date[4:6],
                                      end_date[6:])
    ]
    t = Time(times, format='isot', scale='utc')
    start_jd = t.jd[0]
    end_jd = t.jd[1]
    #----------------------------------------
    # Query data
    cnx = TAT_auth()
    cursor = cnx.cursor()
    print 'target: {0}'.format(name)
    print 'start JD : {0}'.format(start_jd)
    print 'end JD: {0}'.format(end_jd)
    print 'band: {0}, exptime = {1}'.format(band, exptime)
    cursor.execute('select * from {0} where `NAME` = "{1}" \
                    and `JD` between {2} and {3}'\
                    .format(TAT_env.obs_data_tb_name, name, start_jd, end_jd))
    data = cursor.fetchall()
    data = np.array(data)
    cursor.close()
    cnx.close()
    return data
コード例 #2
0
ファイル: make_transit_file.py プロジェクト: jacob975/TATIRP
def select_data_by_bands_exptime(data, start_date, end_date, band, exptime):
    #----------------------------------------
    # Convert date to JD
    times = [
        '{0}-{1}-{2}T12:00:00'.format(start_date[:4], start_date[4:6],
                                      start_date[6:]),
        '{0}-{1}-{2}T12:00:00'.format(end_date[:4], end_date[4:6],
                                      end_date[6:])
    ]
    t = Time(times, format='isot', scale='utc')
    start_jd = t.jd[0]
    end_jd = t.jd[1]
    #----------------------------------------
    cnx = TAT_auth()
    cursor = cnx.cursor()
    # Take the ID of selected images.
    if band == 'skip' and exptime == 'skip':
        print('No band and exptime selection.')
        return data
    elif band == 'skip':
        print('Selected by exptime.')
        band_selection = ''
        exptime_selection = 'and `EXPTIME` = {0}'.format(exptime)
        cursor.execute('select `ID` from {0} where `JD` between {1} and {2}\
                        {3} {4}'.format(TAT_env.im_tb_name, start_jd, end_jd,
                                        band_selection, exptime_selection))
    elif exptime == 'skip':
        print('Selected by bands.')
        band_selection = 'and `FILTER` = "{0}"'.format(band)
        exptime_selection = ''
        cursor.execute('select `ID` from {0} where `JD` between {1} and {2}\
                        {3} {4}'.format(TAT_env.im_tb_name, start_jd, end_jd,
                                        band_selection, exptime_selection))
    else:
        print('Selected by bands and exptime.')
        cursor.execute('select `ID` from {0} where `JD` between {1} and {2}\
                        and `FILTER` = "{3}"\
                        and `EXPTIME` = {4}'.format(TAT_env.im_tb_name,
                                                    start_jd, end_jd, band,
                                                    exptime))
    selected_image_ID = cursor.fetchall()
    cursor.close()
    cnx.close()
    # Selected by Bands and Exposure Time.
    selected_image_ID = np.array(selected_image_ID)
    ID_index = TAT_env.obs_data_titles.index('FILEID')
    selected_data = []
    for source in data:
        dummy_index = np.where(selected_image_ID == source[ID_index])
        if len(dummy_index[0]) >= 1:
            selected_data.append(source)
    selected_data = np.array(selected_data, dtype=object)
    print('data points: {0}'.format(len(selected_data)))
    return selected_data
コード例 #3
0
ファイル: make_transit_file.py プロジェクト: jacob975/TATIRP
def load_data(name):
    cnx = TAT_auth()
    cursor = cnx.cursor()
    cursor.execute(
        'select * from observation_data where `NAME` = "{0}"'.format(name))
    data = cursor.fetchall()
    cursor.close()
    cnx.close()
    data = np.array(data, dtype=object)
    print(data.shape)
    return data
コード例 #4
0
def find_filter(fileID):
    cnx = TAT_auth()
    cursor = cnx.cursor()
    cursor.execute(
        "select `FILTER` from TAT.data_file where ID='{0}'".format(fileID))
    data = cursor.fetchall()
    data = np.array(data).flatten()
    ans = data[0]
    cursor.close()
    cnx.close()
    return ans
コード例 #5
0
def take_data_within(start_date, end_date, ra_cntr_str, dec_cntr_str):
    #----------------------------------------
    times = [
        '{0}-{1}-{2}T12:00:00'.format(start_date[:4], start_date[4:6],
                                      start_date[6:]),
        '{0}-{1}-{2}T12:00:00'.format(end_date[:4], end_date[4:6],
                                      end_date[6:])
    ]
    t = Time(times, format='isot', scale='utc')
    start_jd = t.jd[0]
    end_jd = t.jd[1]
    ra_cntr = float(ra_cntr_str)
    dec_cntr = float(dec_cntr_str)
    #----------------------------------------
    # Query data
    cnx = TAT_auth()
    cursor = cnx.cursor()
    print 'start JD : {0}'.format(start_jd)
    print 'end JD : {0}'.format(end_jd)
    print "Center at ({0}, {1})".format(ra_cntr, dec_cntr)
    print "band: {0}, exptime : {1}".format(band, exptime)
    print 'Start ID : {0}, Numbers of aux star : {1}'.format(
        begin_of_aux, no_of_aux)
    # Selected by Coordinate.
    cursor.execute('select * from {0} where `JD` between {1} and {2} \
                    and `RA` between {3} and {4} \
                    and `DEC` between {5} and {6}'\
                    .format(TAT_env.obs_data_tb_name,
                            start_jd,
                            end_jd,
                            ra_cntr-0.5,
                            ra_cntr+0.5,
                            dec_cntr-0.5,
                            dec_cntr+0.5
                            ))
    data = cursor.fetchall()
    data = np.array(data)
    # Take the ID of selected images.
    if band == 'skip' and exptime == 'skip':
        print('No band and exptime selection.')
        return data
    elif band == 'skip':
        print('Selected by exptime.')
        band_selection = ''
        exptime_selection = 'and `EXPTIME` = {0}'.format(exptime)
        cursor.execute('select `ID` from {0} where `JD` between {1} and {2}\
                        {3} {4}'.format(TAT_env.im_tb_name, start_jd, end_jd,
                                        band_selection, exptime_selection))
    elif exptime == 'skip':
        print('Selected by bands.')
        band_selection = 'and `FILTER` = "{0}"'.format(band)
        exptime_selection = ''
        cursor.execute('select `ID` from {0} where `JD` between {1} and {2}\
                        {3} {4}'.format(TAT_env.im_tb_name, start_jd, end_jd,
                                        band_selection, exptime_selection))
    else:
        print('Selected by bands and exptime.')
        cursor.execute('select `ID` from {0} where `JD` between {1} and {2}\
                        and `FILTER` = "{3}"\
                        and `EXPTIME` = {4}'.format(TAT_env.im_tb_name,
                                                    start_jd, end_jd, band,
                                                    exptime))
    selected_image_ID = cursor.fetchall()
    cursor.close()
    cnx.close()
    # Selected by Bands and Exposure Time.
    selected_image_ID = np.array(selected_image_ID)
    ID_index = TAT_env.obs_data_titles.index('FILEID')
    selected_data = []
    for source in data:
        dummy_index = np.where(selected_image_ID == source[ID_index])
        if len(dummy_index[0]) >= 1:
            selected_data.append(source)
    selected_data = np.array(selected_data)
    return selected_data
コード例 #6
0
def EP_process(data):
    #----------------------------------------
    # Load the index of some parameters
    bjd_index = TAT_env.obs_data_titles.index('BJD')
    inst_mag_index = TAT_env.obs_data_titles.index('INST_MAG')
    e_inst_mag_index = TAT_env.obs_data_titles.index('E_INST_MAG')
    target_name_index = TAT_env.obs_data_titles.index('NAME')
    fileID_index = TAT_env.obs_data_titles.index("FILEID")
    # Pick 10 brightest stars from each frame (They have to be the same star in diff. frames.)
    # Take all the data in the first frame
    first_bjd = np.amin(data[:, bjd_index])
    first_frame_data = data[data[:, bjd_index] == first_bjd]
    # Sort the first frame data by the brightness
    first_frame_data = first_frame_data[np.argsort(
        first_frame_data[:, inst_mag_index])]
    # Take the data from all frames.
    all_fileIDs = data[:, fileID_index]
    fileIDs = [
        item for item, count in collections.Counter(all_fileIDs).items()
        if count > 1
    ]
    source_list = []
    selected_source_name = []
    # Find sources found in all frames.
    for source in first_frame_data[int(begin_of_aux):]:
        if source[target_name_index] == var_star:
            continue
        source_data = data[data[:, target_name_index] ==
                           source[target_name_index]]
        source_fileIDs = source_data[:, fileID_index]
        if len(source_fileIDs) == len(fileIDs):
            source_error = source_data[:, e_inst_mag_index]
            source_error[source_error == 0.0] = 1e-4
            source_data_lite = np.transpose(
                np.array([
                    source_data[:, bjd_index], source_data[:, inst_mag_index],
                    source_error
                ]))
            source_list.append(source_data_lite)
            selected_source_name.append(source[target_name_index])
        if len(source_list) > int(no_of_aux):
            break

    #################################
    # Print Auxiliary Star Names
    print

    #################################
    exit()
    #----------------------------------------
    # Do photometry on Bright Stars only, save the result.
    source_data_array = np.array(source_list)
    stu = photometry_lib.EP(source_data_array[0], source_data_array)
    ems, var_ems, m0s, var_m0s = stu.make_airmass_model()
    #----------------------------------------
    # Pick a image, find the center position.
    cnx = TAT_auth()
    cursor = cnx.cursor()
    print fileIDs
    cursor.execute('select * from {0} where `ID` = {1}'.format(
        TAT_env.im_tb_name, fileIDs[0]))
    img_data = cursor.fetchall()
    cursor.close()
    cnx.close()
    img_ra_cntr = float(img_data[0][4])
    img_dec_cntr = float(img_data[0][5])
    # Get all possible target within the region.
    observed_targets = find_source_match_coords(img_ra_cntr,
                                                img_dec_cntr,
                                                margin=TAT_env.pix1 * 1024. /
                                                3600.)
    # Pick a target star, we make a photometry on it.
    for source in observed_targets:
        # Take the name of the source
        source_name = source[target_name_index]
        # Get all the data of the source
        data2 = data[np.isin(data[:, target_name_index], source_name)]
        # Take time, magnitude, and error of magnitude.
        observation_data_ID = data2[:, 0]
        time_array = data2[:, bjd_index]
        mag_array = data2[:, inst_mag_index]
        err_mag_array = data2[:, e_inst_mag_index]
        # Combine and do EP phot.
        source_data = np.transpose(
            np.array([time_array, mag_array, err_mag_array]))
        failure, correlated_target, matched = stu.phot(source_data)
        if failure:
            print 'One event {0} cannot be measure.'.format(source_name)
            continue
        observation_data_ID = observation_data_ID[matched]
        save2sql_EP(correlated_target, observation_data_ID)
    return False