# resample a patch along time dimension to 10 ms
import numpy as np
import dascore as dc
patch = dc.get_example_patch()
new = patch.resample(time=np.timedelta64(10, 'ms'))
# Resample time dimension to 50 Hz
from dascore.units import Hz
new = patch.resample(time=(50 * Hz))
# Resample distance dimension to a sampling period of 15m
from dascore.units import m
new = patch.resample(distance=15 * m)
# Resample time axis such that there are 50 samples total
new = patch.resample(time=50, samples=True)Resample
Resample(
*args ,
window: Any = None,
interp_kind: Any = linear,
samples: Any = False,
**kwargs ,
)-> None
Resample along a single dimension using Fourier Method and interpolation.
The dimension which should be resampled is passed as kwargs. The key is the dimension name and the value is the new sampling period.
Since Fourier methods only support adding or removing an integer number of frequency bins, the exact desired sampling rate is often not achievable with resampling alone. If the fourier resampling doesn’t produce the exact result, an interpolation (see interpolate) is used to achieve the desired sampling rate.
Parameters
| Parameter | Description |
|---|---|
| patch | The patch to resample. |
| window |
The Fourier-domain window that tapers the Fourier spectrum. See scipy.signal.resample for details. Only used if method == ‘fft’. |
| interp_kind |
The interpolation type if output of fourier resampling doesn’t produce exactly the right sampling rate. |
| samples |
If true, the values in kwargs represent the number of samples along The specified dimension. |
| **kwargs |
keyword arguments to specify dimension and new sampling value. Units can also be used to specify sampling_period or frequency. |
Note
- Unless
samplesisTrue, this function requires a sampling_period. - The resulting Patch can be slightly shorter than the input Patch.
- Coordinates associated with the resampled dimension are dropped because resampling cannot safely infer their new values. A
DASCoreWarningnames any coordinates which were dropped.
Examples
See Also
Methods
| Name | Description |
|---|---|
| check | Refuse a patch which does not carry what the operation needs. |
| get_metadata | Return the resampled coordinates, and the length and positions to hit. |
| model_copy | Copy the model, dropping cached values the update invalidates. |
| new | Create new instance with some attributed updated. |
| numpy_kernel | Return the data resampled by scipy, then interpolated if needed. |
| resample | Resample along a single dimension using Fourier Method and interpolation. |
| reconcile | Return metadata or a patch holding the final data; default as is. |
| run | Run the operation: check, get_metadata, kernel, reconcile, record. |