simulariumio/data_objects/agent_data.py
def from_buffer_data(cls, buffer_data: Dict[str, Any]):
        """
        Create AgentData from a simularium JSON dict containing buffers
        """
        bundle_data = buffer_data["spatialData"]["bundleData"]
        dimensions = AgentData._get_buffer_data_dimensions(buffer_data)
        print(f"original dim = {dimensions}")
        agent_data = AgentData.from_dimensions(dimensions)
        type_ids = np.zeros((dimensions.total_steps, dimensions.max_agents))
        for time_index in range(dimensions.total_steps):
            agent_data.times[time_index] = bundle_data[time_index]["time"]
            frame_data = bundle_data[time_index]["data"]
            agent_index = 0
            buffer_index = 0
            while buffer_index + V1_SPATIAL_BUFFER_STRUCT.NSP_INDEX < len(frame_data):
                # a new agent should start at this index
                agent_data.viz_types[time_index][agent_index] = frame_data[
                    buffer_index + V1_SPATIAL_BUFFER_STRUCT.VIZ_TYPE_INDEX
                ]
                agent_data.unique_ids[time_index][agent_index] = frame_data[
                    buffer_index + V1_SPATIAL_BUFFER_STRUCT.UID_INDEX
                ]
                type_ids[time_index][agent_index] = frame_data[
                    buffer_index + V1_SPATIAL_BUFFER_STRUCT.TID_INDEX
                ]
                agent_data.positions[time_index][agent_index] = [
                    frame_data[buffer_index + V1_SPATIAL_BUFFER_STRUCT.POSX_INDEX],
                    frame_data[buffer_index + V1_SPATIAL_BUFFER_STRUCT.POSY_INDEX],
                    frame_data[buffer_index + V1_SPATIAL_BUFFER_STRUCT.POSZ_INDEX],
                ]
                agent_data.rotations[time_index][agent_index] = [
                    frame_data[buffer_index + V1_SPATIAL_BUFFER_STRUCT.ROTX_INDEX],
                    frame_data[buffer_index + V1_SPATIAL_BUFFER_STRUCT.ROTY_INDEX],
                    frame_data[buffer_index + V1_SPATIAL_BUFFER_STRUCT.ROTZ_INDEX],
                ]
                agent_data.radii[time_index][agent_index] = frame_data[
                    buffer_index + V1_SPATIAL_BUFFER_STRUCT.R_INDEX
                ]
                buffer_index += V1_SPATIAL_BUFFER_STRUCT.NSP_INDEX
                # get the subpoints
                if dimensions.max_subpoints < 1:
                    buffer_index += int(
                        V1_SPATIAL_BUFFER_STRUCT.SP_INDEX
                        - V1_SPATIAL_BUFFER_STRUCT.NSP_INDEX
                    )
                    agent_index += 1
                    continue
                agent_data.n_subpoints[time_index][agent_index] = int(
                    frame_data[buffer_index] / 3.0
                )
                subpoint_index = 0
                dim = 0
                for i in range(int(frame_data[buffer_index])):
                    agent_data.subpoints[time_index][agent_index][subpoint_index][
                        dim
                    ] = frame_data[buffer_index + 1 + i]
                    dim += 1
                    if dim > 2:
                        dim = 0
                        subpoint_index += 1
                buffer_index += int(
                    frame_data[buffer_index]
                    + (
                        V1_SPATIAL_BUFFER_STRUCT.SP_INDEX
                        - V1_SPATIAL_BUFFER_STRUCT.NSP_INDEX
                    )
                )
                agent_index += 1
            agent_data.n_agents[time_index] = agent_index
        type_names = AgentData.get_type_names(
            type_ids, buffer_data["trajectoryInfo"]["typeMapping"]
        )
        display_data = AgentData.get_display_data(
            buffer_data["trajectoryInfo"]["typeMapping"]
        )
        return cls(
            times=agent_data.times,
            n_agents=agent_data.n_agents,
            viz_types=agent_data.viz_types,
            unique_ids=agent_data.unique_ids,
            types=type_names,
            positions=agent_data.positions,
            radii=agent_data.radii,
            rotations=agent_data.rotations,
            n_subpoints=agent_data.n_subpoints,
            subpoints=agent_data.subpoints,
            display_data=display_data,
            draw_fiber_points=False,
        )

        Create AgentData from a simularium JSON dict containing buffers
        
Create AgentData from a simularium JSON dict containing buffers
Create AgentData from a simularium JSON dict containing buffers
def from_buffer_data(cls, buffer_data: Dict[str, Any]):
        bundle_data = buffer_data["spatialData"]["bundleData"]
        dimensions = AgentData._get_buffer_data_dimensions(buffer_data)
        print(f"original dim = {dimensions}")
        agent_data = AgentData.from_dimensions(dimensions)
        type_ids = np.zeros((dimensions.total_steps, dimensions.max_agents))
        for time_index in range(dimensions.total_steps):
            agent_data.times[time_index] = bundle_data[time_index]["time"]
            frame_data = bundle_data[time_index]["data"]
            agent_index = 0
            buffer_index = 0
            while buffer_index + V1_SPATIAL_BUFFER_STRUCT.NSP_INDEX < len(frame_data):
                agent_data.viz_types[time_index][agent_index] = frame_data[
                    buffer_index + V1_SPATIAL_BUFFER_STRUCT.VIZ_TYPE_INDEX
                ]
                agent_data.unique_ids[time_index][agent_index] = frame_data[
                    buffer_index + V1_SPATIAL_BUFFER_STRUCT.UID_INDEX
                ]
                type_ids[time_index][agent_index] = frame_data[
                    buffer_index + V1_SPATIAL_BUFFER_STRUCT.TID_INDEX
                ]
                agent_data.positions[time_index][agent_index] = [
                    frame_data[buffer_index + V1_SPATIAL_BUFFER_STRUCT.POSX_INDEX],
                    frame_data[buffer_index + V1_SPATIAL_BUFFER_STRUCT.POSY_INDEX],
                    frame_data[buffer_index + V1_SPATIAL_BUFFER_STRUCT.POSZ_INDEX],
                ]
                agent_data.rotations[time_index][agent_index] = [
                    frame_data[buffer_index + V1_SPATIAL_BUFFER_STRUCT.ROTX_INDEX],
                    frame_data[buffer_index + V1_SPATIAL_BUFFER_STRUCT.ROTY_INDEX],
                    frame_data[buffer_index + V1_SPATIAL_BUFFER_STRUCT.ROTZ_INDEX],
                ]
                agent_data.radii[time_index][agent_index] = frame_data[
                    buffer_index + V1_SPATIAL_BUFFER_STRUCT.R_INDEX
                ]
                buffer_index += V1_SPATIAL_BUFFER_STRUCT.NSP_INDEX
                if dimensions.max_subpoints < 1:
                    buffer_index += int(
                        V1_SPATIAL_BUFFER_STRUCT.SP_INDEX
                        - V1_SPATIAL_BUFFER_STRUCT.NSP_INDEX
                    )
                    agent_index += 1
                    continue
                agent_data.n_subpoints[time_index][agent_index] = int(
                    frame_data[buffer_index] / 3.0
                )
                subpoint_index = 0
                dim = 0
                for i in range(int(frame_data[buffer_index])):
                    agent_data.subpoints[time_index][agent_index][subpoint_index][
                        dim
                    ] = frame_data[buffer_index + 1 + i]
                    dim += 1
                    if dim > 2:
                        dim = 0
                        subpoint_index += 1
                buffer_index += int(
                    frame_data[buffer_index]
                    + (
                        V1_SPATIAL_BUFFER_STRUCT.SP_INDEX
                        - V1_SPATIAL_BUFFER_STRUCT.NSP_INDEX
                    )
                )
                agent_index += 1
            agent_data.n_agents[time_index] = agent_index
        type_names = AgentData.get_type_names(
            type_ids, buffer_data["trajectoryInfo"]["typeMapping"]
        )
        display_data = AgentData.get_display_data(
            buffer_data["trajectoryInfo"]["typeMapping"]
        )
        return cls(
            times=agent_data.times,
            n_agents=agent_data.n_agents,
            viz_types=agent_data.viz_types,
            unique_ids=agent_data.unique_ids,
            types=type_names,
            positions=agent_data.positions,
            radii=agent_data.radii,
            rotations=agent_data.rotations,
            n_subpoints=agent_data.n_subpoints,
            subpoints=agent_data.subpoints,
            display_data=display_data,
            draw_fiber_points=False,
        )
def from_buffer_data ( cls , buffer_data : Dict [ str , Any ] ) : bundle_data = buffer_data [ "spatialData" ] [ "bundleData" ] dimensions = AgentData . _get_buffer_data_dimensions ( buffer_data ) print ( f"original dim = {dimensions}" ) agent_data = AgentData . from_dimensions ( dimensions ) type_ids = np . zeros ( ( dimensions . total_steps , dimensions . max_agents ) ) for time_index in range ( dimensions . total_steps ) : agent_data . times [ time_index ] = bundle_data [ time_index ] [ "time" ] frame_data = bundle_data [ time_index ] [ "data" ] agent_index = 0 buffer_index = 0 while buffer_index + V1_SPATIAL_BUFFER_STRUCT . NSP_INDEX < len ( frame_data ) : agent_data . viz_types [ time_index ] [ agent_index ] = frame_data [ buffer_index + V1_SPATIAL_BUFFER_STRUCT . VIZ_TYPE_INDEX ] agent_data . unique_ids [ time_index ] [ agent_index ] = frame_data [ buffer_index + V1_SPATIAL_BUFFER_STRUCT . UID_INDEX ] type_ids [ time_index ] [ agent_index ] = frame_data [ buffer_index + V1_SPATIAL_BUFFER_STRUCT . TID_INDEX ] agent_data . positions [ time_index ] [ agent_index ] = [ frame_data [ buffer_index + V1_SPATIAL_BUFFER_STRUCT . POSX_INDEX ] , frame_data [ buffer_index + V1_SPATIAL_BUFFER_STRUCT . POSY_INDEX ] , frame_data [ buffer_index + V1_SPATIAL_BUFFER_STRUCT . POSZ_INDEX ] , ] agent_data . rotations [ time_index ] [ agent_index ] = [ frame_data [ buffer_index + V1_SPATIAL_BUFFER_STRUCT . ROTX_INDEX ] , frame_data [ buffer_index + V1_SPATIAL_BUFFER_STRUCT . ROTY_INDEX ] , frame_data [ buffer_index + V1_SPATIAL_BUFFER_STRUCT . ROTZ_INDEX ] , ] agent_data . radii [ time_index ] [ agent_index ] = frame_data [ buffer_index + V1_SPATIAL_BUFFER_STRUCT . R_INDEX ] buffer_index += V1_SPATIAL_BUFFER_STRUCT . NSP_INDEX if dimensions . max_subpoints < 1 : buffer_index += int ( V1_SPATIAL_BUFFER_STRUCT . SP_INDEX - V1_SPATIAL_BUFFER_STRUCT . NSP_INDEX ) agent_index += 1 continue agent_data . n_subpoints [ time_index ] [ agent_index ] = int ( frame_data [ buffer_index ] / 3.0 ) subpoint_index = 0 dim = 0 for i in range ( int ( frame_data [ buffer_index ] ) ) : agent_data . subpoints [ time_index ] [ agent_index ] [ subpoint_index ] [ dim ] = frame_data [ buffer_index + 1 + i ] dim += 1 if dim > 2 : dim = 0 subpoint_index += 1 buffer_index += int ( frame_data [ buffer_index ] + ( V1_SPATIAL_BUFFER_STRUCT . SP_INDEX - V1_SPATIAL_BUFFER_STRUCT . NSP_INDEX ) ) agent_index += 1 agent_data . n_agents [ time_index ] = agent_index type_names = AgentData . get_type_names ( type_ids , buffer_data [ "trajectoryInfo" ] [ "typeMapping" ] ) display_data = AgentData . get_display_data ( buffer_data [ "trajectoryInfo" ] [ "typeMapping" ] ) return cls ( times = agent_data . times , n_agents = agent_data . n_agents , viz_types = agent_data . viz_types , unique_ids = agent_data . unique_ids , types = type_names , positions = agent_data . positions , radii = agent_data . radii , rotations = agent_data . rotations , n_subpoints = agent_data . n_subpoints , subpoints = agent_data . subpoints , display_data = display_data , draw_fiber_points = False , )
Create AgentData from a simularium JSON dict containing buffers
Create AgentData from a simularium JSON dict containing buffers
"""
        Create AgentData from a simularium JSON dict containing buffers
        """ # a new agent should start at this index # get the subpoints
cls
buffer_data
Dict[str, Any]