def test(): import glob import analysis.experiment as exp reload(exp) fn = exp.filename() print fn fn = filename(dtype = 'img') print fn print glob.glob(fn) data = exp.load(wid = 0); print data.shape import matplotlib.pyplot as plt plt.figure(1); plt.clf(); img = exp.load_img(t=200000); plt.imshow(img, cmap = 'gray') #animate movie import time fig, ax = plt.subplots() figimg = ax.imshow(img, cmap = 'gray'); plt.show(); for t in range(200000, 300000): figimg.set_data(exp.load_img(t=t)); ax.set_title('t=%d' % t); time.sleep(0.001) fig.canvas.draw() fig.canvas.flush_events() reload(exp) sbins = exp.stage_bins(wid = [0,1]) d = exp.load_stage_binned(wid = [0,1], nbins_per_stage=10) a = exp.load_aligned(wid = all, align='time', dtype = 'speed') a_th = np.nanpercentile(a, 85); a[a> a_th] = a_th; a[np.isnan(a)] = -1.0; import analysis.plot as fplt; fplt.plot_array(a) a = exp.load_aligned(wid = all, align='L2', dtype = 'speed') a_th = np.nanpercentile(a, 85); a[a> a_th] = a_th; a[np.isnan(a)] = -1.0; import analysis.plot as fplt; fplt.plot_array(a)
def test(): import glob import analysis.experiment as exp reload(exp) fn = exp.filename() print fn fn = filename(dtype='img') print fn print glob.glob(fn) data = exp.load(wid=0) print data.shape import matplotlib.pyplot as plt plt.figure(1) plt.clf() img = exp.load_img(t=200000) plt.imshow(img, cmap='gray') #animate movie import time fig, ax = plt.subplots() figimg = ax.imshow(img, cmap='gray') plt.show() for t in range(200000, 300000): figimg.set_data(exp.load_img(t=t)) ax.set_title('t=%d' % t) time.sleep(0.001) fig.canvas.draw() fig.canvas.flush_events() reload(exp) sbins = exp.stage_bins(wid=[0, 1]) d = exp.load_stage_binned(wid=[0, 1], nbins_per_stage=10) a = exp.load_aligned(wid=all, align='time', dtype='speed') a_th = np.nanpercentile(a, 85) a[a > a_th] = a_th a[np.isnan(a)] = -1.0 import analysis.plot as fplt fplt.plot_array(a) a = exp.load_aligned(wid=all, align='L2', dtype='speed') a_th = np.nanpercentile(a, 85) a[a > a_th] = a_th a[np.isnan(a)] = -1.0 import analysis.plot as fplt fplt.plot_array(a)
@author: ckirst """ import os import numpy as np import matplotlib.pyplot as plt import analysis.experiment as exp import analysis.plot as aplt import worm.model as wmodel npts = 22 w = wmodel.WormModel(npoints=npts) fn = exp.filename(strain='n2', wid=80, dtype='img') imgdata = np.load(fn, mmap_mode='r') ntimes = imgdata.shape[0] theta, orientation, xy, length = w.theta() ntheta = theta.shape[0] data_path = '/home/ckirst/Desktop' data_names = ['theta', 'orientation', 'xy', 'length', 'center', 'width'] data_sizes = [(ntimes, ntheta), ntimes, (ntimes, 2), ntimes, (ntimes, npts, 2), (ntimes, npts)] data_files = [ os.path.join(data_path, 'analysis_2016_10_26_' + n + '.npy') for n in data_names
coords = [] for i, fn in enumerate(fns): #print 'processing %d / %d' % (i, len(fns)); data = scipy.io.loadmat(fn) xy_part = data['x_y_coor'] coords.append(xy_part) xy = np.vstack(coords) # (1,1) is invalid coordinates inv = np.logical_and(xy[:, 0] == 1.0, xy[:, 1] == 1.0) xy[inv, :] = np.nan print 'worm %d: len = %d' % (wid, xy.shape[0]) fn_out = exp.filename(strain=strain, wid=wid) np.save(fn_out, xy) #%% Precalculate Speed import analysis.features as feat delta = 3 for wid in range(nworms): print 'processing worm %d/%d' % (wid, nworms) xy = exp.load(strain=strain, wid=wid, memmap=None) v = feat.speed(xy, delta=delta) fn_out = exp.filename(strain=strain, wid=wid, dtype='speed')
fig.savefig('align_%d.png' % wid); a[wid] = aan; ### Save mapping to file fn = os.path.join(exp.data_directory, 'n2_roam_align_w=%d_s=all.npy'); for wid in range(nworms): print '%d / %d' % (wid, nworms) np.save(fn % wid, a[wid]) fn = exp.filename(strain = 'n2', wid = 0, dtype = 'roam_align') ### Generate Roaming Data for wid in range(nworms): print '%d / %d' % (wid, nworms) roam = np.array(rd_data.roam[wid][:rd_data.stage_switch[wid][-1]].copy(), dtype = bool); fn = exp.filename(strain = 'n2', wid = wid, dtype = 'roam'); roamall = np.ones(len(v[wid])) * np.nan; roamall[a[wid]] = roam; np.save(fn, roamall)
@author: ckirst """ import os import numpy as np import matplotlib.pyplot as plt import analysis.experiment as exp import analysis.plot as aplt import worm.model as wmodel npts = 22; w = wmodel.WormModel(npoints = npts); fn = exp.filename(strain = 'n2', wid = 80, dtype = 'img') imgdata = np.load(fn, mmap_mode = 'r'); ntimes = imgdata.shape[0]; theta, orientation, xy, length = w.theta(); ntheta = theta.shape[0]; data_path = '/home/ckirst/Desktop'; data_names = ['theta', 'orientation', 'xy', 'length', 'center', 'width']; data_sizes = [(ntimes, ntheta), ntimes, (ntimes,2), ntimes, (ntimes, npts, 2), (ntimes, npts)]; data_files = [os.path.join(data_path, 'analysis_2016_10_26_' + n + '.npy') for n in data_names]; fig_dir = '/home/ckirst/Desktop/labmeeting'
nbins = 80 plt.figure(10) plt.clf() plt.subplot(1, 2, 1) res = plt.hist2d(r_data, v_data, bins=nbins, range=[[0, r_th], [0, v_th]]) plt.subplot(1, 2, 2) res = plt.hist2d(r_data, np.log(v_data), bins=nbins, range=[[0, r_th], [np.nanmin(np.log(v_data)), np.log(v_th)]]) ### Classify into Roaming and Dwelling ? plt.figure(11) plt.clf() plt.subplot(1, 2, 1) plt.hist(r_data, bins=128, range=[0, r_th]) plt.subplot(1, 2, 2) plt.hist(v_data, bins=128, range=[0, v_th]) for wid in range(nworms): rt = exp.load(strain='N2', dtype='phi', wid=wid, memmap=None) roam = rt < 1.42 exp.experiment_directory = '/home/ckirst/Science/Projects/CElegansBehaviour/Experiment/ImageData' fn_out = exp.filename(strain='N2', wid=wid, dtype='roam') np.save(fn_out, roam)
coords = []; for i,fn in enumerate(fns): #print 'processing %d / %d' % (i, len(fns)); data = scipy.io.loadmat(fn) xy_part = data['x_y_coor']; coords.append(xy_part); xy = np.vstack(coords); # (1,1) is invalid coordinates inv = np.logical_and(xy[:,0] == 1.0, xy[:,1] == 1.0); xy[inv,:] = np.nan; print 'worm %d: len = %d' % (wid, xy.shape[0]) fn_out = exp.filename(strain = strain, wid = wid); np.save(fn_out, xy); #%% Precalculate Speed import analysis.features as feat; delta = 3; for wid in range(nworms): print 'processing worm %d/%d' % (wid, nworms); xy = exp.load(strain = strain, wid = wid, memmap = None);
pp[sd2] = ivmall[sd2] plt.plot(pp, 'k') plt.ylim(-1, 20) plt.pause(0.01) fig.savefig('align_%d.png' % wid) a[wid] = aan ### Save mapping to file fn = os.path.join(exp.data_directory, 'n2_roam_align_w=%d_s=all.npy') for wid in range(nworms): print '%d / %d' % (wid, nworms) np.save(fn % wid, a[wid]) fn = exp.filename(strain='n2', wid=0, dtype='roam_align') ### Generate Roaming Data for wid in range(nworms): print '%d / %d' % (wid, nworms) roam = np.array(rd_data.roam[wid][:rd_data.stage_switch[wid][-1]].copy(), dtype=bool) fn = exp.filename(strain='n2', wid=wid, dtype='roam') roamall = np.ones(len(v[wid])) * np.nan roamall[a[wid]] = roam np.save(fn, roamall)