simulariumio/filters/every_nth_subpoint_filter.py
def apply(self, data: TrajectoryData) -> TrajectoryData:
        """
        Reduce the number of subpoints in each frame of the simularium
        data by filtering out all but every nth subpoint
        """
        print("Filtering: every Nth subpoint -------------")
        # get dimensions
        total_steps = data.agent_data.times.size
        max_agents = int(np.amax(data.agent_data.n_agents))
        max_subpoints = int(np.amax(data.agent_data.n_subpoints))
        # get filtered data
        n_subpoints = np.zeros((total_steps, max_agents))
        subpoints = np.zeros((total_steps, max_agents, max_subpoints, 3))
        for time_index in range(total_steps):
            for agent_index in range(int(data.agent_data.n_agents[time_index])):
                new_subpoint_index = 0
                if data.agent_data.n_subpoints[time_index][agent_index] > 0:
                    type_name = data.agent_data.types[time_index][agent_index]
                    if type_name in self.n_per_type:
                        inc = self.n_per_type[type_name]
                    else:
                        inc = self.default_n
                    for subpoint_index in range(
                        int(data.agent_data.n_subpoints[time_index][agent_index])
                    ):
                        if subpoint_index % inc != 0:
                            continue
                        subpoints[time_index][agent_index][
                            new_subpoint_index
                        ] = data.agent_data.subpoints[time_index][agent_index][
                            subpoint_index
                        ]
                        new_subpoint_index += 1
                n_subpoints[time_index][agent_index] = new_subpoint_index
        data.agent_data.n_subpoints = n_subpoints
        data.agent_data.subpoints = subpoints
        print(
            f"filtered dims = {total_steps} timesteps X "
            f"{max_agents} agents X {int(np.amax(n_subpoints))} subpoints"
        )
        return data

        Reduce the number of subpoints in each frame of the simularium
        data by filtering out all but every nth subpoint
        
Reduce the number of subpoints in each frame of the simularium
data by filtering out all but every nth subpoint
Reduce the number of subpoints in each frame of the simularium data by filtering out all but every nth subpoint
def apply(self, data: TrajectoryData) -> TrajectoryData:
        print("Filtering: every Nth subpoint -------------")
        total_steps = data.agent_data.times.size
        max_agents = int(np.amax(data.agent_data.n_agents))
        max_subpoints = int(np.amax(data.agent_data.n_subpoints))
        n_subpoints = np.zeros((total_steps, max_agents))
        subpoints = np.zeros((total_steps, max_agents, max_subpoints, 3))
        for time_index in range(total_steps):
            for agent_index in range(int(data.agent_data.n_agents[time_index])):
                new_subpoint_index = 0
                if data.agent_data.n_subpoints[time_index][agent_index] > 0:
                    type_name = data.agent_data.types[time_index][agent_index]
                    if type_name in self.n_per_type:
                        inc = self.n_per_type[type_name]
                    else:
                        inc = self.default_n
                    for subpoint_index in range(
                        int(data.agent_data.n_subpoints[time_index][agent_index])
                    ):
                        if subpoint_index % inc != 0:
                            continue
                        subpoints[time_index][agent_index][
                            new_subpoint_index
                        ] = data.agent_data.subpoints[time_index][agent_index][
                            subpoint_index
                        ]
                        new_subpoint_index += 1
                n_subpoints[time_index][agent_index] = new_subpoint_index
        data.agent_data.n_subpoints = n_subpoints
        data.agent_data.subpoints = subpoints
        print(
            f"filtered dims = {total_steps} timesteps X "
            f"{max_agents} agents X {int(np.amax(n_subpoints))} subpoints"
        )
        return data
def apply ( self , data : TrajectoryData ) -> TrajectoryData : print ( "Filtering: every Nth subpoint -------------" ) total_steps = data . agent_data . times . size max_agents = int ( np . amax ( data . agent_data . n_agents ) ) max_subpoints = int ( np . amax ( data . agent_data . n_subpoints ) ) n_subpoints = np . zeros ( ( total_steps , max_agents ) ) subpoints = np . zeros ( ( total_steps , max_agents , max_subpoints , 3 ) ) for time_index in range ( total_steps ) : for agent_index in range ( int ( data . agent_data . n_agents [ time_index ] ) ) : new_subpoint_index = 0 if data . agent_data . n_subpoints [ time_index ] [ agent_index ] > 0 : type_name = data . agent_data . types [ time_index ] [ agent_index ] if type_name in self . n_per_type : inc = self . n_per_type [ type_name ] else : inc = self . default_n for subpoint_index in range ( int ( data . agent_data . n_subpoints [ time_index ] [ agent_index ] ) ) : if subpoint_index % inc != 0 : continue subpoints [ time_index ] [ agent_index ] [ new_subpoint_index ] = data . agent_data . subpoints [ time_index ] [ agent_index ] [ subpoint_index ] new_subpoint_index += 1 n_subpoints [ time_index ] [ agent_index ] = new_subpoint_index data . agent_data . n_subpoints = n_subpoints data . agent_data . subpoints = subpoints print ( f"filtered dims = {total_steps} timesteps X " f"{max_agents} agents X {int(np.amax(n_subpoints))} subpoints" ) return data
Reduce the number of subpoints in each frame of the simularium
data by filtering out all but every nth subpoint
Reduce the number of subpoints in each frame of the simularium data by filtering out all but every nth subpoint
"""
        Reduce the number of subpoints in each frame of the simularium
        data by filtering out all but every nth subpoint
        """ # get dimensions # get filtered data
self
data
TrajectoryData