def make_markers(self, ltId, pos, feature, trajectory_dir, num_cluster): # find the feature and coordinate files labteks_found = filter(lambda x: x[:len(ltId)]==ltId, os.listdir(trajectory_dir)) if len(labteks_found) == 0: raise ValueError('%s not found in %s' % (ltId, self.base_dir)) if len(labteks_found) > 1: raise ValueError('multiple labteks found') labtek_dir = os.path.join(trajectory_dir, labteks_found[0]) feature_file = 'hist_tabFeatures_{:>05}_01.pkl'.format(pos) try: fp = open(os.path.join(labtek_dir, feature_file), 'r') tab, coord, hist = pickle.load(fp) fp.close() except: pdb.set_trace() tab, toDel = correct_from_Nan(tab, perMovie=False) new_coord = []#np.array(coord)[[el for el in range(len(coord)) if el not in toDel]] for i,el in enumerate(coord): if i not in toDel: new_coord.append(el) if feature in FEATURES: tab = histLogTrsforming(tab) cm = ColorMap() cr = cm.makeColorRamp(256, ["#FFFF00", "#FF0000"]) # centers_PLT0023_11--ex2005_06_03--sp2005_04_19--tt17--c3_w00210_01.pkl # traj_noF_densities_w00210_01.hdf5.pkl ending = '%05i_01.pkl' % int(pos) feature_index = FEATURES.index(feature) values = tab[:,feature_index] print "Working on feature {} with this range min {} max {}".format(feature, *FEATURE_RANGE[feature]) print "In this well min {} max {}".format(np.min(values), np.max(values)) colors = [cm.getColorFromMap(x, cr, FEATURE_RANGE[feature][0], FEATURE_RANGE[feature][1]) for x in values.tolist()] elif feature=='labels': #we are going to predict on the fly the clustering labels not to have to stock them smw (fast to predict) f=open('../resultData/features_on_films/labelsKM_whole_k{}.pkl'.format(num_cluster)) labels, perc, who, length=pickle.load(f); f.close() where_=np.where(who=='{}--{}'.format(ltId, pos))[0] labels=labels[np.sum(length[:where_]):np.sum(length[:where_+1])] assert(len(labels)==len(new_coord)) colors = [diverging_colors_traj[labels[k]] for k in range(tab.shape[0])] markers = {} for i, track_coord in enumerate(new_coord): tvec, xvec, yvec = track_coord for t, x, y in zip(tvec, xvec, yvec): if not t in markers: markers[t] = [] markers[t].append((x, y, colors[i])) return markers
if __name__ == '__main__': #SCRIPT UTILISE POUR FAIRE LES FEATURES parser = OptionParser(usage="usage: %prog [options]") parser.add_option("--iter", dest="iter", type=int,default=0) parser.add_option("-m", dest="movement_type_index", type=int,default=None) (options, args) = parser.parse_args() simulateur = TrajectorySimulator(settings_filename='tracking/settings/settings_simulator_14_10_20.py') simulateur('simulated_trajectories', 0, options.movement_type_index, "hist_tabFeatures{}_W{}.pkl".format(options.iter, options.movement_type_index)) f=open('../resultData/simulated_traj/trajectories_for_clustering/hist_tabFeatures{}_W{}.pkl'.format(options.iter, options.movement_type_index)) tabFeatures, _, _ = pickle.load(f) r2 = histLogTrsforming(tabFeatures) print r2.shape, 'not normalized' r2=r2[:,:-1] if np.any(np.isnan(r2)): print 'Deleting nan values' r2=np.delete(r2, np.where(np.isnan(r2))[0], 0) #r=(r2-np.mean(r2,0))/np.std(r2,0) r=np.hstack((r2[:,:len(featuresNumeriques)], r2[:, featuresSaved.index('mean straight'), np.newaxis])) print r.shape #print 'computing bins' #histogrammeMatrix = computingBins(histNC, mat_hist_sizes[0]) print 'saving' f=open('../resultData/simulated_traj/trajectories_for_clustering/data_sim_traj{}{}.pkl'.format(options.iter, options.movement_type_index), 'w')