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. {di
(
self,
pad_width: Mapping[Any, int | tuple[int, int]] | None = None,
mode: PadModeOptions = "constant",
stat_length: (
int | tuple[int, int] | Mapping[Any, tuple[int, int]] | None
) = None,
constant_values: T_VarPadConstantValues | None = None,
end_values: int | tuple[int, int] | Mapping[Any, tuple[int, int]] | None = None,
reflect_type: PadReflectOptions = None,
keep_attrs: bool | None = None,
**pad_width_kwargs: Any,
)
| 1244 | return [pad_option.get(d, (0, 0)) for d in self.dims] |
| 1245 | |
| 1246 | def pad( |
| 1247 | self, |
| 1248 | pad_width: Mapping[Any, int | tuple[int, int]] | None = None, |
| 1249 | mode: PadModeOptions = "constant", |
| 1250 | stat_length: ( |
| 1251 | int | tuple[int, int] | Mapping[Any, tuple[int, int]] | None |
| 1252 | ) = None, |
| 1253 | constant_values: T_VarPadConstantValues | None = None, |
| 1254 | end_values: int | tuple[int, int] | Mapping[Any, tuple[int, int]] | None = None, |
| 1255 | reflect_type: PadReflectOptions = None, |
| 1256 | keep_attrs: bool | None = None, |
| 1257 | **pad_width_kwargs: Any, |
| 1258 | ): |
| 1259 | """ |
| 1260 | Return a new Variable with padded data. |
| 1261 | |
| 1262 | Parameters |
| 1263 | ---------- |
| 1264 | pad_width : mapping of hashable to tuple of int |
| 1265 | Mapping with the form of {dim: (pad_before, pad_after)} |
| 1266 | describing the number of values padded along each dimension. |
| 1267 | {dim: pad} is a shortcut for pad_before = pad_after = pad |
| 1268 | mode : str, default: "constant" |
| 1269 | See numpy / Dask docs |
| 1270 | stat_length : int, tuple or mapping of hashable to tuple |
| 1271 | Used in 'maximum', 'mean', 'median', and 'minimum'. Number of |
| 1272 | values at edge of each axis used to calculate the statistic value. |
| 1273 | constant_values : scalar, tuple or mapping of hashable to scalar or tuple |
| 1274 | Used in 'constant'. The values to set the padded values for each |
| 1275 | axis. |
| 1276 | end_values : scalar, tuple or mapping of hashable to tuple |
| 1277 | Used in 'linear_ramp'. The values used for the ending value of the |
| 1278 | linear_ramp and that will form the edge of the padded array. |
| 1279 | reflect_type : {"even", "odd"}, optional |
| 1280 | Used in "reflect", and "symmetric". The "even" style is the |
| 1281 | default with an unaltered reflection around the edge value. For |
| 1282 | the "odd" style, the extended part of the array is created by |
| 1283 | subtracting the reflected values from two times the edge value. |
| 1284 | keep_attrs : bool, optional |
| 1285 | If True, the variable's attributes (`attrs`) will be copied from |
| 1286 | the original object to the new one. If False (default), the new |
| 1287 | object will be returned without attributes. |
| 1288 | **pad_width_kwargs |
| 1289 | One of pad_width or pad_width_kwargs must be provided. |
| 1290 | |
| 1291 | Returns |
| 1292 | ------- |
| 1293 | padded : Variable |
| 1294 | Variable with the same dimensions and attributes but padded data. |
| 1295 | """ |
| 1296 | pad_width = either_dict_or_kwargs(pad_width, pad_width_kwargs, "pad") |
| 1297 | |
| 1298 | # change default behaviour of pad with mode constant |
| 1299 | if mode == "constant" and ( |
| 1300 | constant_values is None or constant_values is dtypes.NA |
| 1301 | ): |
| 1302 | dtype, constant_values = dtypes.maybe_promote(self.dtype) |
| 1303 | else: |