xarray_wrapped_interp1D
- PlasmaCalcs.tools.xarray_tools.xarray_sci.xarray_wrapped_interp1D(array, dim, values, *, wrap, demote=True, method='linear', **kw_interp)
return array interpolated to values, along dim, assuming wrap-around at wrap.
For example: array[‘theta’] = 10, 30, 50, …, 350; dim=’theta’, wrap=360,values=xr.DataArray([0, 5, 20, 355], dim=’myangles’), method=’linear’ –>result[‘myangles’] == [0, 5, 20, 355], with values across myangles being:result.isel(myangles=0) = 0.5*arr.isel(theta=-1) + 0.5*arr.isel(theta=0)result.isel(myangles=1) = 0.25*arr.isel(theta=-1) + 0.75*arr.isel(theta=0)result.isel(myangles=2) = 0.5*arr.isel(theta=0) + 0.5*arr.isel(theta=1)result.isel(myangles=3) = 0.75*arr.isel(theta=-1) + 0.25*arr.isel(theta=0)(e.g., the 0 degrees value is halfway between the 10 degrees and 350 degrees value,instead of being nan or some extrapolation from purely the 10 degrees value).array: xarray.DataArraythe array to be interpolated; any number of dims is fine.dim: strthe dimension to interpolate along.(or, can provide a 1D coordinate, and will automatically infer the implied dim.)values: xarray.DataArray (any number of dims) or single valuetells values to interp to.wrap: numberthe wrap-around value for dim.demote: boolif provided dim= 1D coord (which is not a dimension) and result would vary along dim,this tells whether to demote coord back to coord at the end,i.e. whether to promote dim to a dimension.e.g., maybe array varies across ‘i’ dim, with ‘theta’ coord along ‘i’,and you want to interpolate based on ‘theta’ but keep ‘i’ as the dim afterward,then use demote=True. To make result instead have ‘theta’ as dim, use demote=False.method: ‘linear’ or any other method to provide to xarray.interp(not yet implemented, must use ‘linear’.Other methods might require additional padding, or less padding;that can be implemented later if needed.)additional kwargs get passed to xarray.interp.