def plotPathList(paths): global ax paths = list(paths) print(paths) fit_data = [] data_list = [] for index, file in enumerate(paths):#[repetition:repetition+1]): output_file = Path(str(file).replace("_result.txt", "_evaluated.csv")) # load the data and the config data = getData(file) config = getConfig(file) """ evaluating data""" if not output_file.exists(): #refetchTimestamps(data, config) getVelocity(data, config) # take the mean of all values of each cell data = data.groupby(['cell_id']).mean() correctCenter(data, config) data = filterCells(data, config) # reset the indices data.reset_index(drop=True, inplace=True) getStressStrain(data, config) #data = data[(data.stress < 50)] data.reset_index(drop=True, inplace=True) data["area"] = data.long_axis * data.short_axis * np.pi data.to_csv(output_file, index=False) data = pd.read_csv(output_file) #data = data[(data.area > 0) * (data.area < 2000) * (data.stress < 250)] #data.reset_index(drop=True, inplace=True) data_list.append(data) data = pd.concat(data_list) data.reset_index(drop=True, inplace=True) fitStiffness(data, config) #plotDensityScatter(data.stress, data.strain) #plotStressStrainFit(data, config) #plotBinnedData(data.stress, data.strain, [0, 10, 20, 30, 40, 50, 75, 100, 125, 150, 200, 250]) #plt.title(f'{config["fit"]["p"][0] * config["fit"]["p"][1]:.2f}') fit_data.append([config["fit"]["p"][0], config["fit"]["p"][1], config["fit"]["p"][0] * config["fit"]["p"][1]]) return fit_data
#refetchTimestamps(data, config) getVelocity(data, config) # take the mean of all values of each cell data = data.groupby(['cell_id']).mean() correctCenter(data, config) data = filterCells(data, config) # reset the indices data.reset_index(drop=True, inplace=True) getStressStrain(data, config) fitStiffness(data, config) """ plotting data """ initPlotSettings() # add multipage plotting pp = PdfPages(datafile[:-11] + '.pdf') # generate the velocity profile plot plotVelocityProfile(data, config) pp.savefig() plt.cla() # generate the stress strain plot
def plotPathList(paths): global ax paths = list(paths) print(paths) fit_data = [] data_list = [] for index, file in enumerate(paths): output_file = Path(str(file).replace("_result.txt", "_evaluated.csv")) # load the data and the config data = getData(file) config = getConfig(file) """ evaluating data""" if not output_file.exists(): #refetchTimestamps(data, config) getVelocity(data, config) # take the mean of all values of each cell data = data.groupby(['cell_id']).mean() correctCenter(data, config) data = filterCells(data, config) # reset the indices data.reset_index(drop=True, inplace=True) getStressStrain(data, config) #data = data[(data.stress < 50)] data.reset_index(drop=True, inplace=True) data["area"] = data.long_axis * data.short_axis * np.pi data.to_csv(output_file, index=False) data = pd.read_csv(output_file) if 0: plt.plot(data.rp, data.angle, "o") plt.axhline(0) plt.axvline(0) plt.axhline(45) plt.axhline(-45) print(data.angle) plt.show() #data = data[(data.area > 0) * (data.area < 2000) * (data.stress < 250)] #data.reset_index(drop=True, inplace=True) data_list.append(data) data = pd.concat(data_list) data.reset_index(drop=True, inplace=True) getStressStrain(data, config) if 0: if 1: data.strain[(data.angle > 0) & (data.rp > 0)] *= -1 data.strain[(data.angle < 0) & (data.rp < 0)] *= -1 else: data.strain[(data.angle > 45)] *= -1 data.strain[(data.angle < -45)] *= -1 fits = [] errors = [] for i in np.arange(30, 250, 10): data2 = data[data.stress < i].reset_index(drop=True) print(i, len(data2)) fitStiffness(data2, config) fits.append(config["fit"]["p"]) errors.append(config["fit"]["err"]) print("err", config["fit"]["err"], errors) plotDensityScatter(data.stress, data.strain) plotStressStrainFit(data, config) plotBinnedData(data.stress, data.strain, [0, 10, 20, 30, 40, 50, 75, 100, 125, 150, 200, 250]) #plt.title(f'{config["fit"]["p"][0] * config["fit"]["p"][1]:.2f}') fit_data.append(config["fit"]["p"][0] * config["fit"]["p"][1]) return fits, errors #fit_data
def plotPathList(paths, cmap=None, alpha=None): global ax, global_im paths = list(paths) print(paths) fit_data = [] data_list = [] for index, file in enumerate(paths): output_file = Path(str(file).replace("_result.txt", "_evaluated.csv")) # load the data and the config data = getData(file) config = getConfig(file) """ evaluating data""" if not output_file.exists(): #refetchTimestamps(data, config) getVelocity(data, config) # take the mean of all values of each cell data = data.groupby(['cell_id']).mean() correctCenter(data, config) data = filterCells(data, config) # reset the indices data.reset_index(drop=True, inplace=True) getStressStrain(data, config) #data = data[(data.stress < 50)] data.reset_index(drop=True, inplace=True) data["area"] = data.long_axis * data.short_axis * np.pi data.to_csv(output_file, index=False) data = pd.read_csv(output_file) #data = data[(data.area > 0) * (data.area < 2000) * (data.stress < 250)] #data.reset_index(drop=True, inplace=True) data_list.append(data) data = pd.concat(data_list) data.reset_index(drop=True, inplace=True) fitStiffness(data, config) #plotDensityScatter(data.stress, data.strain, cmap=cmap, alpha=0.5) def densityPlot(x, y, cmap, alpha=0.5): global global_im, global_index from scipy.stats import kde ax = plt.gca() # Thus we can cut the plotting window in several hexbins nbins = np.max(x) / 10 ybins = 20 # Evaluate a gaussian kde on a regular grid of nbins x nbins over data extents k = kde.gaussian_kde(np.vstack([x, y])) if 0: xi, yi = np.mgrid[x.min():x.max():nbins * 1j, y.min():y.max():ybins * 1j] zi = k(np.vstack([xi.flatten(), yi.flatten()])) # plot a density ax.set_title('Calculate Gaussian KDE') ax.pcolormesh(xi, yi, zi.reshape(xi.shape), shading='gouraud', alpha=alpha, cmap=cmap) else: xi, yi = np.meshgrid( np.linspace(-10, 250, 200), np.linspace(0, 1, 80) ) #np.mgrid[x.min():x.max():nbins * 1j, y.min():y.max():ybins * 1j] zi = k(np.vstack([xi.flatten(), yi.flatten()])) im = zi.reshape(xi.shape) if 0: if global_im is None: global_im = np.zeros((im.shape[0], im.shape[1], 3), dtype="uint8") if 1: #global_index == 1: print("_____", im.min(), im.max()) im -= np.percentile(im, 10) global_im[:, :, global_index] = im / im.max() * 255 print("_____", global_im[:, :, global_index].min(), global_im[:, :, global_index].max()) print("COLOR", global_index) global_index += 1 if global_index == 3: print(global_im.shape, global_im.dtype) plt.imshow(global_im[::-1], extent=[ np.min(xi), np.max(xi), np.min(yi), np.max(yi) ], aspect="auto") else: if global_im is None: global_im = [] im -= im.min() im /= im.max() global_im.append(plt.get_cmap(cmap)(im**0.5)) global_im[-1][:, :, 3] = im plt.imshow( global_im[-1][::-1], vmin=0, vmax=1, extent=[np.min(xi), np.max(xi), np.min(yi), np.max(yi)], aspect="auto") global_index += 1 if global_index == 3: print("COLOR", global_im[0].shape, global_im[0].min(), global_im[0].max()) im = global_im[0] + global_im[1] + global_im[2] - 2 #im[im<0] = 0 #im[im>255] = 255 print("COLOR", im.shape, im.min(), im.max()) #plt.imshow(im[::-1], vmin=0, vmax=1, extent=[np.min(xi), np.max(xi), np.min(yi), np.max(yi)], aspect="auto") densityPlot(data.stress, data.strain, cmap=cmap, alpha=alpha) plotStressStrainFit(data, config) #plotStressStrainFit(data, config) #plotBinnedData(data.stress, data.strain, [0, 10, 20, 30, 40, 50, 75, 100, 125, 150, 200, 250]) #plt.title(f'{config["fit"]["p"][0] * config["fit"]["p"][1]:.2f}') fit_data.append(config["fit"]["p"][0] * config["fit"]["p"][1]) return fit_data