Ejemplo n.º 1
0
 def recv(self):
     if self.mode == SCUMode.SendMode:
         raise Exception
     key, length = self.file_received.get()
     return utils.fold_data(self.received_files_data[key], length)
    def get_cutout_phased_df(self,t0=None,P=None,dur=0.2,sigma=None,plot=True,use_median_filter=True):
        """
        A function to get both transit cutout data, and also the final folded transit.
        
        INPUT:
        - t0
        - P
        - dur is the total duration of the data (i.e. if 0.2, then goes from -0.1 to 0.1)
        - sigma 
        
        OUTPUT:
         df with columns:
         - x     the phased folded time
         - y     flux value
         - time  original time value before folding
         - index index of the original value before folding
         
        EXAMPLE:
        df = EP.get_cutout_phased_df(dur=0.4,sigma=3)
        _, mm = k2help.savgol_sigma_clip(df.y,win=21,sigma_upper=3)
        plt.plot(df.x, df.y,"r.")
        dfmm = df[~mm]
        t_fold_final = dfmm.x
        f_fold_final = dfmm.y
        plt.plot(t_fold_final,f_fold_final)

        dfmm_s = dfmm.sort_index()
        plt.plot(dfmm_s.x,dfmm_s.y,"r.")
        plt.plot(dfmm.x,dfmm.y,"k.")
        """
        if t0 is None and P is None:
            t0 = self.planet._pl_tranmid - k2help.KEPLER_JD_OFFSET
            P = self.planet._pl_orbper
            print("Using planet with t0=",t0,"and P=",P)

        if use_median_filter:
            print("Using median filtered data -- assumes you have run that from beginning!")
            t, f = self.t, self.f
        else:
            print("Using whitened flux")
            t, f = self.star.get_whitened_flux()

        m = np.isnan(f)
        t, f = t[~m],f[~m]
        
        ind = self.star.get_masked_indices_in_transit(t,t0,P,dur=dur)
        
        t_unfolded, f_unfolded = t[ind], f[ind]
        
        df = utils.fold_data(t_unfolded,f_unfolded,t0,P,dur=dur,sort=True)

        if sigma is not None:
            S=astropy.stats.sigma_clipping.sigma_clip(df.y.values)
            dfm = df[~S.mask]

        if plot:
            fig, ax = plt.subplots()
            ax.plot(df.x,df.y,"r.",label="folded data")
            if sigma is not None:
                ax.plot(dfm.x,dfm.y,"k.",label="sigma clipped")
            ax.legend(loc="upper right",fontsize=12)

        if sigma is not None:
            return dfm
        else:
            return df