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

Fix error when passing a boolean mask #73

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

grst
Copy link

@grst grst commented Jun 5, 2024

When passing a boolean mask to add_modality (which is supported according to the type hints) using

mask = np.zeros((3000, 3000), dtype="uint8")
mask [ 500:-500, 20:-500] = 1

It failed with

File <redacted>/python3.10/site-packages/wsireg/reg_images/tifffile_reg_image.py:46, in TiffFileRegImage.__init__(self, image_fp, image_res, mask, pre_reg_transforms, preprocessing, channel_names, channel_colors)
     42 self._get_dim_info()
     44 self._dask_image = self._get_dask_image()
---> 46 if mask:
     47     self._mask = self.read_mask(mask)
     49 self.pre_reg_transforms = pre_reg_transforms

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

The fix is simple: check if mask is None: instead of if mask:.

grst added 2 commits June 5, 2024 17:06
When passing a boolean mask to `add_modality` (which is supported according to the type hints) using

```python
mask = np.zeros((3000, 3000), dtype="uint8")
mask [ 500:-500, 20:-500] = 1
```

It failed with

```pytb
File <redacted>/python3.10/site-packages/wsireg/reg_images/tifffile_reg_image.py:46, in TiffFileRegImage.__init__(self, image_fp, image_res, mask, pre_reg_transforms, preprocessing, channel_names, channel_colors)
     42 self._get_dim_info()
     44 self._dask_image = self._get_dask_image()
---> 46 if mask:
     47     self._mask = self.read_mask(mask)
     49 self.pre_reg_transforms = pre_reg_transforms

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
```

The fix is simple: check `if mask is None:` instead of `if mask:`.
@NHPatterson
Copy link
Owner

NHPatterson commented Jun 11, 2024

Thanks for this fix, after it builds I will merge and bump version so it deploys to pip.

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.

2 participants