Ejemplo n.º 1
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
        arc_size = tot_size / num
        arcs = np.arange(num) * arc_size
        res = sp.optimize.root(lambda x: (sp.special.ellipeinc(x, e) - arcs),
                               angles)
        angles = res.x
    return angles


r_min = 5  #cells smaller than r_min (in um) will not be analyzed

video = getInputFile()

#%%
config = getConfig(video)

data = getData(video)
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)

ids = pd.unique(data["cell_id"])

image_reader = imageio.get_reader(video)
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