[docs]classCSMFrame:""" Class representing a single frame of a simulation. The data extracted from a frame file is stored in frame.data as a pandas object. """def__init__(self,pandas_obj,**kwargs):self.data=pandas_objself._npobj=self._get_pos_nparray()self.time=None# time after simulation started
[docs]def_get_pos_nparray(self):""" obtains 3D position frome parsed data. If simulation is 2D or 1D other dimensions are set to 0 """obj=self.dataif'posX'notinobj.columns:returnNoneif'posY'notinobj.columns:obj['posY']=0if'posZ'notinobj.columns:obj['posZ']=0returnobj[['posX','posY','posZ']].to_numpy(dtype=float)
[docs]defcompute_com(self):""" returns centre of mass of all filaments together (uniform mass) """ifself._npobjisNoneorlen(self._npobj)==0:raiseValueError("Cannot compute center of mass: no position data available")returnnp.mean(self._npobj,axis=0)
[docs]defcompute_radius(self):""" returns a measure of "network radius" of filaments (see appendix of Belmonte et al. Mol Syst Biol. 2017 Sep 27;13(9):941. doi: 10.15252/msb.20177796 in https://pmc.ncbi.nlm.nih.gov/articles/instance/5615920/bin/MSB-13-941-s001.pdf)"""ifself._npobjisNoneorlen(self._npobj)==0:raiseValueError("Cannot compute radius: no position data available")# get position vectors of all pointsradial_vectors=self._npobj-self.compute_com()radial_dist=np.linalg.norm(radial_vectors,axis=1)radius=np.sqrt(2*np.mean(radial_dist**2))returnradius