pad

function of dascore.proc.basic source

pad(
    patch: Patch ,
    mode: Literal[‘constant’] = constant,
    constant_values: Any = 0,
    expand_coords = True,
    samples = False,
    **kwargs ,
)-> ‘PatchType’

Pad the patch data along specified dimensions.

Parameters

Parameter Description
mode : str, optional The mode of padding, by default ‘constant’.
constant_values : scalar , optional A single scalar value used as the padding value across all dimensions.
Defaults to 0.
expand_coords : bool, optional Determines how coordinates are adjusted when padding is applied.
If set to True, the coordinates will be expanded to maintain their
order and even sampling (if evenly sampled), by extrapolating
based on the coordinate’s step size. If set to False, or coordinate
is not evenly sampled, the new coordinates introduced by padding
will be padded with NaN values.
**kwargs: Used to specify dimension and number of elements,
either an integer or a tuple (before, after).
In addition, the following strings are supported:
“fft” - pad to the next fast fft length along the given dimension by
adding values to the end of the axis.
“correlate” - prepare the coordinate for correlation/convolution in
the frequency domain by pading to the next fast fft length after
2*n - 1 where n is the current dimension length by adding values
to the end of the axis.

Examples

import dascore as dc
patch = dc.get_example_patch()
# Zero pad `time` dimension with 2 patch's time unit (e.g., sec)
# zeros before and 3 zeros after
padded_patch_1 = patch.pad(time=(2, 3))
# Pad `distance` dimension with 1s 4 samples before and 4 after.
padded_patch_3 = patch.pad(distance=4, constant_values=1, samples=True)
# Get patch ready for fast fft along time dimension.
padded_fft = patch.pad(time="fft")