def fit_2dgaussian(array, cy=None, cx=None, fwhm=4): """ Fitting a 2D Gaussian to the 2D distribution of the data with photutils. Parameters ---------- array : array_like Input frame with a single point source, approximately at the center. cy : int Y integer position of source in the array for extracting a subframe. cx : int X integer position of source in the array for extracting a subframe. fwhm : float Expected FWHM of the gaussian. Returns ------- x : float Source centroid x position on input array from fitting. y : float Source centroid y position on input array from fitting. """ if cy and cx and fwhm: subimage, suby, subx = get_square(array, size=6 * int(fwhm), y=cy, x=cx, position=True) x, y = morphology.centroid_2dg(subimage) x += subx y += suby else: x, y = morphology.centroid_2dg(array) return y, x
def centroid_2dg(self): """ This function ... :return: """ return centroid_2dg(self._data)
def centroidg2d(image_data): cx=np.zeros(64) cy=np.zeros(64) for i in range(64): cx[i],cy[i]=centroid_2dg(image_data3[i,13:18,13:18]) cx[i]+=13 cy[i]+=13 return cx,cy
def centroidg2d(image_data): cx=np.zeros(len(image_data)) cy=np.zeros(len(image_data)) for i in range(len(image_data)): print i cx[i],cy[i]=centroid_2dg(image_data[i,13:18,13:18]) cx[i]+=13 cy[i]+=13 return cx,cy
def centroid(data, coord, box_size=10, wcs=None): coord = [np.float(coord[0]), np.float(coord[1])] ## make cutout mask mask = get_mask(data, coord, box_size) # first, try gaussian xc, yc = centroid_2dg(data, mask=mask) if np.isnan((xc, yc)).any(): print 'Failed to centroid' xc, yc = coord if wcs: ra, dec = pix2wcs([xc, yc], wcs) tbl = Table([[xc], [yc], [ra], [dec]], names=['xcen', 'ycen', 'ra', 'dec']) else: tbl = Table([[xc], [yc]], names=['xcen', 'ycen']) return tbl
def calc_centroids(section): y2, x2 = centroid_2dg(section) print 'VALUE ', section[int(y2+.5),int(x2+.5)] # print y2,x2 return x2+.5, y2+.5
def recenter(image, pos, window_size=15, method="2dg"): """ Recenter each star in each frame of the image cube before performing aperture photometry to take care of slight misalignments between frames because of atmospheric turbulence and tracking/pointing errors. Parameters ---------- image : numpy array 2D image pos : list List of (x,y) tuples for star positions window_size : int Window size in which to fit the gaussian to the star to calculate new center method : string Method used to find center of the star. Options are 1d Gaussian fit, 2d gaussian fit or com (center of mass) Returns ------- xcen, ycen : float Source x and y centers """ pos = np.asarray(pos) ny, nx = image.shape window_size = int(window_size) nstars = pos.shape[0] star_pos = np.zeros([nstars, 2], dtype=np.float32) for i in range(nstars): x, y = pos[i][0], pos[i][1] xmin, xmax = int(x) - int(window_size / 2), int(x) + int(window_size / 2) + 1 ymin, ymax = int(y) - int(window_size / 2), int(y) + int(window_size / 2) + 1 if xmin < 0: xmin = 0 if ymin < 0: ymin = 0 if xmax > nx: xmax = nx if ymax > ny: ymax = ny if method == "1dg": xcen, ycen = centroid_1dg(image[ymin:ymax, xmin:xmax]) elif method == "2dg": xcen, ycen = centroid_2dg(image[ymin:ymax, xmin:xmax]) elif method == "com": xcen, ycen = centroid_com(image[ymin:ymax, xmin:xmax]) if (np.abs(xmin + xcen - x)) > 3.0 or (np.abs(ymin + ycen - y)) > 3.0: star_pos[i, 0] = x star_pos[i, 1] = y else: star_pos[i, 0] = xmin + xcen star_pos[i, 1] = ymin + ycen return star_pos