def test_t_column(self): f = self.features.copy() cols = list(f.columns) name = 'arbitrary name' cols[cols.index('frame')] = name f.columns = cols # smoke tests tp.link_df(f, 5, t_column=name, verify_integrity=True) tp.link_df_iter(f, 5, t_column=name, verify_integrity=True)
def link_df_iter(self, *args, **kwargs): kwargs.update(self.linker_opts) args = list(args) features = args.pop(0) res = pd.concat(tp.link_df_iter( (df for fr, df in features.groupby('frame')), *args, **kwargs)) return res.sort(['particle', 'frame']).reset_index(drop=True)
def link_df_iter(self, *args, **kwargs): kwargs.update(self.linker_opts) kwargs['diagnostics'] = self.do_diagnostics args = list(args) features = args.pop(0) res = pd.concat(tp.link_df_iter( (df for fr, df in features.groupby('frame')), *args, **kwargs)) return pandas_sort(res, ['particle', 'frame']).reset_index(drop=True)
def link_trajectories(self, search_range, memory, filename='data.h5', progress_listener=lambda *args: None): self.log.info('Linking particles in file "' + filename + '"') with trackpy.PandasHDFStore(filename) as store: i = 0 for linked in trackpy.link_df_iter(store, search_range, memory=memory): store.put(linked) progress_listener(i) i += 1 return self
def test_t_column(self): f = self.features.copy() cols = list(f.columns) name = 'arbitrary name' cols[cols.index('frame')] = name f.columns = cols # smoke tests tp.link_df(f, 5, t_column=name, verify_integrity=True) f_iter = (frame for fnum, frame in f.groupby('arbitrary name')) list(tp.link_df_iter(f_iter, 5, t_column=name, verify_integrity=True))
def test_check_iter(self): """Check that link_df_iter() makes a useful error message if we try to pass a single DataFrame.""" list(tp.link_df_iter(self.features.copy(), 5))
##inputs must be of form 'filename', need single quotes pretrack=input('pretrack file:') #load in pretrack file, gdf trackfile=input('filename to save track file(.h5):') #name of file for track file to be saved as .h5 pref=input('prefix for position table and displacement matrix:') #prefix for position table and displacement matrix files lifetime=input('lifetime=') import softpy import numpy as np import pandas as pd import trackpy as tp pt=softpy.sftio.read_gdf(pretrack) pt=pt.T f=pd.DataFrame(pt,columns=['x','y','mass','size','ecc','frame']) #convert to data frame (frame for fnum, frame in f.groupby('frame')) tra=pd.concat(tp.link_df_iter((frame for fnum, frame in f.groupby('frame')),5,memory=10)) tra.to_hdf(trackfile,'table') #save track file dis,tab=softpy.sftio.tra_df_2_disp(tra,lifetime,prefix=pref) dismat=np.concatenate((dis[:,0,:],dis[:,1,:]),axis=1) np.savetxt(pref+'displacements.txt',dismat) #save displacement matrix np.savetxt(pref+'positiontable.txt',tab) #save average position table
minmass=mm , smoothing_size = smoothing_size, separation = separation, threshold = threshold, percentile = percentile, characterize = True, output=s) # ============================================================================= # with tp.PandasHDFStoreSingleNode(savepath_positionh5.format(act)) as s: # with tp.PandasHDFStoreSingleNode(savepath_temp.format(act)) as temp: # Nframe = s.max_frame # for f in range(0,Nframe+1): # frame = s.get(f) # frame_filted = frame[((frame['size'] < 3) & (frame['mass'] <3000) & (frame['ecc'] < 0.3))] # filter 2 # frame_filted.drop(frame_filted.columns[[2,3,4,5,6,7]], axis = 1, inplace = True) # keep only x,y,frame,particle # temp.put(frame_filted) # ============================================================================= with tp.PandasHDFStore(savepath_position.format(act)) as pos:## Reconstruct trajectories with tp.PandasHDFStore(savepath_traj.format(act)) as traj: for linked in tp.link_df_iter(pos, maxdis, memory=mem): traj.put(linked)
import softpy import numpy as np import pandas as pd import trackpy as tp ptbig=softpy.sftio.read_gdf(pretrackbig) ptbig=ptbig.T ptsmall=softpy.sftio.read_gdf(pretracksmall) ptsmall=ptsmall.T fbig=pd.DataFrame(ptbig,columns=['x','y','mass','size','ecc','frame']) #convert to data frame fsmall=pd.DataFrame(ptsmall,columns=['x','y','mass','size','ecc','frame']) (frame for fnum, frame in fbig.groupby('frame')) trabig=pd.concat(tp.link_df_iter((frame for fnum, frame in fbig.groupby('frame')),5,memory=10)) (frame for fnum, frame in fsmall.groupby('frame')) trasmall=pd.concat(tp.link_df_iter((frame for fnum, frame in fsmall.groupby('frame')),5,memory=10)) trabig.to_hdf(trackbig,'tablebig') #save track file trasmall.to_hdf(tracksmall,'tablesmall') disbig,tabbig=softpy.sftio.tra_df_2_disp(trabig,lifetime,prefix=prefbig) dissmall,tabsmall=softpy.sftio.tra_df_2_disp(trasmall,lifetime,prefix=prefsmall) dismatbig=np.concatenate((disbig[:,0,:],disbig[:,1,:]),axis=1) dismatsmall=np.concatenate((dissmall[:,0,:],dissmall[:,1,:]),axis=1) np.savetxt(prefbig+'_displacements.txt',dismatbig) #save displacement matrix np.savetxt(prefbig+'_positiontable.txt',tabbig) #save average position table np.savetxt(prefsmall+'_displacements.txt',dismatsmall) #save displacement matrix