Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix #202
Browse files Browse the repository at this point in the history
Constantin Gahr committed Jul 2, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 83b0a75 commit 75b0305
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions xrft/padding.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Functions to pad and unpad a N-dimensional regular grid
"""

import numpy as np
from xarray.core.utils import either_dict_or_kwargs

@@ -311,7 +312,9 @@ def _pad_coordinates_callback(vector, iaxis_pad_width, iaxis, kwargs):
vector[:n_start] = (
vmin - n_start * spacing + np.linspace(0, spacing * (n_start - 1), n_start)
)
vector[-n_end:] = vmax + spacing + np.linspace(0, spacing * (n_end - 1), n_end)
vector[len(vector) - n_end :] = (
vmax + spacing + np.linspace(0, spacing * (n_end - 1), n_end)
)
return vector


@@ -438,6 +441,6 @@ def _pad_width_to_slice(pad_width, size):
A slice object for removing the padded elements of the coordinate
array.
"""
if type(pad_width) == int:
if isinstance(pad_width, int):
pad_width = (pad_width, pad_width)
return slice(pad_width[0], size - pad_width[1])
1 change: 1 addition & 0 deletions xrft/tests/test_padding.py
Original file line number Diff line number Diff line change
@@ -208,6 +208,7 @@ def test_unpad_pop_pad_width_attributes(sample_da_2d, pad_width_arg):
(
{"x": 4, "y": 3},
{"x": 4},
{"x": 0},
{"y": 3},
{"x": (4, 3), "y": 3},
{"x": (4, 3), "y": (5, 3)},

0 comments on commit 75b0305

Please sign in to comment.