Pad

class of dascore.proc.basic
inherits from: PatchProcessor, DascoreBaseModel, pydantic.main.BaseModel
source

Pad(
    *args ,
    mode: Any = constant,
    constant_values: Any = 0,
    expand_coords: Any = True,
    samples: Any = False,
    **kwargs ,
)-> None

Pad the patch data along specified dimensions.

Parameters

Parameter Description
patch The patch to pad.
mode : str, optional The mode of padding; only ‘constant’ is supported.
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.
samples : bool, optional If True, the values in kwargs represent samples along a dimension
and must be integers. Otherwise, they are assumed to have the same
units as the specified dimension, or have units attached.
**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 padding 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.
Note

A coordinate measured on a padded dimension grows with it, saying nothing over the samples which were added: NaN or NaT for a number or a time, blank for text, and False for a membership flag.

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")

Methods

Name Description
check Refuse a patch which does not carry what the operation needs.
chunk_contract Return what a chunk of the output needs of the input, or None.
get_metadata Return the padded coordinates, and each axis’s (before, after) widths.
kernel Return the data padded with a constant.
model_copy Copy the model, dropping cached values the update invalidates.
new Create new instance with some attributed updated.
numpy_kernel Return the data padded with a constant by numpy.
pad Pad the patch data along specified dimensions.
reconcile Return metadata or a patch holding the final data; default as is.
run Run the operation: check, get_metadata, kernel, reconcile, record.