Source code for cytocalc.csmsimulation

#! /usr/bin/env python3
# A CSMSimulation is a collection of CSMFrames and the
# simulation parameters (read from configurations.cym)

import warnings
from bisect import insort
from typing import List

import numpy as np

from cytocalc.sim_analysis.msd import SimAnalyzerMSD
from cytocalc.sim_analysis.misc import SimAnalyzerMisc
from cytocalc.sim_analysis.network import SimAnalyzerNetwork


[docs] class CSMSimulation: """ Contains a set of CSMFrames that form a simulation. Also contains the simulation parameters. """ def __init__(self): self.frames = [] # list containing cytosim frames self.params = {} # dict containing simulation self.msd = SimAnalyzerMSD(self) self.network = SimAnalyzerNetwork(self) self.misc = SimAnalyzerMisc(self)
[docs] def add_frame(self, csmframe): """Adds a CSMFrame to the simulation at the correct time (frame1.time < frame2.time)""" insort(self.frames, csmframe, key=lambda x: x.time)
[docs] def get_np_object(self, start_frame="0", end_frame=None): """Constructs a numpy object from csm frame data of shape (n_frames,n_particles,3)""" np_frames = [frame._npobj for frame in self.frames[start_frame:end_frame]] return np.stack(np_frames)
[docs] def contraction_rate(self, start_frame=None, end_frame=None, r_sq=0.9): """ Deprecated. Use sim.network.contraction_rate() instead. Ref: :func:`cytocalc.sim_analysis.SimAnalyzerNetwork.contraction_rate` """ warnings.warn("Deprecated. Use sim.network.contraction_rate() instead", DeprecationWarning) return self.network.contraction_rate(start_frame, end_frame, r_sq)
[docs] def compute_msd(self, start_frame: int = 0, end_frame: int = -1, box_size: List[float] = []): """ Deprecated. Use sim.msd.msd() instead. Ref: :func:`cytocalc.sim_analysis.SimAnalyzerMSD.msd` """ warnings.warn("Deprecated. Use sim.msd.msd() instead", DeprecationWarning) return self.msd.msd(start_frame = start_frame, end_frame = end_frame, box_size = box_size, mode = 'direct')
[docs] def compute_time_avg_msd( self, start_frame: int = 0, end_frame: int = -1, box_size: List[float] = [] ): """ Deprecated. Use sim.msd.msd() instead. Ref: :func:`cytocalc.sim_analysis.SimAnalyzerMSD.msd` """ warnings.warn("Deprecated. Use sim.msd.msd() instead", DeprecationWarning) return self.msd.msd(start_frame = start_frame, end_frame = end_frame, box_size = box_size, mode = 'window')
[docs] def bound_couple_vs_time(self, start_frame: int = 0, end_frame: int = -1): """ Deprecated. Use sim.misc.bound_couple_vs_time() instead. Ref: :func:`cytocalc.sim_analysis.SimAnalyzerMisc.bound_couple_vs_time` """ warnings.warn("Deprecated. Use sim.misc.bound_couple_vs_time() instead", DeprecationWarning) return self.misc.bound_couple_vs_time(start_frame, end_frame)