API design question: default value of `index` for ndmeasure functions
- Dominant language
- Python
- Stars
- 226
- Forks
- 56
- PR merge metrics
- No merged PRs in 30d
Description
This is a question about the API design for label indices in `dask_image.ndmeasure` functions.
Where `labels` is given but `index` is None, the label array is overwritten and becomes a mask image. This was not very intuitive for me, and means the behaviour of the `ndmeasure` functions is inconsistent. In some cases (`index=None`) you get an aggregate value, and in others you get values for each individual label (even if there are multiple indices).
I think there's an argument to be made that if `labels` is given and `index=None` the default value should be the range of all non-zero labels (eg: [1, 2, 3, ..., n]). This would mean (a) no nasty surprise aggregations, and (b) you wouldn't need to near-constantly write `index=da.arange(da.max(labels))` or revert to the slightly clunkier `label_comprehension()` syntax (I can never remember the six input arguments).
## Questions
1. Are the majority of use cases different than what I imagine here? If what I expect to be the most common use scenario is actually pretty uncommon, I may need to rethink my opinion.
2. What is your opinion on replacing:
```python
def _norm_input_labels_index(input, labels=None, index=None):
...
elif index is None:
labels = (labels > 0).astype(int)
index = dask.array.ones(tuple(), dtype=int, chunks=tuple())
```
with this instead:
```python
def _norm_input_labels_index(input, labels=None, index=None):
...
elif index is None:
index = dask.array.arange(dask.array.max(labels) + 1)[1:]
```
and making a separate `mask()` convenience function available.
In my view it's much clearer that `area(input, mask(labels))` is expected to return an aggregate value, compared to `area(input, labels, index=None)`.
Contributor guide
Assessment
This issue has not been assessed yet.