コード例 #1
0
def bkg_subtraction(time, flux, scope="tpf", sigma=3):
    """Subtracts background flux from target pixel file.

    Parameters
    ----------
    scope : string, "tpf" or "postcard"
        If `tpf`, will use data from the target pixel file only to estimate and remove the background.
        If `postcard`, will use data from the entire postcard region to estimate and remove the background.
    sigma : float
        The standard deviation cut used to determine which pixels are representative of the background in each cadence.
    """

    tpf_flux_bkg = []

    sigma_clip = SigmaClip(sigma=sigma)
    #    bkg = MMMBackground(sigma_clip=sigma_clip)
    bkg = SExtractorBackground(sigma_clip=sigma_clip)

    bkg_MMM = MMMBackground(sigma_clip=sigma_clip)
    bkg_ModeEstimator = ModeEstimatorBackground(median_factor=3.,
                                                mean_factor=2.,
                                                sigma_clip=sigma_clip)
    bkg_Mean = MeanBackground(sigma_clip)
    bkg_Median = MedianBackground(sigma_clip)
    bkg_SExtractor = SExtractorBackground(sigma_clip)

    bkg_MMM_value = bkg_MMM.calc_background(flux[0])
    bkg_ModeEstimator_value = bkg_ModeEstimator.calc_background(flux[0])
    bkg_Mean_value = bkg_Mean.calc_background(flux[0])
    bkg_Median_value = bkg_Median.calc_background(flux[0])
    bkg_SExtractor_value = bkg_SExtractor.calc_background(flux[0])

    print("MMM Background = {}".format(bkg_MMM_value))
    print("ModeEstimator Background = {}".format(bkg_ModeEstimator_value))
    print("Mean Background = {}".format(bkg_Mean_value))
    print("Median Background = {}".format(bkg_Median_value))
    print("SExtractor Background = {}".format(bkg_SExtractor_value))

    for i in range(len(time)):
        bkg_value = bkg.calc_background(flux[i])
        tpf_flux_bkg.append(bkg_value)

    tpf_flux_bkg = np.array(tpf_flux_bkg)

    return tpf_flux_bkg
コード例 #2
0
    def bkg_subtraction(self, scope="tpf", sigma=1.2):
        """Subtracts background flux from target pixel file.

        Parameters
        ----------
        scope : string, "tpf" or "postcard"
            If `tpf`, will use data from the target pixel file only to estimate and remove the background.
            If `postcard`, will use data from the entire postcard region to estimate and remove the background.
        sigma : float
            The standard deviation cut used to determine which pixels are representative of the background in each cadence.
        """
        time = self.time
        flux = self.bkg_tpf

        self.tpf_flux_bkg = []

        sigma_clip = SigmaClip(sigma=sigma)
        bkg = MMMBackground(sigma_clip=sigma_clip)

        for i in range(len(time)):
            bkg_value = bkg.calc_background(flux[i])
            self.tpf_flux_bkg.append(bkg_value)

        self.tpf_flux_bkg = np.array(self.tpf_flux_bkg)
コード例 #3
0
 def bkg(self):
     sigma_clip = SigmaClip(sigma=3.)
     bkg = MMMBackground(sigma_clip=sigma_clip)
     b = bkg.calc_background(self.flux, axis=(1, 2))
     return b
コード例 #4
0
def bkg(flux, sigma=2.5):
    # Returns background for a single cadence. Default sigma=2.5
    sigma_clip = SigmaClip(sigma=sigma)
    bkg = MMMBackground(sigma_clip=sigma_clip)
    return bkg.calc_background(flux)
コード例 #5
0
coord  = SkyCoord(ra, dec, unit='deg')



ahdu = search_tesscut(coord, sector=args.Sector).download(cutout_size=args.size, download_dir='.')
#w    = WCS(allhdus.hdu[2].header)
hdu  = ahdu.hdu

flux = hdu[1].data['FLUX']
bkgs = np.zeros(len(flux))

#Background
for i,f in enumerate(flux):
    sigma_clip = SigmaClip(sigma=3)
    bkg        = MMMBackground(sigma_clip=sigma_clip)
    bkgs[i]    = bkg.calc_background(f)


#flux = np.log10(np.abs(np.nanmin(flux)) + flux + 1)
time = hdu[1].data['TIME'] + hdu[1].header['BJDREFI']

def animate(i, fig, ax, flux, time, start=0):
    #ax.text(0.98, 0.98, time[i], transform=ax.transAxes, color='white', ha='right', va='top')
    #im = ax.matshow(flux[i+start], cmap=plt.cm.YlGnBu_r)
    im.set_array(flux[i+start])
    te.set_text('%.4f' % time[i+start])
    return im, te

fig, ax = plt.subplots(figsize=[2,2])
ax.set_xticks([])
ax.set_yticks([])