[AstroPy] Fwd: Help with finding absorption lines

Peter Dzwig pdzwig at summaventures.com
Thu May 28 09:53:19 EDT 2020


Angela,

I will think about this some more - and hopefully some more astropy
users will join in.

Going to your point about really small shifts: You don't specify what
you mean by that, but what I did was to provide myself with a tool that
enabled me to plot a small section of the data I had and then overplot
with lines within that. But, again, data density is everything.

To look for the lines you might find NIST the best source, in the end I
used a combination of (fairly) standard data, together with transitions
calculated from quantum mechanics, so that I had tables which included
not only the main lines, but also forbidden and semi-forbidden
transitions. At that point I wasn't interested in molecular orbitals and
so on, but I guess that in prionciple you could extend it to that.

I will, as I say continue to look at it, but I hope others will contribute.

Peter

On 28/05/2020 10:55, Angela Rodrigues wrote:
> Hi Dr. Peter
> 
> Thank you kindly for your reply.
> 
> Here's a folder with the file (it's an hdr file):
> https://drive.google.com/file/d/1Rb25_mzAKq7ZqFI9fPyOX8TnTtspYxpF/view?usp=sharing
> 
> I am looking for really small shifts that reflect chemistry, and
> therefore, I cannot just eyeball it, I need the actual values.
> Indeed it is a complicated task to do without specialized software.
> Regarding the threshold, I've changed it multiple times between 0 and
> 20, and still no absorption values...
> 
> Thank you so much for looking into it! :)
> 
> 
> Peter Dzwig <pdzwig at summaventures.com <mailto:pdzwig at summaventures.com>>
> escreveu no dia quinta, 28/05/2020 à(s) 19:15:
> 
>     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 <mailto:AstroPy at python.org>
>     > https://mail.python.org/mailman/listinfo/astropy
>     >
> 
>     -- 
> 
>     Dr. Peter Dzwig
> 

-- 

Dr. Peter Dzwig


More information about the AstroPy mailing list