Esempio n. 1
0
def EstimatePeriodAndPlot(ID,
                          f_in="../data/mira_asas/",
                          f_out="diag_figs/mira_plots/"):
    """
    Determine the period and make plot with period of
    light curve with ID.
    """
    print ID
    star = np.loadtxt(f_in + ID + ".dat",
                      usecols=(0,1,2),skiprows=0)
    ctimes = star[star[:,1] > 29.5,0]
    star = star[star[:,1] < 29.5,:]
    cvals = np.array(np.max(star[:,1])) * np.ones(ctimes.shape[0])
    ## estimate period
    freqs = lomb.get_freqs2(star[:,0])
    rss = lomb.lomb(star[:,0],star[:,1],star[:,2],freqs)
    period = 1. / freqs[np.argmin(rss)]
    ## make figure
    fig = plt.figure()
    ax = fig.add_subplot(211)
    ax.plot(star[:,0],-star[:,1],'o',color="gray",alpha=.5)
    ax.plot(ctimes,-cvals,'ro',alpha=.5)
    ax.set_yticklabels(np.abs(ax.get_yticks()))
    ax.set_xlabel('Time')
    ax.set_ylabel('Magnitude')
    ax2 = fig.add_subplot(212)
    ax2.plot(star[:,0] % period,-star[:,1],'o',color="gray",alpha=.5)
    ax2.plot(ctimes % period,-cvals,'ro',alpha=.5)
    ax2.set_yticklabels(np.abs(ax2.get_yticks()))
    ax2.set_xlabel('Phase')
    ax2.set_ylabel('Magnitude')
    plt.savefig(f_out + ID + ".pdf")
    plt.close()
    return period
Esempio n. 2
0
def plot_fits(mira):
    ## get the data
    star = np.loadtxt(mira,
                      usecols=(0,1,2),skiprows=0)
    ctimes = star[star[:,1] > 29.5,0]
    times = star[star[:,1] < 29.5,0]
    mags =  star[star[:,1] < 29.5,1]
    errors = star[star[:,1] < 29.5,2]

    ## get lomb-scargle period
    freqs = lomb.get_freqs2(times)
    rss = lomb.lomb(times,mags,errors,freqs)
    period = 1. / freqs[np.argmin(rss)]
    ## from lomb, get A,B,C values


    sin_c, cos_c = likelihood.times2pred(ctimes,1./period)
    sin_uc, cos_uc = likelihood.times2pred(times,1./period)
    f = likelihood.mag2flux(mags)
    e = likelihood.magerr2fluxerr(mags,errors)
    D = np.array([ np.sin(2*np.pi*times/period), 
                   np.cos(2*np.pi*times/period),
                   np.ones(times.size)])
    A,B,C = np.linalg.lstsq(D.T,mags)[0]


    ## fit censoring model to data
    pars = np.array((A,B,C))
    mu_b = np.min(f)
    v_b = 10.0
    cens = False
    pars_fit = op.fmin(likelihood.nll_fixedB_no_cens,pars,
                       (mu_b,v_b,sin_c,cos_c,sin_uc,cos_uc,f,e))


    ## set x limits to time min and max
    ## add legend 

    ## data for plotting
    times_pred = np.linspace(np.min(times),np.max(times),1000)
    mags_pred_ls = (A*np.sin(2.*np.pi*times_pred / period) 
                    + B*np.cos(2.*np.pi*times_pred / period)
                    + C)
    mags_pred_cens = (pars_fit[0]*np.sin(2.*np.pi*times_pred / period) 
                      + pars_fit[1]*np.cos(2.*np.pi*times_pred / period) 
                      + pars_fit[2])
    xmin = np.min(times)
    xmax = np.max(times)


    fig = plt.figure()
    leg_font = matplotlib.font_manager.FontProperties()
    leg_font.set_size(10)


    ## plot in mag space
    ax = fig.add_subplot(211)
    line1 = ax.plot(times_pred,-mags_pred_ls,color='orange',linewidth=1.5)
    line2 = ax.plot(times_pred,-mags_pred_cens,color='blue',linewidth=1.5)
    ax.plot(ctimes,np.min(-mags)*np.ones(ctimes.size),'o',color='red')
    ax.plot(times,-mags,'o',color="gray",alpha=.5)
    ax.set_yticklabels(np.abs(ax.get_yticks()))
    ax.axis([xmin,xmax,ax.axis()[2],ax.axis()[3]])
    plt.legend((line1,line2),("Lomb-Scargle","Censored"),loc='upper left',
               prop=leg_font)
    ax.set_ylabel("Magnitude")
    ax.set_xlabel("Time")

    ## plot in flux space
    ax = fig.add_subplot(212)
    line1 = ax.plot(times_pred,likelihood.mag2flux(mags_pred_ls),
                    color='orange',linewidth=1.5)
    line2 = ax.plot(times_pred,likelihood.mag2flux(mags_pred_cens),
            color='blue',linewidth=1.5)
    ax.plot(ctimes,likelihood.mag2flux(np.max(mags))*np.ones(ctimes.size),
            'o',color='red')
    ax.plot(times,likelihood.mag2flux(mags),'o',color="gray",alpha=.5)
    ax.axis([xmin,xmax,ax.axis()[2],ax.axis()[3]])
    ax.set_ylabel("Flux")
    ax.set_xlabel("Time")
    plt.legend((line1,line2),("Lomb-Scargle","Censored"),loc='upper left',
               prop=leg_font)
    mira_name = mira.split('/')[-1][:-4]
    plt.savefig("diag_figs/mira_ls_censor_simple/" + mira_name + ".pdf")
    plt.close()