Repository: wright-group/WrightTools

Issue:
Many methods in wt.data call `channel._update()` even though this method is set to be removed.



Discussion:

Resolving patch:
diff --git a/WrightTools/data/_data.py b/WrightTools/data/_data.py
--- a/WrightTools/data/_data.py
+++ b/WrightTools/data/_data.py
@@ -380,7 +380,6 @@ def normalize(self, axis=None):
         # divide through by max
         self.values /= np.amax(dummy, axis=axis, keepdims=True)
         # finish
-        self._update()
 
     def null(self):
         """Null value."""
@@ -461,7 +460,6 @@ def trim(self, neighborhood, method='ztest', factor=3, replace='nan',
         else:
             raise KeyError('replace must be one of {nan, mean, mask} or some number')
         # finish
-        self._update()
         if verbose:
             print('%i outliers removed' % len(outliers))
         return outliers
@@ -558,9 +556,6 @@ def _update(self):
             setattr(self, obj.name, obj)
         self.shape = self.channels[0].values.shape
 
-    def _pupdate(self, *args, **kwargs):
-        return self._update(*args, **kwargs)
-
     def bring_to_front(self, channel):
         """Bring a specific channel to the zero-indexed position in channels.
 
@@ -778,7 +773,6 @@ def collapse(self, axis, method='integrate'):
                 channel.values = np.average(channel.values, axis=axis_index)
             else:
                 print('method not recognized in data.collapse')
-            channel._update()
         # cleanup ---------------------------------------------------------------------------------
         self.axes.pop(axis_index)
         self._update()
@@ -880,7 +874,6 @@ def divide(self, divisor, channel=0, divisor_channel=0):
         divisor_channel = divisor.channels[divisor_channel_index]
         # do division
         channel.values /= divisor_channel.values
-        channel._update()
         # transpose out
         self.transpose(transpose_order, verbose=False)
 
@@ -939,7 +932,6 @@ def dOD(self, signal_channel, reference_channel,
         self.channels[signal_channel_index].give_values(out)
         self.channels[signal_channel_index].signed = True
         self.channels[signal_channel_index].null = 0
-        self.channels[signal_channel_index]._update()
 
     def flip(self, axis):
         """Flip direction of arrays along an axis.
@@ -1083,7 +1075,6 @@ def heal(self, channel=0, method='linear', fill_value=np.nan,
             # grid data
             out = griddata(tup, arr[-1], xi, method=method, fill_value=fill_value)
             self.channels[channel_index].values = out
-            self.channels[channel_index]._update()
         # print
         if verbose:
             print('channel {0} healed in {1} seconds'.format(
@@ -1393,7 +1384,6 @@ def offset(self, points, offsets, along, offset_axis,
 
         """
         # axis ------------------------------------------------------------------------------------
-
         if isinstance(along, int):
             axis_index = along
         elif isinstance(along, string_type):
@@ -1401,21 +1391,17 @@ def offset(self, points, offsets, along, offset_axis,
         else:
             print('axis type', type(along), 'not valid')
         axis = self.axes[axis_index]
-
         # values & points -------------------------------------------------------------------------
-
         # get values, points, units
         if units == 'same':
             input_units = axis.units
         else:
             input_units = units
-
         # check offsets is 1D or 0D
         if len(offsets.shape) == 1:
             pass
         else:
             raise RuntimeError('values must be 1D or 0D in offset!')
-
         # check if units is compatible, convert
         dictionary = getattr(wt_units, axis.units_kind)
         if input_units in dictionary.keys():
@@ -1423,26 +1409,21 @@ def offset(self, points, offsets, along, offset_axis,
         else:
             raise RuntimeError('units incompatible in offset!')
         points = wt_units.converter(points, input_units, axis.units)
-
         # create correction array
         function = interp1d(points, offsets, bounds_error=False)
         corrections = function(axis.points)
-
         # remove nans
         finite_indicies = np.where(np.isfinite(corrections))[0]
         left_pad_width = finite_indicies[0]
         right_pad_width = len(corrections) - finite_indicies[-1] - 1
         corrections = np.pad(corrections[np.isfinite(corrections)],
                              (int(left_pad_width), int(right_pad_width)), mode='edge')
-
         # do correction ---------------------------------------------------------------------------
-
         # transpose so axis is last
         transpose_order = np.arange(len(self.axes))
         transpose_order[axis_index] = len(self.axes) - 1
         transpose_order[-1] = axis_index
         self.transpose(transpose_order, verbose=False)
-
         # get offset axis index
         if isinstance(offset_axis, int):
             offset_axis_index = offset_axis
@@ -1450,7 +1431,6 @@ def offset(self, points, offsets, along, offset_axis,
             offset_axis_index = self.axis_names.index(offset_axis)
         else:
             print('offset_axis type', type(offset_axis), 'not valid')
-
         # new points
         new_points = [a.points for a in self.axes]
         old_offset_axis_points = self.axes[offset_axis_index].points
@@ -1470,31 +1450,24 @@ def offset(self, points, offsets, along, offset_axis,
             new_offset_axis_points = np.linspace(_min, _max, n)
         new_points[offset_axis_index] = new_offset_axis_points
         new_xi = tuple(np.meshgrid(*new_points, indexing='ij'))
-
         xi = tuple(np.meshgrid(*[a.points for a in self.axes], indexing='ij'))
         for channel in self.channels:
-
             # 'undo' gridding
             arr = np.zeros((len(self.axes) + 1, channel.values.size))
             for i in range(len(self.axes)):
                 arr[i] = xi[i].flatten()
             arr[-1] = channel.values.flatten()
-
             # do corrections
             corrections = list(corrections)
             corrections = corrections * int((len(arr[0]) / len(corrections)))
             arr[offset_axis_index] += corrections
-
             # grid data
             tup = tuple([arr[i] for i in range(len(arr) - 1)])
             # note that rescale is crucial in this operation
             out = griddata(tup, arr[-1], new_xi, method=method,
                            fill_value=np.nan, rescale=True)
             channel.values = out
-            channel._update()
-
         self.axes[offset_axis_index].points = new_offset_axis_points
-
         # transpose out
         self.transpose(transpose_order, verbose=False)
         self._update()
@@ -1598,7 +1571,6 @@ def scale(self, channel=0, kind='amplitude', verbose=True):
             channel.values = np.log10(channel.values)
         if kind in ['invert']:
             channel.values *= -1.
-        channel._update()
 
     def share_nans(self):
         """Share not-a-numbers between all channels.
@@ -1848,7 +1820,6 @@ def subtract(self, subtrahend, channel=0, subtrahend_channel=0):
         subtrahend_channel = subtrahend.channels[subtrahend_channel_index]
         # do division
         channel.values -= subtrahend_channel.values
-        channel._update()
         # transpose out
         self.transpose(transpose_order, verbose=False)
 


Test patch: