-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow apply_mask
to handle multi-channel Sv dataset
#1010
Conversation
for more information, see https://pre-commit.ci
Codecov Report
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more @@ Coverage Diff @@
## dev #1010 +/- ##
===========================================
- Coverage 80.40% 67.06% -13.35%
===========================================
Files 67 7 -60
Lines 6013 589 -5424
===========================================
- Hits 4835 395 -4440
+ Misses 1178 194 -984
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 65 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
I haven't checked the changes thoroughly, though I did look at most of it. Looks good. I also ran a local, manual test passing the I tested the previous behavior, passing a single-channel Thanks! File /usr/mayorgadat/workmain/acoustics/gh/OSOceanAcoustics/echopype/echopype/mask/api.py:336, in apply_mask(source_ds, mask, var_name, fill_value, storage_options_ds, storage_options_mask)
332 final_mask = np.array([final_mask.data] * source_ds["channel"].size)
334 # Apply the mask to var_name
335 # Somehow keep_attrs=True errors out here, so will attach later
--> 336 var_name_masked = xr.where(final_mask, x=source_ds[var_name], y=fill_value)
338 # Obtain a shallow copy of source_ds
339 output_ds = source_ds.copy(deep=False)
File ~/miniconda3/envs/echopype_dev/lib/python3.9/site-packages/xarray/core/computation.py:1815, in where(cond, x, y, keep_attrs)
1812 keep_attrs = lambda attrs, context: attrs[1]
1814 # alignment for three arguments is complicated, so don't support it yet
-> 1815 return apply_ufunc(
1816 duck_array_ops.where,
1817 cond,
1818 x,
1819 y,
1820 join="exact",
1821 dataset_join="exact",
1822 dask="allowed",
1823 keep_attrs=keep_attrs,
1824 )
File ~/miniconda3/envs/echopype_dev/lib/python3.9/site-packages/xarray/core/computation.py:1159, in apply_ufunc(func, input_core_dims, output_core_dims, exclude_dims, vectorize, join, dataset_join, dataset_fill_value, keep_attrs, kwargs, dask, output_dtypes, output_sizes, meta, dask_gufunc_kwargs, *args)
1157 # feed DataArray apply_variable_ufunc through apply_dataarray_vfunc
1158 elif any(isinstance(a, DataArray) for a in args):
-> 1159 return apply_dataarray_vfunc(
1160 variables_vfunc,
1161 *args,
1162 signature=signature,
1163 join=join,
1164 exclude_dims=exclude_dims,
1165 keep_attrs=keep_attrs,
1166 )
1167 # feed Variables directly through apply_variable_ufunc
1168 elif any(isinstance(a, Variable) for a in args):
File ~/miniconda3/envs/echopype_dev/lib/python3.9/site-packages/xarray/core/computation.py:286, in apply_dataarray_vfunc(func, signature, join, exclude_dims, keep_attrs, *args)
281 result_coords = build_output_coords(
282 args, signature, exclude_dims, combine_attrs=keep_attrs
283 )
285 data_vars = [getattr(a, "variable", a) for a in args]
--> 286 result_var = func(*data_vars)
288 if signature.num_outputs > 1:
289 out = tuple(
290 DataArray(variable, coords, name=name, fastpath=True)
291 for variable, coords in zip(result_var, result_coords)
292 )
File ~/miniconda3/envs/echopype_dev/lib/python3.9/site-packages/xarray/core/computation.py:752, in apply_variable_ufunc(func, signature, exclude_dims, dask, output_dtypes, vectorize, keep_attrs, dask_gufunc_kwargs, *args)
750 data = as_compatible_data(data)
751 if data.ndim != len(dims):
--> 752 raise ValueError(
753 "applied function returned data with unexpected "
754 f"number of dimensions. Received {data.ndim} dimension(s) but "
755 f"expected {len(dims)} dimensions with names: {dims!r}"
756 )
758 var = Variable(dims, data, fastpath=True)
759 for dim, new_size in var.sizes.items():
ValueError: applied function returned data with unexpected number of dimensions. Received 3 dimension(s) but expected 2 dimensions with names: ('ping_time', 'range_sample') |
Co-authored-by: Emilio Mayorga <emiliomayorga@gmail.com>
for more information, see https://pre-commit.ci
I fixed something but the error message when I tried was different from what you pasted. Maybe you could try again and investigate if it still fails? |
I am not sure why the tests fail. Those tests passed locally on my machine... |
I reran my manual test (a notebook) with the latest commits in your PR. The error on
I also ran
Just as in the CI, the other For what it's worth, the tests that fail define the mask_out = _validate_and_collect_mask_input(mask=mask, storage_options_mask=storage_options_mask) Ok, I think I found the problem with the test failures (but not with my manual-test failure)! In # create coordinates that will be used by all DataArrays created
coords = {"channel": ("channel", chan_vals, {"long_name": "channel name"}),
"x": np.arange(n), "y": np.arange(n)} Change "x" to "ping_time" and "y" to "range_sample". That fixes it. I'll push a commit to make the change. |
Woo-hoo, all tests passed! Including the windows-utils tests 😅 . I don't know where that leaves my "manual" failure when passing a single-channel Sv (after creating the dataarray like this |
Great, thanks! The x, y -> ping_time, range_sample was something I had to do in I'll look into the remaining bug. Probably require some clean up instead of the patching mode I was in yesterday. |
This PR generalizes the
apply_mask
implementation so that it can accept multi-channel Sv datasets.Main changes include:
source_ds[var_name]
to must have dimensions('ping_time', 'range_sample')
mask
to must have dimensions('ping_time', 'range_sample')
source_ds
to a new private function_validate_source_ds
_check_var_name_fill_value
to returnfill_value
with sanitized dimensionsutils/test_processinglevels_integration.py::test_raw_to_mvbs