Coverage for spectractor/extractor/spectroscopy.py: 43%
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1from astropy.table import Table
2from scipy.interpolate import interp1d
3import numpy as np
4import matplotlib.pyplot as plt
5import copy
6import os
8from spectractor import parameters
9from spectractor.config import set_logger
10from spectractor.tools import gauss, multigauss_and_bgd, rescale_x_for_legendre, plot_spectrum_simple
13class Line:
14 """Class modeling the emission or absorption lines."""
16 def __init__(self, wavelength, label, atmospheric=False, emission=False, label_pos=[0.007, 0.02],
17 width_bounds=[0.5, 6], use_for_calibration=False):
18 """Class modeling the emission or absorption lines. lines attributes contains main spectral lines
19 sorted in wavelength.
21 Parameters
22 ----------
23 wavelength: float
24 Wavelength of the spectral line in nm
25 label: str
27 atmospheric: bool
28 Set True if the spectral line is atmospheric (default: False)
29 emission: bool
30 Set True if the spectral line has to be detected in emission. Can't be true if the line is atmospheric.
31 (default: False)
32 label_pos: [float, float]
33 Position of the label in the plot with respect to the vertical lin (default: [0.007,0.02])
34 width_bounds: [float, float]
35 Minimum and maximum width (in nm) of the line for fitting procedures (default: [1,7])
36 use_for_calibration: bool
37 Use this line for the dispersion relation calibration, bright line recommended (default: False)
39 Examples
40 --------
41 >>> l = Line(550, label='test', atmospheric=True, emission=True)
42 >>> print(l.wavelength)
43 550
44 >>> print(l.label)
45 test
46 >>> print(l.atmospheric)
47 True
48 >>> print(l.emission)
49 False
50 """
51 self.my_logger = set_logger(self.__class__.__name__)
52 self.wavelength = wavelength # in nm
53 self.label = label
54 self.label_pos = label_pos
55 self.atmospheric = atmospheric
56 self.emission = emission
57 if self.atmospheric:
58 self.emission = False
59 self.width_bounds = width_bounds
60 self.fitted = False
61 self.use_for_calibration = use_for_calibration
62 self.high_snr = False
63 self.fit_lambdas = None
64 self.fit_gauss = None
65 self.fit_bgd = None
66 self.fit_snr = None
67 self.fit_fwhm = None
68 self.fit_popt = None
69 self.fit_popt_gaussian = None
70 self.fit_chisq = None
71 self.fit_eqwidth_mod = None
72 self.fit_eqwidth_data = None
73 self.fit_bgd_npar = parameters.CALIB_BGD_NPARAMS
75 def gaussian_model(self, lambdas, A=1, sigma=2, use_fit=False):
76 """Return a Gaussian model of the spectral line.
78 Parameters
79 ----------
80 lambdas: float, array
81 Wavelength array of float in nm
82 A: float
83 Amplitude of the Gaussian (default: +1)
84 sigma: float
85 Standard deviation of the Gaussian (default: 2)
86 use_fit: bool, optional
87 If True, it overrides the previous setting values and use the Gaussian fit made on data, if ti exists.
89 Returns
90 -------
91 model: float, array
92 The amplitude array of float of the Gaussian model of the line.
94 Examples
95 --------
97 Give lambdas as a float:
99 >>> l = Line(656.3, atmospheric=False, label='$H\\alpha$')
100 >>> sigma = 2.
101 >>> model = l.gaussian_model(656.3, A=1, sigma=sigma, use_fit=False)
102 >>> print(model)
103 1.0
104 >>> model = l.gaussian_model(656.3+sigma*np.sqrt(2*np.log(2)), A=1, sigma=sigma, use_fit=False)
105 >>> print(f"{model:.4f}")
106 0.5000
108 Use a fit (for the example we create a mock fit result):
110 >>> l.fit_lambdas = np.arange(600,700,2)
111 >>> l.fit_gauss = gauss(l.fit_lambdas, 1e-10, 650, 2.3)
112 >>> l.fit_fwhm = 2.3*2*np.sqrt(2*np.log(2))
113 >>> lambdas = np.arange(500,1000,1)
114 >>> model = l.gaussian_model(lambdas, A=1, sigma=sigma, use_fit=True)
115 >>> print(model[:5])
116 [0. 0. 0. 0. 0.]
118 """
119 if use_fit and self.fit_gauss is not None:
120 interp = interp1d(self.fit_lambdas, self.fit_gauss, bounds_error=False, fill_value=0.)
121 return interp(lambdas)
122 else:
123 return gauss(lambdas, A=A, x0=self.wavelength, sigma=sigma)
126class Lines:
127 """Class gathering all the lines and associated methods."""
129 def __init__(self, lines, redshift=0, atmospheric_lines=True, hydrogen_only=False, emission_spectrum=False,
130 orders=[1]):
131 """ Main emission/absorption lines in nm. Sorted lines are sorted in self.lines.
132 See http://www.pa.uky.edu/~peter/atomic/ or https://physics.nist.gov/PhysRefData/ASD/lines_form.html
134 Parameters
135 ----------
136 lines: list
137 List of Line objects to gather and sort.
138 redshift: float, optional
139 Red shift the spectral lines. Must be positive or null (default: 0)
140 atmospheric_lines: bool, optional
141 Set True if the atmospheric spectral lines must be included (default: True)
142 hydrogen_only: bool, optional
143 Set True to gather only the hydrogen spectral lines, atmospheric lines still included (default: False)
144 emission_spectrum: bool, optional
145 Set True if the spectral line has to be detected in emission (default: False)
146 orders: list, optional
147 List of integers corresponding to the diffraction order to account for the line search and the
148 wavelength calibration (default: [1])
150 Examples
151 --------
152 The default first five lines:
154 >>> lines = Lines(ISM_LINES+HYDROGEN_LINES, redshift=0, atmospheric_lines=False, hydrogen_only=False, emission_spectrum=False)
155 >>> print([lines.lines[i].wavelength for i in range(5)])
156 [353.1, 388.8, 397.0, 410.2, 434.0]
158 The four hydrogen lines only:
160 >>> lines = Lines(ISM_LINES+HYDROGEN_LINES+ATMOSPHERIC_LINES, redshift=0, atmospheric_lines=False, hydrogen_only=True, emission_spectrum=True)
161 >>> print([lines.lines[i].wavelength for i in range(4)])
162 [397.0, 410.2, 434.0, 486.3]
163 >>> print(lines.emission_spectrum)
164 True
166 Redshift the hydrogen lines, the atmospheric lines stay unchanged:
168 >>> lines = Lines(ISM_LINES+HYDROGEN_LINES+ATMOSPHERIC_LINES, redshift=1, atmospheric_lines=True, hydrogen_only=True, emission_spectrum=True)
169 >>> print([lines.lines[i].wavelength for i in range(7)])
170 [687.472, 760.3, 763.1, 794.0, 820.4, 822.696, 868.0]
172 Redshift all the spectral lines, except the atmospheric lines:
174 >>> lines = Lines(ISM_LINES+HYDROGEN_LINES+ATMOSPHERIC_LINES, redshift=1, atmospheric_lines=True, hydrogen_only=False, emission_spectrum=True)
175 >>> print([lines.lines[i].wavelength for i in range(5)])
176 [687.472, 706.2, 760.3, 763.1, 777.6]
178 Hydrogen lines at order 1 and 2:
179 >>> lines = Lines(HYDROGEN_LINES, redshift=0, atmospheric_lines=True, hydrogen_only=False, emission_spectrum=True, orders=[1, 2])
180 >>> print([lines.lines[i].wavelength for i in range(len(lines.lines))])
181 [397.0, 410.2, 434.0, 486.3, 656.3, 794.0, 820.4, 868.0, 972.6, 1312.6]
183 Negative redshift:
185 >>> lines = Lines(HYDROGEN_LINES, redshift=-0.5)
187 """
188 self.my_logger = set_logger(self.__class__.__name__)
189 if redshift < -1e-2:
190 self.my_logger.error(f'\n\tRedshift must small in absolute value (|z|<0.01) or be positive or null. '
191 f'Got redshift={redshift}.')
192 self.lines = []
193 self.orders = orders
194 for order in orders:
195 for line in lines:
196 tmp_line = copy.deepcopy(line)
197 tmp_line.wavelength *= order
198 if order > 1:
199 if line.label[-1] == "$":
200 tmp_line.label = tmp_line.label[:-1]
201 tmp_line.label += "^(2)"
202 if line.label[-1] == "$":
203 tmp_line.label += "$"
204 self.lines.append(tmp_line)
205 self.redshift = redshift
206 self.atmospheric_lines = atmospheric_lines
207 self.hydrogen_only = hydrogen_only
208 self.emission_spectrum = emission_spectrum
209 self.lines = self.sort_lines()
211 def sort_lines(self):
212 """Sort the lines in increasing order of wavelength, and add the redshift effect.
214 Returns
215 -------
216 sorted_lines: list
217 List of the sorted lines
219 Examples
220 --------
221 >>> lines = Lines(HYDROGEN_LINES+ATMOSPHERIC_LINES, redshift=0)
222 >>> sorted_lines = lines.sort_lines()
223 >>> print([l.wavelength for l in sorted_lines][:5])
224 [397.0, 410.2, 434.0, 486.3, 656.3]
225 """
226 sorted_lines = []
227 import copy
228 for line in self.lines:
229 if self.hydrogen_only:
230 if not self.atmospheric_lines:
231 if line.atmospheric:
232 continue
233 if '$H\\' not in line.label:
234 continue
235 else:
236 if not line.atmospheric and '$H\\' not in line.label:
237 continue
238 else:
239 if not self.atmospheric_lines and line.atmospheric:
240 continue
241 sorted_lines.append(copy.copy(line))
242 if self.redshift > 0:
243 for line in sorted_lines:
244 if not line.atmospheric:
245 line.wavelength *= (1 + self.redshift)
246 sorted_lines = sorted(sorted_lines, key=lambda x: x.wavelength)
247 return sorted_lines
249 def plot_atomic_lines(self, ax, color_atomic='g', color_atmospheric='b', fontsize=12, force=False):
250 """Over plot the atomic lines as vertical lines, only if they are fitted or with high
251 signal to noise ratio, unless force keyword is set to True.
253 Parameters
254 ----------
255 ax: Axes
256 An Axes instance on which plot the spectral lines.
257 color_atomic: str
258 Color of the atomic lines (default: 'g').
259 color_atmospheric: str
260 Color of the atmospheric lines (default: 'b').
261 fontsize: int
262 Font size of the spectral line labels (default: 12).
263 force: bool
264 Force the plot of vertical lines if set to True (default: False).
266 Examples
267 --------
269 >>> import matplotlib.pyplot as plt
270 >>> f, ax = plt.subplots(1,1)
271 >>> ax.set_xlim(300,1000) # doctest: +ELLIPSIS
272 (300..., 1000...)
273 >>> lines = Lines(HYDROGEN_LINES+ATMOSPHERIC_LINES)
274 >>> lines.lines[5].fitted = True
275 >>> lines.lines[5].high_snr = True
276 >>> lines.lines[-1].fitted = True
277 >>> lines.lines[-1].high_snr = True
278 >>> ax = lines.plot_atomic_lines(ax)
279 >>> if parameters.DISPLAY: plt.show()
281 .. doctest::
282 :hide:
284 >>> assert ax is not None
286 .. plot::
288 import matplotlib.pyplot as plt
289 import numpy as np
290 from spectractor.extractor.spectroscopy import *
291 f, ax = plt.subplots(1,1)
292 ax.set_xlim(300,1000)
293 lines = Lines(HYDROGEN_LINES+ATMOSPHERIC_LINES)
294 lines.lines[5].fitted = True
295 lines.lines[5].high_snr = True
296 lines.lines[-1].fitted = True
297 lines.lines[-1].high_snr = True
298 ax = lines.plot_atomic_lines(ax)
299 plt.show()
301 """
302 xlim = ax.get_xlim()
303 for line in self.lines:
304 if (not line.fitted or not line.high_snr) and not force:
305 continue
306 color = color_atomic
307 if line.atmospheric:
308 color = color_atmospheric
309 ax.axvline(line.wavelength, lw=2, color=color)
310 xpos = (line.wavelength - xlim[0]) / (xlim[1] - xlim[0]) + line.label_pos[0]
311 if 0 < xpos < 1:
312 ax.annotate(line.label, xy=(xpos, line.label_pos[1]), rotation=90, ha='left', va='bottom',
313 xycoords='axes fraction', color=color, fontsize=fontsize)
314 return ax
316 def plot_detected_lines(self, ax=None, print_table=False):
317 """Overplot the fitted lines on a spectrum.
319 Parameters
320 ----------
321 ax: Axes
322 The Axes instance if needed (default: None).
323 print_table: bool, optional
324 If True, print a summary table (default: False).
326 Examples
327 --------
329 Creation of a mock spectrum with emission and absorption lines:
331 >>> from spectractor.extractor.spectrum import Spectrum, detect_lines
332 >>> lambdas = np.arange(300,1000,1)
333 >>> spectrum = 1e4*np.exp(-((lambdas-600)/200)**2)
334 >>> spectrum += HALPHA.gaussian_model(lambdas, A=5000, sigma=3)
335 >>> spectrum += HBETA.gaussian_model(lambdas, A=3000, sigma=2)
336 >>> spectrum += O2_1.gaussian_model(lambdas, A=-3000, sigma=7)
337 >>> spectrum_err = np.sqrt(spectrum)
338 >>> spec = Spectrum()
339 >>> spec.lambdas = lambdas
340 >>> spec.data = spectrum
341 >>> spec.err = spectrum_err
342 >>> fwhm_func = interp1d(lambdas, 0.01 * lambdas)
344 Detect the lines:
346 >>> lines = Lines([HALPHA, HBETA, O2_1], hydrogen_only=True,
347 ... atmospheric_lines=True, redshift=0, emission_spectrum=True)
348 >>> global_chisq = detect_lines(lines, lambdas, spectrum, spectrum_err, fwhm_func=fwhm_func)
350 .. doctest::
351 :hide:
353 >>> assert(global_chisq < 1)
355 Plot the result:
357 >>> spec.lines = lines
358 >>> fig = plt.figure()
359 >>> plot_spectrum_simple(plt.gca(), lambdas, spec.data, data_err=spec.err)
360 >>> lines.plot_detected_lines(plt.gca())
361 >>> plt.show()
363 .. plot::
365 import matplotlib.pyplot as plt
366 from spectractor.tools import plot_spectrum_simple
367 from spectractor.extractor.spectrum import Spectrum, detect_lines
368 from spectractor.extractor.spectroscopy import *
369 lambdas = np.arange(300,1000,1)
370 spectrum = 1e4*np.exp(-((lambdas-600)/200)**2)
371 spectrum += HALPHA.gaussian_model(lambdas, A=5000, sigma=3)
372 spectrum += HBETA.gaussian_model(lambdas, A=3000, sigma=2)
373 spectrum += O2.gaussian_model(lambdas, A=-3000, sigma=7)
374 spectrum_err = np.sqrt(spectrum)
375 spec = Spectrum()
376 spec.lambdas = lambdas
377 spec.data = spectrum
378 spec.err = spectrum_err
379 fwhm_func = interp1d(lambdas, 0.01 * lambdas)
380 lines = Lines([HALPHA, HBETA, O2], hydrogen_only=True, atmospheric_lines=True, redshift=0, emission_spectrum=True)
381 global_chisq = detect_lines(lines, lambdas, spectrum, spectrum_err, fwhm_func=fwhm_func)
382 spec.lines = lines
383 fig = plt.figure()
384 plot_spectrum_simple(plt.gca(), lambdas, spec.data, data_err=spec.err)
385 lines.plot_detected_lines(plt.gca())
386 plt.show()
388 """
389 lambdas = np.zeros(1)
390 for line in self.lines:
391 if line.fitted is True:
392 # look for lines in subset fit
393 bgd_npar = line.fit_bgd_npar
394 parameters.CALIB_BGD_NPARAMS = bgd_npar
395 if lambdas.shape != line.fit_lambdas.shape or not np.allclose(lambdas, line.fit_lambdas, 1e-3):
396 lambdas = np.copy(line.fit_lambdas)
397 if ax is not None:
398 ax.plot(lambdas, multigauss_and_bgd(lambdas, *line.fit_popt), lw=2, color='b')
399 x_norm = rescale_x_for_legendre(lambdas)
400 bgd = np.polynomial.legendre.legval(x_norm, line.fit_popt[0:bgd_npar])
401 ax.plot(lambdas, bgd, lw=2, color='b', linestyle='--')
402 if print_table:
403 self.print_detected_lines(print_table=True)
405 def print_detected_lines(self, output_file_name="", overwrite=False, print_table=False, amplitude_units=""):
406 """Print the detected line on screen as an Astropy table, and write it in a file.
408 Parameters
409 ----------
410 output_file_name: str, optional
411 Output file name. If not empty, save the table in a file (default: '').
412 overwrite: bool, optional
413 If True, overwrite the existing file if it exists (default: False).
414 print_table: bool, optional
415 If True, print a summary table (default: False).
416 amplitude_units: str, optional
417 Units of the line amplitude (default: "").
419 Returns
420 -------
421 table: Table
422 Astropy table containing the main line characteristics.
424 Examples
425 --------
427 Creation of a mock spectrum with emission and absorption lines
428 >>> from spectractor.extractor.spectrum import Spectrum, detect_lines
429 >>> lambdas = np.arange(300,1000,1)
430 >>> spectrum = 1e4*np.exp(-((lambdas-600)/200)**2)
431 >>> spectrum += HALPHA.gaussian_model(lambdas, A=5000, sigma=3)
432 >>> spectrum += HBETA.gaussian_model(lambdas, A=3000, sigma=2)
433 >>> spectrum += O2_1.gaussian_model(lambdas, A=-3000, sigma=7)
434 >>> spectrum_err = np.sqrt(spectrum)
435 >>> spec = Spectrum()
436 >>> spec.lambdas = lambdas
437 >>> spec.data = spectrum
438 >>> spec.err = spectrum_err
439 >>> fwhm_func = interp1d(lambdas, 0.01 * lambdas)
441 Detect the lines
442 >>> lines = Lines([HALPHA, HBETA, O2_1], hydrogen_only=True,
443 ... atmospheric_lines=True, redshift=0, emission_spectrum=True)
444 >>> global_chisq = detect_lines(lines, lambdas, spectrum, spectrum_err, fwhm_func=fwhm_func)
445 >>> assert(global_chisq < 1)
447 Print the result
448 >>> spec.lines = lines
449 >>> t = lines.print_detected_lines(output_file_name="test_detected_lines.csv")
451 .. doctest::
452 :hide:
454 >>> assert len(t) > 0
455 >>> assert os.path.isfile('test_detected_lines.csv')
456 >>> os.remove('test_detected_lines.csv')
457 """
458 lambdas = np.zeros(1)
459 rows = []
460 j = 0
462 for line in self.lines:
463 if line.fitted is True:
464 # look for lines in subset fit
465 bgd_npar = line.fit_bgd_npar
466 parameters.CALIB_BGD_NPARAMS = bgd_npar
467 if lambdas.shape != line.fit_lambdas.shape or not np.allclose(lambdas, line.fit_lambdas, 1e-3):
468 j = 0
469 lambdas = np.copy(line.fit_lambdas)
470 popt = line.fit_popt
471 peak_pos = popt[bgd_npar + 3 * j + 1]
472 FWHM = np.abs(popt[bgd_npar + 3 * j + 2]) * 2.355
473 signal_level = popt[bgd_npar + 3 * j]
474 if line.high_snr:
475 rows.append((line.label, line.wavelength, peak_pos, peak_pos - line.wavelength,
476 FWHM, signal_level, line.fit_snr, line.fit_chisq, line.fit_eqwidth_mod,
477 line.fit_eqwidth_data))
478 j += 1
479 t = None
480 if len(rows) > 0:
481 t = Table(rows=rows, names=(
482 'Line', 'Tabulated', 'Detected', 'Shift', 'FWHM', 'Amplitude', 'SNR', 'Chisq', 'Eqwidth_mod',
483 'Eqwidth_data'),
484 dtype=('a12', 'f4', 'f4', 'f4', 'f4', 'f4', 'f4', 'f4', 'f4', 'f4'))
485 for col in t.colnames[1:5]:
486 t[col].unit = 'nm'
487 t[t.colnames[5]].unit = amplitude_units
488 for col in t.colnames[-2:]:
489 t[col].unit = 'nm'
490 t[t.colnames[-3]].unit = 'reduced'
491 if output_file_name != "":
492 t.write(output_file_name, overwrite=overwrite)
493 if print_table:
494 print(t)
495 if parameters.LSST_SAVEFIGPATH:
496 t.write(os.path.join(parameters.LSST_SAVEFIGPATH, 'extractedLines.fits'), overwrite=True)
497 return t
500# Line catalog
502# Hydrogen lines
503HALPHA = Line(656.3, atmospheric=False, label='$H\\alpha$', label_pos=[-0.04, 0.02], use_for_calibration=True)
504HBETA = Line(486.3, atmospheric=False, label='$H\\beta$', label_pos=[0.007, 0.02], use_for_calibration=True)
505HGAMMA = Line(434.0, atmospheric=False, label='$H\\gamma$', label_pos=[0.007, 0.02], use_for_calibration=False)
506HDELTA = Line(410.2, atmospheric=False, label='$H\\delta$', label_pos=[0.007, 0.02], use_for_calibration=False)
507HEPSILON = Line(397.0, atmospheric=False, label='$H\\epsilon$', label_pos=[-0.04, 0.02], use_for_calibration=False)
508HYDROGEN_LINES = [HALPHA, HBETA, HGAMMA, HDELTA, HEPSILON]
510# Stellar lines (Fraunhofer lines) https://en.wikipedia.org/wiki/Fraunhofer_lines
511FE1 = Line(382.044, atmospheric=False, label=r'$Fe_{I}$', label_pos=[-0.016, 0.02])
512CAII1 = Line(393.366, atmospheric=False, label=r'$Ca_{II}$', label_pos=[-0.016, 0.02])
513CAII2 = Line(396.847, atmospheric=False, label=r'$Ca_{II}$', label_pos=[-0.016, 0.02])
514FE2 = Line(430.790, atmospheric=False, label=r'$Fe_{I}$', label_pos=[-0.016, 0.02])
515FE3 = Line(438.355, atmospheric=False, label=r'$Fe_{I}$', label_pos=[-0.016, 0.02])
516HEI1 = Line(447.1, atmospheric=False, label=r'$He_{I}$', label_pos=[-0.016, 0.02])
517MG1 = Line(517.27, atmospheric=False, label=r'$Mg_{I}$', label_pos=[-0.016, 0.02])
518MG2 = Line(518.36, atmospheric=False, label=r'$Mg_{I}$', label_pos=[-0.016, 0.02])
519FE4 = Line(527.039, atmospheric=False, label=r'$Fe_{I}$', label_pos=[-0.016, 0.02])
520STELLAR_LINES = [FE1, FE2, FE3, FE4, CAII1, CAII2, HEI1, MG1, MG2]
522# Atmospheric lines
523# O2 = Line(762.2, atmospheric=True, label=r'$O_2$', # 762.2 is a weighted average of the O2 line simulated by Libradtran
524# label_pos=[0.007, 0.02],
525# use_for_calibration=True) # http://onlinelibrary.wiley.com/doi/10.1029/98JD02799/pdf
526O2_1 = Line(760.3, atmospheric=True, label='',
527 label_pos=[0.007, 0.02], use_for_calibration=True) # libradtran paper fig.3
528O2_2 = Line(763.1, atmospheric=True, label='$O_2$',
529 label_pos=[0.007, 0.02], use_for_calibration=True) # libradtran paper fig.3
530O2B = Line(687.472, atmospheric=True, label=r'$O_2(B)$', # 687.472 is a weighted average of the O2B line simulated by Libradtran
531 label_pos=[0.007, 0.02], use_for_calibration=True) # https://en.wikipedia.org/wiki/Fraunhofer_lines
532O2Y = Line(898.765, atmospheric=True, label=r'$O_2(Y)$',
533 label_pos=[0.007, 0.02]) # https://en.wikipedia.org/wiki/Fraunhofer_lines
534O2Z = Line(822.696, atmospheric=True, label=r'$O_2(Z)$',
535 label_pos=[0.007, 0.02]) # https://en.wikipedia.org/wiki/Fraunhofer_lines
536# H2O = Line( 960,atmospheric=True,label='$H_2 O$',label_pos=[0.007,0.02],width_bounds=(1,50)) #
537H2O_1 = Line(935, atmospheric=True, label=r'$H_2 O$', label_pos=[0.007, 0.02], # MFL: don't these need different labels?
538 width_bounds=[5, 30]) # libradtran paper fig.3, broad line
539# H2O_2 = Line(960, atmospheric=True, label=r'$H_2 O$', label_pos=[0.007, 0.02], # MFL: don't these need different labels?
540# width_bounds=[5, 30]) # libradtran paper fig.3, broad line
541ATMOSPHERIC_LINES = [O2_1, O2_2, O2B, O2Y, O2Z, H2O_1]
543# ISM lines
544OIII = Line(500.7, atmospheric=False, label=r'$O_{III}$', label_pos=[0.007, 0.02])
545CII1 = Line(723.5, atmospheric=False, label=r'$C_{II}$', label_pos=[0.005, 0.88])
546CII2 = Line(711.0, atmospheric=False, label=r'$C_{II}$', label_pos=[0.005, 0.02])
547CIV = Line(706.0, atmospheric=False, label=r'$C_{IV}$', label_pos=[-0.016, 0.88])
548CII3 = Line(679.0, atmospheric=False, label=r'$C_{II}$', label_pos=[0.005, 0.02])
549CIII1 = Line(673.0, atmospheric=False, label=r'$C_{III}$', label_pos=[-0.016, 0.88])
550CIII2 = Line(570.0, atmospheric=False, label=r'$C_{III}$', label_pos=[0.007, 0.02])
551CIII3 = Line(970.5, atmospheric=False, label=r'$C_{III}$', label_pos=[0.007, 0.02])
552FEII1 = Line(463.8, atmospheric=False, label=r'$Fe_{II}$', label_pos=[-0.016, 0.02])
553FEII2 = Line(515.8, atmospheric=False, label=r'$Fe_{II}$', label_pos=[0.007, 0.02])
554FEII3 = Line(527.3, atmospheric=False, label=r'$Fe_{II}$', label_pos=[0.007, 0.02])
555FEII4 = Line(534.9, atmospheric=False, label=r'$Fe_{II}$', label_pos=[0.007, 0.02])
556HEI1 = Line(388.8, atmospheric=False, label=r'$He_{I}$', label_pos=[0.007, 0.02])
557HEI2 = Line(447.1, atmospheric=False, label=r'$He_{I}$', label_pos=[0.007, 0.02])
558HEI3 = Line(587.5, atmospheric=False, label=r'$He_{I}$', label_pos=[0.007, 0.02])
559HEI4 = Line(750.0, atmospheric=False, label=r'$He_{I}$', label_pos=[0.007, 0.02])
560HEI5 = Line(776.0, atmospheric=False, label=r'$He_{I}$', label_pos=[0.007, 0.02])
561HEI6 = Line(781.6, atmospheric=False, label=r'$He_{I}$', label_pos=[0.007, 0.02])
562HEI7 = Line(848.2, atmospheric=False, label=r'$He_{I}$', label_pos=[0.007, 0.02])
563HEI8 = Line(861.7, atmospheric=False, label=r'$He_{I}$', label_pos=[0.007, 0.02])
564HEI9 = Line(906.5, atmospheric=False, label=r'$He_{I}$', label_pos=[0.007, 0.02])
565HEI10 = Line(923.5, atmospheric=False, label=r'$He_{I}$', label_pos=[0.007, 0.02])
566HEI11 = Line(951.9, atmospheric=False, label=r'$He_{I}$', label_pos=[0.007, 0.02])
567HEI12 = Line(1023.5, atmospheric=False, label=r'$He_{I}$', label_pos=[0.007, 0.02])
568HEI13 = Line(353.1, atmospheric=False, label=r'$He_{I}$', label_pos=[0.007, 0.02])
569OI = Line(630.0, atmospheric=False, label=r'$O_{II}$', label_pos=[0.007, 0.02]) # MFL: label typo?
570OII = Line(732.5, atmospheric=False, label=r'$O_{II}$', label_pos=[0.007, 0.02])
571HEII1 = Line(468.6, atmospheric=False, label=r'$He_{II}$', label_pos=[0.007, 0.02])
572HEII2 = Line(611.8, atmospheric=False, label=r'$He_{II}$', label_pos=[0.007, 0.02])
573HEII3 = Line(617.1, atmospheric=False, label=r'$He_{II}$', label_pos=[0.007, 0.02])
574HEII4 = Line(856.7, atmospheric=False, label=r'$He_{II}$', label_pos=[0.007, 0.02])
575HI = Line(833.9, atmospheric=False, label=r'$H_{I}$', label_pos=[0.007, 0.02])
576ISM_LINES = [OIII, CII1, CII2, CIV, CII3, CIII1, CIII2, CIII3, HEI1, HEI2, HEI3, HEI4, HEI5, HEI6, HEI7, HEI8,
577 HEI9, HEI10, HEI11, HEI12, HEI13, OI, OII, HEII1, HEII2, HEII3, HEII4, HI, FEII1, FEII2, FEII3, FEII4]
579# HG-AR lines https://oceanoptics.com/wp-content/uploads/hg1.pdf
580HG1 = Line(253.652, atmospheric=False, label=r'$Hg$', label_pos=[0.007, 0.02])
581HG2 = Line(296.728, atmospheric=False, label=r'$Hg$', label_pos=[0.007, 0.02])
582HG3 = Line(302.150, atmospheric=False, label=r'$Hg$', label_pos=[0.007, 0.02])
583HG4 = Line(313.155, atmospheric=False, label=r'$Hg$', label_pos=[0.007, 0.02])
584HG5 = Line(334.148, atmospheric=False, label=r'$Hg$', label_pos=[0.007, 0.02])
585HG6 = Line(365.015, atmospheric=False, label=r'$Hg$', label_pos=[0.007, 0.02], use_for_calibration=True)
586HG7 = Line(404.656, atmospheric=False, label=r'$Hg$', label_pos=[0.007, 0.02], use_for_calibration=True)
587HG8 = Line(407.783, atmospheric=False, label=r'$Hg$', label_pos=[0.007, 0.02], use_for_calibration=True)
588HG9 = Line(435.833, atmospheric=False, label=r'$Hg$', label_pos=[0.007, 0.02])
589HG10 = Line(546.074, atmospheric=False, label=r'$Hg$', label_pos=[0.007, 0.02], use_for_calibration=True)
590HG11 = Line(576.960, atmospheric=False, label=r'$Hg$', label_pos=[0.007, 0.02], use_for_calibration=True)
591HG12 = Line(579.066, atmospheric=False, label=r'$Hg$', label_pos=[0.007, 0.02], use_for_calibration=True)
592AR1 = Line(696.543, atmospheric=False, label=r'$Ar$', label_pos=[0.007, 0.02])
593AR2 = Line(706.722, atmospheric=False, label=r'$Ar$', label_pos=[0.007, 0.02])
594AR3 = Line(714.704, atmospheric=False, label=r'$Ar$', label_pos=[0.007, 0.02])
595AR4 = Line(727.294, atmospheric=False, label=r'$Ar$', label_pos=[0.007, 0.02])
596AR5 = Line(738.393, atmospheric=False, label=r'$Ar$', label_pos=[0.007, 0.02])
597AR6 = Line(750.387, atmospheric=False, label=r'$Ar$', label_pos=[0.007, 0.02])
598AR7 = Line(763.511, atmospheric=False, label=r'$Ar$', label_pos=[0.007, 0.02])
599AR8 = Line(772.376, atmospheric=False, label=r'$Ar$', label_pos=[0.007, 0.02])
600AR9 = Line(794.818, atmospheric=False, label=r'$Ar$', label_pos=[0.007, 0.02])
601AR10 = Line(800.616, atmospheric=False, label=r'$Ar$', label_pos=[0.007, 0.02])
602AR11 = Line(811.531, atmospheric=False, label=r'$Ar$', label_pos=[0.007, 0.02])
603AR12 = Line(826.452, atmospheric=False, label=r'$Ar$', label_pos=[0.007, 0.02])
604AR13 = Line(842.465, atmospheric=False, label=r'$Ar$', label_pos=[0.007, 0.02])
605AR14 = Line(852.144, atmospheric=False, label=r'$Ar$', label_pos=[0.007, 0.02])
606AR15 = Line(866.794, atmospheric=False, label=r'$Ar$', label_pos=[0.007, 0.02])
607AR16 = Line(912.297, atmospheric=False, label=r'$Ar$', label_pos=[0.007, 0.02])
608AR17 = Line(922.450, atmospheric=False, label=r'$Ar$', label_pos=[0.007, 0.02])
609AR18 = Line(965.7786, atmospheric=False, label=r'$Ar$', label_pos=[0.007, 0.02])
610AR19 = Line(978.4503, atmospheric=False, label=r'$Ar$', label_pos=[0.007, 0.02])
611HG13 = Line(1013.976, atmospheric=False, label=r'$Hg$', label_pos=[0.007, 0.02])
613HGAR_LINES = [HG1, HG2, HG3, HG4, HG5, HG6, HG7, HG8, HG9, HG10, HG11, HG12,
614 AR1, AR2, AR3, AR4, AR5, AR6, AR7, AR8, AR9, AR10, AR11, AR12, AR13, AR14, AR15, AR16, AR17, AR18, AR19, HG13]
616if __name__ == "__main__": 616 ↛ 617line 616 didn't jump to line 617, because the condition on line 616 was never true
617 import doctest
619 doctest.testmod()