[AstroPy] Fwd: Help with finding absorption lines

Peter Dzwig pdzwig at summaventures.com
Thu May 28 05:15:19 EDT 2020


Angela,

first thing to be said is that I sympathize. :-)  I have had similar
issues although my datasets are very different (QSOs); the second is
that I can't open either of your files. Perhaps you tell us what format
they are in.

I tried running similar code to yours (despite the different context). I
found that the answers, from both thresholding and derivative, I got
were quite sensitive to the data density per unit wavelength, the amount
of noise in the data and the threshold that you set.

Unless the data is sufficiently dense both thresholding and derivative
will produce inaccurate or even false results.

In the end I found the best solution was to make a table of all the
lines that I was interested in and simply overplot them on my spectrum.
I can then see what's where and (using a combination of astropy and
numpy) re-plot and re-examine pertinent parts of the spectrum, but as
ever the limiting factor is data density.

I guess in your case the lines that you would plot would be Calcium,
Cerium, Lanthanum, Carbon, Flourine  - and Neodymium? and some of their
molecular forms. Tables for most are available from NIST:
https://www.nist.gov/pml/atomic-spectra-database

There probably is a best approach - a tutorial would be a good idea -
and I will watch this space to see what solutions others offer.

Regards,

Peter Dzwig

On 28/05/2020 08:43, Angela Rodrigues wrote:
> Hello,
> 
> I have been trying to use astropy to extract lines of absorption from a
> mineral spectrum.
> so I have the attached hdr file with the spectral analysis from a mineral.
> The code to extract the data from the file is as follows:
> 
> import spectral.io.envi as envi
> lib = envi.open('GFZ_HySpex_REMin.hdr')
> 
> a=lib.metadata
> wvl = a.get('wavelength')
> wvl = [int(float(i)) for i in wvl]
> 
> import matplotlib.pyplot as plt
> plt.plot(wvl,spectra[13])
> 
> #grab spectra for parisite
> names = lib.names
> 
> spectra_parisite = spectra[8]
> plt.plot(wvl, spectra_parisite)
> 
> 
> I wanted to extract the absorption lines as in the documentation example
> here <https://specutils.readthedocs.io/en/stable/fitting.html>.
> Here's what I've done:
> 
> 
> w = np.array(wvl)
> 
> import astropy.units as u
> w = w*u.nm
> spectra_parisite = spectra_parisite*u.Jy
> from specutils import Spectrum1D, SpectralRegion
> spectrum = Spectrum1D(spectral_axis = w, flux = spectra_parisite)
> 
> from matplotlib import pyplot as plt
> plt.plot(spectrum.spectral_axis, spectrum.flux)
> plt.xlabel('Spectral Axis ({})'.format(spectrum.spectral_axis.unit))
> plt.ylabel('Flux Axis({})'.format(spectrum.flux.unit))
> plt.grid(True)
> 
> from specutils.manipulation import noise_region_uncertainty
> noise_region = SpectralRegion(450*u.nm, 2500*u.nm)
> spectrum2 = noise_region_uncertainty(spectrum, noise_region)
> 
> from specutils.fitting import find_lines_threshold
> lines = find_lines_threshold(spectrum2, noise_factor=0)
> lines[lines['line_type'] == 'absorption']
> lines[lines['line_type'] == 'emission']
> 
> # Derivative technique
> from specutils.fitting import find_lines_derivative
> lines = find_lines_derivative(spectrum2, flux_threshold=0)
> lines[lines['line_type'] == 'absorption'] 
> 
> 
> However, I get no absorption feature lines. Am I doing something wrong?
> The emission zones seem to be alright, but I really need the absorption
> loci.
> Thank you so much for your help!!
> Warm regards,
> Angela Rodrigues
> 
> _______________________________________________
> AstroPy mailing list
> AstroPy at python.org
> https://mail.python.org/mailman/listinfo/astropy
> 

-- 

Dr. Peter Dzwig


More information about the AstroPy mailing list