Skip to content

Commit bb2e16a

Browse files
author
Chahan Kropf
committed
Fix resolution to be only positive
1 parent a69712b commit bb2e16a

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

climada/util/coordinates.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2183,10 +2183,10 @@ def get_resolution_1d(coords, min_resol=1.0e-8):
21832183
res : float
21842184
Resolution of given grid.
21852185
"""
2186-
res = np.diff(np.unique(coords))
2187-
diff = np.diff(coords)
2188-
mask = (res > min_resol) & np.isin(res, np.abs(diff))
2189-
return diff[np.abs(diff) == res[mask].min()][0]
2186+
res = np.diff(np.unique(coords)) # always positive because unique is sorted
2187+
diff = np.abs(np.diff(coords))
2188+
mask = (res > min_resol) & np.isin(res, diff)
2189+
return diff[diff == res[mask].min()][0]
21902190

21912191

21922192
def get_resolution(*coords, min_resol=1.0e-8):

0 commit comments

Comments
 (0)