Skip to content

Commit fbd57be

Browse files
authored
Merge pull request #1806 from knutfrode/dev
Fix for ascending z-coordinate (typically atompsheric transport) in r…
2 parents 49c2773 + e350fb6 commit fbd57be

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

opendrift/readers/reader_netCDF_CF_generic.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,10 @@ def get_variables(self, requested_variables, time=None,
413413

414414
if hasattr(self, 'z') and (z is not None):
415415
# Find z-index range
416-
# NB: may need to flip if self.z is ascending
417-
indices = np.searchsorted(-self.z, [-z.min(), -z.max()])
416+
if self.z[0] > self.z[-1]: # descending
417+
indices = np.searchsorted(-self.z, [-z.min(), -z.max()])
418+
else: # ascending
419+
indices = np.searchsorted(self.z, [z.min(), z.max()])
418420
indz = np.arange(np.maximum(0, indices.min() - 1 -
419421
self.verticalbuffer),
420422
np.minimum(len(self.z), indices.max() + 1 +

0 commit comments

Comments
 (0)