def beamProfile(ask, folder=None, shape=(512, 512)): stacks, folder = loadStacks(ask, folder) n = len(stacks) profile = np.zeros(shape) norm = 0 for filename in stacks: print(filename) stack = Stack(filename=filename) meanFrame = stack.imageData.mean(0) # Beam identification hist, edg = np.histogram(meanFrame, bins=100) thres = edg[argrelextrema(hist, np.less)[0][0] + 1] beamMask = np.zeros(shape=meanFrame.shape, dtype=bool) beamMask[meanFrame < thres] = True beamFrame = np.ma.masked_array(meanFrame, beamMask) # Normalization meanInt = beamFrame.mean() profile += meanFrame / meanInt norm += meanInt stack.close() norm /= n hist, edg = np.histogram(profile, bins=100) thres = edg[argrelextrema(hist, np.less)[0][0] + 2] beam_mask = np.zeros(shape=profile.shape, dtype=bool) beam_mask[profile < thres] = True beamProfile = np.ma.masked_array(profile, beam_mask) return beamProfile, norm, folder