def fit_msd(comp_key, conn, make_plot=False): (fin,) = conn.execute("select fout from msd where comp_key = ?", (comp_key,)).fetchone() Fin = h5py.File(fin, "r") g_name = _fd("mean_squared_disp", comp_key) msd = Fin[g_name]["msd"][:] dt = Fin[g_name].attrs["dtime"] temp = Fin[g_name].attrs["temperature"] Fin.close() del Fin t = (np.arange(len(msd)) + 1) * dt (x, r, rn, s) = np.linalg.lstsq(np.transpose(np.array([t, np.ones(len(msd))])), msd) if make_plot: fig = plots.tac_figure("t [ms]", "msd [px^2]", "msd and fit") fig.draw_line(t, msd, "x", label="msd") print x[1] fig.draw_line(t, t * x[0] + x[1], label="fit") scale = 6.45 / 60 # u[m]/[pix] # lamda_x = sqrt(2Dt) (Einstein 1905) # msd = 2*lambda_x^2 = 4 D t (Einstein 1905) # the extra 2 is because I am looking at total displacement in 2D D = (x[0] / 4) * (scale ** 2) * 1000 # u[m]^2/sec r = _dilute_D_to_rad(D, temp) # u[m] return (x[0], temp, r)
def display_fit(x,y,p,func,fig=None): """Displays the raw data and the fit. fig is an plots.tac_figure object""" if fig is None: fig = plots.tac_figure('x','y','fitting') fig.plot(x,np.log(y),label='data') fig.plot(x,np.log(func(p,x)),'--x',label=func.__name__ + '('+ ','.join(['%.1e'%k for k in p])+ ')') return fig
def plot_msd_series(comp_key_lst, conn, sname=None): """ Takes in a list of msd computations and makes a nice plot""" tltstr = "mean squared displacement" if not sname is None: tltstr = tltstr + " " + sname fig = plots.tac_figure( "t[ms]", r"$\langle \Delta \rangle ^2$", tltstr, count=len(comp_key_lst), func=matplotlib.axes.Axes.plot ) for c in comp_key_lst: plot_msd(c[0], conn, fig)
def plot_msd_old(comp_key, conn, fig=None): if fig is None: fig = plots.tac_figure("t[s]", "msd", "msd") pass (fin, dset) = conn.execute("select fout,dset_key from comps where comp_key = ?", (comp_key,)).fetchone() (temp,) = conn.execute("select temp from dsets where key = ?", (dset,)).fetchone() Fin = h5py.File(fin, "r") g_name = _fd("mean_squared_disp", comp_key) msd = Fin[g_name] msd = Fin[g_name]["data"][:] dt = Fin[g_name].attrs["dtime"] print print "the delta is ", dt, "for comp ", comp_key t = (np.arange(len(msd)) + 1) * dt cm = plots.color_mapper(27, 33) fig.plot(t, msd, label=str(temp), color=cm.get_color(temp)) Fin.close() del Fin return fig
def plot_msd(comp_key, conn, fig=None): if fig is None: fig = plots.tac_figure("t[s]", "msd", "msd") pass (fin,) = conn.execute("select fout from msd where comp_key = ?", (comp_key,)).fetchone() Fin = h5py.File(fin, "r") g_name = _fd("mean_squared_disp", comp_key) msd = Fin[g_name]["msd"][:] dt = Fin[g_name].attrs["dtime"] temp = Fin[g_name].attrs["temperature"] mtl = Fin[g_name].attrs["min_track_length"] print print "the delta is ", dt, "for comp ", comp_key t = (np.arange(len(msd)) + 1) * dt cm = plots.color_mapper(27, 33) fig.plot(t, msd, label="%(#).2fC, %(!)d" % {"!": mtl, "#": temp}, color=cm.get_color(temp)) Fin.close() del Fin return fig