simulariumio/physicell/physicell_converter.py
def _get_trajectory_data(input_data: PhysicellData) -> Tuple[AgentData, UnitData]:
        """
        Get data from one time step in Simularium format
        """
        ids = {}
        last_id = 0
        type_mapping = {}
        physicell_data = PhysicellConverter._load_data(
            input_data.path_to_output_dir, input_data.nth_timestep_to_read
        )
        # get data dimensions
        total_steps = len(physicell_data)
        max_agents = 0
        discrete_cells = []
        for time_index in range(total_steps):
            discrete_cells.append(physicell_data[time_index].get_cell_df())
            n = len(discrete_cells[time_index]["position_x"])
            if n > max_agents:
                max_agents = n
        if total_steps < 1 or max_agents < 1:
            raise MissingDataError(
                "no timesteps or no agents found in PhysiCell data, "
                "is the path_to_output_dir pointing to an output directory?"
            )
        result = AgentData.from_dimensions(
            DimensionData(
                total_steps=total_steps,
                max_agents=max_agents,
            )
        )
        result.times = (
            input_data.nth_timestep_to_read
            * input_data.timestep
            * np.arange(total_steps)
        )
        # get data
        for time_index in range(total_steps):
            n_agents = int(len(discrete_cells[time_index]["position_x"]))
            result.n_agents[time_index] = n_agents
            for agent_index in range(n_agents):
                result.unique_ids[time_index][agent_index] = agent_index
                cell_type = int(discrete_cells[time_index]["cell_type"][agent_index])
                cell_phase = int(
                    discrete_cells[time_index]["current_phase"][agent_index]
                )
                tid, ids, last_id, type_mapping = PhysicellConverter._get_agent_type(
                    cell_type=cell_type,
                    cell_phase=cell_phase,
                    input_data=input_data,
                    ids=ids,
                    last_id=last_id,
                    type_mapping=type_mapping,
                )
                result.types[time_index].append(type_mapping[tid])
                result.positions[time_index][
                    agent_index
                ] = input_data.meta_data.scale_factor * np.array(
                    [
                        discrete_cells[time_index]["position_x"][agent_index],
                        discrete_cells[time_index]["position_y"][agent_index],
                        discrete_cells[time_index]["position_z"][agent_index],
                    ]
                )
                result.radii[time_index][
                    agent_index
                ] = input_data.meta_data.scale_factor * (
                    input_data.display_data[cell_type].radius
                    if cell_type in input_data.display_data
                    and input_data.display_data[cell_type].radius is not None
                    else np.cbrt(
                        3.0
                        / 4.0
                        * discrete_cells[time_index]["total_volume"][agent_index]
                        / np.pi
                    )
                )
        spatial_units = UnitData(
            physicell_data[0].data["metadata"]["spatial_units"],
            1.0 / input_data.meta_data.scale_factor,
        )
        result.n_timesteps = total_steps
        return result, spatial_units, ids

        Get data from one time step in Simularium format
        
Get data from one time step in Simularium format
Get data from one time step in Simularium format
def _get_trajectory_data(input_data: PhysicellData) -> Tuple[AgentData, UnitData]:
        ids = {}
        last_id = 0
        type_mapping = {}
        physicell_data = PhysicellConverter._load_data(
            input_data.path_to_output_dir, input_data.nth_timestep_to_read
        )
        total_steps = len(physicell_data)
        max_agents = 0
        discrete_cells = []
        for time_index in range(total_steps):
            discrete_cells.append(physicell_data[time_index].get_cell_df())
            n = len(discrete_cells[time_index]["position_x"])
            if n > max_agents:
                max_agents = n
        if total_steps < 1 or max_agents < 1:
            raise MissingDataError(
                "no timesteps or no agents found in PhysiCell data, "
                "is the path_to_output_dir pointing to an output directory?"
            )
        result = AgentData.from_dimensions(
            DimensionData(
                total_steps=total_steps,
                max_agents=max_agents,
            )
        )
        result.times = (
            input_data.nth_timestep_to_read
            * input_data.timestep
            * np.arange(total_steps)
        )
        for time_index in range(total_steps):
            n_agents = int(len(discrete_cells[time_index]["position_x"]))
            result.n_agents[time_index] = n_agents
            for agent_index in range(n_agents):
                result.unique_ids[time_index][agent_index] = agent_index
                cell_type = int(discrete_cells[time_index]["cell_type"][agent_index])
                cell_phase = int(
                    discrete_cells[time_index]["current_phase"][agent_index]
                )
                tid, ids, last_id, type_mapping = PhysicellConverter._get_agent_type(
                    cell_type=cell_type,
                    cell_phase=cell_phase,
                    input_data=input_data,
                    ids=ids,
                    last_id=last_id,
                    type_mapping=type_mapping,
                )
                result.types[time_index].append(type_mapping[tid])
                result.positions[time_index][
                    agent_index
                ] = input_data.meta_data.scale_factor * np.array(
                    [
                        discrete_cells[time_index]["position_x"][agent_index],
                        discrete_cells[time_index]["position_y"][agent_index],
                        discrete_cells[time_index]["position_z"][agent_index],
                    ]
                )
                result.radii[time_index][
                    agent_index
                ] = input_data.meta_data.scale_factor * (
                    input_data.display_data[cell_type].radius
                    if cell_type in input_data.display_data
                    and input_data.display_data[cell_type].radius is not None
                    else np.cbrt(
                        3.0
                        / 4.0
                        * discrete_cells[time_index]["total_volume"][agent_index]
                        / np.pi
                    )
                )
        spatial_units = UnitData(
            physicell_data[0].data["metadata"]["spatial_units"],
            1.0 / input_data.meta_data.scale_factor,
        )
        result.n_timesteps = total_steps
        return result, spatial_units, ids
def _get_trajectory_data ( input_data : PhysicellData ) -> Tuple [ AgentData , UnitData ] : ids = { } last_id = 0 type_mapping = { } physicell_data = PhysicellConverter . _load_data ( input_data . path_to_output_dir , input_data . nth_timestep_to_read ) total_steps = len ( physicell_data ) max_agents = 0 discrete_cells = [ ] for time_index in range ( total_steps ) : discrete_cells . append ( physicell_data [ time_index ] . get_cell_df ( ) ) n = len ( discrete_cells [ time_index ] [ "position_x" ] ) if n > max_agents : max_agents = n if total_steps < 1 or max_agents < 1 : raise MissingDataError ( "no timesteps or no agents found in PhysiCell data, " "is the path_to_output_dir pointing to an output directory?" ) result = AgentData . from_dimensions ( DimensionData ( total_steps = total_steps , max_agents = max_agents , ) ) result . times = ( input_data . nth_timestep_to_read * input_data . timestep * np . arange ( total_steps ) ) for time_index in range ( total_steps ) : n_agents = int ( len ( discrete_cells [ time_index ] [ "position_x" ] ) ) result . n_agents [ time_index ] = n_agents for agent_index in range ( n_agents ) : result . unique_ids [ time_index ] [ agent_index ] = agent_index cell_type = int ( discrete_cells [ time_index ] [ "cell_type" ] [ agent_index ] ) cell_phase = int ( discrete_cells [ time_index ] [ "current_phase" ] [ agent_index ] ) tid , ids , last_id , type_mapping = PhysicellConverter . _get_agent_type ( cell_type = cell_type , cell_phase = cell_phase , input_data = input_data , ids = ids , last_id = last_id , type_mapping = type_mapping , ) result . types [ time_index ] . append ( type_mapping [ tid ] ) result . positions [ time_index ] [ agent_index ] = input_data . meta_data . scale_factor * np . array ( [ discrete_cells [ time_index ] [ "position_x" ] [ agent_index ] , discrete_cells [ time_index ] [ "position_y" ] [ agent_index ] , discrete_cells [ time_index ] [ "position_z" ] [ agent_index ] , ] ) result . radii [ time_index ] [ agent_index ] = input_data . meta_data . scale_factor * ( input_data . display_data [ cell_type ] . radius if cell_type in input_data . display_data and input_data . display_data [ cell_type ] . radius is not None else np . cbrt ( 3.0 / 4.0 * discrete_cells [ time_index ] [ "total_volume" ] [ agent_index ] / np . pi ) ) spatial_units = UnitData ( physicell_data [ 0 ] . data [ "metadata" ] [ "spatial_units" ] , 1.0 / input_data . meta_data . scale_factor , ) result . n_timesteps = total_steps return result , spatial_units , ids
Get data from one time step in Simularium format
Get data from one time step in Simularium format
"""
        Get data from one time step in Simularium format
        """ # get data dimensions # get data
input_data
PhysicellData