Suggested Alternative Mask handling by NDData
See original GitHub issueHere is a suggested alternative for handling the mask information as in NDData
arithmetic operations that I would like to get feedback on from the NDData
folks. The motivation is the future extension of arithmetic operations to NDCube
.
This concept applies when both operands are NDData
instances/subclasses. The idea is that if the array element has the same mask value in both operands, the operation is executed as normal. But if an array element is masked in one operand and unmasked in the other, then the operation is not performed and the value from the unmasked operand is into the result. Are there reasons why the NDData
team thinks this is a bad option to offer? Or any other thoughts or feedback?
Below is a little more detail on implementation.
Mask
The following mask values in the operands leads to the following result on an element-by-element basis.
Both False
-> False
Both True
-> True
One False
, one True
-> False
Data & Uncertainty
Let +
signify any arithmetic operator. And let a suffix of 1
or 2
signify the value from operand 1 or 2. This is carried out on an array element-by-element basis.
Both False
-> data1 + data2
& uncertainty1 + uncertainty2
Both True
-> data1 + data2
& uncertainty1 + uncertainty2
(But result will be masked.)
Mask1 = False
& mask2 = True
-> data1
& uncertainty1
Mask1 = True
& mask2 = False
-> data2
& uncertainty2
This algorithm is not intended to replace the functionality currently available. Instead I wonder whether there is interest in it being implemented as an option in NDData
so users don’t have to code it up themselves, but rather set a kwarg.
Edges Cases
mask = None
is equivalent to all pixels unmaskedoperand1.mask is True
or all elements of the mask areTrue
-> result isoperand2
and vice versa.- Both operands’ masks are
True
or all elements of both operands’ masks areTrue
-> result isNone
or error is raised or an emptyNDData
(if allowed) is returned.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (6 by maintainers)
Top GitHub Comments
I’m an interested user.
Hi @mwcraig, thanks for you comments. I’m glad you think this is useful. I think the first thing to understand is what the API should be. Should the
nddata
arithmetic methods have a library of different paradigms that can be chosen by a kwarg, e.g.handle_mask='ignore masked'
. If so, where should the different implementations live?(Note that this paradigm is different to the current
handle_mask
options in that it impacts the values in data and uncertainty whereas currenthandle_mask
options only impact the mask.)Or should each paradigm be its own mixin and the kwargs dispensed with in the user facing API? This might be simpler, but probably makes the code base bigger. The downside for users is that once they instantiate an object, they can only use the one paradigm on their data.