[AstroPy] Issue when comparing thresholding and derivative changess for line-finding

Peter Dzwig pdzwig at summaventures.com
Tue Sep 24 05:00:43 EDT 2019


All,

I am looking at some SDSS spectra, and will ultimately want to identify
individual lines and want to compare thresholding and derivative changes
as techniques to use.

It keeps throwing errors that I can't make head or tail of. The core of
the code is:

["norm_spec" is the continuum normalised spectrum (normalised over the
whole range) which has been transformed to the rest frame.]


    from specutils import SpectralRegion
    from specutils.manipulation import noise_region_uncertainty
    from specutils.fitting import find_lines_threshold,
find_lines_derivative

    noise_region = SpectralRegion(3250*u.AA, 3800*u.AA)
    spec_em_nr=noise_region_uncertainty(norm_spec, noise_region)

# First use thresholding to get lines

    print( '\n'*2,"THRESHOLDING", '\n'*2)
    lines = find_lines_threshold(spec_em_nr, noise_factor=2)

    lem = lines[lines['line_type'] == 'emission']
    labs = lines[lines['line_type'] == 'absorption']

    print("Emission lines (thresholding)",lem[:])

    print("Absorption lines (thresholding)",labs[:])

# Next use derivative to get lines

    print( '\n'*2,"DERIVATIVE", '\n'*2)


    lines = find_lines_derivative(spec_em_nr, flux_threshold=4.0)

    lem2 = lines[lines['line_type'] == 'emission']
    labs2 = lines[lines['line_type'] == 'absorption']

    print("Emission lines (derivative)",lem2[:])

    print("Absorption lines (derivative)",labs2[:])




THRESHOLDING


Emission lines (thresholding)

line_center    line_type line_center_index
   Angstrom
----------------- --------- -----------------
2731.765380859375  emission              1652
2803.130615234375  emission              1764
   4388.775390625  emission              3711

Absorption lines (thresholding) line_center line_type line_center_index
  Angstrom
----------- --------- -----------------


[ Don't expect any ALs. this is just there for completeness]

 DERIVATIVE


Then:

/home/peter/anaconda3/lib/python3.6/site-packages/astropy/table/column.py:965:
FutureWarning: elementwise comparison failed; returning scalar instead,
but in the future will perform elementwise comparison
  return getattr(self.data, op)(other)

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-11-2fbc9eae66cc> in <module>()
    288     lines = find_lines_derivative(spec_em_nr, flux_threshold=4.0)
    289
--> 290     lem2 = lines[lines['line_type'] == 'emission']
    291     labs2 = lines[lines['line_type'] == 'absorption']
    292

~/anaconda3/lib/python3.6/site-packages/astropy/table/table.py in
__getitem__(self, item)
   1225             return self.columns[item]
   1226         elif isinstance(item, (int, np.integer)):
-> 1227             return self.Row(self, item)
   1228         elif (isinstance(item, np.ndarray) and item.shape == ()
and item.dtype.kind == 'i'):
   1229             return self.Row(self, item.item())

~/anaconda3/lib/python3.6/site-packages/astropy/table/row.py in
__init__(self, table, index)
     36         if index < -n or index >= n:
     37             raise IndexError('index {0} out of range for table
with length {1}'
---> 38                              .format(index, len(table)))
     39
     40         # Ensure that the row index is positive [#8422]

IndexError: index False out of range for table with length 0


​The thresholding produces results, although poor.

I don't understand the message when doing the derivative, nor why it has
been thrown.

Most of the code comes pretty much straight from the relevant pages in
SpecUtils

Can anyone offer any thoughts? recommendations?

I am running astropy in Jupyter Notebooks, current versions of both and
Ubuntu 18.04 with updates to date.


Peter Dzwig


PS FWIW the spectrum itself is at

<https://data.sdss.org/sas/dr15/sdss/spectro/redux/26/spectra/lite/2107/spec-2107-53786-0069.fits>
-- 

Dr. Peter Dzwig



More information about the AstroPy mailing list