marvin
marvin copied to clipboard
slicing cubes that don't have a proper db equivalent from datamodel should fail earlier
Describe the bug
Cubes that are being accessed via the db fail when slicing and the datamodel value does not have a valid entry in the database. For example, slicing MPL-4 cubes to grab spaxels and the spectral_resolution
is not present in the database. It fails deep in the Spectrum
Quantity
generation with a TypeError: The value must be a valid Python or Numpy numeric type.
error. I don't think the release matters here but that's how I uncovered it.
To Reproduce
- delete a spectral resolution array in the database for a specific cube
from marvin import config
config.setRelease('MPL-4')
from marvin.tools import Cube
cube = Cube('8485-1901')
cube[17,17]
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-45-02b2682b5165> in <module>()
----> 1 cube[17,17]
/Users/Brian/Work/github_projects/Marvin/python/marvin/tools/cube.pyc in __getitem__(self, xy)
124 """Returns the spaxel for ``(x, y)``"""
125
--> 126 return self.getSpaxel(x=xy[1], y=xy[0], xyorig='lower')
127
128 @staticmethod
/Users/Brian/Work/github_projects/Marvin/python/marvin/tools/cube.pyc in getSpaxel(self, x, y, ra, dec, properties, models, **kwargs)
575 cube=self,
576 maps=properties,
--> 577 modelcube=models, **kwargs)
578
579 def getRSS(self):
/Users/Brian/Work/github_projects/Marvin/python/marvin/utils/general/general.pyc in getSpaxel(cube, maps, modelcube, x, y, ra, dec, xyorig, **kwargs)
204 _spaxels.append(
205 marvin.tools.spaxel.Spaxel(jCube[0][ii], iCube[0][ii],
--> 206 cube=cube, maps=maps, modelcube=modelcube, **kwargs))
207
208 if len(_spaxels) == 1 and isScalar:
/Users/Brian/Work/github_projects/Marvin/python/marvin/tools/spaxel.pyc in __init__(self, x, y, cube, maps, modelcube, lazy, **kwargs)
140
141 if lazy is False:
--> 142 self.load()
143
144 def __dir__(self):
/Users/Brian/Work/github_projects/Marvin/python/marvin/tools/spaxel.pyc in load(self, force)
281
282 for tool in ['cube', 'maps', 'modelcube']:
--> 283 self._load_tool(tool, force=(force is not None and force == tool))
284
285 self._set_radec()
/Users/Brian/Work/github_projects/Marvin/python/marvin/tools/spaxel.pyc in _load_tool(self, tool, force)
327 setattr(self, quantities_dict,
328 getattr(getattr(self, '_' + tool), '_get_spaxel_quantities')(self.x, self.y,
--> 329 spaxel=self))
330
331 def getCube(self):
/Users/Brian/Work/github_projects/Marvin/python/marvin/tools/cube.pyc in _get_spaxel_quantities(self, x, y, spaxel)
496 wavelength=self._wavelength,
497 unit=dm.unit,
--> 498 pixmask_flag=dm.pixmask_flag)
499
500 if self.data_origin == 'api':
/Users/Brian/Work/github_projects/Marvin/python/marvin/tools/quantities/spectrum.pyc in __new__(cls, flux, wavelength, scale, unit, wavelength_unit, ivar, std, mask, dtype, copy, pixmask_flag, **kwargs)
64 unit = CompositeUnit(unit.scale * scale, unit.bases, unit.powers)
65
---> 66 obj = Quantity(flux, unit=unit, dtype=dtype, copy=copy)
67 obj = obj.view(cls)
68 obj._set_unit(unit)
/Users/Brian/anaconda2/lib/python2.7/site-packages/astropy/units/quantity.pyc in __new__(cls, value, unit, dtype, copy, order, subok, ndmin)
379 isinstance(value.item(() if value.ndim == 0 else 0),
380 numbers.Number))):
--> 381 raise TypeError("The value must be a valid Python or "
382 "Numpy numeric type.")
383
TypeError: The value must be a valid Python or Numpy numeric type.
Expected behavior
When looping over the datamodel
in _get_spaxel_quantities
we could probably perform a check to ensure a valid database entry exists. If it's not critical to the Spectrum
initialization, issue a warning and generate a Spectrum
or return some kind of null value.
Additional context Add any other context about the problem here.