act.transform.transform_dataset#
- act.transform.transform_dataset(ds, target=None, dim=None, transform=None, qc_prefix='qc_', qc_mask=None, target_ds=None, per_var_transform=None, per_var_kwargs=None, **kwargs)[source]#
Apply a transform to every variable in
dsthat containsdim.For each variable, if a companion QC variable named
{qc_prefix}<var>exists in the dataset it is used automatically.- Parameters:
ds (xarray.Dataset) – Input Dataset.
target (xarray.DataArray or numpy.ndarray, optional) – Target coordinate values. Mutually exclusive with
target_ds.dim (str) – Dimension name along which to transform.
transform ({“bin_average”, “interpolate”, “subsample”}) – Default transform to apply to every matching variable.
qc_prefix (str) – Prefix used to find companion QC variables (default
"qc_").qc_mask (int, str, list[str], or None) – Integer bitmask, QC assessment name, or None. An assessment name is matched against each QC companion’s
flag_assessmentsmetadata; None selects"Bad", which requiresflag_masksmetadata on each QC companion (aValueErroris raised otherwise).target_ds (xarray.Dataset, optional) – Source dataset containing the target coordinate. If its coordinate declares a CF bounds variable, that target-grid bounds variable is included in the output; input bounds are only consumed for the transform and are not copied.
per_var_transform (dict, optional) – Mapping of variable name to a transform override.
per_var_kwargs (dict, optional) – Mapping of variable name to keyword argument overrides.
**kwargs – Additional keyword arguments forwarded to the underlying transform (e.g.
t_range,std_bad_max).
- Returns:
xarray.Dataset – New dataset with transformed variables on the target coordinate. Each transformed variable has a companion QC variable included.
See also
act.transform.bin_averageBin-average a single DataArray.
act.transform.interpolateInterpolate a single DataArray.
act.transform.subsampleSubsample a single DataArray.
Examples
Bin-average every time-dependent variable onto a 30-minute time base. Each variable’s
qc_<var>companion is found and honored automatically, and forbin_averagethe coordinate’s CFboundsvariable is picked up asinput_bounds. The bounds variable itself is not transformed.import act ds = act.io.arm.read_arm_netcdf(filename, cleanup_qc=True) target = act.transform.make_coord('2023-03-01', '2023-03-02', '30min') new_ds = act.transform.transform_dataset( ds, target=target, dim='time', transform='bin_average', qc_mask=4 )
One transform is rarely right for every variable in a file, which is the usual reason to use this instead of looping yourself.
per_var_transformoverrides the transform for named variables andper_var_kwargsoverrides their keyword arguments – here a categorical present-weather code is subsampled rather than averaged, since averaging two codes yields a value that corresponds to no weather condition.new_ds = act.transform.transform_dataset( ds, target=target, dim='time', transform='bin_average', # default for everything else qc_mask=4, per_var_transform={'pwd_pw_code_inst': 'subsample'}, per_var_kwargs={'wspd_arith_mean': {'std_ind_max': 0.8}}, )
Transform onto another Dataset’s coordinate instead of an explicit target, which is convenient for putting two datastreams on a common time base.
targetandtarget_dsare mutually exclusive.new_ds = act.transform.transform_dataset( ds, target_ds=other_ds, dim='time', transform='interpolate' )