diff --git a/particle.py b/particle.py index 5fefd0b..909536b 100644 --- a/particle.py +++ b/particle.py @@ -49,6 +49,15 @@ class Particles: attr[key] = pp[col[key],:,0].squeeze() return cls(num,time,attr,period) + @classmethod + def from_position(cls,x,y,z,time,period): + assert x.ndim==1 and y.ndim==1 and z.ndim==1,\ + "'x','y','z' must be one dimensional arrays of length Np." + assert len(x)==len(y) and len(y)==len(z) + num = len(x) + attr = {'id': np.arange(1,num+1),'x': np.asarray(x),'y': np.asarray(y),'z': np.asarray(z)} + return cls(num,time,attr,period) + def __getitem__(self,val): if isinstance(val,int): lo,hi = val,val+1