Commit 428edd6e authored by Jan Klaus Rieck's avatar Jan Klaus Rieck

rewrite defdepth() so that it getbox() extracts depth levels WITHIN specified range

parent f8f34b70
Pipeline #3652 failed with stage
in 1 minute and 44 seconds
......@@ -15,7 +15,7 @@ import xarray as xr
def defdepth(dataset, depth):
""" Define a dictionary containing the indices on the depth axis of a
`xarray.DataSet` that are closest to the required depth in meters.
`xarray.DataSet` that are within the required depth in meters.
Parameters
----------
......@@ -34,20 +34,20 @@ def defdepth(dataset, depth):
if (len(depth) == 1) or (len(depth) == 2):
# check if depth has an appropriate length
# then find the index that is closest to the desired
# minimum depth and assign it to k1
# minimum depth and deeper and assign it to k1
d = {}
if 'depth_c' in dataset:
k1_c = int((np.abs(dataset['depth_c'].values+depth[0])).argmin())
k1_c = int(np.argmax(dataset['depth_c'].values+depth[0] < 0))
if 'depth_l' in dataset:
k1_l = int((np.abs(dataset['depth_l'].values+depth[0])).argmin())
k1_l = int(np.argmax(dataset['depth_c'].values+depth[0] < 0))
if len(depth) == 2:
# if a max. depth is given in the argument
# k2 is defined
if 'depth_c' in dataset:
k2_c = int((np.abs(dataset['depth_c']+depth[1])).argmin())
k2_c = int(np.argmax(dataset['depth_c'].values+depth[1] < 0))
d['z_c'] = slice(k1_c, k2_c)
if 'depth_l' in dataset:
k2_l = int((np.abs(dataset['depth_l']+depth[1])).argmin())
k2_l = int(np.argmax(dataset['depth_l'].values+depth[1] < 0))
d['z_l'] = slice(k1_l, k2_l)
elif len(depth) == 1:
# if no max. depth is given, only one depth level
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment