Commit ef97f92e authored by Jan Klaus Rieck's avatar Jan Klaus Rieck

defdepth(): handle cases where one of the depth dimensions does not exist

parent 2ef8bbb3
Pipeline #3619 failed with stage
in 1 minute and 28 seconds
......@@ -35,20 +35,27 @@ def defdepth(dataset, depth):
# check if depth has an appropriate length
# then find the index that is closest to the desired
# minimum depth and assign it to k1
k1_c = int((np.abs(dataset['depth_c'].values+depth[0])).argmin())
k1_l = int((np.abs(dataset['depth_l'].values+depth[0])).argmin())
d = {}
if 'depth_c' in dataset:
k1_c = int((np.abs(dataset['depth_c'].values+depth[0])).argmin())
if 'depth_l' in dataset:
k1_l = int((np.abs(dataset['depth_l'].values+depth[0])).argmin())
if len(depth) == 2:
# if a max. depth is given in the argument
# k2 is defined
k2_c = int((np.abs(dataset['depth_c']+depth[1])).argmin())
k2_l = int((np.abs(dataset['depth_l']+depth[1])).argmin())
d = {'z_c': slice(k1_c, k2_c),
'z_l': slice(k1_l, k2_l)}
if 'depth_c' in dataset:
k2_c = int((np.abs(dataset['depth_c']+depth[1])).argmin())
d['z_c'] = slice(k1_c, k2_c)
if 'depth_l' in dataset:
k2_l = int((np.abs(dataset['depth_l']+depth[1])).argmin())
d['z_l'] = slice(k1_l, k2_l)
elif len(depth) == 1:
# if no max. depth is given, only one depth level
# will be exracted
d = {'z_c': k1_c,
'z_l': k1_l}
if 'depth_c' in dataset:
d['z_c'] = k1_c
if 'depth_l' in dataset:
d['z_l'] = k1_l
else:
raise ValueError('please provide 1 (single depth) or 2 '
+ '(depth range) values in keyword depth')
......
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