initialization from x,y,z arrays
This commit is contained in:
parent
3d6ecf2bda
commit
420d4a2e9f
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue