Exemplo n.º 1
0
def _get_data(sector, cdips_cat_vnum=None, is_not_cdips_still_good=0):

    if is_not_cdips_still_good:
        classifxn_csv = os.path.join(
            CLASSIFXNDIR,
            "sector-{}_PCs_NOT_CDIPS_STILL_GOOD.csv".format(sector))
    else:
        classifxn_csv = os.path.join(
            CLASSIFXNDIR, "sector-{}_PCs_CLEAR_THRESHOLD.csv".format(sector))

    df = pd.read_csv(classifxn_csv, sep=';')

    cdips_df = get_cdips_catalog(ver=cdips_cat_vnum)

    pfpath = os.path.join(
        resultsbase, 'cdips_lc_periodfinding/'
        'sector-{}/'.format(sector) +
        'initial_period_finding_results_supplemented.csv')
    pfdf = pd.read_csv(pfpath, sep=';')

    supppath = os.path.join(
        resultsbase, 'cdips_lc_stats/sector-{}/'.format(sector) +
        'supplemented_cdips_lc_statistics.txt')
    supplementstatsdf = pd.read_csv(supppath, sep=';')

    toidf = get_toi_catalog()
    ctoidf = get_exofop_ctoi_catalog()

    return df, cdips_df, pfdf, supplementstatsdf, toidf, ctoidf
Exemplo n.º 2
0
def _get_nbhd_dataframes():
    """
    WARNING!: this "bright" subset is a crossmatch between the full NGC 2516
    target list (CG18+KC19+M21), and the CDIPS target catalog (G_Rp<16; v0.4).
    However, since the CDIPS targets didn't incorporate M21, it's not as direct
    of a match as desired. This is fine for understanding the auto-detection of
    rotation periods. But for overall cluster rotation period completeness,
    it's not.

    The "neighborhood" was selected via

        bounds = { 'parallax_lower': 1.5, 'parallax_upper': 4.0, 'ra_lower': 108,
        'ra_upper': 132, 'dec_lower': -76, 'dec_upper': -45 }

        nbhd_df = query_neighborhood(bounds, groupname, n_max=6000,
                                     overwrite=False, manual_gmag_limit=17)

    This procedure yields:
        Got 7052 neighbors with Rp<16
        Got 893 in core from CDIPS target catalog
        Got 1345 in corona from CDIPS target catalog
    """

    df = get_cdips_catalog(ver=0.4)

    nbhd_df, core_df, halo_df, full_df, target_df = _get_fullfaint_dataframes()

    #
    # do the "bright" selection by a crossmatch between the full target list
    # and the CDIPS catalog. so implicitly, it's a CDIPS target star catalog
    # match.  this misses some Meingast stars, b/c they weren't in the CDIPS
    # v0.4 target list. but this
    #
    cdips_df = df['source_id']
    mdf = full_df.merge(cdips_df, on='source_id', how='inner')

    nbhd_df = nbhd_df[nbhd_df.phot_rp_mean_mag < 16]

    core_df = mdf[mdf.subcluster == 'core']
    halo_df = mdf[mdf.subcluster == 'halo']

    print(42 * '.')
    print('"Bright" sample:')
    print(f'...Got {len(nbhd_df)} neighbors with Rp<16')
    print(f'...Got {len(core_df)} in core from CDIPS target catalog')
    print(f'...Got {len(halo_df)} in corona from CDIPS target catalog')
    print(42 * '.')

    return nbhd_df, core_df, halo_df, full_df, target_df
Exemplo n.º 3
0
def plot_TIC268_nbhd_small(outdir=RESULTSDIR):

    set_style()

    df = get_cdips_catalog(ver=0.4)

    kc19_sel = ((df.cluster.str.contains('NGC_2516')) &
                (df.reference.str.contains('Kounkel_2019')))
    cg18_sel = ((df.cluster.str.contains('NGC_2516')) &
                (df.reference.str.contains('CantatGaudin_2018')))

    target_df = df[df.source_id == 5489726768531119616]  # TIC 2683...
    kc19_df = df[kc19_sel]
    cg18_df = df[cg18_sel]

    kc19_df = kc19_df[~(kc19_df.source_id.isin(cg18_df.source_id))]

    ##########

    # NGC 2516 rough
    bounds = {
        'parallax_lower': 1.5,
        'parallax_upper': 4.0,
        'ra_lower': 108,
        'ra_upper': 132,
        'dec_lower': -76,
        'dec_upper': -45
    }
    groupname = 'customngc2516'

    nbhd_df = query_neighborhood(bounds,
                                 groupname,
                                 n_max=6000,
                                 overwrite=False,
                                 manual_gmag_limit=17)

    sel_nbhd = ((~nbhd_df.source_id.isin(kc19_df.source_id))
                & (~nbhd_df.source_id.isin(cg18_df.source_id)))
    from copy import deepcopy
    orig_nbhd_df = deepcopy(nbhd_df)
    nbhd_df = nbhd_df[sel_nbhd]

    print(f'Got {len(nbhd_df)} neighbors')
    print(f'Got {len(cg18_df)} in core')
    print(f'Got {len(kc19_df)} in corona')

    ##########

    plt.close('all')

    f, axs = plt.subplots(figsize=(4, 3), ncols=2)

    xv, yv = 'ra', 'dec'
    axs[0].scatter(nbhd_df[xv],
                   nbhd_df[yv],
                   c='gray',
                   alpha=0.5,
                   zorder=2,
                   s=7,
                   rasterized=True,
                   linewidths=0,
                   label='Field',
                   marker='.')
    axs[0].scatter(kc19_df[xv],
                   kc19_df[yv],
                   c='lightskyblue',
                   alpha=0.9,
                   zorder=3,
                   s=7,
                   rasterized=True,
                   linewidths=0.15,
                   label='Corona',
                   marker='.',
                   edgecolors='k')
    axs[0].scatter(cg18_df[xv],
                   cg18_df[yv],
                   c='k',
                   alpha=0.9,
                   zorder=4,
                   s=7,
                   rasterized=True,
                   label='Core',
                   marker='.')
    axs[0].plot(target_df[xv],
                target_df[yv],
                alpha=1,
                mew=0.5,
                zorder=8,
                label='TOI 1937',
                markerfacecolor='lightskyblue',
                markersize=14,
                marker='*',
                color='black',
                lw=0)

    axs[0].set_xlabel(r'$\alpha$ [deg]')
    axs[0].set_ylabel(r'$\delta$ [deg]')
    axs[0].set_xlim([108, 132])
    axs[0].set_ylim([-76, -45])

    ##########

    get_yval = (lambda _df: np.array(_df['phot_g_mean_mag'] + 5 * np.log10(_df[
        'parallax'] / 1e3) + 5))
    get_xval = (lambda _df: np.array(_df['phot_bp_mean_mag'] - _df[
        'phot_rp_mean_mag']))

    axs[1].scatter(get_xval(nbhd_df),
                   get_yval(nbhd_df),
                   c='gray',
                   alpha=0.8,
                   zorder=2,
                   s=7,
                   rasterized=True,
                   linewidths=0,
                   label='Field',
                   marker='.')
    axs[1].scatter(get_xval(kc19_df),
                   get_yval(kc19_df),
                   c='lightskyblue',
                   alpha=1,
                   zorder=3,
                   s=7,
                   rasterized=True,
                   linewidths=0.15,
                   label='Corona',
                   marker='.',
                   edgecolors='k')
    axs[1].scatter(get_xval(cg18_df),
                   get_yval(cg18_df),
                   c='k',
                   alpha=0.9,
                   zorder=4,
                   s=7,
                   rasterized=True,
                   linewidths=0,
                   label='Core',
                   marker='.')
    axs[1].plot(get_xval(target_df),
                get_yval(target_df),
                alpha=1,
                mew=0.5,
                zorder=8,
                label='TOI 1937',
                markerfacecolor='lightskyblue',
                markersize=14,
                marker='*',
                color='black',
                lw=0)

    axs[1].set_ylim(axs[1].get_ylim()[::-1])

    axs[1].set_xlabel('Bp - Rp [mag]')
    axs[1].set_ylabel('Absolute G [mag]', labelpad=-6)

    ##########

    words = ['Field', 'Corona', 'Core', 'TOI1937'][::-1]
    colors = ['gray', 'lightskyblue', 'k', 'lightskyblue'][::-1]
    rainbow_text(0.98, 0.02, words, colors, size='medium', ax=axs[0])

    f.tight_layout(w_pad=2)

    outpath = os.path.join(outdir, 'small_ngc2516.png')
    savefig(f, outpath)
Exemplo n.º 4
0
import os
from glob import glob
import pandas as pd, numpy as np
from astropy.table import Table

OVERWRITE = 0
CDIPSVER = 0.6

# Bedell's 1 arcsecond DR2 X Kepler match
KEPGAIAFUN = '/Users/luke/local/kepler_gws/kepler_dr2_1arcsec.fits'
df_kep = Table.read(KEPGAIAFUN, format='fits').to_pandas()
df_kep.source_id = df_kep.source_id.astype(str)
df_kep['planet?'] = df_kep['planet?'].str.decode('utf-8')

df_cdips = get_cdips_catalog(ver=CDIPSVER)
df_cdips['source_id'] = df_cdips.source_id.astype(str)

mdf = df_kep.merge(df_cdips, how='inner', on='source_id')

outdf = mdf[~pd.isnull(mdf.reference_id)]

outpath = os.path.join(DATADIR, '20210916_kepgaiafun_X_cdipsv0pt6.csv')
outdf.to_csv(outpath, index=False)
print(f'Wrote {outpath}')

selcols = [
    'kepid', 'source_id', 'kepmag', 'phot_g_mean_mag_x', 'cluster',
    'reference_id', 'mean_age', 'planet?', 'nkoi', 'nconfp',
    'kepler_gaia_ang_dist'
]
    /nfs/phtess2/ar0/TESS/PROJ/lbouma/CDIPS_LCS/get_lc_list.sh
"""

import os
import pandas as pd
from cdips.utils.catalogs import get_cdips_catalog
from cdips.utils import today_YYYYMMDD

lclistpath = f'/nfs/phtess2/ar0/TESS/PROJ/lbouma/CDIPS_LCS/lc_list_{today_YYYYMMDD()}.txt'

with open(lclistpath, 'r') as f:
    lines = f.readlines()

lines = [l.rstrip('\n') for l in lines]

df = get_cdips_catalog()

sourceids = [l.split('/')[-1].split('gaiatwo')[-1].split('-')[0].lstrip('0') for l in lines]

lcdf = pd.DataFrame({'path':lines, 'source_id':sourceids})

lcdf.source_id = lcdf.source_id.astype(str)
df.source_id = df.source_id.astype(str)

mdf = lcdf.merge(df, on='source_id', how='left')

outdir = '/nfs/phtess2/ar0/TESS/PROJ/lbouma/cdips/results/lc_metadata'
outpath = os.path.join(
    outdir, f'source_ids_to_cluster_merge_{today_YYYYMMDD()}.csv'
)
mdf.to_csv(outpath, index=False, sep=';')
Exemplo n.º 6
0
def get_cluster_lc_paths(N_lcs=100):
    """
    Draw light curves from a set of clusters that I think might be good in
    S14-S19 to test planet injection/recovery.

    These are in a list of 8 clusters, and have RP<14.
    """
    from cdips.utils.catalogs import get_cdips_catalog

    df = get_cdips_catalog(ver=0.6)
    df = df[~pd.isnull(df.cluster)]

    cluster_names = [
        "Stephenson_1",  # logt 7.5, 100-500pc, Theia 73, we are familiar
        "Alpha_per",  # logt 7.8, 100-200pc, Theia 133
        "RSG_5",  # logt 7.5, 300-400pc.
        "kc19group_506",  # 350 Myr, 100pc (!!!).
        "kc19group_507",  # 350 Myr, 100-200pc.
        "AB_Dor",  # ~120 Myr, 100-300pc from KC19.
        "Pleiades",  # 120 Myr, 120 pc.
    ]
    special_names = [
        "UBC_1",  # 350 Myr, 300-400pc, Theia 520
    ]

    sel = np.zeros(len(df)).astype(bool)
    for cluster_name in cluster_names:
        sel |= df.cluster.str.contains(cluster_name)

    # avoid e.g., "UBC_186" matching for "UBC_1".
    for cluster_name in special_names:
        sel |= (df.cluster == cluster_name)
        sel |= df.cluster.str.contains(cluster_name + ',')

    sdf = df[sel]

    # NOTE: a further cut, to deal with less crappy data
    sel = sdf.phot_rp_mean_mag < 14
    sdf = sdf[sel]

    outdir = resultsdirectory
    camdpath = os.path.join(outdir, f'camd_{"_".join(cluster_names)}.png')
    if not os.path.exists(camdpath):
        plt.close('all')
        get_yval = (lambda _df: np.array(_df['phot_g_mean_mag'] + 5 * np.log10(
            _df['parallax'] / 1e3) + 5))
        get_xval = (lambda _df: np.array(_df['phot_bp_mean_mag'] - _df[
            'phot_rp_mean_mag']))
        fig, axs = plt.subplots(ncols=2)

        s = 0.5
        axs[0].scatter(get_xval(sdf),
                       get_yval(sdf),
                       c='k',
                       alpha=1,
                       zorder=3,
                       s=s,
                       rasterized=False,
                       linewidths=0.1,
                       marker='o',
                       edgecolors='k')
        axs[0].set_xlabel("BP-RP [mag]")
        axs[0].set_ylabel("M_G [mag]")

        axs[1].scatter(get_xval(sdf),
                       sdf.phot_g_mean_mag,
                       c='k',
                       alpha=1,
                       zorder=3,
                       s=s,
                       rasterized=False,
                       linewidths=0.1,
                       marker='o',
                       edgecolors='k')
        axs[1].set_xlabel("BP-RP [mag]")
        axs[1].set_ylabel("G [mag]")

        fig.savefig(camdpath, bbox_inches='tight', dpi=400)

    # NOTE: OK!  Now, find the light curves, from S14-S19, corresponding to
    # these clusters.
    from cdips.utils.lcutils import make_lc_list
    lclistpath = (
        "/nfs/phtess2/ar0/TESS/PROJ/lbouma/CDIPS_LCS/S14_S19_lc_list_20211019.txt"
    )

    if not os.path.exists(lclistpath):
        make_lc_list(lclistpath, sector_interval=[14, 19])

    lcdf = pd.read_csv(lclistpath, names=["lcpath"])
    lcdf['source_id'] = lcdf.lcpath.apply(lambda x: x.split('/')[-1].split(
        'gaiatwo')[1].split('-')[0].lstrip('0'))

    sdf['source_id'] = sdf.source_id.astype(str)
    mdf = sdf.merge(lcdf, on="source_id", how="left")

    smdf = mdf[~pd.isnull(mdf.lcpath)]

    res = Counter(smdf.cluster)
    print(42 * '-')
    print(
        f'Got {len(smdf)} T<14 light curves in {cluster_names} & {special_names}...'
    )
    print(f'Most common 40:\n{res.most_common(n=40)}')

    outpath = f'S14_S19_20211020_lcpaths_{"_".join(cluster_names)}.csv'
    smdf.to_csv(outpath, index=False)
    print(f'Saved {outpath}')

    lcpaths = nparr(smdf.lcpath)
    np.random.shuffle(lcpaths)

    lcpaths = np.random.choice(lcpaths, size=N_lcs)

    return lcpaths
Exemplo n.º 7
0
def plot_TIC268_nbhd_full(outdir=RESULTSDIR):

    set_style()

    df = get_cdips_catalog(ver=0.4)

    kc19_sel = ((df.cluster.str.contains('NGC_2516')) &
                (df.reference.str.contains('Kounkel_2019')))
    cg18_sel = ((df.cluster.str.contains('NGC_2516')) &
                (df.reference.str.contains('CantatGaudin_2018')))

    target_df = df[df.source_id == 5489726768531119616]  # TIC 2683...
    kc19_df = df[kc19_sel]
    cg18_df = df[cg18_sel]

    ##########

    plt.close('all')

    params = ['ra', 'dec', 'parallax', 'pmra', 'pmdec']
    nparams = len(params)

    qlimd = {
        'ra': 0,
        'dec': 0,
        'parallax': 0,
        'pmra': 0,
        'pmdec': 0,
        'radial_velocity': 0
    }  # whether to limit axis by quantile

    ldict = {
        'ra': r'$\alpha$ [deg]',
        'dec': r'$\delta$ [deg]',
        'parallax': r'$\pi$ [mas]',
        'pmra': r'$\mu_{{\alpha}} \cos\delta$ [mas/yr]',
        'pmdec': r'$\mu_{{\delta}}$ [mas/yr]',
        'radial_velocity': 'RV [km/s]'
    }

    f, axs = plt.subplots(figsize=(6, 6), nrows=nparams - 1, ncols=nparams - 1)

    for i in range(nparams):
        for j in range(nparams):
            print(i, j)
            if j == nparams - 1 or i == nparams - 1:
                continue
            if j > i:
                axs[i, j].set_axis_off()
                continue

            xv = params[j]
            yv = params[i + 1]
            print(i, j, xv, yv)

            axs[i, j].scatter(kc19_df[xv],
                              kc19_df[yv],
                              c='gray',
                              alpha=0.9,
                              zorder=2,
                              s=5,
                              rasterized=True,
                              linewidths=0,
                              label='Core',
                              marker='.')
            axs[i, j].scatter(cg18_df[xv],
                              cg18_df[yv],
                              c='k',
                              alpha=0.9,
                              zorder=3,
                              s=5,
                              rasterized=True,
                              linewidths=0,
                              label='Corona')
            axs[i, j].plot(target_df[xv],
                           target_df[yv],
                           alpha=1,
                           mew=0.5,
                           zorder=8,
                           label='TOI 1937',
                           markerfacecolor='yellow',
                           markersize=14,
                           marker='*',
                           color='black',
                           lw=0)

            # set the axis limits as needed
            if qlimd[xv]:
                xlim = (np.nanpercentile(kc19_df[xv], 25),
                        np.nanpercentile(kc19_df[xv], 75))
                axs[i, j].set_xlim(xlim)
            if qlimd[yv]:
                ylim = (np.nanpercentile(kc19_df[yv], 25),
                        np.nanpercentile(kc19_df[yv], 75))
                axs[i, j].set_ylim(ylim)

            # fix labels
            if j == 0:
                axs[i, j].set_ylabel(ldict[yv])
                if not i == nparams - 2:
                    # hide xtick labels
                    labels = [
                        item.get_text()
                        for item in axs[i, j].get_xticklabels()
                    ]
                    empty_string_labels = [''] * len(labels)
                    axs[i, j].set_xticklabels(empty_string_labels)

            if i == nparams - 2:
                axs[i, j].set_xlabel(ldict[xv])
                if not j == 0:
                    # hide ytick labels
                    labels = [
                        item.get_text()
                        for item in axs[i, j].get_yticklabels()
                    ]
                    empty_string_labels = [''] * len(labels)
                    axs[i, j].set_yticklabels(empty_string_labels)

            if (not (j == 0)) and (not (i == nparams - 2)):
                # hide ytick labels
                labels = [
                    item.get_text() for item in axs[i, j].get_yticklabels()
                ]
                empty_string_labels = [''] * len(labels)
                axs[i, j].set_yticklabels(empty_string_labels)
                # hide xtick labels
                labels = [
                    item.get_text() for item in axs[i, j].get_xticklabels()
                ]
                empty_string_labels = [''] * len(labels)
                axs[i, j].set_xticklabels(empty_string_labels)

    # axs[2,2].legend(loc='best', handletextpad=0.1, fontsize='medium', framealpha=0.7)
    # leg = axs[2,2].legend(bbox_to_anchor=(0.8,0.8), loc="upper right",
    #                       handletextpad=0.1, fontsize='medium',
    #                       bbox_transform=f.transFigure)

    for ax in axs.flatten():
        format_ax(ax)

    f.tight_layout(h_pad=0.1, w_pad=0.1)

    outpath = os.path.join(outdir, 'full_kinematics.png')
    savefig(f, outpath)