コード例 #1
0
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)

        #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])

    return fit_data
コード例 #2
0
def load_one_data(input_path):

    output_file = Path(str(file).replace("_result.txt", "_evaluated.csv"))
    output_config_file = Path(
        str(file).replace("_result.txt", "_evaluated_config.txt"))

    # load the data and the config
    data = getData(file)
    config = getConfig(file)
    config["channel_width_m"] = 0.00019001261833616293
    """ evaluating data"""
    getVelocity(data, config)
    # take the mean of all values of each cell
    #data = data.groupby(['cell_id'], as_index=False).mean()

    if 0:
        tt_file = Path(str(file).replace("_result.txt", "._tt.csv"))
        if tt_file.exists():
            data.set_index("cell_id", inplace=True)
            data_tt = pd.read_csv(tt_file)
            data["omega"] = np.zeros(len(data)) * np.nan
            for i, d in data_tt.iterrows():
                if d.tt_r2 > 0.2:  # and d.id in data.index:
                    data.at[d.id, "omega"] = d.tt * 2 * np.pi

            data.reset_index(inplace=True)
        else:
            print("WARNING: tank treading has not been evaluated yet")

    correctCenter(data, config)

    #data = filterCells(data, config, solidity_threshold, irregularity_threshold)
    # 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["pressure"] = config["pressure_pa"] * 1e-5

    data, p = apply_velocity_fit(data)

    omega, mu1, eta1, k_cell, alpha_cell, epsilon = get_cell_properties(data)

    #fitStiffness(data, config)
    return data, config
コード例 #3
0
    def save(self, data):
        evaluation_version = 8
        from pathlib import Path

        import pandas as pd
        import numpy as np
        import json
        from deformationcytometer.evaluation.helper_functions import correctCenter, filterCells, getStressStrain, \
            apply_velocity_fit, get_cell_properties

        file = self.filenames[data["filename"]]

        data = pd.concat(file["cells"])
        data.reset_index(drop=True, inplace=True)

        config = file["config"]

        # take the mean of all values of each cell
        data = data.groupby(['cell_id'], as_index=False).mean()

        correctCenter(data, config)

        # data = filterCells(data, config)
        # reset the indices
        data.reset_index(drop=True, inplace=True)

        getStressStrain(data, config)

        data["area"] = data.long_axis * data.short_axis * np.pi
        data["pressure"] = config["pressure_pa"] * 1e-5

        data, p = apply_velocity_fit(data)

        omega, mu1, eta1, k_cell, alpha_cell, epsilon = get_cell_properties(data)

        output_file = Path(str(data["filename"])[:-4] + "_evaluated_new.csv")
        output_config_file = Path(str(data["filename"])[:-4] + "_evaluated_config_new.txt")
        data.to_csv(output_file, index=False)
        config["evaluation_version"] = evaluation_version
        data.to_csv(output_file, index=False)
        # print("config", config, type(config))
        with output_config_file.open("w") as fp:
            json.dump(config, fp, indent=0)
コード例 #4
0
 def tank_treading(self, data):
     # TODO implement tank threading for non video database
     image_reader = CachedImageReader(str(self.filename))
     getVelocity(data, self.config)
     correctCenter(data, self.config)
     data = data[(data.solidity > self.sol_threshold)
                 & (data.irregularity < self.reg_threshold)]
     ids = pd.unique(data["cell_id"])
     results = []
     for id in ids:
         d = data[data.cell_id == id]
         crops, shifts, valid = getCroppedImages(image_reader, d)
         if len(crops) <= 1:
             continue
         crops = crops[valid]
         time = (d.timestamp - d.iloc[0].timestamp) * 1e-3
         speed, r2 = doTracking(crops,
                                data0=d,
                                times=np.array(time),
                                pixel_size=self.config["pixel_size"])
         results.append([id, speed, r2])
     data = pd.DataFrame(results, columns=["id", "tt", "tt_r2"])
     data.to_csv(self.filename[:-4] + "_addon_tt.csv")
コード例 #5
0
def load_all_data_old(input_path,
                      solidity_threshold=0.96,
                      irregularity_threshold=1.06,
                      pressure=None,
                      repetition=None,
                      new_eval=False):
    global ax

    evaluation_version = 8

    paths = get_folders(input_path, pressure=pressure, repetition=repetition)
    fit_data = []
    data_list = []
    filters = []
    config = {}
    for index, file in enumerate(paths):
        #print(file)
        output_file = Path(str(file).replace("_result.txt", "_evaluated.csv"))
        output_config_file = Path(
            str(file).replace("_result.txt", "_evaluated_config.txt"))

        # load the data and the config
        data = getData(file)
        config = getConfig(file)
        config["channel_width_m"] = 0.00019001261833616293

        if output_config_file.exists():
            with output_config_file.open("r") as fp:
                config = json.load(fp)
                config["channel_width_m"] = 0.00019001261833616293

        config_changes = check_config_changes(config, evaluation_version,
                                              solidity_threshold,
                                              irregularity_threshold)
        if "filter" in config:
            filters.append(config["filter"])
        """ evaluating data"""
        if not output_file.exists() or config_changes or new_eval:

            getVelocity(data, config)
            # take the mean of all values of each cell
            data = data.groupby(['cell_id'], as_index=False).mean()

            tt_file = Path(str(file).replace("_result.txt", "_tt.csv"))
            if tt_file.exists():
                data.set_index("cell_id", inplace=True)
                data_tt = pd.read_csv(tt_file)
                data["omega"] = np.zeros(len(data)) * np.nan
                for i, d in data_tt.iterrows():
                    if d.tt_r2 > 0.2:
                        data.at[d.id, "omega"] = d.tt * 2 * np.pi

                data.reset_index(inplace=True)
            else:
                print("WARNING: tank treading has not been evaluated yet")

            correctCenter(data, config)

            data = filterCells(data, config, solidity_threshold,
                               irregularity_threshold)
            # 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["pressure"] = config["pressure_pa"] * 1e-5

            data, p = apply_velocity_fit(data)

            omega, mu1, eta1, k_cell, alpha_cell, epsilon = get_cell_properties(
                data)

            try:
                config["evaluation_version"] = evaluation_version
                config["network_evaluation_done"] = True
                config["solidity"] = solidity_threshold
                config["irregularity"] = irregularity_threshold
                data.to_csv(output_file, index=False)
                #print("config", config, type(config))
                with output_config_file.open("w") as fp:
                    json.dump(config, fp, indent=0)

            except PermissionError:
                pass

        else:
            with output_config_file.open("r") as fp:
                config = json.load(fp)
                config["channel_width_m"] = 0.00019001261833616293

        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)
    l_before = np.sum([d["l_before"] for d in filters])
    l_after = np.sum([d["l_after"] for d in filters])

    config["filter"] = {"l_before": l_before, "l_after": l_after}
    try:
        data = pd.concat(data_list)
    except ValueError:
        raise ValueError("No object found", input_path)
    data.reset_index(drop=True, inplace=True)

    #fitStiffness(data, config)
    return data, config
コード例 #6
0
    def save(self, data):
        evaluation_version = 8
        from pathlib import Path

        import pandas as pd
        import numpy as np
        import json
        from deformationcytometer.evaluation.helper_functions import correctCenter, filterCells, getStressStrain, \
            apply_velocity_fit, get_cell_properties, match_cells_from_all_data

        filename = data["filename"]
        image_width = data["data_info"]["shape"][2]

        file = self.filenames[filename]

        data = pd.concat(file["cells"])
        data.reset_index(drop=True, inplace=True)

        config = file["config"]

        try:
            correctCenter(data, config)
        except Exception as err:
            print("WARNING: could not fit center for", filename, err)

        if 0:
            try:
                # take the mean of all values of each cell
                data = data.groupby(['cell_id'], as_index=False).mean()
            except pd.core.base.DataError:
                pass

        # data = filterCells(data, config)
        # reset the indices
        data.reset_index(drop=True, inplace=True)

        getStressStrain(data, config)

        data["area"] = data.long_axis * data.short_axis * np.pi
        data["pressure"] = config["pressure_pa"] * 1e-5

        data, p = apply_velocity_fit(data)

        # do matching of velocities again
        try:
            match_cells_from_all_data(data, config, image_width)
        except AttributeError:
            pass

        omega, mu1, eta1, k_cell, alpha_cell, epsilon = get_cell_properties(
            data)

        output_file = Path(str(filename)[:-4] + self.output)
        output_config_file = Path(
            str(filename)[:-4] + "_evaluated_config_new.txt")
        data.to_csv(output_file, index=False)
        config["evaluation_version"] = evaluation_version
        data.to_csv(output_file, index=False)

        with output_config_file.open("w") as fp:
            json.dump(config, fp, indent=0)
コード例 #7
0
    plotDensityLevels, plotBinnedData, plot_joint_density, split_axes, load_all_data_new
import numpy as np
import pylustrator
pylustrator.start()

if 0:
    """"""
    #\\131.188.117.96\biophysDS\emirzahossein\microfluidic cell rhemeter data\microscope_1\january_2021\2021_03_01_NIH3T3_LatrunculinB_doseresponse\100 nM - Kontrolle\2021_03_01_12_21_37.tif
    #\\131.188.117.96\biophysDS\emirzahossein\microfluidic cell rhemeter data\microscope_1\january_2021\2021_03_01_NIH3T3_LatrunculinB_doseresponse\100 nM - Kontrolle\2021_03_01_12_24_36.tif
    #\\131.188.117.96\biophysDS\emirzahossein\microfluidic cell rhemeter data\microscope_1\january_2021\2021_03_01_NIH3T3_LatrunculinB_doseresponse\3.162 nM - Kontrolle\2021_03_01_14_20_57.tif
    #\\131.188.117.96\biophysDS\emirzahossein\microfluidic cell rhemeter data\microscope_1\january_2021\2021_03_01_NIH3T3_LatrunculinB_doseresponse\316.2 nM - Kontrolle\2021_03_01_11_45_42.tif
    from deformationcytometer.evaluation.helper_functions import correctCenter
    data, config = load_all_data_new(
        r"\\131.188.117.96\biophysDS\emirzahossein\microfluidic cell rhemeter data\microscope_1\january_2021\2021_03_01_NIH3T3_LatrunculinB_doseresponse\100 nM - Kontrolle\2021_03_01_12_21_37_result.txt"
    )
    correctCenter(data, config)
    d = data
    y_pos = d.rp
    vel = d.velocity
    valid_indices = np.isfinite(y_pos) & np.isfinite(vel)

    plt.plot(y_pos, vel, "o")
    plt.show()
    """"""

experiment = {}

#if parent-subfolders exist:
import glob
from pathlib import Path
import natsort
コード例 #8
0
    def __init__(self, *args, **kwargs):
        clickpoints.Addon.__init__(self, *args, **kwargs)

        self.layout = QtWidgets.QVBoxLayout(self)

        # Check if the marker type is present
        self.marker_type_cell = self.db.setMarkerType("cell", "#0a2eff",
                                                      self.db.TYPE_Ellipse)
        self.marker_type_cell2 = self.db.setMarkerType("cell2", "#Fa2eff",
                                                       self.db.TYPE_Ellipse)
        self.cp.reloadTypes()

        self.loadData()

        clickpoints.Addon.__init__(self, *args, **kwargs)
        # set the title and layout
        self.setWindowTitle("DeformationCytometer - ClickPoints")
        self.layout = QtWidgets.QVBoxLayout(self)

        # add export buttons
        layout = QtWidgets.QHBoxLayout()
        self.button_stressstrain = QtWidgets.QPushButton("stress-strain")
        self.button_stressstrain.clicked.connect(self.plot_stress_strain)
        layout.addWidget(self.button_stressstrain)

        self.button_stressy = QtWidgets.QPushButton("y-strain")
        self.button_stressy.clicked.connect(self.plot_y_strain)
        layout.addWidget(self.button_stressy)

        self.button_y_angle = QtWidgets.QPushButton("y-angle")
        self.button_y_angle.clicked.connect(self.plot_y_angle)
        layout.addWidget(self.button_y_angle)

        self.layout.addLayout(layout)

        # add a plot widget
        self.plot = MatplotlibWidget(self)
        self.layout.addWidget(self.plot)
        self.layout.addWidget(NavigationToolbar(self.plot, self))
        self.plot.figure.canvas.mpl_connect('button_press_event',
                                            self.button_press_callback)

        # add a progress bar
        self.progressbar = QtWidgets.QProgressBar()
        self.layout.addWidget(self.progressbar)

        # connect slots
        # self.signal_update_plot.connect(self.updatePlotImageEvent)
        # self.signal_plot_finished.connect(self.plotFinishedEvent)

        # initialize the table
        # self.updateTable()
        # self.selected = None

        filename = self.db.getImage(0).get_full_filename()
        print(filename.replace(".tif", "_config.txt"))
        self.config = getConfig(filename.replace(".tif", "_config.txt"))
        self.data = getData(filename.replace(".tif", "_result.txt"))

        getVelocity(self.data, self.config)

        try:
            correctCenter(self.data, self.config)
        except ValueError:
            pass

        self.data = self.data.groupby(['cell_id']).mean()

        self.data = filterCells(self.data, self.config)
        self.data.reset_index(drop=True, inplace=True)

        getStressStrain(self.data, self.config)
コード例 #9
0
def dataWithGradient(filename):
    # %%
    config = getConfig(filename)
    config["channel_width_m"] = 0.00019001261833616293

    data = getData(filename)
    getVelocity(data, config)

    # take the mean of all values of each cell
    # data = data.groupby(['cell_id']).mean()

    correctCenter(data, config)
    # exit()

    data = data[(data.solidity > 0.96) & (data.irregularity < 1.06)]
    # data = data[(data.solidity > 0.98) & (data.irregularity < 1.02)]
    data.reset_index(drop=True, inplace=True)

    getStressStrain(data, config)

    def getVelGrad(r):
        p0, p1, p2 = config["vel_fit"]
        r = r
        p0 = p0 * 1e3
        r0 = config["channel_width_m"] * 0.5 * 1e6  # 100e-6
        return - (p1 * p0 * (np.abs(r) / r0) ** p1) / r

    vel = fit_func_velocity(config)

    import scipy.optimize

    def curve(x, x0, delta1, a1, delta2, a2, w):
        x = np.abs(x)
        delta1 = 2
        return x0 * ((a1+a2) - a1 * (x) ** delta1 - (a2 * x) ** delta2)

    def derivative(x, x0, d1, a1, d2, a2):
        d1 = 2
        return -((d1 * (a1 * np.abs(x)) ** d1 + d2 * (a2 * np.abs(x)) ** d2) * x0) / x

    # def curve(x, x0, delta, delta2):
    #    return x0 * ((2) - (x)**delta - (x)**delta2)
    return data

    x = data.rp * 1e-6
    y = data.velocity * 1e-3
    x, y = removeNan(x, y)
    p, popt = scipy.optimize.curve_fit(curve, x, y, [1.00512197e-02, 1.00000000e+00, 9.15342978e+03, 4.85959006e+00,
 1.15235584e+04])#[25e-3, 1, 1 / 95e-6, 2, 1 / 95e-6])
    getVelGrad = lambda x: derivative(x*1e-6, *p)
    vel = lambda x: curve(x*1e-6, *p) * 1e3

    data["grad"] = getVelGrad(data.rp)#/(2*np.pi)
    dx = data.short_axis/2
    #data["grad"] = (vel(data.rp+dx)-vel(data.rp))*1e-3/(dx*1e-6)
    if 1:
        print("vel fit", p)
        plt.figure(10)
        plt.subplot(131)
        plt.plot(data.rp * 1e-6, data.velocity * 1e-3, "o")
        dx = 1
        x = np.arange(-100, 100, dx) * 1e-6
        v = vel(x * 1e6) * 1e-3
        plt.plot(x, v, "r+")
        plt.axhline(0, color="k", lw=0.8)

        plt.subplot(132)
        grad = np.diff(v) / np.diff(x)  # * 1e3
        plt.plot(data.rp * 1e-6, data.velocity_gradient, "o")
        plt.plot(data.rp * 1e-6, getVelGrad(data.rp), "s")
        plt.plot(x[:-1] + 0.5 * np.diff(x), grad, "-+")
        plt.show()
    return data