desihub / speclite

Lightweight utilities for working with spectroscopic data
14 stars 19 forks source link

"Wavelength values must be strictly increasing." error for monotonically increasing array #14

Closed moustakas closed 8 years ago

moustakas commented 8 years ago

I've double- and triple-checked that the wavelength array for the ELG basis spectra is monotonically increasing, and yet speclite.filters is still throwing an error:

from speclite import filters
from desisim.io import read_basis_templates
flux, wave, meta = read_basis_templates(objtype='ELG')
rfilt = filters.load_filters('decam2014-r')
rfilt.get_ab_maggies(flux[0,:], wave)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-9-a86f52a94e30> in <module>()
----> 1 rfilt.get_ab_maggies(flux[0,:], wave)

/usr/local/lib/python2.7/site-packages/speclite-0.4.dev342-py2.7.egg/speclite/filters.pyc in get_ab_maggies(self, spectrum, wavelength, axis, mask_invalid)
   1455         """
   1456         return self._get_table(spectrum, wavelength, axis, mask_invalid,
-> 1457                                method=FilterResponse.get_ab_maggies)
   1458 
   1459 

/usr/local/lib/python2.7/site-packages/speclite-0.4.dev342-py2.7.egg/speclite/filters.pyc in _get_table(self, spectrum, wavelength, axis, mask_invalid, method)
   1408             except ValueError as e:
   1409                 if not mask_invalid:
-> 1410                     raise e
   1411                 # Create a missing column the first time we need it.
   1412                 if missing_column is None:

ValueError: Wavelength values must be strictly increasing.
dkirkby commented 8 years ago

How did you check that your wavelengths are monotonically increasing? This test indicates that they are not:

flux, wave, meta = read_basis_templates(objtype='ELG')
np.any(np.diff(wave) <= 0)
dkirkby commented 8 years ago

On closer inspection, there are 12 bins with zero size (shown in red below) and the dynamic range of your bin sizes is impressive (> 10 orders of magnitude !):

def plot_dwave(wave):
    dwave = np.diff(wave)
    ok = dwave > 0
    plt.plot(wave[1:][ok], dwave[ok], 'b.')
    bad = np.where(dwave <= 0)[0]
    for w in wave[1:][bad]:
        plt.axvline(w, color='r')
    plt.xscale('log')
    plt.yscale('log')
    plt.xlim(wave[0], wave[-1])
    plt.xlabel('Wavelength [A]')
    plt.ylabel('Bin Size [A]')
    plt.grid()

dwave

moustakas commented 8 years ago

I was using np.flop in Python and my own 'monotonic' function in IDL to check this, neither of which considered repeated values...argh! In any case, indeed there were a handful of repeated wavelengths which took some time to track down. Remaking the ELG and BGS templates now, ensuring both sorted and unique wavelengths...

dkirkby commented 8 years ago

np.flop?? (the top search result from google takes me to the Tuscarawas County Public Library, so I am intrigued!)

moustakas commented 8 years ago

Oops, I meant np.roll() Although the selection of Betamax videos at the Tuscarawas Library is awesome.