def collapse(self, axis, method="sum"):
        """Collapse the dataset along one axis, adding lower rank channels.

        New channels have names ``<channel name>_<axis name>_<method>``.

        Parameters
        ----------
        axis : int or str
            The axis to collapse along.
            If given as an integer, the axis in the underlying array is used.
            If given as a string, the axis must exist, and be a 1D array-aligned axis.
            (i.e. have a shape with a single value which is not ``1``)
            The axis to collapse along is inferred from the shape of the axis.
        method : {'average', 'sum', 'max', 'min'} (optional)
            The method of collapsing the given axis. Method may also be list
            of methods corresponding to the channels of the object. Default
            is sum. NaNs are ignored.
            Can also be a list, allowing for different treatment for varied channels.
            In this case, None indicates that no change to that channel should occur.

        See Also
        --------
        chop
            Divide the dataset into its lower-dimensionality components.
        split
            Split the dataset while maintaining its dimensionality.
        moment
            Take the moment along a particular axis
        """
        if method in ("int", "integrate"):
            warnings.warn(
                "integrate method of collapse is deprecated, use moment(moment=0) instead",
                wt_exceptions.VisibleDeprecationWarning,
            )
            for channel in self.channel_names:
                try:
                    self.moment(axis, channel, moment=0)
                    self.rename_channels(
                        **{self.channel_names[-1]: f"{channel}_{axis}_{method}"}, verbose=False
                    )
                except wt_exceptions.ValueError:
                    pass  # may have some channels which fail, do so silently
            return
        # get axis index --------------------------------------------------------------------------
        if isinstance(axis, int):
            axis_index = axis
        elif isinstance(axis, str):
            index = self.axis_names.index(axis)
            axes = [i for i in range(self.ndim) if self.axes[index].shape[i] > 1]
            if len(axes) > 1:
                raise wt_exceptions.MultidimensionalAxisError(axis, "collapse")
            elif len(axes) == 0:
                raise wt_exceptions.ValueError(
                    "Axis {} is a single point, cannot collapse".format(axis)
                )
            axis_index = axes[0]
        else:
            raise wt_exceptions.TypeError("axis: expected {int, str}, got %s" % type(axis))

        new_shape = list(self.shape)
        new_shape[axis_index] = 1
        func = {
            "sum": np.nansum,
            "max": np.nanmax,
            "maximum": np.nanmax,
            "min": np.nanmin,
            "minimum": np.nanmin,
            "ave": np.nanmean,
            "average": np.nanmean,
            "mean": np.nanmean,
        }

        # methods ---------------------------------------------------------------------------------
        if isinstance(method, str):
            methods = [method for _ in self.channels]
        if isinstance(method, list):
            if len(method) == len(self.channels):
                methods = method
            else:
                raise wt_exceptions.ValueError(
                    "method argument must have same number of elements as there are channels"
                )
            for m in methods:
                if m not in func.keys():
                    raise wt_exceptions.ValueError("method '{}' not recognized".format(m))

        warnings.warn("collapse", category=wt_exceptions.EntireDatasetInMemoryWarning)

        # collapse --------------------------------------------------------------------------------
        for method, channel in zip(methods, self.channel_names):
            if method is None:
                continue

            if self[channel].shape[axis_index] == 1:
                continue  # Cannot collapse any further, don't clutter data object

            new_shape = list(self[channel].shape)
            new_shape[axis_index] = 1
            rtype = self[channel].dtype
            if method in ["ave", "average", "mean"]:
                rtype = np.result_type(self[channel].dtype, float)

            new = self.create_channel(
                "{}_{}_{}".format(channel, axis, method),
                values=np.empty(new_shape, dtype=rtype),
                units=self[channel].units,
            )

            new[:] = func[method](self[channel], axis=axis_index, keepdims=True)
Collapse the dataset along one axis, adding lower rank channels.

        New channels have names ``<channel name>_<axis name>_<method>``.

        Parameters
        ----------
        axis : int or str
            The axis to collapse along.
            If given as an integer, the axis in the underlying array is used.
            If given as a string, the axis must exist, and be a 1D array-aligned axis.
            (i.e. have a shape with a single value which is not ``1``)
            The axis to collapse along is inferred from the shape of the axis.
        method : {'average', 'sum', 'max', 'min'} (optional)
            The method of collapsing the given axis. Method may also be list
            of methods corresponding to the channels of the object. Default
            is sum. NaNs are ignored.
            Can also be a list, allowing for different treatment for varied channels.
            In this case, None indicates that no change to that channel should occur.

        See Also
        --------
        chop
            Divide the dataset into its lower-dimensionality components.
        split
            Split the dataset while maintaining its dimensionality.
        moment
            Take the moment along a particular axis