simulariumio/filters/every_nth_agent_filter.py
def apply(self, data: TrajectoryData) -> TrajectoryData:
        """
        Reduce the number of agents in each frame of the simularium
        data by filtering out all but every nth agent
        """
        print("Filtering: every Nth agent -------------")
        # get filtered data
        start_dimensions = data.agent_data.get_dimensions()
        result = AgentData.from_dimensions(start_dimensions)
        result.times = data.agent_data.times
        result.draw_fiber_points = data.agent_data.draw_fiber_points
        for time_index in range(start_dimensions.total_steps):
            new_agent_index = 0
            n_found = {}
            n_a = int(data.agent_data.n_agents[time_index])
            for agent_index in range(n_a):
                type_name = str(data.agent_data.types[time_index][agent_index])
                if type_name not in n_found:
                    n_found[type_name] = -1
                n_found[type_name] += 1
                if type_name in self.n_per_type:
                    inc = self.n_per_type[type_name]
                else:
                    inc = self.default_n
                if inc < 1 or n_found[type_name] % inc != 0:
                    continue
                result.viz_types[time_index][
                    new_agent_index
                ] = data.agent_data.viz_types[time_index][agent_index]
                result.unique_ids[time_index][
                    new_agent_index
                ] = data.agent_data.unique_ids[time_index][agent_index]
                result.types[time_index].append(
                    data.agent_data.types[time_index][agent_index]
                )
                result.positions[time_index][
                    new_agent_index
                ] = data.agent_data.positions[time_index][agent_index]
                result.radii[time_index][new_agent_index] = data.agent_data.radii[
                    time_index
                ][agent_index]
                result.rotations[time_index][
                    new_agent_index
                ] = data.agent_data.rotations[time_index][agent_index]
                result.n_subpoints[time_index][
                    new_agent_index
                ] = data.agent_data.n_subpoints[time_index][agent_index]
                result.subpoints[time_index][new_agent_index][
                    : np.shape(data.agent_data.subpoints[time_index][agent_index])[0]
                ] = data.agent_data.subpoints[time_index][agent_index]
                new_agent_index += 1
            result.n_agents[time_index] = new_agent_index
        data.agent_data = result
        print(
            f"filtered dims = {start_dimensions.total_steps} timesteps X "
            f"{int(np.amax(result.n_agents))} agents X "
            f"{int(np.amax(data.agent_data.n_subpoints))} subpoints"
        )
        return data

        Reduce the number of agents in each frame of the simularium
        data by filtering out all but every nth agent
        
Reduce the number of agents in each frame of the simularium
data by filtering out all but every nth agent
Reduce the number of agents in each frame of the simularium data by filtering out all but every nth agent
def apply(self, data: TrajectoryData) -> TrajectoryData:
        print("Filtering: every Nth agent -------------")
        start_dimensions = data.agent_data.get_dimensions()
        result = AgentData.from_dimensions(start_dimensions)
        result.times = data.agent_data.times
        result.draw_fiber_points = data.agent_data.draw_fiber_points
        for time_index in range(start_dimensions.total_steps):
            new_agent_index = 0
            n_found = {}
            n_a = int(data.agent_data.n_agents[time_index])
            for agent_index in range(n_a):
                type_name = str(data.agent_data.types[time_index][agent_index])
                if type_name not in n_found:
                    n_found[type_name] = -1
                n_found[type_name] += 1
                if type_name in self.n_per_type:
                    inc = self.n_per_type[type_name]
                else:
                    inc = self.default_n
                if inc < 1 or n_found[type_name] % inc != 0:
                    continue
                result.viz_types[time_index][
                    new_agent_index
                ] = data.agent_data.viz_types[time_index][agent_index]
                result.unique_ids[time_index][
                    new_agent_index
                ] = data.agent_data.unique_ids[time_index][agent_index]
                result.types[time_index].append(
                    data.agent_data.types[time_index][agent_index]
                )
                result.positions[time_index][
                    new_agent_index
                ] = data.agent_data.positions[time_index][agent_index]
                result.radii[time_index][new_agent_index] = data.agent_data.radii[
                    time_index
                ][agent_index]
                result.rotations[time_index][
                    new_agent_index
                ] = data.agent_data.rotations[time_index][agent_index]
                result.n_subpoints[time_index][
                    new_agent_index
                ] = data.agent_data.n_subpoints[time_index][agent_index]
                result.subpoints[time_index][new_agent_index][
                    : np.shape(data.agent_data.subpoints[time_index][agent_index])[0]
                ] = data.agent_data.subpoints[time_index][agent_index]
                new_agent_index += 1
            result.n_agents[time_index] = new_agent_index
        data.agent_data = result
        print(
            f"filtered dims = {start_dimensions.total_steps} timesteps X "
            f"{int(np.amax(result.n_agents))} agents X "
            f"{int(np.amax(data.agent_data.n_subpoints))} subpoints"
        )
        return data
def apply ( self , data : TrajectoryData ) -> TrajectoryData : print ( "Filtering: every Nth agent -------------" ) start_dimensions = data . agent_data . get_dimensions ( ) result = AgentData . from_dimensions ( start_dimensions ) result . times = data . agent_data . times result . draw_fiber_points = data . agent_data . draw_fiber_points for time_index in range ( start_dimensions . total_steps ) : new_agent_index = 0 n_found = { } n_a = int ( data . agent_data . n_agents [ time_index ] ) for agent_index in range ( n_a ) : type_name = str ( data . agent_data . types [ time_index ] [ agent_index ] ) if type_name not in n_found : n_found [ type_name ] = - 1 n_found [ type_name ] += 1 if type_name in self . n_per_type : inc = self . n_per_type [ type_name ] else : inc = self . default_n if inc < 1 or n_found [ type_name ] % inc != 0 : continue result . viz_types [ time_index ] [ new_agent_index ] = data . agent_data . viz_types [ time_index ] [ agent_index ] result . unique_ids [ time_index ] [ new_agent_index ] = data . agent_data . unique_ids [ time_index ] [ agent_index ] result . types [ time_index ] . append ( data . agent_data . types [ time_index ] [ agent_index ] ) result . positions [ time_index ] [ new_agent_index ] = data . agent_data . positions [ time_index ] [ agent_index ] result . radii [ time_index ] [ new_agent_index ] = data . agent_data . radii [ time_index ] [ agent_index ] result . rotations [ time_index ] [ new_agent_index ] = data . agent_data . rotations [ time_index ] [ agent_index ] result . n_subpoints [ time_index ] [ new_agent_index ] = data . agent_data . n_subpoints [ time_index ] [ agent_index ] result . subpoints [ time_index ] [ new_agent_index ] [ : np . shape ( data . agent_data . subpoints [ time_index ] [ agent_index ] ) [ 0 ] ] = data . agent_data . subpoints [ time_index ] [ agent_index ] new_agent_index += 1 result . n_agents [ time_index ] = new_agent_index data . agent_data = result print ( f"filtered dims = {start_dimensions.total_steps} timesteps X " f"{int(np.amax(result.n_agents))} agents X " f"{int(np.amax(data.agent_data.n_subpoints))} subpoints" ) return data
Reduce the number of agents in each frame of the simularium
data by filtering out all but every nth agent
Reduce the number of agents in each frame of the simularium data by filtering out all but every nth agent
"""
        Reduce the number of agents in each frame of the simularium
        data by filtering out all but every nth agent
        """ # get filtered data
self
data
TrajectoryData