simulariumio/cytosim/cytosim_converter.py
def _parse_objects(
        object_type: str,
        data_lines: List[str],
        scale_factor: float,
        object_info: CytosimObjectInfo,
        result: AgentData,
        used_unique_IDs: List[int],
    ) -> Tuple[Dict[str, Any], List[int]]:
        """
        Parse a Cytosim output file containing objects
        (fibers, solids, singles, or couples) to get agents
        """
        time_index = -1
        uids = {}
        is_fiber = "fiber" in object_type
        for line in data_lines:
            if CytosimConverter._ignore_line(line):
                continue
            columns = line.split()
            if line[0] == "%":
                if "frame" in line:
                    # start of frame
                    time_index += 1
                elif "time" in line:
                    # time metadata
                    result.times[time_index] = float(columns[2])
                elif "fiber" in columns[1]:
                    # start of fiber object
                    (result, uids, used_unique_IDs,) = CytosimConverter._parse_object(
                        object_type,
                        columns,
                        time_index,
                        scale_factor,
                        object_info,
                        result,
                        uids,
                        used_unique_IDs,
                    )
                    result.n_agents[time_index] += 1
                continue
            elif is_fiber:
                # each fiber point
                subpoint_index = int(
                    result.n_subpoints[time_index][int(result.n_agents[time_index] - 1)]
                )
                # position
                result.subpoints[time_index][int(result.n_agents[time_index] - 1)][
                    subpoint_index
                ] = scale_factor * np.array(
                    [
                        float(columns[1].strip("+,")),
                        float(columns[2].strip("+,")),
                        float(columns[3].strip("+,")),
                    ]
                )
                result.n_subpoints[time_index][
                    int(result.n_agents[time_index] - 1)
                ] += 1
            else:
                # each non-fiber object
                (result, uids, used_unique_IDs,) = CytosimConverter._parse_object(
                    object_type,
                    columns,
                    time_index,
                    scale_factor,
                    object_info,
                    result,
                    uids,
                    used_unique_IDs,
                )
                # position
                result.positions[time_index][
                    int(result.n_agents[time_index])
                ] = scale_factor * (
                    np.array(
                        [
                            float(columns[object_info.position_indices[0]].strip("+,")),
                            float(columns[object_info.position_indices[1]].strip("+,")),
                            float(columns[object_info.position_indices[2]].strip("+,")),
                        ]
                    )
                )
                result.n_agents[time_index] += 1
        result.n_timesteps = time_index + 1
        return (result, used_unique_IDs)

        Parse a Cytosim output file containing objects
        (fibers, solids, singles, or couples) to get agents
        
Parse a Cytosim output file containing objects
(fibers, solids, singles, or couples) to get agents
Parse a Cytosim output file containing objects ( fibers solids singles or couples ) to get agents
def _parse_objects(
        object_type: str,
        data_lines: List[str],
        scale_factor: float,
        object_info: CytosimObjectInfo,
        result: AgentData,
        used_unique_IDs: List[int],
    ) -> Tuple[Dict[str, Any], List[int]]:
        time_index = -1
        uids = {}
        is_fiber = "fiber" in object_type
        for line in data_lines:
            if CytosimConverter._ignore_line(line):
                continue
            columns = line.split()
            if line[0] == "%":
                if "frame" in line:
                    time_index += 1
                elif "time" in line:
                    result.times[time_index] = float(columns[2])
                elif "fiber" in columns[1]:
                    (result, uids, used_unique_IDs,) = CytosimConverter._parse_object(
                        object_type,
                        columns,
                        time_index,
                        scale_factor,
                        object_info,
                        result,
                        uids,
                        used_unique_IDs,
                    )
                    result.n_agents[time_index] += 1
                continue
            elif is_fiber:
                subpoint_index = int(
                    result.n_subpoints[time_index][int(result.n_agents[time_index] - 1)]
                )
                result.subpoints[time_index][int(result.n_agents[time_index] - 1)][
                    subpoint_index
                ] = scale_factor * np.array(
                    [
                        float(columns[1].strip("+,")),
                        float(columns[2].strip("+,")),
                        float(columns[3].strip("+,")),
                    ]
                )
                result.n_subpoints[time_index][
                    int(result.n_agents[time_index] - 1)
                ] += 1
            else:
                (result, uids, used_unique_IDs,) = CytosimConverter._parse_object(
                    object_type,
                    columns,
                    time_index,
                    scale_factor,
                    object_info,
                    result,
                    uids,
                    used_unique_IDs,
                )
                result.positions[time_index][
                    int(result.n_agents[time_index])
                ] = scale_factor * (
                    np.array(
                        [
                            float(columns[object_info.position_indices[0]].strip("+,")),
                            float(columns[object_info.position_indices[1]].strip("+,")),
                            float(columns[object_info.position_indices[2]].strip("+,")),
                        ]
                    )
                )
                result.n_agents[time_index] += 1
        result.n_timesteps = time_index + 1
        return (result, used_unique_IDs)
def _parse_objects ( object_type : str , data_lines : List [ str ] , scale_factor : float , object_info : CytosimObjectInfo , result : AgentData , used_unique_IDs : List [ int ] , ) -> Tuple [ Dict [ str , Any ] , List [ int ] ] : time_index = - 1 uids = { } is_fiber = "fiber" in object_type for line in data_lines : if CytosimConverter . _ignore_line ( line ) : continue columns = line . split ( ) if line [ 0 ] == "%" : if "frame" in line : time_index += 1 elif "time" in line : result . times [ time_index ] = float ( columns [ 2 ] ) elif "fiber" in columns [ 1 ] : ( result , uids , used_unique_IDs , ) = CytosimConverter . _parse_object ( object_type , columns , time_index , scale_factor , object_info , result , uids , used_unique_IDs , ) result . n_agents [ time_index ] += 1 continue elif is_fiber : subpoint_index = int ( result . n_subpoints [ time_index ] [ int ( result . n_agents [ time_index ] - 1 ) ] ) result . subpoints [ time_index ] [ int ( result . n_agents [ time_index ] - 1 ) ] [ subpoint_index ] = scale_factor * np . array ( [ float ( columns [ 1 ] . strip ( "+," ) ) , float ( columns [ 2 ] . strip ( "+," ) ) , float ( columns [ 3 ] . strip ( "+," ) ) , ] ) result . n_subpoints [ time_index ] [ int ( result . n_agents [ time_index ] - 1 ) ] += 1 else : ( result , uids , used_unique_IDs , ) = CytosimConverter . _parse_object ( object_type , columns , time_index , scale_factor , object_info , result , uids , used_unique_IDs , ) result . positions [ time_index ] [ int ( result . n_agents [ time_index ] ) ] = scale_factor * ( np . array ( [ float ( columns [ object_info . position_indices [ 0 ] ] . strip ( "+," ) ) , float ( columns [ object_info . position_indices [ 1 ] ] . strip ( "+," ) ) , float ( columns [ object_info . position_indices [ 2 ] ] . strip ( "+," ) ) , ] ) ) result . n_agents [ time_index ] += 1 result . n_timesteps = time_index + 1 return ( result , used_unique_IDs )
Parse a Cytosim output file containing objects
(fibers, solids, singles, or couples) to get agents
Parse a Cytosim output file containing objects ( fibers solids singles or couples ) to get agents
"""
        Parse a Cytosim output file containing objects
        (fibers, solids, singles, or couples) to get agents
        """ # start of frame # time metadata # start of fiber object # each fiber point # position # each non-fiber object # position
object_type
str
data_lines
List[str]
scale_factor
float
object_info
CytosimObjectInfo
result
AgentData
used_unique_IDs
List[int]