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

ad[0].multiply(1.) fails with astropy 5.3 #437

Open
KathleenLabrie opened this issue Jun 3, 2023 · 4 comments
Open

ad[0].multiply(1.) fails with astropy 5.3 #437

KathleenLabrie opened this issue Jun 3, 2023 · 4 comments
Assignees
Labels
bug 🐛 Something should be working but it isn't compatibility Compatibility issues. eg with Python, dependencies like astropy, IRAF or other software component - astrodata astrodata error 🤕 The code issues an error severity-critical 💥 Blocker issue urgency-high Fix ASAP

Comments

@KathleenLabrie
Copy link
Contributor

KathleenLabrie commented Jun 3, 2023

The astrodata multiply method fails with astropy 5.3. It does not fail on a raw file, so it has to be something to do with either the variance or the mask. (Looks like the mask from the error.)

Test file at: https://drive.google.com/drive/folders/1diCPWxBYZ7Dw6SHmGyJkJ2Z3IHxvtyxZ?usp=share_link

import astrodata, gemini_instruments

ad = astrodata.open('N20160102S0423_varAdded_crash.fits')
ad[0].multiply(1.)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/klabrie/data/GemKLRepo/activedragons/astrodata/core.py", line 798, in __imul__
    self._standard_nddata_op(NDDataObject.multiply, oper)
  File "/Users/klabrie/data/GemKLRepo/activedragons/astrodata/core.py", line 759, in _standard_nddata_op
    return self._oper(partial(fn, handle_mask=np.bitwise_or,
  File "/Users/klabrie/data/GemKLRepo/activedragons/astrodata/core.py", line 756, in _oper
    ndd[ind[n]] = operator(ndd[ind[n]], operand)
  File "/Users/klabrie/condaenvs/testastropy53/lib/python3.10/site-packages/astropy/nddata/mixins/ndarithmetic.py", line 618, in multiply
    return self._prepare_then_do_arithmetic(
  File "/Users/klabrie/condaenvs/testastropy53/lib/python3.10/site-packages/astropy/nddata/mixins/ndarithmetic.py", line 731, in _prepare_then_do_arithmetic
    result, init_kwds = operand._arithmetic(operation, operand2, **kwargs)
  File "/Users/klabrie/data/GemKLRepo/activedragons/astrodata/nddata.py", line 73, in _arithmetic
    return super()._arithmetic(
  File "/Users/klabrie/condaenvs/testastropy53/lib/python3.10/site-packages/astropy/nddata/mixins/ndarithmetic.py", line 335, in _arithmetic
    kwargs["mask"] = self._arithmetic_mask(
  File "/Users/klabrie/condaenvs/testastropy53/lib/python3.10/site-packages/astropy/nddata/mixins/ndarithmetic.py", line 527, in _arithmetic_mask
    return handle_mask(self.mask, operand.mask, **kwds)
TypeError: unsupported operand type(s) for |: 'int' and 'NoneType'
@saimn
Copy link
Contributor

saimn commented Jun 5, 2023

Probably related to astropy/astropy#14175

@KathleenLabrie KathleenLabrie added bug 🐛 Something should be working but it isn't error 🤕 The code issues an error severity-critical 💥 Blocker issue urgency-high Fix ASAP component - astrodata astrodata compatibility Compatibility issues. eg with Python, dependencies like astropy, IRAF or other software labels Jun 21, 2023
@KathleenLabrie
Copy link
Contributor Author

Also broken is the multiplication with a file without a mask.

ad_withmask.multiply(ad_nomask)

If I do ad_withmask.multiply(ad_withmask), no error. Starting to look more and more like a bug in astropy itself. The propagation of the mask does not take into account that one of the operand might not have a mask.

@KathleenLabrie
Copy link
Contributor Author

Completely removing astrodata from the equation. Just using NDDataRef now. Either I'm not using it the right way, or there is a bug in astropy v5.3. I need someone with more knowledge than me to assess that.

>>> import numpy as np
>>> from astropy.nddata import NDDataRef

>>> array = np.array([[0, 1, 0], [1, 0, 1], [0, 1, 0]])
>>> mask = np.array([[0, 1, 64], [8, 0, 1], [2, 1, 0]])

>>> nref_nomask = NDDataRef(array)
>>> nref_mask = NDDataRef(array, mask=mask)

# multiply no mask by constant (no mask * no mask)
>>> nref_nomask.multiply(1., handle_mask=np.bitwise_or).mask   # returns nothing, no mask

# multiply no mask by itself (no mask * no mask)
>>> nref_nomask.multiply(nref_nomask, handle_mask=np.bitwise_or).mask # return nothing, no mask

# multply mask by constant (mask * no mask)
>>> nref_mask.multiply(1., handle_mask=np.bitwise_or).mask
...
TypeError: unsupported operand type(s) for |: 'int' and 'NoneType'

# multiply mask by itself (mask * mask)
>>> nref_mask.multiply(nref_mask, handle_mask=np.bitwise_or).mask
array([[ 0,  1, 64],
       [ 8,  0,  1],
       [ 2,  1,  0]])

# multiply mask by no mask (mask * no mask)
>>> nref_mask.multiply(nref_nomask, handle_mask=np.bitwise_or).mask
...
TypeError: unsupported operand type(s) for |: 'int' and 'NoneType'

@chris-simpson @saimn, do you think that this needs reporting to astropy or am I doing something I shouldn't be doing?

@saimn
Copy link
Contributor

saimn commented Jun 22, 2023

@KathleenLabrie - Yes please open a new issue, with the example to reproduce 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something should be working but it isn't compatibility Compatibility issues. eg with Python, dependencies like astropy, IRAF or other software component - astrodata astrodata error 🤕 The code issues an error severity-critical 💥 Blocker issue urgency-high Fix ASAP
Projects
None yet
Development

No branches or pull requests

3 participants