simulariumio/trajectory_converter.py
def _read_trajectory_data(input_data: TrajectoryData) -> Dict[str, Any]:
        """
        Return an object containing the data shaped for Simularium format
        """
        print("Converting Trajectory Data -------------")
        inconsistent_type = TrajectoryConverter._check_types_match_subpoints(input_data)
        if inconsistent_type:
            raise DataError(inconsistent_type)
        simularium_data = {}
        # trajectory info
        total_steps = (
            input_data.agent_data.n_timesteps
            if input_data.agent_data.n_timesteps >= 0
            else len(input_data.agent_data.times)
        )
        type_ids, type_mapping = input_data.agent_data.get_type_ids_and_mapping()
        traj_info = {
            "version": CURRENT_VERSION.TRAJECTORY_INFO,
            "timeUnits": {
                "magnitude": input_data.time_units.magnitude,
                "name": input_data.time_units.name,
            },
            "timeStepSize": TrajectoryConverter._format_timestep(
                float(input_data.agent_data.times[1] - input_data.agent_data.times[0])
                if total_steps > 1
                else 0.0
            ),
            "totalSteps": total_steps,
            "spatialUnits": {
                "magnitude": input_data.spatial_units.magnitude,
                "name": input_data.spatial_units.name,
            },
            "size": {
                "x": float(input_data.meta_data.box_size[0]),
                "y": float(input_data.meta_data.box_size[1]),
                "z": float(input_data.meta_data.box_size[2]),
            },
            "cameraDefault": {
                "position": {
                    "x": float(input_data.meta_data.camera_defaults.position[0]),
                    "y": float(input_data.meta_data.camera_defaults.position[1]),
                    "z": float(input_data.meta_data.camera_defaults.position[2]),
                },
                "lookAtPosition": {
                    "x": float(
                        input_data.meta_data.camera_defaults.look_at_position[0]
                    ),
                    "y": float(
                        input_data.meta_data.camera_defaults.look_at_position[1]
                    ),
                    "z": float(
                        input_data.meta_data.camera_defaults.look_at_position[2]
                    ),
                },
                "upVector": {
                    "x": float(input_data.meta_data.camera_defaults.up_vector[0]),
                    "y": float(input_data.meta_data.camera_defaults.up_vector[1]),
                    "z": float(input_data.meta_data.camera_defaults.up_vector[2]),
                },
                "fovDegrees": float(input_data.meta_data.camera_defaults.fov_degrees),
            },
            "typeMapping": type_mapping,
        }
        # add any paper metadata
        if input_data.meta_data.trajectory_title:
            traj_info["trajectoryTitle"] = input_data.meta_data.trajectory_title
        if not input_data.meta_data.model_meta_data.is_default():
            traj_info["modelInfo"] = dict(input_data.meta_data.model_meta_data)
        simularium_data["trajectoryInfo"] = traj_info
        # spatial data
        spatialData = {
            "version": CURRENT_VERSION.SPATIAL_DATA,
            "msgType": 1,
            "bundleStart": 0,
            "bundleSize": total_steps,
        }
        if input_data.agent_data.subpoints is not None:
            spatialData[
                "bundleData"
            ] = TrajectoryConverter._get_spatial_bundle_data_subpoints(
                input_data.agent_data, type_ids
            )
        else:
            spatialData[
                "bundleData"
            ] = TrajectoryConverter._get_spatial_bundle_data_no_subpoints(
                input_data.agent_data, type_ids
            )
        simularium_data["spatialData"] = spatialData
        # plot data
        simularium_data["plotData"] = {
            "version": CURRENT_VERSION.PLOT_DATA,
            "data": input_data.plots,
        }
        return simularium_data

        Return an object containing the data shaped for Simularium format
        
Return an object containing the data shaped for Simularium format
Return an object containing the data shaped for Simularium format
def _read_trajectory_data(input_data: TrajectoryData) -> Dict[str, Any]:
        print("Converting Trajectory Data -------------")
        inconsistent_type = TrajectoryConverter._check_types_match_subpoints(input_data)
        if inconsistent_type:
            raise DataError(inconsistent_type)
        simularium_data = {}
        total_steps = (
            input_data.agent_data.n_timesteps
            if input_data.agent_data.n_timesteps >= 0
            else len(input_data.agent_data.times)
        )
        type_ids, type_mapping = input_data.agent_data.get_type_ids_and_mapping()
        traj_info = {
            "version": CURRENT_VERSION.TRAJECTORY_INFO,
            "timeUnits": {
                "magnitude": input_data.time_units.magnitude,
                "name": input_data.time_units.name,
            },
            "timeStepSize": TrajectoryConverter._format_timestep(
                float(input_data.agent_data.times[1] - input_data.agent_data.times[0])
                if total_steps > 1
                else 0.0
            ),
            "totalSteps": total_steps,
            "spatialUnits": {
                "magnitude": input_data.spatial_units.magnitude,
                "name": input_data.spatial_units.name,
            },
            "size": {
                "x": float(input_data.meta_data.box_size[0]),
                "y": float(input_data.meta_data.box_size[1]),
                "z": float(input_data.meta_data.box_size[2]),
            },
            "cameraDefault": {
                "position": {
                    "x": float(input_data.meta_data.camera_defaults.position[0]),
                    "y": float(input_data.meta_data.camera_defaults.position[1]),
                    "z": float(input_data.meta_data.camera_defaults.position[2]),
                },
                "lookAtPosition": {
                    "x": float(
                        input_data.meta_data.camera_defaults.look_at_position[0]
                    ),
                    "y": float(
                        input_data.meta_data.camera_defaults.look_at_position[1]
                    ),
                    "z": float(
                        input_data.meta_data.camera_defaults.look_at_position[2]
                    ),
                },
                "upVector": {
                    "x": float(input_data.meta_data.camera_defaults.up_vector[0]),
                    "y": float(input_data.meta_data.camera_defaults.up_vector[1]),
                    "z": float(input_data.meta_data.camera_defaults.up_vector[2]),
                },
                "fovDegrees": float(input_data.meta_data.camera_defaults.fov_degrees),
            },
            "typeMapping": type_mapping,
        }
        if input_data.meta_data.trajectory_title:
            traj_info["trajectoryTitle"] = input_data.meta_data.trajectory_title
        if not input_data.meta_data.model_meta_data.is_default():
            traj_info["modelInfo"] = dict(input_data.meta_data.model_meta_data)
        simularium_data["trajectoryInfo"] = traj_info
        spatialData = {
            "version": CURRENT_VERSION.SPATIAL_DATA,
            "msgType": 1,
            "bundleStart": 0,
            "bundleSize": total_steps,
        }
        if input_data.agent_data.subpoints is not None:
            spatialData[
                "bundleData"
            ] = TrajectoryConverter._get_spatial_bundle_data_subpoints(
                input_data.agent_data, type_ids
            )
        else:
            spatialData[
                "bundleData"
            ] = TrajectoryConverter._get_spatial_bundle_data_no_subpoints(
                input_data.agent_data, type_ids
            )
        simularium_data["spatialData"] = spatialData
        simularium_data["plotData"] = {
            "version": CURRENT_VERSION.PLOT_DATA,
            "data": input_data.plots,
        }
        return simularium_data
def _read_trajectory_data ( input_data : TrajectoryData ) -> Dict [ str , Any ] : print ( "Converting Trajectory Data -------------" ) inconsistent_type = TrajectoryConverter . _check_types_match_subpoints ( input_data ) if inconsistent_type : raise DataError ( inconsistent_type ) simularium_data = { } total_steps = ( input_data . agent_data . n_timesteps if input_data . agent_data . n_timesteps >= 0 else len ( input_data . agent_data . times ) ) type_ids , type_mapping = input_data . agent_data . get_type_ids_and_mapping ( ) traj_info = { "version" : CURRENT_VERSION . TRAJECTORY_INFO , "timeUnits" : { "magnitude" : input_data . time_units . magnitude , "name" : input_data . time_units . name , } , "timeStepSize" : TrajectoryConverter . _format_timestep ( float ( input_data . agent_data . times [ 1 ] - input_data . agent_data . times [ 0 ] ) if total_steps > 1 else 0.0 ) , "totalSteps" : total_steps , "spatialUnits" : { "magnitude" : input_data . spatial_units . magnitude , "name" : input_data . spatial_units . name , } , "size" : { "x" : float ( input_data . meta_data . box_size [ 0 ] ) , "y" : float ( input_data . meta_data . box_size [ 1 ] ) , "z" : float ( input_data . meta_data . box_size [ 2 ] ) , } , "cameraDefault" : { "position" : { "x" : float ( input_data . meta_data . camera_defaults . position [ 0 ] ) , "y" : float ( input_data . meta_data . camera_defaults . position [ 1 ] ) , "z" : float ( input_data . meta_data . camera_defaults . position [ 2 ] ) , } , "lookAtPosition" : { "x" : float ( input_data . meta_data . camera_defaults . look_at_position [ 0 ] ) , "y" : float ( input_data . meta_data . camera_defaults . look_at_position [ 1 ] ) , "z" : float ( input_data . meta_data . camera_defaults . look_at_position [ 2 ] ) , } , "upVector" : { "x" : float ( input_data . meta_data . camera_defaults . up_vector [ 0 ] ) , "y" : float ( input_data . meta_data . camera_defaults . up_vector [ 1 ] ) , "z" : float ( input_data . meta_data . camera_defaults . up_vector [ 2 ] ) , } , "fovDegrees" : float ( input_data . meta_data . camera_defaults . fov_degrees ) , } , "typeMapping" : type_mapping , } if input_data . meta_data . trajectory_title : traj_info [ "trajectoryTitle" ] = input_data . meta_data . trajectory_title if not input_data . meta_data . model_meta_data . is_default ( ) : traj_info [ "modelInfo" ] = dict ( input_data . meta_data . model_meta_data ) simularium_data [ "trajectoryInfo" ] = traj_info spatialData = { "version" : CURRENT_VERSION . SPATIAL_DATA , "msgType" : 1 , "bundleStart" : 0 , "bundleSize" : total_steps , } if input_data . agent_data . subpoints is not None : spatialData [ "bundleData" ] = TrajectoryConverter . _get_spatial_bundle_data_subpoints ( input_data . agent_data , type_ids ) else : spatialData [ "bundleData" ] = TrajectoryConverter . _get_spatial_bundle_data_no_subpoints ( input_data . agent_data , type_ids ) simularium_data [ "spatialData" ] = spatialData simularium_data [ "plotData" ] = { "version" : CURRENT_VERSION . PLOT_DATA , "data" : input_data . plots , } return simularium_data
Return an object containing the data shaped for Simularium format
Return an object containing the data shaped for Simularium format
"""
        Return an object containing the data shaped for Simularium format
        """ # trajectory info # add any paper metadata # spatial data # plot data
input_data
TrajectoryData