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
] pos = "inlet" axes = [] for j in range(3): data_list = [] config_list = [] for pressure in [1, 2, 3]: data1, config1 = load_all_data(files[j], pressure=pressure) data_list.append(data1) config_list.append(config1) data = pd.concat(data_list) config = config_list[0] p = fitStiffness(data, config) if 0: fits = get_bootstrap_fit(data, config, 100) np.save(__file__[:-3] + f"_fits{j}.npy", fits) else: fits = np.load(__file__[:-3] + f"_fits{j}.npy") print("fits", fits.shape) p2 = np.std(fits, axis=0) for i in config_list: config1["fit"] = config["fit"] for i in range(3): axes.append(plt.subplot(3, 4, 4 * j + 1 + i)) if i == 0: plt.text( 0.5, 0.5,
import numpy as np import matplotlib.pyplot as plt import pylustrator pylustrator.start() data3, config3 = load_all_data([ r"\\131.188.117.96\biophysDS\emirzahossein\microfluidic cell rhemeter data\microscope_1\september_2020\2020_09_30_alginate2%_NIH3T3_blebbistatin\inlet\[0-9]\*_result.txt" ], pressure=3) data3b, config3b = load_all_data([ r"\\131.188.117.96\biophysDS\emirzahossein\microfluidic cell rhemeter data\microscope_1\september_2020\2020_09_30_alginate2%_NIH3T3_DMSO\inlet\[0-9]\*_result.txt", ], pressure=3) fitStiffness(data3, config3) fitStiffness(data3b, config3b) plt.subplot(121) plotStressStrain(data3b, config3b) plotStressStrainFit(data3b, config3b) plt.title("DMSO") plt.text(0.5, 0.5, f"k = {config3b['fit']['p'][0]:3.0f} Pa\n$\\alpha$ = {config3b['fit']['p'][1]:2.2f}") plt.subplot(122) plotStressStrain(data3, config3) plotStressStrainFit(data3, config3) plt.title("blebbistation") plt.text(0.5, 0.5, f"k = {config3['fit']['p'][0]:3.0f} Pa\n$\\alpha$ = {config3['fit']['p'][1]:2.2f}")
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
(np.pi * 2 * config1["imaging_pos_mm"])))**alpha) + p2 #return np.log(x/k + 1) / ((np.abs(w2) + (v2/(np.pi*2*config1["imaging_pos_mm"]))) ** alpha) + p2 def fitfunc3(x, p0, p1, p2): # for stress versus strain k = p0 #(p0 + x) alpha = p1 #return x / (k * (np.abs(w)) ** alpha) return x / (k * (np.abs(w3) + (v3 / (np.pi * 2 * config1["imaging_pos_mm"])))**alpha) + p2 #return np.log(x/k + 1) / ((np.abs(w3) + (v3/(np.pi*2*config1["imaging_pos_mm"]))) ** alpha) + p2 indices = data.stress < 9999999 p = fitStiffness(data, config) p1 = p p2 = p p3 = p if 0: ps = [] ii = np.arange(10, 300, 50) for i in ii: indices = data.stress < i p = fitStiffness(data[data.stress < i], config) ps.append(p) print(i, p) p1 = p p2 = p p3 = p
data1, config1 = load_all_data([ r"\\131.188.117.96\biophysDS\emirzahossein\microfluidic cell rhemeter data\microscope4\2020_july\2020_07_29_aslginate2%_NIH_diff_x_position_2\inlet\[0-9]\*_result.txt", r"\\131.188.117.96\biophysDS\emirzahossein\microfluidic cell rhemeter data\microscope4\2020_july\2020_07_29_aslginate2%_NIH_diff_x_position_3\inlet\[0-9]\*_result.txt", ], pressure=1) data = data1#pd.concat([data1, data2, data3]) config = config1 fits = [] frac = np.arange(0.1, 1.1, 0.1) for i in frac: d = data[data.stress < i] ps = [] for j in range(100): d0 = d.sample(frac=i, replace=True) p = fitStiffness(d0, config) #p = np.random.rand(3) ps.append(p) fits.append(ps) fits = np.array(fits) #np.save(__file__[:-3], fits) print(fits) print(fits.shape) fit_means = np.mean(fits, axis=-2) print(fit_means) fit_stds = np.std(fits, axis=-2) print(fit_stds) for i in range(3): plt.subplot(1, 3, i+1) print(fit_means.shape)
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