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

adapt expected depth levels in test_xorca_box.py

parent 428edd6e
Pipeline #3657 passed with stage
in 2 minutes and 24 seconds
......@@ -15,7 +15,9 @@ import xarray as xr
def defdepth(dataset, depth):
""" Define a dictionary containing the indices on the depth axis of a
`xarray.DataSet` that are within the required depth in meters.
`xarray.DataSet` that are within the required depth in meters (or
are closest to the specified input depth when only one value is provided
with `depth`).
Parameters
----------
......@@ -37,25 +39,27 @@ def defdepth(dataset, depth):
# minimum depth and deeper and assign it to k1
d = {}
if 'depth_c' in dataset:
k1_c = int(np.argmax(dataset['depth_c'].values+depth[0] < 0))
k1_c = int(np.argmax(dataset['depth_c'].values + depth[0] < 0))
if 'depth_l' in dataset:
k1_l = int(np.argmax(dataset['depth_c'].values+depth[0] < 0))
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.argmax(dataset['depth_c'].values+depth[1] < 0))
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.argmax(dataset['depth_l'].values+depth[1] < 0))
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
# will be exracted
if 'depth_c' in dataset:
d['z_c'] = k1_c
d['z_c'] = int((np.abs(dataset['depth_c'].values
+ depth[0])).argmin())
if 'depth_l' in dataset:
d['z_l'] = k1_l
d['z_l'] = int((np.abs(dataset['depth_l'].values
+ depth[0])).argmin())
else:
raise ValueError('please provide 1 (single depth) or 2 '
+ '(depth range) values in keyword depth')
......
......@@ -163,7 +163,7 @@ ds_2d = xr.Dataset({'dummy_0cc': (['t', 'y_c', 'x_c'], dummy_3Dt),
expected_depths = {}
expected_depths['1'] = {'z_c': 9, 'z_l': 10}
expected_depths['2'] = {'z_c': slice(17, 23, None), 'z_l': slice(18, 24, None)}
expected_depths['2'] = {'z_c': slice(18, 24, None), 'z_l': slice(18, 24, None)}
@pytest.mark.parametrize('d',
......
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