def dense_uniformcut(self, particle_col,selected_intervals): if particle_col.particles: particle_col.particles = sorted(particle_col.particles,key=operator.attrgetter(self.GEO)) particles = [] intervals = selected_intervals #intervals = np.linspace(self.MIN,self.MAX,self.MAXBEATS) for i in intervals: method = getattr(particle_col, 'get' + self.GEO)() if len(method) > 0: index = find_nearest(method,i) particles.append(particle_col.particles[index]) particle_col.particles = np.delete(particle_col.particles,index) return particles
def sparse_uniformcut(self, particle_col): if particle_col.particles: # first, sort the particles in the collection by eta coordinate particle_col.particles = sorted(particle_col.particles,key=operator.attrgetter(self.GEO)) #create a record which specifies which beats the particles will play at record = np.array([HACK]*(self.MAXBEATS)) #create even geometric intervals that each beach will correspond to intervals = np.linspace(self.MIN,self.MAX,self.MAXBEATS) #for each particle or physics object in the collection... for p_idx, p in enumerate(particle_col.particles): #find the closest interval that the geometric coordinate of the particle corresponds to index = find_nearest(intervals,getattr(p, self.GEO)) while HACK in record: new_order = filter(lambda a: a!=HACK,record) if record[index] == HACK: record[index] = p_idx break #set the next indices to check if the previous was occupied else: available = np.where(record == HACK)[0] closest_available_index = available[find_nearest(available,index)] record[closest_available_index] = p_idx break #even though we intend to sort particles by eta, the above clustering could cause some particles to flip. #therefore, we use the new order below new_order = filter(lambda a: a!=HACK,record) particle_col.particles = [particle_col.particles[i] for i in new_order] return particle_col.particles, record