Ejemplo n.º 1
0
    def center_of_mass(self):
        """
        Calculates the position of the source across all cadences using `muchbettermoments` and `self.best_aperture`.

        Finds the brightest pixel in a (`height`, `width`) region summed up over all cadence.
        Searches a smaller (3x3) region around this pixel at each cadence and uses `muchbettermoments` to find the maximum.
        """

        self.x_com = []
        self.y_com = []

        summed_pixels = np.sum(self.aperture * self.tpf, axis=0)
        brightest = np.where(summed_pixels == np.max(summed_pixels))
        cen = [brightest[0][0], brightest[1][0]]

        if cen[0] < 3.0:
            cen[0] = 3
        if cen[1] < 3.0:
            cen[1] = 3
        if cen[0] + 3 > np.shape(self.tpf[0])[0]:
            cen[0] = np.shape(self.tpf[0])[0] - 3
        if cen[1] + 3 > np.shape(self.tpf[0])[1]:
            cen[1] = np.shape(self.tpf[0])[1] - 3

        for a in range(len(self.tpf)):
            data = self.tpf[a, cen[0] - 3:cen[0] + 2, cen[1] - 3:cen[1] + 2]
            c_0 = quadratic_2d(data)
            c_frame = [cen[0] + c_0[0], cen[1] + c_0[1]]
            self.x_com.append(c_frame[0])
            self.y_com.append(c_frame[1])
        return
Ejemplo n.º 2
0
def test_recover_center_of_gaussian_wo_noise():
    u = np.linspace(0, 8, 9)
    x, y = np.meshgrid(u, u)
    true_center = [3.45, 4.73]
    z = 10 * np.exp(-(x - true_center[1])**2 - (y - true_center[0])**2)
    center = quadratic_2d(z)
    np.testing.assert_almost_equal(center, true_center, decimal=1)
Ejemplo n.º 3
0
        def isolated_center(x, y, image):
            """Finds the centroid of each isolated source with quadratic_2d.

            Parameters
            ----------
            x : array-like
                Initial guesses of x positions for sources.
            y : array-like
                Initial guesses of y positions for sources.            
            image : np.ndarray
                FFI flux data.
                
            Returns
            -------
            cenx : array-like
                Controid x coordinates for all good input sources.
            ceny : array-like
                Centroid y coordinates for all good input sources.
            good : list
                Indexes into input arrays corresponding to good sources.
            """
            cenx, ceny, good = [], [], []
            print("Finding isolated centers of sources")
            for i in range(len(x)):
                 if x[i] > 0. and y[i] > 0.:
                     tpf = Cutout2D(image, position=(x[i], y[i]), size=(7,7), mode='partial')
                     origin = tpf.origin_original
                     cen = quadratic_2d(tpf.data)
                     cenx.append(cen[0]+origin[0]); ceny.append(cen[1]+origin[1])
                     good.append(i)
            cenx, ceny = np.array(cenx), np.array(ceny)
            return cenx, ceny, good
Ejemplo n.º 4
0
def isolated_center(x, y, image):
    """ Finds the center of each isolated TPF with quadratic_2d """
    cenx, ceny, good = [], [], []
    for i in range(len(x)):
        if x[i] > 0. and y[i] > 0.:
            tpf = Cutout2D(image,
                           position=(x[i], y[i]),
                           size=(7, 7),
                           mode='partial')
            cen = quadratic_2d(tpf.data)
            cenx.append(cen[0])
            ceny.append(cen[1])
            good.append(i)
    cenx, ceny = np.array(cenx), np.array(ceny)
    return cenx, ceny, good