🍾 Xarray is now 10 years old! 🎉

xarray.IndexVariable.pad

xarray.IndexVariable.pad#

IndexVariable.pad(pad_width=None, mode='constant', stat_length=None, constant_values=None, end_values=None, reflect_type=None, keep_attrs=None, **pad_width_kwargs)[source]#

Return a new Variable with padded data.

Parameters:
  • pad_width (mapping of hashable to tuple of int) – Mapping with the form of {dim: (pad_before, pad_after)} describing the number of values padded along each dimension. {dim: pad} is a shortcut for pad_before = pad_after = pad

  • mode (str, default: "constant") – See numpy / Dask docs

  • stat_length (int, tuple or mapping of hashable to tuple) – Used in ‘maximum’, ‘mean’, ‘median’, and ‘minimum’. Number of values at edge of each axis used to calculate the statistic value.

  • constant_values (scalar, tuple or mapping of hashable to tuple) – Used in ‘constant’. The values to set the padded values for each axis.

  • end_values (scalar, tuple or mapping of hashable to tuple) – Used in ‘linear_ramp’. The values used for the ending value of the linear_ramp and that will form the edge of the padded array.

  • reflect_type ({"even", "odd"}, optional) – Used in “reflect”, and “symmetric”. The “even” style is the default with an unaltered reflection around the edge value. For the “odd” style, the extended part of the array is created by subtracting the reflected values from two times the edge value.

  • keep_attrs (bool, optional) – If True, the variable’s attributes (attrs) will be copied from the original object to the new one. If False (default), the new object will be returned without attributes.

  • **pad_width_kwargs – One of pad_width or pad_width_kwargs must be provided.

Returns:

padded (Variable) – Variable with the same dimensions and attributes but padded data.