MCPcopy
hub / github.com/pydata/xarray / _bottleneck_reduce

Method _bottleneck_reduce

xarray/computation/rolling.py:646–693  ·  view source on GitHub ↗
(self, func, keep_attrs, **kwargs)

Source from the content-addressed store, hash-verified

644 )
645
646 def _bottleneck_reduce(self, func, keep_attrs, **kwargs):
647 # bottleneck doesn't allow min_count to be 0, although it should
648 # work the same as if min_count = 1
649 # Note bottleneck only works with 1d-rolling.
650 if self.min_periods == 0:
651 min_count = 1
652 else:
653 min_count = self.min_periods
654
655 axis = self.obj.get_axis_num(self.dim[0])
656
657 padded = self.obj.variable
658 if self.center[0]:
659 if is_duck_dask_array(padded.data):
660 # workaround to make the padded chunk size larger than
661 # self.window - 1
662 shift = -(self.window[0] + 1) // 2
663 offset = (self.window[0] - 1) // 2
664 valid = (slice(None),) * axis + (
665 slice(offset, offset + self.obj.shape[axis]),
666 )
667 else:
668 shift = (-self.window[0] // 2) + 1
669 valid = (slice(None),) * axis + (slice(-shift, None),)
670 padded = padded.pad({self.dim[0]: (0, -shift)}, mode="constant")
671
672 if is_duck_dask_array(padded.data):
673 values = dask_array_ops.dask_rolling_wrapper(
674 func, padded, axis=axis, window=self.window[0], min_count=min_count
675 )
676 else:
677 values = func(
678 padded.data, window=self.window[0], min_count=min_count, axis=axis
679 )
680 # index 0 is at the rightmost edge of the window
681 # need to reverse index here
682 # see GH #8541
683 if func in [bottleneck.move_argmin, bottleneck.move_argmax]:
684 values = self.window[0] - 1 - values
685
686 if self.center[0]:
687 values = values[valid]
688
689 attrs = self.obj.attrs if keep_attrs else {}
690
691 return self.obj.__class__(
692 values, self.obj.coords, attrs=attrs, name=self.obj.name
693 )
694
695 def _array_reduce(
696 self,

Callers 1

_array_reduceMethod · 0.95

Calls 4

is_duck_dask_arrayFunction · 0.90
funcFunction · 0.70
get_axis_numMethod · 0.45
padMethod · 0.45

Tested by

no test coverage detected