marvin icon indicating copy to clipboard operation
marvin copied to clipboard

Setting of mask in map arithmetic for a single property of a single spaxel throws TypeError

Open bretthandrews opened this issue 6 years ago • 0 comments

Describe the bug Map arithmetic does not work with an individual spaxel-property (i.e., a single property for a single spaxel).

To Reproduce Steps to reproduce the behavior:

from marvin.tools import Maps
maps = Maps('8485-1901')
ha = maps.emline_gflux_ha_6564
ha[17, 17] * 2

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-79-bcaa2c9b153e> in <module>()
----> 1 ha[17, 17] * 2

~/projects/sdss/sas/mangawork/manga/marvin/python/marvin/tools/quantities/map.py in __mul__(self, map2)
    508     def __mul__(self, map2):
    509         """Multiply two maps."""
--> 510         return self._arith(map2, '*')
    511
    512     def __div__(self, map2):

~/projects/sdss/sas/mangawork/manga/marvin/python/marvin/tools/quantities/map.py in _arith(self, term2, op)
    443             map_out = self._map_arith(term2, op)
    444         else:
--> 445             map_out = self._scalar_arith(term2, op)
    446         return map_out
    447

~/projects/sdss/sas/mangawork/manga/marvin/python/marvin/tools/quantities/map.py in _scalar_arith(self, scalar, op)
    463
    464         bad = np.isnan(map_value) | np.isinf(map_value)
--> 465         map_mask[bad] = map_mask[bad] | self.pixmask.labels_to_value('DONOTUSE')
    466
    467         return EnhancedMap(value=map_value, unit=self.unit, ivar=map_ivar, mask=map_mask,

TypeError: 'numpy.int64' object does not support item assignment

This occurs because map_mask is an integer for a single spaxel-property instead of a 2-D array (as it is for a normal Map).

Suggested fix Do a try...except around line 465. If bad is True, then combine map_mask with DONOTUSE mask.

try:
    map_mask[bad] = map_mask[bad] | self.pixmask.labels_to_value('DONOTUSE')
except TypeError:
    if bad:
        map_mask = map_mask | self.pixmask.labels_to_value('DONOTUSE')

bretthandrews avatar Dec 05 '18 16:12 bretthandrews