read particles from special mat-files

This commit is contained in:
Michael Krayer 2021-12-03 10:34:11 +01:00
parent 1909cd8119
commit 5f56e95d31
1 changed files with 14 additions and 1 deletions

View File

@ -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
return pp