Skip to content
Snippets Groups Projects
Commit 5add0064 authored by Jan Caron's avatar Jan Caron
Browse files

Fixed Field.clip()

parent b269505c
No related branches found
No related tags found
No related merge requests found
...@@ -475,7 +475,7 @@ class Field(NDArrayOperatorsMixin): ...@@ -475,7 +475,7 @@ class Field(NDArrayOperatorsMixin):
raise AssertionError('Can only handle 3D or 2D cases (see documentation for specifics)!') raise AssertionError('Can only handle 3D or 2D cases (see documentation for specifics)!')
def clip(self, vmin=None, vmax=None, sigma=None, mask=None): def clip(self, vmin=None, vmax=None, sigma=None, mask=None):
"""Clip (limit) the values in an array. For vector fields, this will take the amplitude into account """Clip (limit) the values in an array. For vector fields, this will take the amplitude into account.
Parameters Parameters
---------- ----------
...@@ -517,9 +517,8 @@ class Field(NDArrayOperatorsMixin): ...@@ -517,9 +517,8 @@ class Field(NDArrayOperatorsMixin):
if vmax is None: if vmax is None:
vmax = np.nanmax(amp_masked) vmax = np.nanmax(amp_masked)
if self.vector: # Vector fields need to scale components according to masked amplitude if self.vector: # Vector fields need to scale components according to masked amplitude
mask_vec = np.logical_and(mask, amp <= vmax) # Only vmax is important! mask_vec = (amp <= vmax)[..., None] # Only vmax is important for vectors! mask_vec broadcast to components!
data = amp / np.where(mask_vec, 1, amp) # TODO: needs testing! data = np.where(mask_vec, self.data, vmax * self.data/amp[..., None]) # Scale outliers to vmax!
# TODO: Test np.clip(field) (also ufunc?? think not...) seems to work, but what about others?
else: # For scalar fields, just delegate to the numpy function: else: # For scalar fields, just delegate to the numpy function:
data = np.clip(self.data, vmin, vmax) data = np.clip(self.data, vmin, vmax)
return Field(data, self.scale, self.vector) return Field(data, self.scale, self.vector)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment