act.transform.interpolate#
- act.transform.interpolate(data, target, dim, qc=None, qc_mask=None, t_range=None)[source]#
Bilinearly interpolate
dataontotargetcoordinate values alongdim.- Parameters:
data (xarray.DataArray) – Input DataArray.
target (xarray.DataArray or numpy.ndarray) – Target coordinate values to interpolate onto.
dim (str) – Name of the dimension along which to apply the transform.
qc (xarray.DataArray, optional) – Optional integer QC DataArray with same shape as
data.qc_mask (int, str, list[str], or None) – Integer bitmask, QC assessment name, or None. An assessment name is matched against
qc.attrs['flag_assessments']; None selects"Bad", which requiresflag_masksmetadata onqc(aValueErroris raised otherwise); withoutqcno QC bits are excluded.t_range (float or numpy.timedelta64, optional) – Maximum distance from a target point to an input point for interpolation. Must be a timedelta when
dimis a datetime coordinate and a number otherwise. Defaults to no limit.
- Returns:
result (xarray.DataArray) – Interpolated DataArray on the target coordinate.
result_qc (xarray.DataArray) – Integer QC DataArray with same shape as
result, with CFflag_masks/flag_meanings/flag_assessmentsattributes set.
See also
act.transform.bin_averageWeighted average over output bins.
act.transform.subsampleNearest-neighbor selection onto the target coordinate.
act.transform.transform_datasetApply a transform to every variable in a Dataset.
Examples
Interpolate onto a finer time base. Interpolation reports an instant rather than summarizing an interval, so prefer it over
bin_averagewhen moving to a finer grid or onto offset timestamps.import act ds = act.io.arm.read_arm_netcdf(filename, cleanup_qc=True) target = act.transform.make_coord('2023-03-01', '2023-03-02', '30s') result, result_qc = act.transform.interpolate(ds['temp_mean'], target, dim='time')
Honor input QC and limit how far an output point may reach for an input sample. When the coordinate is a datetime,
t_rangemust be a timedelta; by default there is no limit. Output points with no usable sample within range are flaggedQC_OUTSIDE_RANGE.import numpy as np from act.transform.constants import QC_INTERPOLATE, QC_OUTSIDE_RANGE result, result_qc = act.transform.interpolate( ds['temp_mean'], target, dim='time', qc=ds['qc_temp_mean'], qc_mask=4, t_range=np.timedelta64(5, 'm'), ) # Points where a bad or missing neighbor had to be skipped over. stretched = (result_qc.values & QC_INTERPOLATE).astype(bool)