def tiptiltestimator_circle(image, cx=None, cy=None, beta=None, lambdaoverd=None, window=None): def cuberoot(x): if x < 0: return -(-x)**(1.0 / 3) else: return x**(1.0 / 3) xs, ys = np.meshgrid(np.arange(image.shape[0]), np.arange(image.shape[1])) subim = pre.subimage(image, (round(cx), round(cy)), window=window) subx = pre.subimage(xs, (round(cx), round(cy)), window=window) suby = pre.subimage(ys, (round(cx), round(cy)), window=window) cumx = np.cumsum(np.sum(subim, axis=1)) cumy = np.cumsum(np.sum(subim, axis=0)) f_interpx = interp1d(subx[0], cumx) f_interpy = interp1d(suby[:, 0], cumy) deltaIx = max(cumx) - 2 * f_interpx(cx) deltaIy = max(cumy) - 2 * f_interpy(cy) Tx = cuberoot(deltaIx / beta) * cuberoot(deltaIx**2 / (deltaIx**2 + deltaIy**2)) Ty = cuberoot(deltaIy / beta) * cuberoot(deltaIy**2 / (deltaIx**2 + deltaIy**2)) return Tx, Ty
def get_delta_I(image, cx=None, cy=None, quad_width_pix=7., inner_rad_pix=0., zone_type=None): if zone_type == 'inner': image = image * pro.circle(image, cx, cy, inner_rad_pix) elif zone_type == 'outer': image = image * (1 - pro.circle(image, cx, cy, inner_rad_pix)) window = np.ceil(quad_width_pix * 2.) xs, ys = np.meshgrid(np.arange(image.shape[0]), np.arange(image.shape[1])) subim = pre.subimage(image, (np.round(cx), np.round(cy)), window=window) subx = pre.subimage(xs, (np.round(cx), np.round(cy)), window=window) suby = pre.subimage(ys, (np.round(cx), np.round(cy)), window=window) cumx = np.cumsum(np.sum(subim, axis=1)) cumy = np.cumsum(np.sum(subim, axis=0)) f_interpx = interp1d(subx[0, :], cumx) f_interpy = interp1d(suby[:, 0], cumy) deltaIx = max(cumx) - 2 * f_interpx(cx - 1) deltaIy = max(cumy) - 2 * f_interpy(cy - 1) #plt.imshow(subim) #plt.show() return deltaIy, deltaIx
def recenter_satellites(image, spots, window=20): """centroid each satellite spot using a 2d gaussian""" #satellite centers scs = np.zeros((len(spots), 2)) for idx,xy in enumerate(spots): subim = pre.subimage(image, xy, window=window) popt = snm.image_centroid_gaussian1(subim) xcenp = popt[1] ycenp = popt[2] xcen = xy[0]-round(window/2)+xcenp ycen = xy[1]-round(window/2)+ycenp scs[idx,:] = xcen, ycen return scs
def fit_satellite_centers(image, spotcenters_init, window=20): """ Returns the center of the image given approximative spot centers """ # fit satellite centers scs = np.zeros((len(spotcenters_init), 2)) for idx, xy in enumerate(spotcenters_init): subim = pre.subimage(image, xy, window=window) popt = snm.image_centroid_gaussian1(subim) xcenp = popt[1] ycenp = popt[2] xcen = xy[0] - round(window / 2) + xcenp ycen = xy[1] - round(window / 2) + ycenp scs[idx, :] = xcen, ycen return scs
def get_satellite_centroids(image, window=20): """centroid each satellite spot using a 2d gaussian""" spots = pre.get_spot_locations(image, eq=True, comment='SHIFT-Click on the satellites CLOCKWISE'+ 'starting from 10 o clock,\n then close the window') #satellite centers scs = np.zeros((len(spots), 2)) for idx,xy in enumerate(spots): subim = pre.subimage(image, xy, window=window) popt = snm.image_centroid_gaussian1(subim) xcenp = popt[1] ycenp = popt[2] xcen = xy[0]-round(window/2)+xcenp ycen = xy[1]-round(window/2)+ycenp scs[idx,:] = xcen, ycen return scs
def recompute_centroid(image, spots, window=20): """centroid each satellite spot using a 2d gaussian""" #spots = pre.get_spot_locations(image, eq=True, # comment='SHIFT-Click on the satellites CLOCKWISE'+ # 'starting from 10 o clock,\n then close the window') #satellite centers scs = np.zeros((4, 2)) for idx, xy in enumerate(spots): subim = pre.subimage(image, xy, window=window) popt = snm.image_centroid_gaussian1(subim) xcenp = popt[1] ycenp = popt[2] xcen = xy[0] - round(window / 2) + xcenp ycen = xy[1] - round(window / 2) + ycenp scs[idx, :] = xcen, ycen center = np.mean(scs, axis=0) print "CENTER IS: ", center return center
"Click the four spots then press enter in this window\n") if intconf['auto']: xy0 = DM.convert_kvecs_pixels(kvecr, 0, **im_params) xy1 = DM.convert_kvecs_pixels(-kvecr, 0, **im_params) xy2 = DM.convert_kvecs_pixels(0, kvecr, **im_params) xy3 = DM.convert_kvecs_pixels(0, -kvecr, **im_params) xypixels = [xy0, xy1, xy2, xy3] print "Fitting spot amplitudes and positions" #loops over the spots you clicked meanintensity = 0 meankvec = 0 meanphotom = 0 for idx, xy in enumerate(xypixels): subim = pre.subimage(im, xy, window=10) subx = pre.subimage(ximcoords, xy, window=10) suby = pre.subimage(yimcoords, xy, window=10) gauss_params = snm.fitgaussian((subx, suby), subim) amplitude = gauss_params[0] #convert pixels returns an xy pair. # in theory all the kvecs should be (x, 0) or (0, y) # in which case the norm will be equal to x or y kvec = np.linalg.norm( DM.convert_pixels_kvecs(gauss_params[1], gauss_params[2], **im_params)) print "Gaussian centroid", gauss_params[1], gauss_params[2] print "corr. k-vector", kvec meanintensity = (meanintensity * float(idx) / float(idx + 1) + amplitude / float(idx + 1))
p3k.sci_offset_up(-offs) #ipdb.set_trace() else : img_off = pre.combine_quadrants(pf.open(off_filename)) img_off = img_off - bgd2 # detect the position of the offseted image ipdb.set_trace() nx=img_off.shape[0] ny=img_off.shape[1] x, y = np.meshgrid(np.arange(nx),np.arange(ny)) fun = pre.get_spot_locations(img_off) indmax = fun[0] subIm= pre.subimage(img_off, (indmax[0],indmax[1]), window=25) subx = pre.subimage(x, (indmax[0],indmax[1]), window=25) suby = pre.subimage(y, (indmax[0],indmax[1]), window=25) gauss_params = snm.fitgaussian((subx, suby), subIm) cx_off, cy_off = gauss_params[1], gauss_params[2] # calibrate pixel size D_pix = np.sqrt((cx_off-centerx)**2+(cy_off-centery)**2) lambdaoverd_arc = config['Image_params']['lambdaoverd_arc'] lambdaoverd = lambdaoverd_arc * D_pix / offs Itot = np.sum(pre.subimage(img_off, (cx_off,cy_off), window = 2*quad_width_pix)) if home: Itot *= Itot_corr_factor
# f.write('%6f\n' %(T_up_comm)) # f.close() # f=open(save_file_name+'comm_Tleft','a') # f.write('%6f\n' %(T_left_comm)) # f.close() ###################################################################### ### DISPLAY # displays the subimage with the axes of the tiptilt mirror (white dashed lines) # and a representation of the estimated tiptilt (orientation and amplitude) #theta= np.arctan(delta_i_y_std/delta_i_x_std) theta = np.arctan(-Tleft_est / Tup_est) + angle if (-Tup_est) < 0.: theta = theta - np.pi subim = pre.subimage(img, (centerx, centery), np.ceil(2 * quad_width_pix)) # circle acirc = np.arange(0., 2 * np.pi, 2 * np.pi / 100.) xcirc = inner_rad_pix * np.cos(acirc) + quad_width_pix ycirc = inner_rad_pix * np.sin(acirc) + quad_width_pix plt.plot(xcirc, ycirc, 'w--') x1 = quad_width_pix * np.cos(angle + np.pi) + quad_width_pix x2 = quad_width_pix * np.cos(angle) + quad_width_pix y1 = quad_width_pix * np.sin(angle + np.pi) + quad_width_pix y2 = quad_width_pix * np.sin(angle) + quad_width_pix plt.plot([x1, x2], [y1, y2], 'w--') x1 = quad_width_pix * np.cos(angle + np.pi / 2.) + quad_width_pix x2 = quad_width_pix * np.cos(angle - np.pi / 2.) + quad_width_pix y1 = quad_width_pix * np.sin(angle + np.pi / 2.) + quad_width_pix y2 = quad_width_pix * np.sin(angle - np.pi / 2.) + quad_width_pix