simulariumio/data_objects/agent_data.py
def from_dataframe(cls, traj: pd.DataFrame):
        """
        Create AgentData from a pandas DataFrame with columns:
        time, unique_id, type, positionX, positionY, positionZ, radius
        (only for default agents, no fibers)
        """
        times = np.unique(traj.loc[0, "time"].to_numpy())
        n_agents = np.squeeze(
            traj.groupby("time").agg(["count"])["unique_id"].to_numpy()
        )
        grouped_traj = (
            traj.set_index(["time", traj.groupby("time").cumcount()])
            .unstack(fill_value=0)
            .stack()
        )
        unique_ids = np.array(
            grouped_traj["unique_id"]
            .groupby(level=0)
            .apply(lambda x: x.values.tolist())
            .tolist()
        )
        positions = np.array(
            grouped_traj[["positionX", "positionY", "positionZ"]]
            .groupby(level=0)
            .apply(lambda x: x.values.tolist())
            .tolist()
        )
        rotations = np.array(
            grouped_traj[["rotationX", "rotationY", "rotationZ"]]
            .groupby(level=0)
            .apply(lambda x: x.values.tolist())
            .tolist()
        )
        radii = np.array(
            grouped_traj["radius"]
            .groupby(level=0)
            .apply(lambda x: x.values.tolist())
            .tolist()
        )
        grouped_traj = (
            traj.set_index(["time", traj.groupby("time").cumcount()])
            .unstack(fill_value="")
            .stack()
        )
        type_names = (
            grouped_traj["type"]
            .groupby(level=0)
            .apply(lambda x: x.values.tolist())
            .tolist()
        )
        return cls(
            times=times,
            n_agents=n_agents,
            viz_types=VIZ_TYPE.DEFAULT * np.ones_like(unique_ids),
            unique_ids=unique_ids,
            types=type_names,
            positions=positions,
            radii=radii,
            rotations=rotations,
        )

        Create AgentData from a pandas DataFrame with columns:
        time, unique_id, type, positionX, positionY, positionZ, radius
        (only for default agents, no fibers)
        
Create AgentData from a pandas DataFrame with columns:
time, unique_id, type, positionX, positionY, positionZ, radius
(only for default agents, no fibers)
Create AgentData from a pandas DataFrame with columns : time unique_id type positionX positionY positionZ radius ( only for default agents no fibers )
def from_dataframe(cls, traj: pd.DataFrame):
        times = np.unique(traj.loc[0, "time"].to_numpy())
        n_agents = np.squeeze(
            traj.groupby("time").agg(["count"])["unique_id"].to_numpy()
        )
        grouped_traj = (
            traj.set_index(["time", traj.groupby("time").cumcount()])
            .unstack(fill_value=0)
            .stack()
        )
        unique_ids = np.array(
            grouped_traj["unique_id"]
            .groupby(level=0)
            .apply(lambda x: x.values.tolist())
            .tolist()
        )
        positions = np.array(
            grouped_traj[["positionX", "positionY", "positionZ"]]
            .groupby(level=0)
            .apply(lambda x: x.values.tolist())
            .tolist()
        )
        rotations = np.array(
            grouped_traj[["rotationX", "rotationY", "rotationZ"]]
            .groupby(level=0)
            .apply(lambda x: x.values.tolist())
            .tolist()
        )
        radii = np.array(
            grouped_traj["radius"]
            .groupby(level=0)
            .apply(lambda x: x.values.tolist())
            .tolist()
        )
        grouped_traj = (
            traj.set_index(["time", traj.groupby("time").cumcount()])
            .unstack(fill_value="")
            .stack()
        )
        type_names = (
            grouped_traj["type"]
            .groupby(level=0)
            .apply(lambda x: x.values.tolist())
            .tolist()
        )
        return cls(
            times=times,
            n_agents=n_agents,
            viz_types=VIZ_TYPE.DEFAULT * np.ones_like(unique_ids),
            unique_ids=unique_ids,
            types=type_names,
            positions=positions,
            radii=radii,
            rotations=rotations,
        )
def from_dataframe ( cls , traj : pd . DataFrame ) : times = np . unique ( traj . loc [ 0 , "time" ] . to_numpy ( ) ) n_agents = np . squeeze ( traj . groupby ( "time" ) . agg ( [ "count" ] ) [ "unique_id" ] . to_numpy ( ) ) grouped_traj = ( traj . set_index ( [ "time" , traj . groupby ( "time" ) . cumcount ( ) ] ) . unstack ( fill_value = 0 ) . stack ( ) ) unique_ids = np . array ( grouped_traj [ "unique_id" ] . groupby ( level = 0 ) . apply ( lambda x : x . values . tolist ( ) ) . tolist ( ) ) positions = np . array ( grouped_traj [ [ "positionX" , "positionY" , "positionZ" ] ] . groupby ( level = 0 ) . apply ( lambda x : x . values . tolist ( ) ) . tolist ( ) ) rotations = np . array ( grouped_traj [ [ "rotationX" , "rotationY" , "rotationZ" ] ] . groupby ( level = 0 ) . apply ( lambda x : x . values . tolist ( ) ) . tolist ( ) ) radii = np . array ( grouped_traj [ "radius" ] . groupby ( level = 0 ) . apply ( lambda x : x . values . tolist ( ) ) . tolist ( ) ) grouped_traj = ( traj . set_index ( [ "time" , traj . groupby ( "time" ) . cumcount ( ) ] ) . unstack ( fill_value = "" ) . stack ( ) ) type_names = ( grouped_traj [ "type" ] . groupby ( level = 0 ) . apply ( lambda x : x . values . tolist ( ) ) . tolist ( ) ) return cls ( times = times , n_agents = n_agents , viz_types = VIZ_TYPE . DEFAULT * np . ones_like ( unique_ids ) , unique_ids = unique_ids , types = type_names , positions = positions , radii = radii , rotations = rotations , )
Create AgentData from a pandas DataFrame with columns:
time, unique_id, type, positionX, positionY, positionZ, radius
(only for default agents, no fibers)
Create AgentData from a pandas DataFrame with columns : time unique_id type positionX positionY positionZ radius ( only for default agents no fibers )
"""
        Create AgentData from a pandas DataFrame with columns:
        time, unique_id, type, positionX, positionY, positionZ, radius
        (only for default agents, no fibers)
        """
cls
traj
pd.DataFrame