Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix #202 #209

Merged
merged 2 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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])
4 changes: 4 additions & 0 deletions xrft/tests/test_padding.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Unit tests for padding functions
"""

import pytest
import numpy as np
import xarray as xr
Expand Down Expand Up @@ -208,11 +209,14 @@ 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, "y": 0},
{"x": (4, 3), "y": 3},
{"x": (4, 3), "y": (5, 3)},
{"x": (4, 3)},
{"y": (5, 3)},
{"x": (0, 3), "y": (5, 0)},
),
)
def test_unpad_ifft_fft_pad_round_trip(sample_da_2d, pad_width):
Expand Down
1 change: 1 addition & 0 deletions xrft/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Test utility functions of xrft
"""

import pytest
import numpy as np
import pandas as pd
Expand Down
1 change: 1 addition & 0 deletions xrft/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Utility functions for xrft
"""

import numpy as np

from .xrft import _diff_coord
Expand Down
2 changes: 1 addition & 1 deletion xrft/xrft.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def _diff_coord(coord):
return np.diff(coord)
elif pd.api.types.is_datetime64_dtype(v0):
diff = np.diff(coord).astype("timedelta64[ns]").astype("f8")
diff = (diff/1e9) #convert back to seconds
diff = diff / 1e9 # convert back to seconds
return diff
else:
return np.diff(coord)
Expand Down
Loading