Skip to content
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

Add apply_mask function to mask sub-package #905

Merged
merged 16 commits into from
Dec 21, 2022

Conversation

b-reyes
Copy link
Contributor

@b-reyes b-reyes commented Dec 19, 2022

This PR implements the apply_mask function discussed in #817 (comment) and subsequent comments in #817.

@b-reyes b-reyes added this to the 0.6.4 milestone Dec 19, 2022
echopype/mask/api.py Outdated Show resolved Hide resolved
echopype/mask/api.py Outdated Show resolved Hide resolved
echopype/mask/api.py Outdated Show resolved Hide resolved
echopype/mask/api.py Outdated Show resolved Hide resolved
echopype/mask/api.py Outdated Show resolved Hide resolved
echopype/mask/api.py Outdated Show resolved Hide resolved
echopype/mask/api.py Outdated Show resolved Hide resolved
echopype/mask/api.py Outdated Show resolved Hide resolved
Comment on lines +278 to +307
@pytest.mark.parametrize(
("n", "n_chan", "var_name", "mask", "mask_file", "fill_value", "is_delayed", "var_masked_truth"),
[
(2, 1, "var1", np.identity(2), None, np.nan, False, np.array([[1, np.nan], [np.nan, 1]])),
(2, 1, "var1", np.identity(2), None, 2.0, False, np.array([[1, 2.0], [2.0, 1]])),
(2, 1, "var1", np.identity(2), None, np.array([[[np.nan, np.nan], [np.nan, np.nan]]]),
False, np.array([[1, np.nan], [np.nan, 1]])),
(2, 1, "var1", np.identity(2), None, xr.DataArray(data=np.array([[[np.nan, np.nan], [np.nan, np.nan]]]),
coords={"channel": ["chan1"],
"ping_time": [0, 1],
"range_sample": [0, 1]}),
False, np.array([[1, np.nan], [np.nan, 1]])),
(2, 1, "var1", [np.identity(2), np.array([[0, 1], [0, 1]])], [None, None], 2.0,
False, np.array([[2.0, 2.0], [2.0, 1]])),
(2, 1, "var1", np.identity(2), None, 2.0, True, np.array([[1, 2.0], [2.0, 1]])),
(2, 1, "var1", np.identity(2), "test.zarr", 2.0, True, np.array([[1, 2.0], [2.0, 1]])),
(2, 1, "var1", [np.identity(2), np.array([[0, 1], [0, 1]])], ["test0.zarr", "test1.zarr"], 2.0,
False, np.array([[2.0, 2.0], [2.0, 1]])),
(2, 1, "var1", [np.identity(2), np.array([[0, 1], [0, 1]])], ["test0.zarr", None], 2.0,
False, np.array([[2.0, 2.0], [2.0, 1]])),
],
ids=["single_mask_default_fill", "single_mask_float_fill", "single_mask_np_array_fill",
"single_mask_DataArray_fill", "list_mask_all_np", "single_mask_ds_delayed",
"single_mask_as_path", "list_mask_all_path", "list_mask_some_path"]
)
def test_apply_mask(n: int, n_chan: int, var_name: str,
mask: Union[np.ndarray, List[np.ndarray]],
mask_file: Optional[Union[str, List[str]]],
fill_value: Union[int, float, np.ndarray, xr.DataArray],
is_delayed: bool, var_masked_truth: np.ndarray):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what test contains right now is more of the integrated test flavor, and some of those can be split out to unit test the mask validation and collection function.

My suggestion is create/split things into the following:

  • unit tests for validate_and_collect_mask_input:
    • test allowable types of mask sources
    • test the allowable forms of mask (list or single)
  • unit tests for _check_var_name_fill_value
    • test whether var_name is in source_ds
    • test whether fill_value is of the same shape as source_ds["var_name"]
  • integration tests that actually applies the tests (you have these already)

echopype/utils/io.py Outdated Show resolved Hide resolved
Copy link
Member

@leewujung leewujung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@b-reyes : thanks for the PR! All of my actual comments are textual, with the exception of the tests -- I think it would be good to set up unit tests for the functions used by the main function.

Update: I think we should consider the suggested test refactoring as a separate PR as part of the test hackday, so that this can be merged by end of day for @emiliom to add the provenance piece.

echopype/mask/api.py Outdated Show resolved Hide resolved
echopype/mask/api.py Outdated Show resolved Hide resolved
echopype/mask/api.py Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented Dec 21, 2022

Codecov Report

Merging #905 (40bacf4) into dev (584dfff) will decrease coverage by 6.25%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##              dev     #905      +/-   ##
==========================================
- Coverage   78.71%   72.46%   -6.26%     
==========================================
  Files          56        5      -51     
  Lines        5253      345    -4908     
==========================================
- Hits         4135      250    -3885     
+ Misses       1118       95    -1023     
Flag Coverage Δ
unittests 72.46% <100.00%> (-6.26%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
echopype/utils/io.py 78.12% <100.00%> (-12.50%) ⬇️
echopype/utils/coding.py 25.92% <0.00%> (-66.67%) ⬇️
echopype/utils/prov.py 34.78% <0.00%> (-60.87%) ⬇️
echopype/mask/api.py
echopype/calibrate/calibrate_ek.py
echopype/convert/parsed_to_zarr_ek60.py
echopype/echodata/convention/__init__.py
echopype/convert/utils/ek_raw_io.py
echopype/testing.py
... and 44 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@b-reyes
Copy link
Contributor Author

b-reyes commented Dec 21, 2022

@leewujung I have addressed all of your comments. As you suggested, we will wait to do the test refactoring as a separate PR as part of the test hackday.

@leewujung leewujung self-requested a review December 21, 2022 05:08
Copy link
Member

@leewujung leewujung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@b-reyes : thank you! I will merge this now.

@leewujung leewujung merged commit de693e7 into OSOceanAcoustics:dev Dec 21, 2022
@b-reyes b-reyes deleted the add-apply-mask branch December 21, 2022 18:35
leewujung added a commit that referenced this pull request Dec 22, 2022
See #905 for all conversations and detailed commits.
lsetiawan pushed a commit to lsetiawan/echopype that referenced this pull request Feb 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants