Example #1
0
def periodradius(epos, SNR=True, Parametric=False):

	f, (ax, axR, axP)= helpers.make_panels(plt)
	
	sim=epos.synthetic_survey
	title='Simulated Detections'
	fsuffix='detect'

	if SNR:
		transit=epos.transit
		title= 'Simulated Transiting Planets'
		fsuffix='transit'
	
	''' plot R(P), main panel'''
	ax.set_title(title)
	helpers.set_axes(ax, epos, Trim=True)
	if SNR: ax.plot(transit['P'], transit['Y'], ls='', marker='.', color='C6')
	ax.plot(sim['P'], sim['Y'], ls='', marker='.', color='C0')

	''' Period side panel '''
	#helpers.set_axis_distance(axP, epos, Trim=True)
	axP.set_xlabel(ax.get_xlabel())
	#axP.set_yscale('log')
	#axP.set_ylim([2e-3,5])	
	#axP.set_yticks([0.01,0.1,1])
	#axP.set_yticklabels(['1%','10%','100%'])
	axP.yaxis.tick_right()
	axP.yaxis.set_ticks_position('both')
	#axP.tick_params(axis='y', which='minor',left='off',right='off')
	
	if SNR: axP.hist(transit['P'], bins=epos.MC_xvar, color='C6')
	axP.hist(sim['P'], bins=epos.MC_xvar)

	''' Radius side panel'''
	#helpers.set_axis_size(axR, epos, Trim=True, In= epos.MassRadius)
	axR.set_ylabel(ax.get_ylabel())

	#axR.set_xscale('log')
	#axR.set_xlim([2e-3,5])
	#axR.set_xticks([1,10,100,1000])
	#axR.set_xticklabels(['1','10','100','1000'], rotation=70)
	for tick in axR.get_xticklabels():
		tick.set_rotation(70)
	#axR.tick_params(axis='x', which='minor',top='off',bottom='off')
	#axP.tick_params(axis='y', which='minor',left='off',right='off')

	if SNR: axR.hist(transit['Y'],orientation='horizontal', bins=epos.MC_yvar, color='C6')
	axR.hist(sim['Y'],orientation='horizontal', bins=epos.MC_yvar)
	
	# labels
	if SNR:
		xpos= epos.MC_xvar[-1]
		ypos= axP.get_ylim()[-1]/1.05
		axP.text(xpos, ypos, 'Detected ', color='C0', ha='right', va='top')
		axP.text(xpos, ypos/1.3, 'Undetected ', color='C6', ha='right', va='top')
	
	#ax.legend(loc='lower left', shadow=False, prop={'size':14}, numpoints=1)
	helpers.save(plt, '{}output/periodradius.{}'.format(epos.plotdir,fsuffix))
Example #2
0
def periodratio_inc(epos, color='C1', imin=1e-2):
    pfm = epos.pfm

    f, (ax, axy, axx) = helpers.make_panels(plt, Fancy=True)
    ''' Inc-sma'''
    ax.set_title('Input Multi-planets {}'.format(epos.name))

    ax.set_xlabel('Period ratio')
    ax.set_ylabel('Inclination [degree]')

    ax.set_xlim(0.9, 10)
    ax.set_ylim(imin, 90)

    ax.set_xscale('log')
    ax.set_yscale('log')
    ''' grids '''
    dP = np.logspace(0, 1)
    dP_bins = np.logspace(0, 1, 15)

    #ax.axhline(np.median(pfm['inc']), ls='--')
    single = pfm['dP'] == np.nan
    inner = pfm['dP'] == 1
    nth = pfm['dP'] > 1

    # exoplanet data + hist
    ax.plot(pfm['dP'][nth], epos.pfm['inc'][nth], color=color, **fmt_symbol)

    # print pfm['dP'][single]
    # print pfm['dP'][nth]
    # print pfm['dP'][inner]
    # print pfm['dP'][nth].size, pfm['np'] # ok

    #ax.plot(pfm['dP'][single], pfm['R'][single], color='0.7', **fmt_symbol)
    #ax.plot(pfm['dP'][nth], pfm['R'][nth], color=color, **fmt_symbol)
    #ax.plot(pfm['dP'][inner], pfm['R'][inner], color='C1', **fmt_symbol)
    ''' Histogram Period Ratio'''
    axx.hist(pfm['dP'][nth], bins=dP_bins, color=color)
    ax.axvline(np.median(pfm['dP'][nth]), ls='--', color=color)

    ax.axvline(2, ls='--', color='b', zorder=0)
    ax.axvline(1.5, ls='--', color='b', zorder=0)
    ''' Histogram Inclination'''
    #axy.set_yscale('log')
    #axy.set_ylim(ax.get_ylim())
    inc = np.logspace(np.log10(imin), 2)
    axy.hist(pfm['inc'], bins=inc, orientation='horizontal', color=color)

    #helpers.set_axes(ax, epos, Trim=True)
    #helpers.set_axis_distance(axP, epos, Trim=True)

    helpers.save(plt, epos.plotdir + 'model/Pratio-inc')
Example #3
0
def periodradius(epos, Nth=False, MC=True):

    f, (ax, axR, axP) = helpers.make_panels(plt)

    if MC:
        sim = epos.synthetic_survey
        ID = sim['ID']
        P = sim['P']
        Y = sim['Y']
        outdir = 'output'
        title = 'Simulated Detections'
    else:
        ID = epos.obs_starID
        P = epos.obs_xvar
        Y = epos.obs_yvar
        outdir = 'survey'
        title = r'Planet Candidates (score$\geq$0.9)'
    ''' plot R(P), main panel'''
    ax.set_title(title)
    helpers.set_axes(ax, epos, Trim=True)
    ''' Period side panel '''
    helpers.set_axis_distance(axP, epos, Trim=True)
    #axP.set_yscale('log')
    #axP.set_ylim([2e-3,5])
    #axP.set_yticks([0.01,0.1,1])
    #axP.set_yticklabels(['1%','10%','100%'])
    axP.yaxis.tick_right()
    axP.yaxis.set_ticks_position('both')
    #axP.tick_params(axis='y', which='minor',left='off',right='off')

    #axP.hist(sim['P'], bins=epos.MC_xvar, color='0.7')
    ''' Radius side panel'''
    helpers.set_axis_size(axR, epos, Trim=True, In=epos.MassRadius)

    #axR.set_xscale('log')
    #axR.set_xlim([2e-3,5])
    #axR.set_xticks([1,10,100,1000])
    #axR.set_xticklabels(['1','10','100','1000'], rotation=70)
    for tick in axR.get_xticklabels():
        tick.set_rotation(70)
    #axR.tick_params(axis='x', which='minor',top='off',bottom='off')
    #axP.tick_params(axis='y', which='minor',left='off',right='off')
    ''' which multiplanets to color '''
    # 	single, multi= EPOS.multi.indices(sim['ID'])
    # 	for k, (label, subset) in enumerate(zip(['single','multi'],[single, multi])):
    # 		ax.plot(sim['P'][subset], sim['Y'][subset], ls='', marker='.', mew=0, ms=5.0, \
    # 			label=label)

    if Nth:
        single, multi, ksys, multis = EPOS.multi.nth_planet(ID, P)
        suffix = '.nth'
        label_single = 'single'
    else:
        single, multi, ksys, multis = EPOS.multi.indices(ID)
        suffix = ''
        label_single = '1'

    ax.plot(P[single], Y[single], ls='', marker='.', \
      color='0.7', label=label_single)
    ''' Multiplanets with colors'''
    Stacked = True
    plist = []
    ylist = []
    colors = []
    CDF = False
    #stacked histogram

    for k, subset in zip(ksys, multis):
        ht, = ax.plot(P[subset], Y[subset], ls='', marker='.', \
         label=k)

        if not CDF:
            if Stacked:
                plist.insert(0, P[subset])
                ylist.insert(0, Y[subset])
                colors.insert(0, ht.get_color())
            # pdf
            else:
                axP.hist(P[subset],
                         bins=epos.MC_xvar,
                         color=ht.get_color(),
                         histtype='step')
                if k == ksys[-1]:
                    axP.hist(P[single],
                             bins=epos.MC_xvar,
                             color='0.7',
                             histtype='step')
        else:
            # cumulative
            Plist = np.sort(P[subset])
            axP.step(Plist, np.arange(Plist.size, dtype=float) / Plist.size)

    if Stacked:
        plist.append(P[single])
        ylist.append(Y[single])
        colors.append('0.7')
        axP.hist(plist, bins=epos.MC_xvar, color=colors, histtype='barstacked')
        axR.hist(ylist,
                 bins=epos.MC_yvar,
                 orientation='horizontal',
                 color=colors,
                 histtype='barstacked')

    else:
        #axR.hist(Y,orientation='horizontal', bins=epos.MC_yvar, color='0.7')
        axR.hist(Y,
                 orientation='horizontal',
                 bins=epos.MC_yvar,
                 color='k',
                 histtype='step')
        axR.hist(Y[single],
                 orientation='horizontal',
                 bins=epos.MC_yvar,
                 color='0.7')

    #ax.legend(loc='lower left', shadow=False, prop={'size':14}, numpoints=1)
    ax.legend(bbox_to_anchor=(1.0, 1.0),
              markerscale=2,
              frameon=True,
              borderpad=0.2,
              handlelength=1,
              handletextpad=0.2)

    helpers.save(plt, '{}{}/PR.multi{}'.format(epos.plotdir, outdir, suffix))
Example #4
0
def periodratio(epos, color='C0', clr_obs='C3', Simple=False, Fancy=True):
    pfm = epos.pfm

    if Fancy:
        f, (ax, axR, axP) = helpers.make_panels(plt, Fancy=True)
        f.suptitle('Multi-planets {}'.format(epos.title))
    else:
        f, (ax, axR, axP) = helpers.make_panels_right(plt)
        ax.set_title('Input Multi-planets {}'.format(epos.title))
    ''' Inc-sma'''
    ax.set_xlabel('Semi-Major Axis [au]')
    ax.set_ylabel('Period ratio')

    #ax.set_xlim(epos.mod_xlim)
    ax.set_ylim(0.9, 10)

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

    #ax.axhline(np.median(pfm['inc']), ls='--')
    single = pfm['dP'] == np.nan
    inner = pfm['dP'] == 1
    nth = pfm['dP'] > 1

    # print pfm['dP'][single]
    # print pfm['dP'][nth]
    # print pfm['dP'][inner]
    # print pfm['dP'][nth].size, pfm['np'] # ok

    ax.plot(pfm['sma'][single], pfm['dP'][single], color='0.7', **fmt_symbol)
    ax.plot(pfm['sma'][nth], pfm['dP'][nth], color=color, **fmt_symbol)
    ax.plot(pfm['sma'][inner], pfm['dP'][inner], color='C1', **fmt_symbol)
    ''' Histogram Period Ratio'''
    axR.set_yscale('log')
    axR.set_ylim(0.9, 10)

    #dP= np.logspace(0,1,15)
    dP = np.logspace(0, 1, 25)
    axR.hist(pfm['dP'][nth], bins=dP, orientation='horizontal', color=color)
    if not Simple:
        ax.axhline(np.median(pfm['dP'][nth]), ls='--', color=color, zorder=-1)

    #Model best-fit
    dP = np.logspace(0, 1)
    xmax = axR.get_xlim()[-1]
    with np.errstate(divide='ignore'):
        Dgrid = np.log10(2. * (dP**(2. / 3.) - 1.) / (dP**(2. / 3.) + 1.))
    Dgrid[0] = -2

    if Simple:
        scale = -0.37
        pdf = scipy.stats.norm(scale, 0.19).pdf(Dgrid)
        pdf *= xmax / max(pdf)
        axR.plot(pdf, dP, ls='-', color=clr_obs)

        pscale = np.interp(scale, Dgrid, dP)
        #ax.axhline(pscale, color=clr_obs, ls='--')
    else:
        for scale, ls in zip([-0.30, -0.37, -0.41], [':', '--', ':']):
            pdf = scipy.stats.norm(scale, 0.19).pdf(Dgrid)
            pdf *= xmax / max(pdf)
            axR.plot(pdf, dP, ls=ls, color='purple')

            pscale = np.interp(scale, Dgrid, dP)
            ax.axhline(pscale, color='purple', ls=ls, zorder=-1)
    ''' Histogram Inner Planet'''
    axP.set_xscale('log')
    axP.set_xlim(ax.get_xlim())
    sma = np.geomspace(*ax.get_xlim(), num=25)
    axP.hist(pfm['sma'][inner], bins=sma, color='C1', label='Inner Planet')

    ymax = axP.get_ylim()[-1]
    P = np.geomspace(0.5, 730)
    smaP = (P / 365.25)**(1. / 1.5)
    pdf = brokenpowerlaw1D(P, 10, 1.5, -0.8)
    pdf *= ymax / max(pdf)

    #axP.legend(frameon=False)
    if Fancy:
        ax.text(0.02,
                0.98,
                'Inner Planet',
                ha='left',
                va='top',
                color='C1',
                transform=ax.transAxes)
        ax.text(0.02,
                0.98,
                '\nOuter Planet(s)',
                ha='left',
                va='top',
                color=color,
                transform=ax.transAxes)
    else:
        axP.text(0.98,
                 0.95,
                 'Inner Planet',
                 ha='right',
                 va='top',
                 color='C1',
                 transform=axP.transAxes)

    axP.plot(smaP, pdf, ls='-', color=clr_obs)

    #helpers.set_axes(ax, epos, Trim=True)
    #helpers.set_axis_distance(axP, epos, Trim=True)
    #helpers.set_axis_size(axR, epos, Trim=True) #, In= epos.MassRadius)

    helpers.save(plt, epos.plotdir + 'model/Pratio-sma')
Example #5
0
def panels_mass(epos, Population=False, color='C1'):
    f, (ax, axM, axP) = helpers.make_panels(plt)
    pfm = epos.pfm
    eta = epos.modelpars.get('eta', Init=True)
    ''' Bins '''
    dw = 0.5  # bin width in ln space
    xbins = np.exp(
        np.arange(np.log(pfm['P limits'][0]),
                  np.log(pfm['P limits'][-1]) + dw, dw))
    ybins = np.exp(
        np.arange(np.log(pfm['M limits'][0]),
                  np.log(pfm['M limits'][-1]) + dw, dw))
    ''' Posterior '''
    if Population:
        assert hasattr(epos, 'func')
        fname = '.pop'

        # side panels marginalized over M and P limits
        pps, pdf, pdf_X, pdf_Y = periodradius(epos, Init=True)
        _, _, pdf_X, _ = periodradius(epos, Init=True, ybin=ybins)
        _, _, _, pdf_Y = periodradius(epos, Init=True, xbin=xbins)
        pps, _, _, _ = periodradius(epos, Init=True, xbin=xbins, ybin=ybins)
        #pdf/= np.max(pdf)
        #pdflog= np.log10(pdf) # in %
        levels = np.linspace(0, np.max(pdf))
        lines = np.array([0.1, 0.5]) * np.max(pdf)

        ax.contourf(epos.X_in, epos.Y_in, pdf, cmap='Purples', levels=levels)
        #ax.contour(epos.X_in, epos.Y_in, pdf, levels=lines)

        # Side panels
        #print 'pps model= {}'.format(eta)
        scale = dw
        axP.plot(epos.MC_xvar,
                 pdf_X * scale,
                 marker='',
                 ls='-',
                 color='purple')
        axM.plot(pdf_Y * scale,
                 epos.in_yvar,
                 marker='',
                 ls='-',
                 color='purple')
    else:
        fname = ''
    ''' plot main panel'''
    ax.set_title(epos.name)
    #helpers.set_axes(ax, epos, Trim=True)

    ax.set_xscale('log')
    ax.set_yscale('log')
    #ax.set_xlim(epos.mod_xlim)
    #ax.set_ylim(epos.mod_ylim)

    ax.plot(pfm['P'], pfm['M'], color=color, **fmt_symbol)
    xlim = ax.get_xlim()
    ylim = ax.get_ylim()
    ''' Period side panel '''
    #axP.yaxis.tick_right()
    #axP.yaxis.set_ticks_position('both')
    #axP.tick_params(axis='y', which='minor',left='off',right='off')

    axP.set_xscale('log')
    axP.set_xlim(xlim)
    #ax.set_xlabel('Semi-Major Axis [au]')
    axP.set_xlabel('Orbital Period [days]')

    axP.hist(pfm['P'],
             color=color,
             bins=xbins,
             weights=np.full(pfm['np'], eta / pfm['np']))
    ''' Mass side panel'''
    #helpers.set_axis_size(axR, epos, Trim=True) #, In= epos.MassRadius)
    axM.set_ylabel(r'Planet Mass [M$_\bigoplus$]')
    axM.set_yscale('log')
    axM.set_ylim(ylim)

    axM.hist(pfm['M'],
             bins=ybins,
             orientation='horizontal',
             weights=np.full(pfm['np'], eta / pfm['np']),
             color=color)

    helpers.save(plt, '{}model/input.mass{}'.format(epos.plotdir, fname))
Example #6
0
def panels_radius(epos,
                  Population=False,
                  Occurrence=False,
                  Observation=False,
                  Tag=False,
                  color='C0',
                  clr_obs='C3',
                  Shade=True,
                  Fancy=True,
                  Zoom=False):
    f, (ax, axR, axP) = helpers.make_panels(plt, Fancy=Fancy)
    pfm = epos.pfm
    eta = epos.modelpars.get('eta', Init=True)

    title = ''
    if not 'R' in pfm:
        pfm['R'], _ = epos.MR(pfm['M'])

    if Tag:
        # function that return a simulation subset based on the tag
        subset = {
            'Fe/H<=0': lambda tag: tag <= 0,
            'Fe/H>0': lambda tag: tag > 0
        }
    ''' Bins '''
    dwR = 0.2  # bin width in ln space
    dwP = 0.3
    if Zoom:
        xbins = np.exp(
            np.arange(np.log(epos.xzoom[0]),
                      np.log(epos.xzoom[-1]) + dwP, dwP))
        ybins = np.exp(
            np.arange(np.log(epos.yzoom[0]),
                      np.log(epos.yzoom[-1]) + dwR, dwR))
    else:
        xbins = np.exp(
            np.arange(np.log(epos.xtrim[0]),
                      np.log(epos.xtrim[-1]) + dwP, dwP))
        ybins = np.exp(
            np.arange(np.log(epos.ytrim[0]),
                      np.log(epos.ytrim[-1]) + dwR, dwR))
    ''' Plot model occurrence or observed counts'''
    if Observation:
        # plot model planets * completeness
        weights = eta * epos.occurrence['model']['completeness'] / pfm['ns']
    else:
        weights = np.full(pfm['np'], eta / pfm['ns'])

    if 'draw prob' in pfm and not Tag:
        prob = pfm['draw prob'][pfm['ID']]
        weights *= prob * pfm['ns']  # system weights sum up to 1
        #nonzero= np.where(prob>0, 1., 0.)
        #weights*= nonzero*(pfm['np']/nonzero.sum())

    # histograms
    if Tag:
        for key, f in subset.iteritems():
            toplot = f(pfm['tag'])
            #weights= eta*epos.occurrence['model']['completeness'] \
            #		*np.where(toplot,1.,0.)/f(pfm['system tag']).sum()
            weights = np.where(toplot, eta, 0.) / f(pfm['system tag']).sum()
            axP.hist(pfm['P'],
                     bins=xbins,
                     weights=weights,
                     histtype='step',
                     label=key)
            axR.hist(pfm['R'],
                     bins=ybins,
                     orientation='horizontal',
                     weights=weights,
                     histtype='step')
    else:
        # color have to be 1-element lists ??
        axP.hist(pfm['P'], bins=xbins, weights=weights, color=[color])
        axR.hist(pfm['R'],
                 bins=ybins,
                 orientation='horizontal',
                 weights=weights,
                 color=[color])
    ''' Overplot observations? '''
    if Population:
        assert hasattr(epos, 'func')
        fname = '.pop' + ('.zoom' if Zoom else '')

        title = epos.title

        pps, pdf, pdf_X, pdf_Y = periodradius(epos, Init=True)
        _, _, pdf_X, _ = periodradius(epos, Init=True, ybin=ybins)
        _, _, _, pdf_Y = periodradius(epos, Init=True, xbin=xbins)
        pps, _, _, _ = periodradius(epos, Init=True, xbin=xbins, ybin=ybins)
        #pdf/= np.max(pdf)
        #pdflog= np.log10(pdf) # in %
        levels = np.linspace(0, np.max(pdf))
        lines = np.array([0.1, 0.5]) * np.max(pdf)

        if Shade:
            ax.contourf(epos.X_in,
                        epos.Y_in,
                        pdf,
                        cmap='Purples',
                        levels=levels)
            #ax.contour(epos.X_in, epos.Y_in, pdf, levels=lines)

            # Side panels
            #print 'pps model= {}'.format(eta)
            axP.plot(epos.MC_xvar,
                     pdf_X * dwP,
                     marker='',
                     ls='-',
                     color='purple')
            axR.plot(pdf_Y * dwR,
                     epos.in_yvar,
                     marker='',
                     ls='-',
                     color='purple')
        else:
            # renormalize
            xnorm = axP.get_ylim()[1] / max(pdf_X)
            ynorm = axR.get_xlim()[1] / max(pdf_Y)

            axP.plot(epos.MC_xvar,
                     pdf_X * xnorm,
                     marker='',
                     ls='-',
                     color=clr_obs)
            axR.plot(pdf_Y * ynorm,
                     epos.in_yvar,
                     marker='',
                     ls='-',
                     color=clr_obs)

    elif Observation:
        fname = '.obs' + ('.zoom' if Zoom else '')

        title = epos.title + ': Counts'

        ax.plot(epos.obs_xvar,
                epos.obs_yvar,
                ls='',
                marker='.',
                ms=5.0,
                color='0.5')

        weights = np.full(epos.obs_xvar.size, 1. / epos.nstars)
        axP.hist(epos.obs_xvar,
                 bins=xbins,
                 weights=weights,
                 histtype='step',
                 color='0.5')
        axR.hist(epos.obs_yvar,
                 bins=ybins,
                 weights=weights,
                 orientation='horizontal',
                 histtype='step',
                 color='0.5')

    elif Occurrence:
        fname = '.occ' + ('.zoom' if Zoom else '')
        title = epos.title + r': Occurrence, $\eta={:.2g}$'.format(eta)

        ax.plot(epos.obs_xvar,
                epos.obs_yvar,
                ls='',
                marker='.',
                ms=5.0,
                color='0.5')

        cut = epos.obs_yvar > 0.45

        weights = 1. / (epos.occurrence['planet']['completeness'][cut] *
                        epos.nstars)
        axP.hist(epos.obs_xvar[cut],
                 bins=xbins,
                 weights=weights,
                 histtype='step',
                 color='k')
        axR.hist(epos.obs_yvar[cut],
                 bins=ybins,
                 weights=weights,
                 orientation='horizontal',
                 histtype='step',
                 color='k')

    elif Tag:
        fname = '.tag'
        ax.set_title(epos.title + ': Tag')

        axP.legend(frameon=False, fontsize='small')
        # 		for k, tag in enumerate(subset):
        # 			axP.text(0.98,0.95-0.05*k,tag,ha='right',va='top',color='C1',
        # 				transform=axP.transAxes)

    else:
        fname = ''

    if Fancy:
        plt.suptitle(title, ha='center')  #, x=0.05)
    else:
        ax.set_title(title)
    ''' plot main panel'''
    #helpers.set_axes(ax, epos, Trim=True)

    helpers.set_axes(ax, epos, Trim=True)
    if Tag:
        for key, f in subset.iteritems():
            todraw = f(pfm['tag'])
            ax.plot(pfm['P'][todraw], pfm['R'][todraw], **fmt_symbol)
    elif 'draw prob' in pfm:
        #fmt_symbol['alpha']= 0.6*pfm['draw prob'][pfm['ID']] # alpha can't be array
        todraw = pfm['draw prob'][pfm['ID']] > 0
        ax.plot(pfm['P'][todraw], pfm['R'][todraw], color=color, **fmt_symbol)
    else:
        ax.plot(pfm['P'], pfm['R'], color=color, **fmt_symbol)
    ''' Period side panel '''
    #axP.yaxis.tick_right()
    #axP.yaxis.set_ticks_position('both')
    #axP.tick_params(axis='y', which='minor',left='off',right='off')
    helpers.set_axis_distance(axP, epos, Trim=True)
    ''' Mass side panel'''
    helpers.set_axis_size(axR, epos, Trim=True)  #, In= epos.MassRadius)

    helpers.save(plt, '{}model/input.radius{}'.format(epos.plotdir, fname))
Example #7
0
def panels(epos, MCMC=False):

	f, (ax, axR, axP)= helpers.make_panels(plt)
	
	sim=epos.synthetic_survey
	
	clr_bf= 'g'
		
	''' plot R(P), main panel'''
	ax.set_title('Simulated Detections')
	helpers.set_axes(ax, epos, Trim=True)
	if epos.MonteCarlo:
		ax.plot(sim['P'], sim['Y'], ls='', marker='.', color=clr_bf if MCMC else 'C0')
	else:
		levels= np.linspace(0,np.max(sim['pdf']))		
		ax.contourf(epos.MC_xvar, epos.MC_yvar, sim['pdf'].T, cmap='Blues', levels=levels)

	''' Period side panel '''
	helpers.set_axis_distance(axP, epos, Trim=True)
	#axP.set_yscale('log')
	#axP.set_ylim([2e-3,5])	
	#axP.set_yticks([0.01,0.1,1])
	#axP.set_yticklabels(['1%','10%','100%'])
	axP.yaxis.tick_right()
	axP.yaxis.set_ticks_position('both')
	#axP.tick_params(axis='y', which='minor',left='off',right='off')
			
	''' Radius side panel'''
	helpers.set_axis_size(axR, epos, Trim=True) #, In= epos.MassRadius)

	#axR.set_xscale('log')
	#axR.set_xlim([2e-3,5])
	#axR.set_xticks([1,10,100,1000])
	#axR.set_xticklabels(['1','10','100','1000'], rotation=70)
	for tick in axR.get_xticklabels():
		tick.set_rotation(70)
	#axR.tick_params(axis='x', which='minor',top='off',bottom='off')
	#axP.tick_params(axis='y', which='minor',left='off',right='off')

	''' Histograms / posterior samples '''
	try:
		xbins= np.geomspace(*epos.xzoom, num=20)
		ybins= np.geomspace(*epos.yzoom, num=10)
	except:
		xbins= np.logspace(*np.log10(epos.xzoom), num=20)
		ybins= np.logspace(*np.log10(epos.yzoom), num=10)
	xscale= np.log(xbins[1]/xbins[0])
	yscale= np.log(ybins[1]/ybins[0])

	if MCMC:
		histkeys= {'color':'b', 'alpha':0.1}
		for ss in epos.ss_sample:
			if epos.MonteCarlo:
				axP.hist(ss['P zoom'], bins=xbins, histtype='step', **histkeys)
				axR.hist(ss['Y zoom'], bins=ybins, orientation='horizontal', \
					histtype='step', **histkeys)
			else:
				axP.plot(ss['P zoom'], ss['P zoom pdf']*xscale, 
					marker='', ls='-', **histkeys)
				axR.plot(ss['Y zoom pdf']*yscale, ss['Y zoom'], 
					marker='', ls='-', **histkeys)
		histdict= {'histtype':'step', 'color':clr_bf}
	else:
		histdict={}
	
	if epos.MonteCarlo:
		axP.hist(sim['P zoom'], bins=xbins, **histdict)
		axR.hist(sim['Y zoom'], bins=ybins, orientation='horizontal', **histdict)
	else:
		axP.plot(sim['P zoom'], sim['P zoom pdf']*xscale, marker='', ls='-')
		axR.plot(sim['Y zoom pdf']*yscale, sim['Y zoom'], marker='', ls='-')

	''' Observations'''
	axP.hist(epos.obs_zoom['x'], bins=xbins,histtype='step', color='C1')
	axR.hist(epos.obs_zoom['y'], bins=ybins, orientation='horizontal',histtype='step', color='C1')
	
	''' Box/ lines'''
	if epos.Zoom:
		for zoom in epos.xzoom: axP.axvline(zoom, ls='--', color='k')
		for zoom in epos.yzoom: axR.axhline(zoom, ls='--', color='k')
		ax.add_patch(patches.Rectangle( (epos.xzoom[0],epos.yzoom[0]), 
			epos.xzoom[1]-epos.xzoom[0], epos.yzoom[1]-epos.yzoom[0],fill=False, zorder=1) )
	
	#ax.legend(loc='lower left', shadow=False, prop={'size':14}, numpoints=1)
	
	fdir= 'mcmc' if MCMC else 'output'
	helpers.save(plt, '{}{}/pdf.zoom'.format(epos.plotdir, fdir))
Example #8
0
def periodradius(epos, SNR=True, Model=False, color='C1'):

    f, (ax, axR, axP) = helpers.make_panels(plt, Fancy=True)

    sim = epos.synthetic_survey
    title = 'Simulated Detections: {}'.format(epos.name)
    fsuffix = 'detect'
    xbins = epos.MC_xvar
    ybins = epos.MC_yvar

    if SNR:
        transit = epos.transit
        title = 'Simulated Transiting Planets'
        fsuffix = 'transit'
    elif Model:
        pfm = epos.pfm
        fsuffix = 'population'

        dwR = 0.2  # bin width in ln space
        dwP = 0.3

        xbins = np.exp(
            np.arange(np.log(epos.mod_xlim[0]),
                      np.log(epos.mod_xlim[-1]) + dwP, dwP))
        ybins = np.exp(
            np.arange(np.log(epos.ytrim[0]),
                      np.log(epos.ytrim[-1]) + dwR, dwR))
    ''' plot R(P), main panel'''
    f.suptitle(title)
    helpers.set_axes(ax, epos, Trim=True)
    if SNR:
        ax.plot(transit['P'], transit['Y'], ls='', marker='.', color='C6')
    elif Model:
        ax.plot(pfm['P'], pfm['R'], ls='', marker='.', ms=5.0, color='0.5')
    ax.plot(sim['P'], sim['Y'], ls='', marker='.', color=color)

    if Model:
        xlim = ax.get_xlim()
        ax.set_xlim(xlim[0], epos.mod_xlim[-1])
        #ax.set_ylim(epos.mod_ylim)
    ''' Period side panel '''
    #helpers.set_axis_distance(axP, epos, Trim=True)
    axP.set_xlabel(ax.get_xlabel())
    #axP.set_yscale('log')
    #axP.set_ylim([2e-3,5])
    #axP.set_yticks([0.01,0.1,1])
    #axP.set_yticklabels(['1%','10%','100%'])
    axP.yaxis.tick_right()
    axP.yaxis.set_ticks_position('both')
    #axP.tick_params(axis='y', which='minor',left='off',right='off')

    if SNR:
        axP.hist(transit['P'], bins=xbins, color='C6', density=True)
    elif Model:
        axP.hist(pfm['P'], bins=xbins, color='0.5', density=True, log=True)
        axP.hist(pfm['P'],
                 bins=xbins,
                 color='k',
                 density=True,
                 log=True,
                 histtype='step',
                 zorder=10,
                 ls='-')
    axP.hist(sim['P'], bins=xbins, density=Model, log=Model, color=color)
    ''' Radius side panel'''
    #helpers.set_axis_size(axR, epos, Trim=True, In= epos.MassRadius)
    axR.set_ylabel(ax.get_ylabel())

    #axR.set_xscale('log')
    #axR.set_xlim([2e-3,5])
    #axR.set_xticks([1,10,100,1000])
    #axR.set_xticklabels(['1','10','100','1000'], rotation=70)
    for tick in axR.get_xticklabels():
        tick.set_rotation(70)
    #axR.tick_params(axis='x', which='minor',top='off',bottom='off')
    #axP.tick_params(axis='y', which='minor',left='off',right='off')

    if SNR:
        axR.hist(transit['Y'],
                 orientation='horizontal',
                 bins=ybins,
                 color='C6',
                 density=True)
    elif Model:
        axR.hist(pfm['R'],
                 orientation='horizontal',
                 bins=ybins,
                 color='0.5',
                 density=True,
                 log=True)
        axR.hist(pfm['R'],
                 orientation='horizontal',
                 bins=ybins,
                 color='k',
                 density=True,
                 log=True,
                 histtype='step',
                 zorder=10,
                 ls='-')
    axR.hist(sim['Y'],
             orientation='horizontal',
             bins=ybins,
             density=Model,
             log=Model,
             color=color)

    # labels
    if SNR:
        xpos = epos.MC_xvar[-1]
        ypos = axP.get_ylim()[-1] / 1.05
        axP.text(xpos, ypos, 'Detected ', color=color, ha='right', va='top')
        axP.text(xpos,
                 ypos / 1.3,
                 'Undetected ',
                 color='C6',
                 ha='right',
                 va='top')
    elif Model:
        xpos = ax.get_xlim()[-1]
        ypos = ax.get_ylim()[-1] / 1.05
        ax.text(xpos, ypos, 'Detected ', color=color, ha='right', va='top')
        ax.text(xpos,
                ypos / 1.3,
                'Undetected ',
                color='0.5',
                ha='right',
                va='top')

    #ax.legend(loc='lower left', shadow=False, prop={'size':14}, numpoints=1)
    helpers.save(plt, '{}output/periodradius.{}'.format(epos.plotdir, fsuffix))