From 420d4a2e9f583df21983222a87cec7095b01a8cc Mon Sep 17 00:00:00 2001 From: Michael Krayer Date: Thu, 19 Aug 2021 17:26:38 +0200 Subject: [PATCH] initialization from x,y,z arrays --- particle.py | 9 +++++++++ 1 file changed, 9 insertions(+) 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