def mean_var_xy(xy, rx=10, ry=10): int_x, int_y = int(round(xy[0])), int(round(xy[1])) xys = [] for i in range(int_x - rx, int_x + rx + 1): for j in range(int_y - ry, int_y + ry + 1): xys.append((i, j)) xys = tuple(xys) subimages = np.zeros((100, len(xys))) dirpath = "/home/fengguo/Data/Si2g_200N/nomvt/" for i in range(100): path = dirpath + "S2gnomvt_%s_mar.tiff" % stringint(i, 4) f = open(path, "rb") f.seek(offset) image = np.fromfile(f, dtype=formatdata, count=nb_elem).reshape(framedim) for j in range(len(xys)): subimages[i, j] = image[xys[j]] + bkg[xys[j]] - 100 f.close() mean, std = np.zeros(len(xys)), np.zeros(len(xys)) for i in range(len(xys)): mean[i], std[i] = subimages[:, i].mean(), subimages[:, i].std() var = std ** 2 return mean, var
xys = peaks[:, 0:2] xykb = np.zeros((peaks.shape[0], 4)) for n in range(xys.shape[0]): # xys.shape[0]): pixels = [] int_x, int_y = int(round(xys[n, 1])), int(round(xys[n, 0])) for i in range(int_x - rx, int_x + rx + 1): for j in range(int_y - ry, int_y + ry + 1): pixels.append((i, j)) pixels = tuple(pixels) subimages = np.zeros((100, len(pixels))) # dirpath = '/home/fengguo/Data/Si2g_200N/nomvt/' for i in range(100): path = dirpath + "S2gnomvt_%s_mar.tiff" % stringint(i, 4) f = open(path, "rb") f.seek(offset) image = np.fromfile(f, dtype=formatdata, count=nb_elem).reshape(framedim) for j in range(len(pixels)): subimages[i, j] = image[pixels[j]] + bkg[pixels[j]] - 100 f.close() mean, std = np.zeros(subimages.shape[1]), np.zeros(subimages.shape[1]) for i in range(subimages.shape[1]): mean[i], std[i] = subimages[:, i].mean(), subimages[:, i].std() var = std ** 2 k, b = linregress(mean, var)[0:2] xykb[n] = xys[n, 0], xys[n, 1], k, b np.save("xykb", xykb) # mean = images[:]
xsbl = image[xs - 1, ys:ye].max() > thre ysbl = image[xs:xe, ys - 1].max() > thre xebl = image[xe + 1, ys:ye].max() > thre yebl = image[xs:xe, ye + 1].max() > thre if xsbl: xs = xs - 1 if ysbl: ys = ys - 1 if xebl: xe = xe + 1 if yebl: ye = ye + 1 pk_bound[i] = xi, yi, xs, ys, xe, ye mean, std = np.zeros((xe - xs, ye - ys)), np.zeros((xe - xs, ye - ys)) images = np.zeros((100, xe - xs, ye - ys)) for j in range(100): path = dirpath + 'S1gnomvt_%s_mar.tiff' % stringint(j, 4) f = open(path, 'rb') f.seek(offset) images[j] = np.fromfile(f, dtype=formatdata, count=nb_elem).reshape( framedim)[xs:xe, ys:ye] + bkg[xs:xe, ys:ye] - 100 f.close() for k in range(xe - xs): for l in range(ye - ys): mean[k, l], std[k, l] = images[:, k, l].mean(), images[:, k, l].std() np.save('mean%i' % i, mean) np.save('std%i' % i, std) np.save('peak_bound', pk_bound)
xsbl, ysbl, xebl, yebl = True, True, True, True while xsbl or ysbl or xebl or yebl: xsbl = image[xs-1, ys:ye].max() > thre ysbl = image[xs:xe, ys-1].max() > thre xebl = image[xe+1, ys:ye].max() > thre yebl = image[xs:xe, ye+1].max() > thre if xsbl: xs = xs-1 if ysbl: ys = ys-1 if xebl: xe = xe+1 if yebl: ye = ye+1 pk_bound[i] = xi, yi, xs, ys, xe, ye mean, std = np.zeros((xe-xs,ye-ys)), np.zeros((xe-xs,ye-ys)) images = np.zeros((100,xe-xs,ye-ys)) for j in range(100): path = dirpath + 'S1gnomvt_%s_mar.tiff'%stringint(j, 4) f = open(path, 'rb') f.seek(offset) images[j] = np.fromfile(f, dtype = formatdata, count = nb_elem).reshape(framedim)[xs:xe, ys:ye]+bkg[xs:xe, ys:ye]-100 f.close() for k in range(xe-xs): for l in range(ye-ys): mean[k, l], std[k, l] = images[:, k, l].mean(), images[:, k, l].std() np.save('mean%i'%i,mean) np.save('std%i'%i,std) np.save('peak_bound',pk_bound)
print i f_cur, f_ref = open('%i200'%i,'w'),open('%iref'%i,'w') f_cur.write('%i %i %i'%(len(mch),0,len(mch))) f_ref.write('%i %i %i'%(len(mch),0,len(mch))) for j in range(len(mch)): f_cur.write('\n%i %i %f %f'%(j+1,0,cur[mch[j,1],0],-cur[mch[j,1],1])) f_ref.write('\n%i %i %f %f'%(j+1,0,ref[mch[j,0],0],-ref[mch[j,0],1])) f_cur.close() f_ref.close() """ dd5, xcen5, ycen5, beta5, gamma5 = 59.836, 1365.74, 943.05, 0.373, 0.504 dd200, xcen200, ycen200, beta200, gamma200 = 59.836, 1365.74, 943.05, 0.373, 0.504 for n in range(0,1): ref = np.load('pos%s_5.npy'%stringint(n,4)) cur = np.load('pos%s_50.npy'%stringint(n+7,4)) k_ref, k_cur = np.zeros((ref.shape[0], 3)), np.zeros((cur.shape[0], 3)) det2lab_mat5 = Det_Lab_Mat(beta5, gamma5) for i in range(ref.shape[0]): k_ref[i] = Detector_to_Lab(ref[i], det2lab_mat5, dd = dd5, xcen_pix = xcen5, ycen_pix = ycen5, pix_size = pix_size) det2lab_mat200 = Det_Lab_Mat(beta200, gamma200) for i in range(cur.shape[0]): k_cur[i] = Detector_to_Lab(cur[i], det2lab_mat200, dd = dd200, xcen_pix = xcen200, ycen_pix = ycen200, pix_size = pix_size) mch = np.array(Trace(k_ref, k_cur).values()) f_cur, f_ref = open('%i200'%n,'w'),open('%iref'%n,'w') print len(mch) f_cur.write('%i %i %i'%(len(mch),0,len(mch))) f_ref.write('%i %i %i'%(len(mch),0,len(mch))) for j in range(len(mch)):
import numpy as np import finding as FIND from common import stringint offset = 4096 bkg_offset = 110 framedim = (2594, 2774) nb_elem = framedim[0]*framedim[1] formatdata = np.uint16 bkg_path = os.path.join('/', 'home', 'fengguo', 'Data', 'back_5s_0001.tif') ref_path = '/home/fengguo/Data/Si1g_5N/scan/' + 'S1gscan_0440_mar.tiff' path = '/home/fengguo/Data/Si1g_200N/scan/' + 'S2gscan_0001_mar.tiff' bkg_f = open(bkg_path, 'rb') bkg_f.seek(bkg_offset) bkg = np.fromfile(bkg_f, dtype = formatdata, count = nb_elem).reshape(framedim) bkg_f.close() for i in range(0, 881): path = '/home/fengguo/Data/Si1g_200N/scan/' + 'S2gscan_%s_mar.tiff'%stringint(4,i) f = open(path, 'rb') f.seek(offset) image = np.fromfile(f, dtype = formatdata, count = nb_elem).reshape(framedim) raw_image = image+bkg-100 pos=FindingPosition(raw_image, xdim = 2594, ydim = 2774) np.save('pos%s'%stringint(4,i),pos)