diff --git a/particle.py b/particle.py index 909536b..e9e06cd 100644 --- a/particle.py +++ b/particle.py @@ -49,6 +49,19 @@ class Particles: attr[key] = pp[col[key],:,0].squeeze() return cls(num,time,attr,period) + @classmethod + def from_mat(cls,file,select_col=None): + from .helper import load_mat + pp = load_mat(file,'pp',cast_integer=False) # int casting is expensive and useless on potentially large array + col,time,ccinfo = load_mat(file,['colpy','time','ccinfo'],cast_integer=True) + period = [None,None,None] + if bool(ccinfo['xperiodic']): period[0]=ccinfo['b'] + if bool(ccinfo['yperiodic']): period[1]=ccinfo['d'] + if bool(ccinfo['zperiodic']): period[2]=ccinfo['f'] + for key in col: + col[key]-=1 + return cls.from_array(pp,col,time,period,select_col=select_col) + @classmethod def from_position(cls,x,y,z,time,period): assert x.ndim==1 and y.ndim==1 and z.ndim==1,\ @@ -608,4 +621,4 @@ def translate_circular(pp,col,translation,bounds,axis=0): L = bounds[2*axis+1] keys = ('x','y','z') pp[col[keys[axis]],:,:] = (pp[col[keys[axis]],:,:]+translation)%L - return pp \ No newline at end of file + return pp