convenience method for grid as numpy array
This commit is contained in:
parent
ec23f3acd4
commit
34d77ad2ac
9
field.py
9
field.py
|
|
@ -206,6 +206,15 @@ class Field3d:
|
|||
assert idx<self.dim(axis=axis), "'idx' is out-of-bounds."
|
||||
return self.origin[axis]+idx*self.spacing[axis]
|
||||
|
||||
def grid(self,axis=None):
|
||||
if axis is None:
|
||||
return tuple(self.grid(axis=ii) for ii in range(3))
|
||||
assert axis<3, "'axis' must be one of 0,1,2."
|
||||
return self.origin[axis]+np.arange(0,self.dim(axis=axis))*self.spacing[axis]
|
||||
def x(self): return self.grid(axis=0)
|
||||
def y(self): return self.grid(axis=1)
|
||||
def z(self): return self.grid(axis=2)
|
||||
|
||||
def nearest_gridpoint(self,coord,axis=None,lower=False):
|
||||
if axis is None:
|
||||
assert len(coord)==3, "If 'axis' is None, 'coord' must be a tuple/list of length 3."
|
||||
|
|
|
|||
Loading…
Reference in New Issue