def get_data(datdir, prefd, sufd, nf1, nf2): # read Maxipix, Eiger edf images #### t0 = time.time() swrite = stdout.write sflush = stdout.flush print("start reading the files") # creating filenames filenames = nfiles.filename(datdir + prefd, sufd, nf1, nf2) lfilenames = len(filenames) # reading first image to get dimenstions of the matrix headers = EdfMethods.headeredf(filenames[0]) dim1 = np.intc(headers['Dim_1']) dim2 = np.intc(headers['Dim_2']) nx = dim2 ny = dim1 data = np.zeros((lfilenames, nx, ny), np.uint16) i = 0 for mfile in filenames: data[i, :, :] = EdfMethods.loadedf(mfile) i += 1 swrite(4 * '\x08') swrite(str(int(i * 100. / lfilenames)) + '%') sflush() print("\n") print("Reading time %3.3f sec" % (time.time() - t0)) return data
def get_delta(datdir, prefd, sufd, nf1, nf2, scan="1"): if sufd == ".edf": filenames = nfiles.filename(datdir + prefd, sufd, nf1, nf2) h = EdfMethods.headeredf(filenames[10]) delta = float( h['motor_pos'].split(" ")[h['motor_mne'].split(" ").index('del')]) if sufd == ".h5": filename = datdir + prefd + sufd with h5py.File(filename, mode="r") as h5: delta = h5['/' + scan + '.1/instrument/positioners/delta'][()] return delta
def get_ccd_event_datan(datdir, prefd, sufd, nf1, nf2, darkdir, df1, df2, sname, lth, bADU, tADU, mNp, aduph, savdir, mask_file, thr=20, frc=0.15): ### read ccd edf images and convert for Pierre's event correlator using numba #### t0 = time.time() swrite = stdout.write sflush = stdout.flush print("start reading the files") # creating filenames filenames = nfiles.filename(datdir + prefd, sufd, nf1, nf2) lfilenames = len(filenames) # -1 # reading first image to get dimenstions of the matrix headers = EdfMethods.headeredf(filenames[0]) dim1 = np.intc(headers['Dim_1']) dim2 = np.intc(headers['Dim_2']) nx = dim2 ny = dim1 ############reading mask########## try: mask_data = EdfMethods.loadedf(mask_file) print("use mask file " + mask_file) ind = np.where(mask_data > 0) for_norm = dim1 * dim2 - len(mask_data[ind]) except: mask_data = np.zeros((dim2, dim1), np.uint8) print("no mask applied") for_norm = dim1 * dim2 # 1024**2 pass print("Numebr of pixels used " + str(for_norm)) ########reading dark########## darkfilenames = nfiles.filename(darkdir + prefd, sufd, df1, df2) ndarks = 0 for dfile in darkfilenames: if ndarks == 0: darkimg = np.asfarray(EdfMethods.loadedf(dfile), dtype=np.float32) else: darkimg += np.asfarray(EdfMethods.loadedf(dfile), dtype=np.float32) ndarks += 1 darkimg = darkimg / ndarks n_frames = len(filenames) ll = nx * ny # total number of pixels lp = int(n_frames * frc) # total number of frames with events 15% mask = np.array(np.ravel(mask_data), np.uint8) evs = np.zeros((ll, lp), np.uint8) tms = np.zeros((ll, lp), np.uint16) cnt = np.ravel(np.zeros((ll, ), np.uint16)) afr = np.ravel(np.zeros((ll, ), np.uint32)) tr = 0 trace = np.zeros((n_frames, ), np.uint32) it = 0 print("Number of frames %d" % n_frames) ###########reading and summing files########### for i in range(lfilenames): swrite(4 * '\x08') swrite(str(int(i * 100. / lfilenames)) + '%') sflush() matr = np.asfarray(EdfMethods.loadedf(filenames[i]), dtype=np.float32) try: matr[ind] = 0 except: pass msumpix, mpix, fr = dropimgood(matr, darkimg, lth, bADU, tADU, mNp, aduph, nx, ny) # dropletize CCD frames fr = np.ravel(fr) evs, tms, cnt, afr, mask, tr = neigercompress(evs, tms, cnt, afr, mask, tr, fr, thr, it, ll, lp) trace[i] = tr it += 1 if not os.path.exists(savdir): answ = input("create a director (y)/n").lower() if answ == "n": print("exit") exit() else: os.makedirs(savdir) print("directory " + savdir + " has been created") afr = afr / n_frames afr = np.reshape(afr, (nx, ny)) mask = np.reshape(mask, (nx, ny)) evs, tms, c = nprepare(np.ravel(evs), np.ravel(tms)) evs = np.array(evs[:c], np.int8) tms = tms[:c] print("Reading time %3.3f sec" % (time.time() - t0)) return evs, tms, cnt, afr, n_frames, mask, trace
def get_ccd_event_data(datdir, prefd, sufd, nf1, nf2, darkdir, df1, df2, sname, lth, bADU, tADU, mNp, aduph, savdir, mask_file): ### read ccd edf images and convert for event correlator #### time0 = time.time() swrite = stdout.write sflush = stdout.flush print("start reading the files") # creating filenames filenames = nfiles.filename(datdir + prefd, sufd, nf1, nf2) lfilenames = len(filenames) # -1 # reading first image to get dimenstions of the matrix headers = EdfMethods.headeredf(filenames[0]) dim1 = np.intc(headers['Dim_1']) dim2 = np.intc(headers['Dim_2']) nx = dim2 ny = dim1 ############reading mask########## try: mask_data = EdfMethods.loadedf(mask_file) print("use mask file " + mask_file) ind = np.where(mask_data > 0) for_norm = dim1 * dim2 - len(mask_data[ind]) except: print("no mask applied") for_norm = dim1 * dim2 # 1024**2 pass print("Numebr of pixels used " + str(for_norm)) ########creating image matrix of zeros############ img = np.zeros((dim2, dim1)) ########reading dark########## darkfilenames = nfiles.filename(darkdir + prefd, sufd, df1, df2) ndarks = 0 for dfile in darkfilenames: if ndarks == 0: darkimg = np.asfarray(EdfMethods.loadedf(dfile), dtype=np.float32) else: darkimg += np.asfarray(EdfMethods.loadedf(dfile), dtype=np.float32) ndarks += 1 darkimg = darkimg / ndarks pixels = [] s = [] data = [] pread = [] for i in range(2): data.append(Queue(2)) # pread.append(Process(target=mread_ccd, args=(filenames[i:-1:2],data[i],darkimg,lth,bADU,tADU,mNp,aduph,nx,ny))) pread.append( Process(target=mread_ccd, args=(filenames[:-1:2], data[0], darkimg, lth, bADU, tADU, mNp, aduph, nx, ny))) pread.append( Process(target=mread_ccd, args=(filenames[1::2], data[1], darkimg, lth, bADU, tADU, mNp, aduph, nx, ny))) for i in range(2): pread[i].start() ii = 0 ###########reading and summing files########### for i in range(lfilenames): swrite(4 * '\x08') swrite(str(int(i * 100. / lfilenames)) + '%') sflush() fromproc = data[ii].get() pixels.append(fromproc[0]) s.append(fromproc[1]) img += fromproc[2] ii += 1 if ii == 2: ii = 0 for i in range(2): pread[i].join() data[i].close() dtime = time.time() - time0 print('reading of %d files took %5.2f sec' % (lfilenames, dtime)) if not os.path.exists(savdir): answ = input("create a director (y)/n") if answ == "n": print("exit") exit() else: os.makedirs(savdir) print("directory " + savdir + " has been created") return pixels, s, for_norm, img