コード例 #1
0
    def test_check_distance(self):
        """
        create_configurations should return:
        [[30, 0.01, 1.5, 4, 'models/gauss_2.0_5x5.conv']], 1

        prfs_d = extract_settings_elvis()
        # How many times the cross search radius will be increased
        tolerance_factor = 2

        df = df[df[keys[0]] + prfs_d['tolerance'] * tolerance_factor > i_alpha]
        df = df[i_alpha > df[keys[0]] - prfs_d['tolerance'] * tolerance_factor]
        df = df[df[keys[1]] + prfs_d['tolerance'] * tolerance_factor > i_delta]
        df = df[i_delta > df[keys[1]] - prfs_d['tolerance'] * tolerance_factor]

        :return:
        """
        i_alpha = 1.0
        i_delta = 1.0
        index = misc.check_distance(self.df_, i_alpha, i_delta)

        return self.assertIs(index, 0)
コード例 #2
0
def create_stars_catalog_thread(idx_l, sub_list, stars_df, full_d, scamp_df):
    """

    :param idx_l:
    :param sub_list:
    :param stars_df:
    :param full_d:
    :return:
    """
    keys = ['ALPHA_J2000', 'DELTA_J2000']

    cat_d = create_empty_catalog_dict()
    total_thread = len(sub_list)
    stdout.write('total stars {} of thread {}\n'.format(total_thread, idx_l))
    for idx, star in enumerate(sub_list):
        source_df = stars_df[stars_df['IDX'].isin([star])]
        alpha = source_df['RA2000(Gaia)'].iloc[0]
        delta = source_df['DEC2000(Gaia)'].iloc[0]

        source_d = create_empty_catalog_dict()
        for dither in range(1, 5, 1):
            sex_df = check_source(full_d[dither], alpha, delta, keys)
            # Should check source in Scamp too!
            if sex_df.empty is not True:
                # Returns the index of the closest found source
                index = check_distance(sex_df, alpha, delta)
                sex_df = sex_df.iloc[[index]]

                cat_number = sex_df['CATALOG_NUMBER'].iloc[0]
                df = scamp_df[scamp_df['CATALOG_NUMBER'].isin([cat_number])]

                df = check_source(df, alpha, delta, keys)
                if df.empty is not True:
                    source_d['DITHER'].append(dither)

                    catalog_number = int(sex_df['CATALOG_NUMBER'].iloc[0])
                    source_d['CATALOG_NUMBER'].append(catalog_number)

                    x_world = float(sex_df['X_WORLD'].iloc[0])
                    source_d['X_WORLD'].append(x_world)

                    y_world = float(sex_df['Y_WORLD'].iloc[0])
                    source_d['Y_WORLD'].append(y_world)

                    mag_auto = float(sex_df['MAG_AUTO'].iloc[0])
                    source_d['MAG_AUTO'].append(mag_auto)

                    magerr_auto = float(sex_df['MAGERR_AUTO'].iloc[0])
                    source_d['MAGERR_AUTO'].append(magerr_auto)

                    a_image = float(sex_df['A_IMAGE'].iloc[0])
                    source_d['A_IMAGE'].append(a_image)

                    b_image = float(sex_df['B_IMAGE'].iloc[0])
                    source_d['B_IMAGE'].append(b_image)

                    theta_image = float(sex_df['THETA_IMAGE'].iloc[0])
                    source_d['THETA_IMAGE'].append(theta_image)

                    erra_image = float(sex_df['ERRA_IMAGE'].iloc[0])
                    source_d['ERRA_IMAGE'].append(erra_image)

                    errb_image = float(sex_df['ERRB_IMAGE'].iloc[0])
                    source_d['ERRB_IMAGE'].append(errb_image)

                    erra_world = float(sex_df['ERRA_WORLD'].iloc[0])
                    source_d['ERRA_WORLD'].append(erra_world)

                    errb_world = float(sex_df['ERRB_WORLD'].iloc[0])
                    source_d['ERRB_WORLD'].append(errb_world)

                    errtheta_world = float(sex_df['ERRTHETA_WORLD'].iloc[0])
                    source_d['ERRTHETA_WORLD'].append(errtheta_world)

                    class_star = float(sex_df['CLASS_STAR'].iloc[0])
                    source_d['CLASS_STAR'].append(class_star)

                    pm = float(df['PM'].iloc[0])
                    source_d['PM'].append(pm)

                    pmerr = float(df['PMERR'].iloc[0])
                    source_d['PMERR'].append(pmerr)

        if len(source_d['DITHER']) != 0:
            for key_ in source_d.keys():
                for value_ in source_d[key_]:
                    cat_d[key_].append(value_)

    cat_df = DataFrame(cat_d,
                       columns=[
                           'DITHER', 'CATALOG_NUMBER', 'X_WORLD', 'Y_WORLD',
                           'MAG_AUTO', 'MAGERR_AUTO', 'A_IMAGE', 'B_IMAGE',
                           'THETA_IMAGE', 'ERRA_IMAGE', 'ERRB_IMAGE',
                           'ERRA_WORLD', 'ERRB_WORLD', 'ERRTHETA_WORLD',
                           'CLASS_STAR', 'PM', 'PMERR'
                       ])
    cat_df.to_csv('tmp_stars/stars_{}.csv'.format(idx_l))
コード例 #3
0
def create_stars_catalog_thread(idx_l, sub_list, inputs_d, full_d):
    """

    :param idx_l:
    :param sub_list:
    :param inputs_d:
    :param full_d:
    :return:
    """
    save = True
    keys = ['ALPHA_J2000', 'DELTA_J2000']

    cat_d = create_empty_catalog_dict()
    total_thread = len(sub_list)
    stdout.write('total stars {} of thread {}\n'.format(total_thread, idx_l))
    for idx, star in enumerate(sub_list):
        stars_df = inputs_d['stars']
        source_df = stars_df[stars_df['IDX'].isin([star])]
        alpha = source_df['RA2000(Gaia)'].iloc[0]
        delta = source_df['DEC2000(Gaia)'].iloc[0]

        source_d = create_empty_catalog_dict()
        for dither in range(1, 5, 1):
            o_df = check_source(full_d[dither], alpha, delta, keys)

            if o_df.empty is not True:
                # Returns the index of the closest found source
                index = check_distance(o_df, alpha, delta)
                o_df = o_df.iloc[[index]]

                source_d['DITHER'].append(dither)

                catalog_number = int(o_df['CATALOG_NUMBER'].iloc[0])
                source_d['CATALOG_NUMBER'].append(catalog_number)

                x_world = float(o_df['X_WORLD'].iloc[0])
                source_d['X_WORLD'].append(x_world)

                y_world = float(o_df['Y_WORLD'].iloc[0])
                source_d['Y_WORLD'].append(y_world)

                mag_auto = float(o_df['MAG_AUTO'].iloc[0])
                source_d['MAG_AUTO'].append(mag_auto)

                magerr_auto = float(o_df['MAGERR_AUTO'].iloc[0])
                source_d['MAGERR_AUTO'].append(magerr_auto)

                erra_world = float(o_df['ERRA_WORLD'].iloc[0])
                source_d['ERRA_WORLD'].append(erra_world)

                errb_world = float(o_df['ERRB_WORLD'].iloc[0])
                source_d['ERRB_WORLD'].append(errb_world)

                errtheta_world = float(o_df['ERRTHETA_WORLD'].iloc[0])
                source_d['ERRTHETA_WORLD'].append(errtheta_world)

        if len(source_d['DITHER']) != 0:
            for key_ in source_d.keys():
                for value_ in source_d[key_]:
                    cat_d[key_].append(value_)

    cat_df = DataFrame(cat_d,
                       columns=[
                           'DITHER', 'CATALOG_NUMBER', 'X_WORLD', 'Y_WORLD',
                           'MAG_AUTO', 'MAGERR_AUTO', 'ERRA_WORLD',
                           'ERRB_WORLD', 'ERRTHETA_WORLD'
                       ])
    if save:
        cat_df.to_csv('tmp_stars/stars_{}.csv'.format(idx_l))
コード例 #4
0
def create_galaxies_catalog_thread(idx_l, sub_list, galaxies_df, full_d):
    """

    :param idx_l:
    :param sub_list:
    :param galaxies_df:
    :param full_d:
    :return:
    """
    save = True
    keys = ['ALPHA_J2000', 'DELTA_J2000']

    cat_d = create_empty_catalog_dict()
    total_thread = len(sub_list)
    stdout.write('total galaxies {} of thread {}\n'.format(
        total_thread, idx_l))
    for idx, galaxy in enumerate(sub_list):
        source_df = galaxies_df[galaxies_df['IDX'].isin([galaxy])]
        alpha = source_df['ra'].iloc[0]
        delta = source_df['dec'].iloc[0]

        source_d = create_empty_catalog_dict()
        for dither in range(1, 5, 1):
            o_df = check_source(full_d[dither], alpha, delta, keys)
            if o_df.empty is not True:
                # Returns the index of the closest found source
                index = check_distance(o_df, alpha, delta)
                o_df = o_df.iloc[[index]]
                source_d['DITHER'].append(dither)

                catalog_number = int(o_df['CATALOG_NUMBER'].iloc[0])
                source_d['CATALOG_NUMBER'].append(catalog_number)

                x_world = float(o_df['X_WORLD'].iloc[0])
                source_d['X_WORLD'].append(x_world)

                y_world = float(o_df['Y_WORLD'].iloc[0])
                source_d['Y_WORLD'].append(y_world)

                mag_auto = float(o_df['MAG_AUTO'].iloc[0])
                source_d['MAG_AUTO'].append(mag_auto)

                magerr_auto = float(o_df['MAGERR_AUTO'].iloc[0])
                source_d['MAGERR_AUTO'].append(magerr_auto)

                a_image = float(o_df['A_IMAGE'].iloc[0])
                source_d['A_IMAGE'].append(a_image)

                b_image = float(o_df['B_IMAGE'].iloc[0])
                source_d['B_IMAGE'].append(b_image)

                theta_image = float(o_df['THETA_IMAGE'].iloc[0])
                source_d['THETA_IMAGE'].append(theta_image)

                erra_image = float(o_df['ERRA_IMAGE'].iloc[0])
                source_d['ERRA_IMAGE'].append(erra_image)

                errb_image = float(o_df['ERRB_IMAGE'].iloc[0])
                source_d['ERRB_IMAGE'].append(errb_image)

                erra_world = float(o_df['ERRA_WORLD'].iloc[0])
                source_d['ERRA_WORLD'].append(erra_world)

                errb_world = float(o_df['ERRB_WORLD'].iloc[0])
                source_d['ERRB_WORLD'].append(errb_world)

                errtheta_world = float(o_df['ERRTHETA_WORLD'].iloc[0])
                source_d['ERRTHETA_WORLD'].append(errtheta_world)

                class_star = float(o_df['CLASS_STAR'].iloc[0])
                source_d['CLASS_STAR'].append(class_star)

        if len(source_d['DITHER']) != 0:
            for key_ in source_d.keys():
                for value_ in source_d[key_]:
                    cat_d[key_].append(value_)

    # for key_ in cat_d.keys():
    #     print(key_, len(cat_d[key_]))

    cat_df = DataFrame(cat_d,
                       columns=[
                           'DITHER', 'CATALOG_NUMBER', 'X_WORLD', 'Y_WORLD',
                           'MAG_AUTO', 'MAGERR_AUTO', 'A_IMAGE', 'B_IMAGE',
                           'THETA_IMAGE', 'ERRA_IMAGE', 'ERRB_IMAGE',
                           'ERRA_WORLD', 'ERRB_WORLD', 'ERRTHETA_WORLD',
                           'CLASS_STAR'
                       ])
    if save:
        cat_df.to_csv('tmp_galaxies/galaxies_{}.csv'.format(idx_l))
def create_ssos_catalog_thread(idx_l, sub_list, ssos_df, full_d):
    """

    :param idx_l:
    :param sub_list:
    :param ssos_df:
    :param full_d:
    :return:
    """
    keys = ['ALPHA_J2000', 'DELTA_J2000']

    # Creates an empty catalog for all detected sources
    cat_d = create_output_catalog_dict()
    total_thread = len(sub_list)
    stdout.write('total SSOs {} of thread {}\n'.format(total_thread, idx_l))

    for idx, sso in enumerate(sub_list):
        source_df = ssos_df[ssos_df['SOURCE'].isin([sso])]

        for dither_ in source_df['DITHER'].tolist():
            dither_df = source_df[source_df['DITHER'].isin([dither_])]
            # Gets alpha/delta of actual source
            alpha = float(dither_df['RA'].iloc[0])
            delta = float(dither_df['DEC'].iloc[0])

            o_df = check_source(full_d[dither_], alpha, delta, keys)
            if o_df.empty is not True:
                # Returns the index of the closest found source
                index = check_distance(o_df, alpha, delta)

                o_df = o_df.iloc[[index]]

                idx_ = int(dither_df['IDX'].iloc[0])
                cat_d['IDX'].append(idx_)

                source = int(dither_df['SOURCE'].iloc[0])
                cat_d['SOURCE'].append(source)

                cat_d['DITHER'].append(dither_)

                alpha_j2000 = float(o_df['ALPHA_J2000'].iloc[0])
                cat_d['RA'].append(alpha_j2000)

                delta_j2000 = float(o_df['DELTA_J2000'].iloc[0])
                cat_d['DEC'].append(delta_j2000)

                vel = float(dither_df['VEL'].iloc[0])
                cat_d['VEL'].append(vel)

                abmag = float(dither_df['ABMAG'].iloc[0])
                cat_d['ABMAG'].append(abmag)

                theta = float(dither_df['THETA'].iloc[0])
                cat_d['THETA'].append(theta)

                mag_auto = float(o_df['MAG_AUTO'].iloc[0])
                cat_d['MAG_AUTO'].append(mag_auto)

                a_image = float(o_df['A_IMAGE'].iloc[0])
                cat_d['A_IMAGE'].append(a_image)

                b_image = float(o_df['B_IMAGE'].iloc[0])
                cat_d['B_IMAGE'].append(b_image)

                theta_image = float(o_df['THETA_IMAGE'].iloc[0])
                cat_d['THETA_IMAGE'].append(theta_image)

                erra_image = float(o_df['ERRA_IMAGE'].iloc[0])
                cat_d['ERRA_IMAGE'].append(erra_image)

                errb_image = float(o_df['ERRB_IMAGE'].iloc[0])
                cat_d['ERRB_IMAGE'].append(errb_image)

                magerr_auto = float(o_df['MAGERR_AUTO'].iloc[0])
                cat_d['MAGERR_AUTO'].append(magerr_auto)

                erra_world = float(o_df['ERRA_WORLD'].iloc[0])
                cat_d['ERRA_WORLD'].append(erra_world)

                errb_world = float(o_df['ERRB_WORLD'].iloc[0])
                cat_d['ERRB_WORLD'].append(errb_world)

                errtheta_world = float(o_df['ERRTHETA_WORLD'].iloc[0])
                cat_d['ERRTHETA_WORLD'].append(errtheta_world)

                class_star = float(o_df['CLASS_STAR'].iloc[0])
                cat_d['CLASS_STAR'].append(class_star)

    cat_df = DataFrame(cat_d,
                       columns=[
                           'IDX', 'SOURCE', 'DITHER', 'RA', 'DEC', 'VEL',
                           'ABMAG', 'THETA', 'MAG_AUTO', 'A_IMAGE', 'B_IMAGE',
                           'THETA_IMAGE', 'ERRA_IMAGE', 'ERRB_IMAGE',
                           'MAGERR_AUTO', 'ERRA_WORLD', 'ERRB_WORLD',
                           'ERRTHETA_WORLD', 'CLASS_STAR'
                       ])

    cat_df.to_csv('tmp_ssos/ssos_{}.csv'.format(idx_l))