# %% import os # os.chdir(os.path.dirname(os.path.abspath('examples.py'))) import findpeaks print(dir(findpeaks)) print(findpeaks.__version__) # %% from findpeaks import findpeaks fp = findpeaks(method="topology", denoise=None, window=3) # X = fp.import_example("2dpeaks_image") X = fp.import_example("2dpeaks") results = fp.fit(X) fp.plot_preprocessing() fp.plot() fp.plot_peristence() fp.plot_mesh() fp = findpeaks(method="mask") X = fp.import_example() results = fp.fit(X) fp.plot() fp.plot_preprocessing() fp.plot_peristence() fp.plot_mesh() # %% from findpeaks import findpeaks
x_label = "X" if args.y_label is not None: y_label = args.y_label elif "YLabel" in header: y_label = headers[0]["YLabel"] else: y_label = "Y" # find limits if args.x_max is None or args.y_max is None: xmax = list(map(len, x)) ysum = list(map(np.sum, y)) ymax = list(map(np.max, y)) for i in range(len(x)): peakx = findpeaks(y[i]) peakx = peakx[peakx != 1] peaky = y[i][peakx] for j in range(1, xmax[i], int(xmax[i]/1000) + 1): if np.sum(y[i][:j]) >= ysum[i] * 0.999: xmax[i] = j break ymax[i] = np.max(peaky) * 1.1 xmax = max(xmax) ymax = max(ymax) if args.verbose: print("Automatically detected axis limits:") print("xmax: ", xmax)
else: z_label = "Z" matrix = np.loadtxt(input_file) input_file.close() if args.verbose: print("{:d} by {:d} matrix file loaded.".format(matrix.shape[0], matrix.shape[1])) matrix_smooth = ndimage.gaussian_filter(matrix, sigma=2.0, order=0) if args.x_max is None or args.y_max is None or args.z_max is None: # find peaks msum = np.sum(matrix) xsums = np.sum(matrix, 0) ysums = np.sum(matrix, 1) peakx = findpeaks(xsums) peaky = findpeaks(ysums) # ignore peaks at 1 peakx = peakx[peakx != 1] peaky = peaky[peaky != 1] peakz = matrix[peaky, :][:, peakx] # peakxv = xsums[peakx] # print "peakxv: ", peakxv # xmax = np.max(peakx[peakxv > (msum * 0.0005)]) * 2 # peakyv = ysums[peaky] # print "peakyv: ", peakyv # ymax = np.max(peaky[peakyv > (msum * 0.0005)]) * 2 xmax = len(xsums) ymax = len(ysums)
else: z_label = "Z" matrix = np.loadtxt(input_file) input_file.close() if args.verbose: print("{:d} by {:d} matrix file loaded.".format(matrix.shape[0], matrix.shape[1])) matrix_smooth = ndimage.gaussian_filter(matrix, sigma=2.0, order=0) if args.x_max is None or args.y_max is None or args.z_max is None: # find peaks msum = np.sum(matrix) xsums = np.sum(matrix, 0) ysums = np.sum(matrix, 1) peakx = findpeaks(xsums) peaky = findpeaks(ysums) # ignore peaks at 1 peakx = peakx[peakx != 1] peaky = peaky[peaky != 1] peakz = matrix[peaky,:][:,peakx] # peakxv = xsums[peakx] # print "peakxv: ", peakxv # xmax = np.max(peakx[peakxv > (msum * 0.0005)]) * 2 # peakyv = ysums[peaky] # print "peakyv: ", peakyv # ymax = np.max(peaky[peakyv > (msum * 0.0005)]) * 2 xmax = len(xsums) ymax = len(ysums)
x_label = "X" if args.y_label is not None: y_label = args.y_label elif "YLabel" in header: y_label = headers[0]["YLabel"] else: y_label = "Y" # find limits if args.x_max is None or args.y_max is None: xmax = list(map(len, x)) ysum = list(map(np.sum, y)) ymax = list(map(np.max, y)) for i in range(len(x)): peakx = findpeaks(y[i]) peakx = peakx[peakx != 1] peaky = y[i][peakx] for j in range(1, xmax[i], int(xmax[i] / 1000) + 1): if np.sum(y[i][:j]) >= ysum[i] * 0.999: xmax[i] = j break ymax[i] = np.max(peaky) * 1.1 xmax = max(xmax) ymax = max(ymax) if args.verbose: print("Automatically detected axis limits:") print("xmax: ", xmax)
xamount = 0.65 else: xamount = 0.99 # leave only coverage levels we are interested in last_column = np.transpose(np.matrix(np.sum(matrix[:,(mincov+covbands):], 1))) matrix = np.concatenate([matrix[:,mincov:(mincov+covbands)], last_column], 1) # find limits if args.x_max is None or args.y_max is None: totals = np.squeeze(np.asarray(np.sum(matrix, 1))) xmax = len(totals) - 1 ysum = np.sum(totals) ymax = np.max(totals) peakx = findpeaks(totals) peakx = peakx[peakx != 1] peaky = totals[peakx] for i in range(1, xmax, int(xmax/100) + 1): if np.sum(totals[:i]) >= ysum * xamount: xmax = i break ymax = np.max(peaky) * 1.1 if args.verbose: print("Automatically detected axis limits:") print("xmax: ", xmax) print("ymax: ", ymax) if args.x_max is not None: xmax = args.x_max
xamount = 0.99 # leave only coverage levels we are interested in last_column = np.transpose( np.matrix(np.sum(matrix[:, (mincov + covbands):], 1))) matrix = np.concatenate([matrix[:, mincov:(mincov + covbands)], last_column], 1) # find limits if args.x_max is None or args.y_max is None: totals = np.squeeze(np.asarray(np.sum(matrix, 1))) xmax = len(totals) - 1 ysum = np.sum(totals) ymax = np.max(totals) peakx = findpeaks(totals) peakx = peakx[peakx != 1] peaky = totals[peakx] for i in range(1, xmax, int(xmax / 100) + 1): if np.sum(totals[:i]) >= ysum * xamount: xmax = i break ymax = np.max(peaky) * 1.1 if args.verbose: print("Automatically detected axis limits:") print("xmax: ", xmax) print("ymax: ", ymax) if args.x_max is not None: xmax = args.x_max