<div dir="ltr"><div>Hi Dr. Peter</div><div><br></div><div>Thank you kindly for your reply. <br></div><div><br></div><div>Here's a folder with the file (it's an hdr file):</div><div><a href="https://drive.google.com/file/d/1Rb25_mzAKq7ZqFI9fPyOX8TnTtspYxpF/view?usp=sharing">https://drive.google.com/file/d/1Rb25_mzAKq7ZqFI9fPyOX8TnTtspYxpF/view?usp=sharing</a></div><div><br></div><div>I am looking for really small shifts that reflect chemistry, and therefore, I cannot just eyeball it, I need the actual values. <br></div><div>Indeed it is a complicated task to do without specialized software. <br></div><div>Regarding the threshold, I've changed it multiple times between 0 and 20, and still no absorption values... <br></div><div><br></div><div>Thank you so much for looking into it! :)<br></div><div> <br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Peter Dzwig <<a href="mailto:pdzwig@summaventures.com">pdzwig@summaventures.com</a>> escreveu no dia quinta, 28/05/2020 à(s) 19:15:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Angela,<br>
<br>
first thing to be said is that I sympathize. :-)  I have had similar<br>
issues although my datasets are very different (QSOs); the second is<br>
that I can't open either of your files. Perhaps you tell us what format<br>
they are in.<br>
<br>
I tried running similar code to yours (despite the different context). I<br>
found that the answers, from both thresholding and derivative, I got<br>
were quite sensitive to the data density per unit wavelength, the amount<br>
of noise in the data and the threshold that you set.<br>
<br>
Unless the data is sufficiently dense both thresholding and derivative<br>
will produce inaccurate or even false results.<br>
<br>
In the end I found the best solution was to make a table of all the<br>
lines that I was interested in and simply overplot them on my spectrum.<br>
I can then see what's where and (using a combination of astropy and<br>
numpy) re-plot and re-examine pertinent parts of the spectrum, but as<br>
ever the limiting factor is data density.<br>
<br>
I guess in your case the lines that you would plot would be Calcium,<br>
Cerium, Lanthanum, Carbon, Flourine  - and Neodymium? and some of their<br>
molecular forms. Tables for most are available from NIST:<br>
<a href="https://www.nist.gov/pml/atomic-spectra-database" rel="noreferrer" target="_blank">https://www.nist.gov/pml/atomic-spectra-database</a><br>
<br>
There probably is a best approach - a tutorial would be a good idea -<br>
and I will watch this space to see what solutions others offer.<br>
<br>
Regards,<br>
<br>
Peter Dzwig<br>
<br>
On 28/05/2020 08:43, Angela Rodrigues wrote:<br>
> Hello,<br>
> <br>
> I have been trying to use astropy to extract lines of absorption from a<br>
> mineral spectrum.<br>
> so I have the attached hdr file with the spectral analysis from a mineral.<br>
> The code to extract the data from the file is as follows:<br>
> <br>
> import spectral.io.envi as envi<br>
> lib = envi.open('GFZ_HySpex_REMin.hdr')<br>
> <br>
> a=lib.metadata<br>
> wvl = a.get('wavelength')<br>
> wvl = [int(float(i)) for i in wvl]<br>
> <br>
> import matplotlib.pyplot as plt<br>
> plt.plot(wvl,spectra[13])<br>
> <br>
> #grab spectra for parisite<br>
> names = lib.names<br>
> <br>
> spectra_parisite = spectra[8]<br>
> plt.plot(wvl, spectra_parisite)<br>
> <br>
> <br>
> I wanted to extract the absorption lines as in the documentation example<br>
> here <<a href="https://specutils.readthedocs.io/en/stable/fitting.html" rel="noreferrer" target="_blank">https://specutils.readthedocs.io/en/stable/fitting.html</a>>.<br>
> Here's what I've done:<br>
> <br>
> <br>
> w = np.array(wvl)<br>
> <br>
> import astropy.units as u<br>
> w = w*u.nm<br>
> spectra_parisite = spectra_parisite*u.Jy<br>
> from specutils import Spectrum1D, SpectralRegion<br>
> spectrum = Spectrum1D(spectral_axis = w, flux = spectra_parisite)<br>
> <br>
> from matplotlib import pyplot as plt<br>
> plt.plot(spectrum.spectral_axis, spectrum.flux)<br>
> plt.xlabel('Spectral Axis ({})'.format(spectrum.spectral_axis.unit))<br>
> plt.ylabel('Flux Axis({})'.format(spectrum.flux.unit))<br>
> plt.grid(True)<br>
> <br>
> from specutils.manipulation import noise_region_uncertainty<br>
> noise_region = SpectralRegion(450*u.nm, 2500*u.nm)<br>
> spectrum2 = noise_region_uncertainty(spectrum, noise_region)<br>
> <br>
> from specutils.fitting import find_lines_threshold<br>
> lines = find_lines_threshold(spectrum2, noise_factor=0)<br>
> lines[lines['line_type'] == 'absorption']<br>
> lines[lines['line_type'] == 'emission']<br>
> <br>
> # Derivative technique<br>
> from specutils.fitting import find_lines_derivative<br>
> lines = find_lines_derivative(spectrum2, flux_threshold=0)<br>
> lines[lines['line_type'] == 'absorption'] <br>
> <br>
> <br>
> However, I get no absorption feature lines. Am I doing something wrong?<br>
> The emission zones seem to be alright, but I really need the absorption<br>
> loci.<br>
> Thank you so much for your help!!<br>
> Warm regards,<br>
> Angela Rodrigues<br>
> <br>
> _______________________________________________<br>
> AstroPy mailing list<br>
> <a href="mailto:AstroPy@python.org" target="_blank">AstroPy@python.org</a><br>
> <a href="https://mail.python.org/mailman/listinfo/astropy" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/astropy</a><br>
> <br>
<br>
-- <br>
<br>
Dr. Peter Dzwig<br>
</blockquote></div>