[AstroPy] pysynphot issue with changes in numpy
Jessica Lu
jlu at astro.caltech.edu
Tue Jul 12 19:57:07 EDT 2011
Hi, I use pysynphot and I have encountered a bug in the latest scisoft installation of pysynphot v0.8.2 and numpy v1.5.1. I have uploaded some atmosphere models from the literature (AMES dusty) and then I try to access them using the following call
import pysynphot
sp = pysynphot.Icat('AMESdusty', 3000.5, 0, 3.51)
where Teff = 3000.5 K, metallicity = 0 ([M/H]) and log_gravity = 3.51.
The issue appears to be that the only log_g values at 3100 K are [4, 4.5, 5, 5.5, 6.0] and the log_g values at 3000 K are [3.5, 4, 4.5, 5, 5.5, 6.0]. In catalog.py there is an uncaught exception at:
lowerArray = MA.masked_inside(array, lower, par)
from:
list6,list7 = self._breakList(list2, 2, log_g)
This appears to be because this call returns something different now:
lower = MA.maximum(less)
than it used to in previous versions of numpy. If less was already entirely masked, then numpy.ma.maximum(less) would return the whole less array over again, but now it appears to be set to a one-element masked array containing a numpy.ma.MaskedContent object. And masked_inside doesn't know what to do with this type of object (in numpy.ma.core.masked_inside, the condition = <BLAH> statement is what actually throws the exception as it expects both lower and par to be floats). Here is a spot test:
import numpy
log_g_array = numpy.array([4.0, 4.5])
log_g = 3.0
less = numpy.ma.masked_greater(log_g_array, log_g)
lower = numpy.ma.maximum(less)
# Here comes the exception, didn't used to do this.
lowerArray = numpy.ma.masked_inside(log_g_array, lower, log_g)
The fix I have is probably not optimal but seems to work. Replace the lowerArray = (and upperArray = ) lines with:
# Catch the cases when the upper/lower return
# is not valid (returns a list). This happens when
# all the array values in greater/less are masked.
if hasattr(upper, '__contains__'):
upperArray = greater
else:
upperArray = MA.masked_inside(array, par, upper)
if hasattr(lower, '__contains__'):
lowerArray = less
else:
lowerArray = MA.masked_inside(array, lower, par)
There is one other use-case which I am not sure how this code would deal with. If the various spectra in the model tables are not pre-sorted by increasing Teff, metallicity, and log_g, then some funny results could result from the lines in Icat.__init__():
sp1 = self._getSpectrum(list6[0], catdir)
sp2 = self._getSpectrum(list7[0], catdir)
...
because list6[0] is only the correct one to use if the are pre-sorted.
Thanks,
Jessica Lu
More information about the AstroPy
mailing list