You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am experiencing some issues with the way coordinates are padded. Currently the coordinates are padded according to the mode parameter passed to pad()here. For my particular issue I want to be able to have different modes for the data, but effectively pin the mode that is used to pad the coordinate values.
A simple example:
importxarrayasxrimportnumpyasnpda=xr.DataArray([1,2,3], dims=['x'], coords={'x':[4,5,6]})
da
If I pad with constant
da.pad(x=(0,1), mode='constant')
I get this:
which is the coordinate padding I need.
But if I pad with wrap:
da.pad(x=(0,1), mode='wrap')
which gives me repeated coordinate values
Describe the solution you'd like
I would like to be able to do something like this:
This change seems to be enough to get the behaviour @jbusecke wants without breaking any existing tests:
diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py
index 855718cf..21fb0203 100644
--- a/xarray/core/dataset.py+++ b/xarray/core/dataset.py@@ -7228,6 +7228,7 @@ class Dataset(DataWithCoords, DatasetReductions, DatasetArithmetic, Mapping):
) = None,
end_values: int | tuple[int, int] | Mapping[Any, tuple[int, int]] | None = None,
reflect_type: str = None,
+ coord_mode: str = None,
**pad_width_kwargs: Any,
) -> Dataset:
"""Pad this dataset along one or more dimensions.
@@ -7304,6 +7305,7 @@ class Dataset(DataWithCoords, DatasetReductions, DatasetArithmetic, Mapping):
default with an unaltered reflection around the edge value. For
the "odd" style, the extended part of the array is created by
subtracting the reflected values from two times the edge value.
+ coord_mode : str, default: mode
**pad_width_kwargs
The keyword arguments form of ``pad_width``.
One of ``pad_width`` or ``pad_width_kwargs`` must be provided.
@@ -7339,7 +7341,7 @@ class Dataset(DataWithCoords, DatasetReductions, DatasetArithmetic, Mapping):
pad_width = either_dict_or_kwargs(pad_width, pad_width_kwargs, "pad")
if mode in ("edge", "reflect", "symmetric", "wrap"):
- coord_pad_mode = mode+ coord_pad_mode = coord_mode if coord_mode is not None else mode
coord_pad_options = {
"stat_length": stat_length,
"constant_values": constant_values,
Is your feature request related to a problem?
I am experiencing some issues with the way coordinates are padded. Currently the coordinates are padded according to the
mode
parameter passed topad()
here. For my particular issue I want to be able to have different modes for the data, but effectively pin the mode that is used to pad the coordinate values.A simple example:
If I pad with
constant
I get this:
![image](https://user-images.githubusercontent.com/14314623/160675610-7eb3e06c-6c63-488c-9d96-acc46bd4852e.png)
which is the coordinate padding I need.
But if I pad with
wrap
:which gives me repeated coordinate values
![image](https://user-images.githubusercontent.com/14314623/160675749-a6b035dc-6939-4024-802a-03800a6dbda9.png)
Describe the solution you'd like
I would like to be able to do something like this:
and get something like this
![image](https://user-images.githubusercontent.com/14314623/160676264-06a467ce-b456-44ed-881b-658a27acb1e6.png)
Since #3596 internally already defines
coord_pad_mode
it should be easy enough to expose this to the user?Possibly related (but I think not incompatible with the changes propsed here?): #3868
Happy to work with @TomNicholas on a PR, but wanted to get some feedback/comments first.
cc @dcherian @mark-boer who worked on this code.
Describe alternatives you've considered
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: