Exemple #1
0
def star_catalog_cmd(df):

    f, ax = plt.subplots(figsize=(4, 3))

    ax.scatter(df['phot_bp_mean_mag'] - df['phot_rp_mean_mag'],
               df['phot_g_mean_mag'],
               rasterized=True,
               s=0.2,
               alpha=1,
               linewidths=0,
               zorder=5)

    ax.yaxis.set_ticks_position('both')
    ax.xaxis.set_ticks_position('both')
    ax.get_yaxis().set_tick_params(which='both', direction='in')
    ax.get_xaxis().set_tick_params(which='both', direction='in')
    for tick in ax.xaxis.get_major_ticks():
        tick.label.set_fontsize('small')
    for tick in ax.yaxis.get_major_ticks():
        tick.label.set_fontsize('small')
    ax.set_xlabel('$G_{\mathrm{BP}} - G_{\mathrm{RP}}$')
    ax.set_ylabel('$G$')
    ylim = ax.get_ylim()
    ax.set_ylim((max(ylim), min(ylim)))

    f.tight_layout(pad=0.2)
    savefig(f, '../../results/star_catalog_cmd.png')
Exemple #2
0
def star_catalog_mag_histogram(df, magstr, savpath=None):

    f, ax = plt.subplots(figsize=(4, 3))

    bins = np.arange(np.floor(np.min(df[magstr])),
                     np.ceil(np.max(df[magstr])) + 0.5, 1)
    ax.hist(df[magstr],
            bins=bins,
            cumulative=True,
            color='black',
            fill=False,
            linewidth=0.5)

    ax.yaxis.set_ticks_position('both')
    ax.xaxis.set_ticks_position('both')
    ax.get_yaxis().set_tick_params(which='both', direction='in')
    ax.get_xaxis().set_tick_params(which='both', direction='in')
    for tick in ax.xaxis.get_major_ticks():
        tick.label.set_fontsize('small')
    for tick in ax.yaxis.get_major_ticks():
        tick.label.set_fontsize('small')
    if magstr == 'phot_rp_mean_mag':
        ax.set_xlabel('Apparent mag [$G_\mathrm{{RP}}$]')
    if magstr == 'phot_bp_mean_mag':
        ax.set_xlabel('Apparent mag [$G_\mathrm{{BP}}$]')
    ax.set_ylabel('Cumulative number')
    ax.set_yscale('log')

    ax.set_xlim([2, 16])

    f.tight_layout(pad=0.2)
    if not isinstance(savpath, str):
        savpath = '../../results/star_catalog_mag_histogram_{}.png'.format(
            magstr)
    savefig(f, savpath)
Exemple #3
0
def plot_scatter_x_y_sep(df, outpath):

    f, ax = plt.subplots(figsize=(4, 4))

    norm = mpl.colors.Normalize(vmin=-2., vmax=1.)

    cax = ax.scatter(df['x_meas'],
                     df['y_meas'],
                     c=np.log10(df['sep']),
                     cmap='viridis',
                     s=1,
                     rasterized=True,
                     linewidths=0,
                     zorder=1,
                     norm=norm)

    ax.set_xlabel('Column index [px]')
    ax.set_ylabel('Row index [px]')

    cbar = f.colorbar(cax, extend='both')
    cbar.set_label(
        r'$|\vec{{x}}_{{\mathrm{{measured}}}} - \vec{{x}}_{{\mathrm{{projected}}}}|$ [pixels]'
    )

    savefig(f, outpath)
def plot_zorro_speckle():

    datapath = (
        '../data/WASP4_zorro_speckle/WASP-4_20190928_832_companionbounds.csv')
    df = pd.read_csv(datapath)

    fig, ax = plt.subplots(figsize=(4, 3))

    ax.plot(df.ang_sep, df.delta_mag, color='k')

    img = mpimg.imread(
        '../data/WASP4_zorro_speckle/WASP-4_20190928_832_img.png')

    # [left, bottom, width, height]
    inset = fig.add_axes([0.55, 0.23, .4, .4])
    inset.imshow(img)
    inset.axis('off')
    plt.setp(inset, xticks=[], yticks=[])

    ax.set_ylabel('$\Delta$mag (832 nm)')
    ax.set_xlabel('Angular separation [arcsec]')

    ax.get_yaxis().set_tick_params(which='both', direction='in')
    ax.get_xaxis().set_tick_params(which='both', direction='in')
    ax.tick_params(right=True, which='both', direction='in')
    ax.tick_params(top=True, which='both', direction='in')
    fig.tight_layout(h_pad=0, w_pad=0)

    figpath = ('../results/zorro_speckle.png')
    savefig(fig, figpath)
Exemple #5
0
def plot_sep_hist(df, outpath):

    f, ax = plt.subplots(figsize=(4, 3))

    weights = np.ones_like(nparr(df['sep'])) / float(len(df))

    ax.hist(df['sep'],
            bins=np.logspace(-2, 1, 19),
            weights=weights,
            color='black',
            fill=False,
            linewidth=0.5)

    ax.text(
        0.98,
        0.98,
        'mean={:.3f}px\nstdev={:.3f}px\nmedian={:.3f}px\n90$^{{\mathrm{{th}}}}$pctile={:.3f}px'
        .format(df['sep'].mean(), df['sep'].std(), df['sep'].median(),
                df['sep'].quantile(q=0.9)),
        va='top',
        ha='right',
        transform=ax.transAxes)
    ax.set_xscale('log')
    ax.set_xlabel(
        r'$|\vec{{x}}_{{\mathrm{{measured}}}} - \vec{{x}}_{{\mathrm{{projected}}}}|$ [pixels]'
    )
    #ax.set_xlabel('Measured - projected centroid separation [pixels]')
    ax.set_ylabel('Relative fraction')

    ax.yaxis.set_ticks_position('both')
    ax.xaxis.set_ticks_position('both')
    ax.get_yaxis().set_tick_params(which='both', direction='in')
    ax.get_xaxis().set_tick_params(which='both', direction='in')

    savefig(f, outpath)
Exemple #6
0
def plot_quiver_meas_proj_sep(df, outpath):

    f, ax = plt.subplots(figsize=(4, 4))

    norm = mpl.colors.Normalize(vmin=-2., vmax=1.)

    cax = ax.quiver(
        df['x_meas'],
        df['y_meas'],
        df['x_proj'] - df['x_meas'],
        df['y_proj'] - df['y_meas'],
        np.log10(df['sep']),
        angles='xy',
        scale_units='xy',
        scale=0.02,  #1,
        cmap='viridis',
        norm=norm)

    divider = make_axes_locatable(ax)
    cax1 = divider.append_axes('right', size='5%', pad=0.05)

    cbar = f.colorbar(cax, cax=cax1, extend='both')
    cbar.set_label(
        r'$|\vec{{x}}_{{\mathrm{{measured}}}} - \vec{{x}}_{{\mathrm{{projected}}}}|$ [pixels]'
    )

    ax.set_xlabel('Column index [px]')
    ax.set_ylabel('Row index [px]')

    ax.yaxis.set_ticks_position('both')
    ax.xaxis.set_ticks_position('both')
    ax.get_yaxis().set_tick_params(which='both', direction='in')
    ax.get_xaxis().set_tick_params(which='both', direction='in')

    savefig(f, outpath)
Exemple #7
0
def plot_catalog_to_gaia_match_statistics(bigdf, outpath, isD14=False):

    if not isD14:
        dist_arcsec = (np.array(bigdf['dist_deg'])*u.deg).to(u.arcsec)
    else:
        dist_arcsec = (np.array(bigdf['dist'])*u.deg).to(u.arcsec)

    f,axs = plt.subplots(nrows=1, ncols=3, figsize=(12,4))

    axs[0].hist(dist_arcsec.value, bins=np.arange(0,5.5,0.5), color='black',
                fill=False, linewidth=0.5)

    axs[0].set_xlabel('Distance [arcsec]', fontsize='x-large')
    axs[0].set_ylabel('Number per bin', fontsize='x-large')
    axs[0].set_yscale('log')

    if isD14:
        axs[1].hist(bigdf['gaia_gmag']-bigdf['gmag_estimate'], color='black',
                    bins=np.arange(-2,2+0.5,0.5),
                    fill=False, linewidth=0.5)
    else:
        axs[1].hist(bigdf['gmag_match_minus_estimate'], color='black',
                    bins=np.arange(-2,2+0.5,0.5),
                    fill=False, linewidth=0.5)

    axs[1].set_xlabel('$G_{\mathrm{true}}$ - '
                      '$G_{\mathrm{pred}}$', fontsize='x-large')
    axs[1].set_ylabel('Number per bin', fontsize='x-large')
    axs[1].set_xlim([-2.1,2.1])
    axs[1].set_yscale('log')

    if isD14:
        axs[2].scatter(bigdf['gaia_gmag'],
                       bigdf['gaia_gmag']-bigdf['gmag_estimate'], s=5,
                       alpha=0.1, rasterized=True, linewidths=0, color='black')
    else:
        axs[2].scatter(bigdf['gmag_match'], bigdf['gmag_match_minus_estimate'],
                       s=5, alpha=0.1, rasterized=True, linewidths=0,
                       color='black')

    axs[2].set_xlabel('$G_{\mathrm{true}}$', fontsize='x-large')
    axs[2].set_ylabel('$G_{\mathrm{true}}$ - '
                      '$G_{\mathrm{pred}}$', fontsize='x-large')
    axs[2].set_xlim([4,18])
    axs[2].set_ylim([-2.1,2.1])

    for ax in axs:
        ax.yaxis.set_ticks_position('both')
        ax.xaxis.set_ticks_position('both')
        ax.get_yaxis().set_tick_params(which='both', direction='in')
        ax.get_xaxis().set_tick_params(which='both', direction='in')
        for tick in ax.xaxis.get_major_ticks():
            tick.label.set_fontsize('large')
        for tick in ax.yaxis.get_major_ticks():
            tick.label.set_fontsize('large')

    f.tight_layout(pad=0.2, w_pad=0.5)
    savefig(f, outpath)
Exemple #8
0
def star_catalog_skymap(df, pfdf, closesubset=False):

    if closesubset:
        df = df[df['parallax'] > 0]
        plx_as = df['parallax'] / 1000
        df = df[1 / plx_as < 1000]

    ra = coord.Angle(nparr(df['ra']) * u.deg)
    ra = ra.wrap_at(180 * u.deg)
    dec = coord.Angle(nparr(df['dec']) * u.deg)

    f = plt.figure(figsize=(4, 3))
    ax = f.add_subplot(111, projection='mollweide')

    ax.scatter(ra.radian,
               dec.radian,
               rasterized=True,
               s=0.5,
               alpha=0.5,
               linewidths=0,
               zorder=5,
               c='C0',
               label='CDIPS stars')
    if isinstance(pfdf, pd.DataFrame):
        ra = coord.Angle(nparr(pfdf['ra_x']) * u.deg)
        ra = ra.wrap_at(180 * u.deg)
        dec = coord.Angle(nparr(pfdf['dec_x']) * u.deg)
        ax.scatter(ra.radian,
                   dec.radian,
                   rasterized=True,
                   s=0.5,
                   alpha=0.5,
                   linewidths=0,
                   zorder=5,
                   c='C1',
                   label='Sector 6')

    ax.set_xticklabels([
        '14h', '16h', '18h', '20h', '22h', '0h', '2h', '4h', '6h', '8h', '10h'
    ])
    ax.tick_params(axis='both', which='major', labelsize='x-small')
    ax.tick_params(axis='both', which='minor', labelsize='x-small')
    ax.grid(True, linestyle='--', linewidth=0.5, alpha=0.3, zorder=-1)

    f.tight_layout()
    f.subplots_adjust(left=0.1, right=0.9, top=0.8, bottom=0.2)

    csstr = '_closesubset' if closesubset else ''
    opstr = '_overplotlcs' if isinstance(pfdf, pd.DataFrame) else ''

    outpath = '../../results/star_catalog_skymap{csstr}{opstr}.png'.format(
        csstr=csstr, opstr=opstr)
    savefig(f, outpath)
Exemple #9
0
def star_catalog_hrd_scat(df):

    # 2d SCATTER CASE
    df = df[df['parallax'] > 0]
    plx_as = df['parallax'] / 1000
    df = df[1 / plx_as < 1000]

    f, ax = plt.subplots(figsize=(4, 3))

    color = df['phot_bp_mean_mag'] - df['phot_rp_mean_mag']
    M_omega = df['phot_g_mean_mag'] + 5 * np.log10(df['parallax'] / 1000) + 5

    ax.scatter(color,
               M_omega,
               rasterized=True,
               s=0.1,
               alpha=1,
               linewidths=0,
               zorder=5)

    ax.yaxis.set_ticks_position('both')
    ax.xaxis.set_ticks_position('both')
    ax.get_yaxis().set_tick_params(which='both', direction='in')
    ax.get_xaxis().set_tick_params(which='both', direction='in')
    for tick in ax.xaxis.get_major_ticks():
        tick.label.set_fontsize('small')
    for tick in ax.yaxis.get_major_ticks():
        tick.label.set_fontsize('small')
    ax.set_xlabel('$G_{\mathrm{BP}} - G_{\mathrm{RP}}$')
    ax.set_ylabel('$M_\omega = G + 5\log_{10}(\omega_{\mathrm{as}}) + 5$')
    ylim = ax.get_ylim()
    ax.set_ylim((max(ylim), min(ylim)))

    ax.set_xlim((-0.7, 4.3))

    txtstr = ('$\omega>0$, $1/\omega_{\mathrm{as}} < 1000$, ' +
              '{} stars'.format(len(df)))
    ax.text(0.97,
            0.97,
            txtstr,
            ha='right',
            va='top',
            fontsize='x-small',
            transform=ax.transAxes)

    f.tight_layout(pad=0.2)
    savefig(f, '../../results/star_catalog_hrd_scat.png')
Exemple #10
0
def plot_highresimg_mass_semimaj_constraints(df, instrument=None, df2=None):

    assert instrument in ['Zorro', 'NIRC2', 'both']

    n_grid_edges = 51
    mass_grid = (np.logspace(np.log10(1), np.log10(300), num=n_grid_edges) *
                 u.Mjup)
    sma_grid = (np.logspace(np.log10(3), np.log10(500), num=n_grid_edges) *
                u.AU)

    fig, ax = plt.subplots(figsize=(4, 3))

    dist_pc = 1 / (3.7145e-3)  # Bouma+2019, Table 1

    if df2 is None:
        df['sma_AU'] = df.ang_sep * dist_pc
        ax.plot(
            nparr(df['sma_AU']) * u.AU,
            (nparr(df['m_comp/m_sun']) * u.Msun).to(u.Mjup))
    if not df2 is None:
        labels = ['Zorro', 'NIRC2']
        for l, d in zip(labels, [df, df2]):
            d['sma_AU'] = d.ang_sep * dist_pc
            ax.plot(nparr(d['sma_AU']) * u.AU,
                    (nparr(d['m_comp/m_sun']) * u.Msun).to(u.Mjup),
                    label=l)
            ax.legend()

    ax.set_xscale('log')
    ax.set_yscale('log')

    ax.set_xlabel('Semi-major axis [AU]')
    ax.set_ylabel('Companion mass [M$_\mathrm{{jup}}$]')

    ax.set_xlim([sma_grid.value.min(), sma_grid.value.max()])
    ax.set_ylim([mass_grid.value.min(), 1000])

    ax.get_yaxis().set_tick_params(which='both', direction='in')
    ax.get_xaxis().set_tick_params(which='both', direction='in')
    fig.tight_layout(h_pad=0, w_pad=0)

    figpath = '../results/{}_mass_semimaj_constraints.png'.format(instrument)
    savefig(fig, figpath)
Exemple #11
0
def plot_quilt_PCs(overwrite=1, paper_aspect_ratio=1):
    """
    paper_aspect_ratio: if true, uses figsize set for paper. if false, uses
    figsize set for poster.
    """

    aspectstr = '' if paper_aspect_ratio else '_poster'
    outpath = os.path.join(OUTDIR, 'quilt_PCs{}.png'.format(aspectstr))
    if os.path.exists(outpath) and not overwrite:
        print('found {} and not overwrite; skip'.format(outpath))
        return

    # looked through by eye in geeqie. copied from geeqie paths, if they looked
    # good enough to show off in a plot like this. PEP8 forgive me.
    fpaths = [
        '/home/lbouma/proj/cdips/results/fit_gold/sector-6/fitresults/hlsp_cdips_tess_ffi_gaiatwo0003007171311355035136-0006_tess_v01_llc/hlsp_cdips_tess_ffi_gaiatwo0003007171311355035136-0006_tess_v01_llc_fitparameters_phased_mandelagol_fit_empiricalerrs.png',
        '/home/lbouma/proj/cdips/results/fit_gold/sector-6/fitresults/hlsp_cdips_tess_ffi_gaiatwo0003125263468681400320-0006_tess_v01_llc/hlsp_cdips_tess_ffi_gaiatwo0003125263468681400320-0006_tess_v01_llc_fitparameters_phased_mandelagol_fit_empiricalerrs.png',
        '/home/lbouma/proj/cdips/results/fit_gold/sector-6/fitresults/hlsp_cdips_tess_ffi_gaiatwo0003220266049321724416-0006_tess_v01_llc/hlsp_cdips_tess_ffi_gaiatwo0003220266049321724416-0006_tess_v01_llc_fitparameters_phased_mandelagol_fit_empiricalerrs.png',
        '/home/lbouma/proj/cdips/results/fit_gold/sector-7/fitresults/hlsp_cdips_tess_ffi_gaiatwo0003027361888196408832-0007_tess_v01_llc/hlsp_cdips_tess_ffi_gaiatwo0003027361888196408832-0007_tess_v01_llc_fitparameters_phased_mandelagol_fit_empiricalerrs.png',
        '/home/lbouma/proj/cdips/results/fit_gold/sector-7/fitresults/hlsp_cdips_tess_ffi_gaiatwo0003114869682184835584-0007_tess_v01_llc/hlsp_cdips_tess_ffi_gaiatwo0003114869682184835584-0007_tess_v01_llc_fitparameters_phased_mandelagol_fit_empiricalerrs.png',
        '/home/lbouma/proj/cdips/results/fit_gold/sector-7/fitresults/hlsp_cdips_tess_ffi_gaiatwo0005510676828723793920-0007_tess_v01_llc/hlsp_cdips_tess_ffi_gaiatwo0005510676828723793920-0007_tess_v01_llc_fitparameters_phased_mandelagol_fit_empiricalerrs.png',
        '/home/lbouma/proj/cdips/results/fit_gold/sector-7/fitresults/hlsp_cdips_tess_ffi_gaiatwo0005546259498914769280-0007_tess_v01_llc/hlsp_cdips_tess_ffi_gaiatwo0005546259498914769280-0007_tess_v01_llc_fitparameters_phased_mandelagol_fit_empiricalerrs.png',
        '/home/lbouma/proj/cdips/results/fit_gold/sector-7/fitresults/hlsp_cdips_tess_ffi_gaiatwo0005605128927705695232-0007_tess_v01_llc/hlsp_cdips_tess_ffi_gaiatwo0005605128927705695232-0007_tess_v01_llc_fitparameters_phased_mandelagol_fit_empiricalerrs.png',
        '/home/lbouma/proj/cdips/results/fit_gold/sector-7/fitresults/hlsp_cdips_tess_ffi_gaiatwo0005617126180115568256-0007_tess_v01_llc/hlsp_cdips_tess_ffi_gaiatwo0005617126180115568256-0007_tess_v01_llc_fitparameters_phased_mandelagol_fit_empiricalerrs.png'
    ]

    np.random.seed(42)
    spaths = np.random.choice(fpaths, size=3 * 2, replace=False)
    ylims = [  # for seed 42
        (0.957, 1.015), (0.97, 1.017), (0.995, 1.003), (0.983, 1.008),
        (0.983, 1.008), (0.972, 1.008)
    ]
    yticks = [[0.975, 1.000], [0.98, 1.00], [0.996, 1.000], [0.99, 1.00],
              [0.990, 1.000], [0.98, 1.00]]
    alphas = np.ones_like(spaths)
    #alphas = [
    #    0.45, 0.6, 0.5, 0.45, 0.5, 0.45
    #]
    inds = [''] * 6  # ['a)','b)','c)','d)','e)','f)']

    gaiaids = list(
        map(
            lambda x: int(
                os.path.basename(x).split('gaiatwo')[1].split('-')[0].lstrip(
                    '0')), spaths))

    if paper_aspect_ratio:
        f, axs = plt.subplots(nrows=3, ncols=2, figsize=(6, 4.5))
    else:
        f, axs = plt.subplots(nrows=3, ncols=2, figsize=(6, 3))
    axs = axs.flatten()

    ix = 0
    for fpath, ax, a, ind in zip(spaths, axs, alphas, inds):
        plot_phase_PC(fpath, ax, ind, alpha=a)
        print('{}: {}'.format(ind, gaiaids[ix]))
        ix += 1

    for ix, ax in enumerate(axs):
        ax.set_ylim(ylims[ix])
        if yticks[ix] is not None:
            ax.set_yticks(yticks[ix])
        ax.yaxis.set_ticks_position('both')
        ax.xaxis.set_ticks_position('both')
        ax.get_yaxis().set_tick_params(which='both', direction='in')
        ax.get_xaxis().set_tick_params(which='both', direction='in')

    #f.text(0.5,0, 'Phase', ha='center')
    f.text(0.5,
           -0.02,
           'Time from transit center [hours]',
           ha='center',
           fontsize='medium')
    f.text(-0.01,
           0.5,
           'Relative flux',
           va='center',
           rotation=90,
           fontsize='medium')

    f.tight_layout(h_pad=0.35, w_pad=0.85, pad=0.8)
    savefig(f, outpath)
Exemple #12
0
def plot_mass_semimaj_constraints(prob_arr=None,
                                  mass_grid=None,
                                  sma_grid=None,
                                  with_contrast=False,
                                  discrete_color=False,
                                  linear_z=False,
                                  figpath=None,
                                  rvsonly=False):

    if prob_arr is None:

        # n_mass_grid_edges = 31 # a 4x4 grid has 5 edges. want: 64+1, 128+1...
        # n_sma_grid_edges = 31 # a 4x4 grid has 5 edges.
        # n_injections_per_cell = 16 # 500 # want: 500
        n_mass_grid_edges = 129  # a 4x4 grid has 5 edges. want: 51
        n_sma_grid_edges = 129  # a 4x4 grid has 5 edges. want: 51
        n_injections_per_cell = 512  # 500 # want: 500

        mass_grid = (
            np.logspace(np.log10(1), np.log10(900), num=n_mass_grid_edges) *
            u.Mjup)
        sma_grid = (
            np.logspace(np.log10(3), np.log10(500), num=n_sma_grid_edges) *
            u.AU)

        sizestr = '{}x{}x{}'.format(n_mass_grid_edges - 1,
                                    n_sma_grid_edges - 1,
                                    n_injections_per_cell)
        pklpath = ('../data/rv_simulations/mass_semimaj_loglikearr_{}.pickle'.
                   format(sizestr))
        log_like_arr = pickle.load(open(pklpath, 'rb'))
        ao_detected_arr = pickle.load(
            open(pklpath.replace('loglikearr', 'aodetectedarr'), 'rb'))

        #
        # Convert log-likelihood values to relative probability by taking the exp.
        # Then average out the "sample" dimension (mass, sma, eccentricity, etc).
        #
        rv_log_like = np.log(np.exp(log_like_arr).mean(axis=2))

        rv_and_ao_log_like = np.log(
            nparr(np.exp(log_like_arr) * (1 - ao_detected_arr)).mean(axis=2))

        # -2*logprob == chi^2
        # Convert likelihood values to a normalized probability via
        #   P ~ -exp(-chi^2/2)
        rv_prob_arr = np.exp(rv_log_like) / np.exp(rv_log_like).sum().sum()

        rv_and_ao_prob_arr = np.exp(rv_and_ao_log_like) / np.exp(
            rv_and_ao_log_like).sum().sum()

        prob_arr = rv_and_ao_prob_arr
        if rvsonly:
            prob_arr = rv_prob_arr

    #################
    # make the plot #
    #################

    fig, ax = plt.subplots(figsize=(4, 3))

    X, Y = np.meshgrid(sma_grid[:-1].value, mass_grid[:-1].value)

    cmap = plt.cm.gray_r

    if not linear_z:

        cutoff = -6.3

        if discrete_color:
            bounds = np.round(np.linspace(cutoff,
                                          np.log10(prob_arr).max(), 5), 1)
            norm = mpl.colors.BoundaryNorm(bounds, cmap.N)
        else:
            norm = mpl.colors.Normalize(vmin=np.log10(prob_arr).max(),
                                        vmax=cutoff)

        im = ax.pcolormesh(X,
                           Y,
                           np.log10(prob_arr),
                           cmap=cmap,
                           norm=norm,
                           shading='flat')  # vs 'gouraud'

    else:

        if discrete_color:
            bounds = np.linspace(10**(cutoff), prob_arr.max(), 5)
            norm = mpl.colors.BoundaryNorm(bounds, cmap.N)
        else:
            norm = mpl.colors.Normalize(vmin=prob_arr.max(), vmax=10**(cutoff))

        im = ax.pcolormesh(X, Y, prob_arr, cmap=cmap, norm=norm)

    if with_contrast:

        from contrast_to_masslimit import get_companion_bounds
        zdf = get_companion_bounds('Zorro')

        dist_pc = 1 / (3.7145e-3)  # Bouma+2019, Table 1
        zdf['sma_AU'] = zdf.ang_sep * dist_pc

        ax.plot(nparr(zdf['sma_AU']) * u.AU,
                (nparr(zdf['m_comp/m_sun']) * u.Msun).to(u.Mjup),
                color='C0',
                lw=1,
                zorder=4)

        # NOTE: not really ruled out!
        # t = ax.text(
        #     100, 450, 'Ruled out by\nspeckle imaging',
        #     fontsize=7.5, ha='center', va='center',
        #     # path_effects=[pe.withStroke(linewidth=0.5, foreground="white")],
        #     color='C0', zorder=3
        # )

        # ax.fill_between(
        #     nparr(zdf['sma_AU'])*u.AU,
        #     (nparr(zdf['m_comp/m_sun'])*u.Msun).to(u.Mjup),
        #     1000,
        #     color='white',
        #     alpha=0.8,
        #     zorder=2
        # )

    _sma = np.logspace(np.log10(90), np.log10(180))
    _mass_min = 2  # rescale
    k = _mass_min / min(_sma**2)
    _mass = k * _sma**2
    ax.plot(_sma, _mass, color='k', lw=1)
    ax.text(np.percentile(_sma, 60),
            np.percentile(_mass, 40),
            '$M\propto a^2$',
            fontsize=7.5,
            ha='left',
            va='center',
            path_effects=[pe.withStroke(linewidth=0.5, foreground="white")],
            color='black')

    ax.set_xscale('log')
    ax.set_yscale('log')

    ax.set_xlabel('Semi-major axis [AU]')
    ax.set_ylabel('Companion mass [M$_\mathrm{{Jup}}$]')

    cbar = fig.colorbar(im,
                        orientation='vertical',
                        extend='min',
                        label='$\log_{{10}}$(probability)')
    cbar.ax.tick_params(labelsize=6, direction='out')

    ax.set_ylim([1, 1e3])
    ax.set_xlim([3, 310])

    ax.get_yaxis().set_tick_params(which='both', direction='in')
    ax.get_xaxis().set_tick_params(which='both', direction='in')
    ax.tick_params(right=True, which='both', direction='in')
    ax.tick_params(top=True, which='both', direction='in')
    fig.tight_layout(h_pad=0, w_pad=0)

    dstr = '_discretecolor' if discrete_color else ''
    wstr = '_with_contrast' if with_contrast else ''
    lzstr = '_linearz' if linear_z else ''
    rvstr = '_rvonly' if rvsonly else ''
    if figpath is None:
        figpath = ('../results/mass_semimaj_constraints{}{}{}{}.png'.format(
            wstr, dstr, lzstr, rvstr))
    savefig(fig, figpath)
Exemple #13
0
def plot_quilt_s6_s7(overwrite=1):

    outpath = os.path.join(OUTDIR, 'quilt_s6_s7.png')
    if os.path.exists(outpath) and not overwrite:
        print('found {} and not overwrite; skip'.format(outpath))
        return

    gaiaids = [
        3064530810048196352,  # TOI 496 -- V-shaped giant PC, NGC 2548
        3080104185367102592,  # TOI 625, a UMS HJ. T=9.6, so nice.
        3027361888196408832,  # eccentric EB
        3125738423345810048,  # 80Myr member semidetached EB with sick OOT
        3326715714242517248,  # V684 Mon, 10 Myr old detached binary.
        3064487241899832832,  # semidetached EB, NGC 2548
        3024952755135530496,  # two-spotted pulsator, NGC 2184
        3209428644243836928,  # M42 Dias, rapid rotating m dwarf, V468 Ori
        3214130293403123712  # zhuchang-class weirdo.
        #2949587413510194688, # double-hump rotator / pulsator??
        #5274902193830445312  # sick PMS star. pulsating? spots??
    ]

    lctypes = ['PCA2'] * 9
    pgtypes = ['tls'] * 3 + ['gls'] + ['tls'] * 2 + ['gls', 'gls', 'gls']
    peakindices = [0, 0, 0, 0, 1, 0, 0, 0, 0]

    lcpaths = []
    for g in gaiaids:
        globpaths = glob(
            '/home/lbouma/cdips_lcs/sector-?/cam?_ccd?/*{}*.fits'.format(g))
        if len(globpaths) >= 1:
            # weird edge case
            if g == 2949587413510194688:
                lcpaths.append(globpaths[1])
                continue
            lcpaths.append(globpaths[0])
        else:
            raise AssertionError('error! got no lc matches')

    ylims = [
        None, (0.989, 1.005), None, None, None, None, None, (0.96, 1.04), None
    ]
    yticks = [[0.98, 1.00], [0.99, 1.00], None, [0.90, 1.00], [0.93, 1.00],
              [0.98, 1.01], [0.98, 1.01], [0.97, 1.03], [0.85, 1.15]]

    alphas = np.ones_like(lcpaths).astype(int) * 0.7

    inds = [''] * len(lcpaths)

    f, axs = plt.subplots(nrows=3, ncols=3, figsize=(7.5, 4.5))
    axs = axs.flatten()

    ix = 0

    overwritecsv = 0  # option to save time

    for fpath, ax, a, ind, lctype, pgtype, peakindex in zip(
            lcpaths, axs, alphas, inds, lctypes, pgtypes, peakindices):

        plot_phase(fpath,
                   ax,
                   ind,
                   alpha=a,
                   lctype=lctype,
                   periodogramtype=pgtype,
                   peakindex=peakindex,
                   overwritecsv=overwritecsv)
        print('{}: {}'.format(ind, gaiaids[ix]))
        ix += 1

        if ix < 7:
            ax.set_xticklabels('')

    for ix, ax in enumerate(axs):

        if ylims[ix] is not None:
            ax.set_ylim(ylims[ix])

        if yticks[ix] is not None:
            ax.set_yticks(yticks[ix])

        ax.yaxis.set_major_formatter(FormatStrFormatter('%.2f'))
        ax.yaxis.set_ticks_position('both')
        ax.xaxis.set_ticks_position('both')
        ax.get_yaxis().set_tick_params(which='both', direction='in')
        ax.get_xaxis().set_tick_params(which='both', direction='in')

        for tick in ax.yaxis.get_major_ticks():
            tick.label.set_fontsize('small')
        for tick in ax.xaxis.get_major_ticks():
            tick.label.set_fontsize('small')

    f.text(0.5, -0.035, 'Phase', ha='center', fontsize='medium')
    f.text(-0.03,
           0.5,
           'Relative flux',
           va='center',
           rotation=90,
           fontsize='medium')

    f.tight_layout(h_pad=0.15, w_pad=0.5, pad=0.1)

    savefig(f, outpath)