MOS Spectroscopy of Extragalactic Field#

Use case: emission-line measurements and template matching on 1D spectra.
Data: CEERS NIRSpec observations
Tools: specutils, astropy, matplotlib, jdaviz.
Cross-intrument:
Documentation: This notebook is part of a STScI’s larger post-pipeline Data Analysis Tools Ecosystem.

Introduction#

In this notebook, we will inspect a set of spectra and perform a seris of spectroscopic analyses on an example spectrum, including continuum fitting and subtraction, line identification, centroiding and flux measurements, gaussian fitting, equivalent widths, and template fitting. We will do so using the interactive jdaviz package and the command line. We will use a JWST/NIRSpec spectroscopic dataset from the CEERS program.

Objective of the notebook#

The aim of the notebook is to showcase how to use the visualization tool Jdaviz or the combination Specutils+Matplotlib to measure the properties of the OII emission line in a NIRSpec spectrum.

Workflow#

  • visualize the spectroscopic dataset in Mosviz

  • select one galaxy (s02904) and visualize it in Specviz2d

  • perform the 1D extraction of the bright companion using the Spectral Extraction plugin in Specviz2d

  • attach the wavelength axis to the extracted 1D spectrum

  • select the OII emission line and measure

    • the redshift of the source

    • the properties of the emission line

  • fit a model with continuum + a Gaussian to the OII emission line

  • perform the same tasks using Specutils and Matplotlib instead of Jdaviz

  • find the best-fitting template of the observed spectrum

System requirements#

First, we create an environment with jdaviz which contains all the spectroscopic packages we need.

conda create -n jdaviz python
conda activate jdaviz
pip install jdaviz

Imports#

# general os
import zipfile
import urllib.request
from pathlib import Path

# general plotting
from matplotlib import pyplot as plt

# table/math handling
import numpy as np

# astropy
import astropy
import astropy.units as u
from astropy.io import fits, ascii
from astropy.nddata import StdDevUncertainty
from astropy.modeling import models
from astropy.visualization import quantity_support

# specutils
import specutils
from specutils import Spectrum1D, SpectralRegion
from specutils.fitting import fit_generic_continuum
from specutils.fitting import find_lines_threshold
from specutils.fitting import fit_lines
from specutils.manipulation import extract_region
from specutils.analysis import centroid
from specutils.analysis import line_flux
from specutils.analysis import equivalent_width
from specutils.analysis import template_comparison

# jdaviz
import jdaviz
from jdaviz import Mosviz, Specviz2d, Specviz  # noqa

# glue
from glue.core.roi import XRangeROI

np.seterr(all='ignore')  # hides irrelevant warnings about divide-by-zero, etc
quantity_support()  # auto-recognizes units on matplotlib plots

# Matplotlib parameters
params = {'legend.fontsize': '18', 
          'axes.labelsize': '18',
          'axes.titlesize': '18', 
          'xtick.labelsize': '18',
          'ytick.labelsize': '18', 
          'lines.linewidth': 2, 
          'axes.linewidth': 2, 
          'animation.html': 'html5'}
plt.rcParams.update(params)
plt.rcParams.update({'figure.max_open_warning': 0})

Check versions. Should be:#

Numpy: 1.25.2
Astropy: 5.3.2
Specutils: 1.11.0
Jdaviz: 3.7

print("Numpy: ", np.__version__)
print("Astropy: ", astropy.__version__)
print("Specutils: ", specutils.__version__)
print("Jdaviz: ", jdaviz.__version__)
Numpy:  1.26.4
Astropy:  6.1.0
Specutils:  1.15.0
Jdaviz:  3.10.1

Open data in Mosviz#

In Mosviz we can explore all the data products in the folder. This cell takes a minute or two to run. Since we are not including images, we can expand the 2D/1D spectra viewers to use the full width of the GUI. We can also keep the plugin tray open on metadata to check specifics of the files we are looking at.

Mosviz with its 2D spectrum, 1D spectrum, and table viewer.

Choose one galaxy#

We choose s02904 because we want to extract the very bright companion below the target.

file1d = pathtodata / 'jw01345-o064_s02904_nirspec_f100lp-g140m_x1d.fits'
file2d = pathtodata / 'jw01345-o064_s02904_nirspec_f100lp-g140m_s2d.fits'

Use Specviz2d to extract a better 1D spectrum#

We open the Spectral Extraction plugin and select the appropriate trace (Polynomial, order 3, on pixel 2), background (Manual, on pixel 8, width 2, statistic average), and extraction (From Plugin, Horne). We then click Extract and inspect the extracted spectrum in the 1D viewer.

specviz2d = Specviz2d()
specviz2d.load_data(file2d)
specviz2d.show()

Developer note
Is there a way to get out an uncertainty array from the extraction?
This is being worked on.

# Get out extracted spectrum from Specviz2d
spectra = specviz2d.get_data('Spectrum 1D')
spectra
<Spectrum1D(flux=[0.0 ... 0.0] MJy (shape=(1325,), mean=0.00000 MJy); spectral_axis=<SpectralAxis 
   (observer to target:
      radial_velocity=0.0 km / s
      redshift=0.0)
  [0.96262388 0.96262388 0.96262388 ... 1.89519827 1.89583322 1.89583322] um> (length=1325))>
# Include some fake uncertainty for now
spec1d = Spectrum1D(spectral_axis=spectra.spectral_axis,
                    flux=spectra.flux,
                    uncertainty=StdDevUncertainty((np.zeros(len(spectra.flux)) + 1E-13) * spectra.unit))
spec1d
<Spectrum1D(flux=[0.0 ... 0.0] MJy (shape=(1325,), mean=0.00000 MJy); spectral_axis=<SpectralAxis 
   (observer to target:
      radial_velocity=0.0 km / s
      redshift=0.0)
  [0.96262388 0.96262388 0.96262388 ... 1.89519827 1.89583322 1.89583322] um> (length=1325); uncertainty=StdDevUncertainty)>
# And open in Specviz
specviz = Specviz()
specviz.load_data(spec1d, data_label='spec1d calibrated')
specviz.show()

There are still some artifacts in the data, but we can select a subset masking the artifacts and get out a spectrum without unwanted spikes. We can do so using the tool to select a subset with the “add” option (in the top bar) to select multiple regions as part of a single subset.

# Create a subset in the area of interest if it has not been created manually
try:
    region1 = specviz.get_data(data_label='spec1d calibrated', spectral_subset='Subset 1')
    print(region1)
    region1_exists = True
except Exception:
    print("There are no subsets selected.")
    region1_exists = False
    
# Spectral region for masking artifacts
if not region1_exists:
    sv = specviz.app.get_viewer('spectrum-viewer')
    sv.toolbar_active_subset.selected = []
    sv.apply_roi(XRangeROI(1., 1.58))  
There are no subsets selected.
# Get spectrum out with mask
spec1d_region = specviz.get_spectral_regions()
spec1d_masked = extract_region(spec1d, spec1d_region['Subset 1'], return_single_spectrum=True)
# Load in specviz
specviz.load_data(spec1d_masked, data_label='spec1d masked')
# Write the extracted spectrum to a fits file
file_extracted = Path('./extracted_spectrum.fits')
spec1d_masked.write(file_extracted, overwrite=True)
# Check that it has everything
hdu = fits.open(file_extracted)
hdu.info()
Filename: extracted_spectrum.fits
No.    Name      Ver    Type      Cards   Dimensions   Format
  0  PRIMARY       1 PrimaryHDU       4   ()      
  1                1 BinTableHDU     17   911R x 3C   [D, D, D]   
hdu[1].data
FITS_rec([(1.00020414, 2.20226191e-13, 1.e-13),
          (1.0008411 , 7.11024936e-14, 1.e-13),
          (1.00149188, 3.35875760e-13, 1.e-13),
          (1.00212885, 2.73494495e-13, 1.e-13),
          (1.00276581, 2.33289362e-13, 1.e-13),
          (1.00340278, 2.08752581e-13, 1.e-13),
          (1.00403974, 3.60731324e-13, 1.e-13),
          (1.00467671, 2.91254772e-13, 1.e-13),
          (1.00531368, 3.54084183e-13, 1.e-13),
          (1.00595064, 1.58528613e-13, 1.e-13),
          (1.00658761, 1.00099923e-13, 1.e-13),
          (1.00722458, 1.93899402e-13, 1.e-13),
          (1.00786154, 2.71433068e-13, 1.e-13),
          (1.00849851, 5.44897721e-13, 1.e-13),
          (1.00913548, 2.77380637e-13, 1.e-13),
          (1.00977245, 5.20373636e-13, 1.e-13),
          (1.01040941, 3.18918981e-13, 1.e-13),
          (1.01104638, 2.26125943e-13, 1.e-13),
          (1.01168335, 3.19381799e-13, 1.e-13),
          (1.01232032, 3.14886887e-13, 1.e-13),
          (1.01295729, 2.44143994e-13, 1.e-13),
          (1.01359426, 4.88193151e-13, 1.e-13),
          (1.01423123, 2.53360983e-13, 1.e-13),
          (1.0148682 , 1.27069879e-13, 1.e-13),
          (1.01550516, 4.64169909e-13, 1.e-13),
          (1.01614213, 2.08450736e-13, 1.e-13),
          (1.0167791 , 2.73294743e-13, 1.e-13),
          (1.01741607, 3.41261670e-13, 1.e-13),
          (1.01806689, 1.28366805e-13, 1.e-13),
          (1.01870387, 2.49072251e-13, 1.e-13),
          (1.01934084, 1.26547081e-13, 1.e-13),
          (1.01997781, 1.97832808e-13, 1.e-13),
          (1.02061478, 1.62252138e-13, 1.e-13),
          (1.02125175, 1.70550677e-13, 1.e-13),
          (1.02188873, 4.56591770e-13, 1.e-13),
          (1.0225257 , 3.02788739e-13, 1.e-13),
          (1.02316267, 2.49439997e-13, 1.e-13),
          (1.02379965, 3.97524604e-13, 1.e-13),
          (1.02443662, 2.53102488e-13, 1.e-13),
          (1.02507359, 3.03111230e-13, 1.e-13),
          (1.02571057, 6.63408469e-14, 1.e-13),
          (1.02634754, 4.50355456e-14, 1.e-13),
          (1.02698451, 1.39524997e-13, 1.e-13),
          (1.02762149, 4.23035735e-13, 1.e-13),
          (1.02825846, 1.30840441e-13, 1.e-13),
          (1.02889544, 2.38858164e-13, 1.e-13),
          (1.02953241, 1.90624463e-13, 1.e-13),
          (1.03016938, 1.56144866e-13, 1.e-13),
          (1.03080636, 3.47522079e-13, 1.e-13),
          (1.03144333, 3.05209873e-13, 1.e-13),
          (1.03208031, 2.66962446e-13, 1.e-13),
          (1.03271728, 4.45226992e-13, 1.e-13),
          (1.03335426, 3.47891271e-13, 1.e-13),
          (1.03399123, 2.72119563e-13, 1.e-13),
          (1.03462821, 2.85247721e-13, 1.e-13),
          (1.03526518, 1.95890246e-13, 1.e-13),
          (1.03590216, 3.64113112e-13, 1.e-13),
          (1.03653913, 5.22469764e-13, 1.e-13),
          (1.03717611, 3.54889614e-13, 1.e-13),
          (1.03781308, 3.96473035e-13, 1.e-13),
          (1.03845006, 2.99263516e-13, 1.e-13),
          (1.03908704, 7.15882448e-14, 1.e-13),
          (1.03972401, 1.87265535e-13, 1.e-13),
          (1.04036099, 1.80539887e-13, 1.e-13),
          (1.04099796, 5.28958335e-13, 1.e-13),
          (1.04163494, 1.51612494e-13, 1.e-13),
          (1.04227191, 2.32234510e-13, 1.e-13),
          (1.04290889, 4.02132384e-13, 1.e-13),
          (1.04354587, 3.60423596e-13, 1.e-13),
          (1.04418284, 4.07250692e-13, 1.e-13),
          (1.04481982, 2.05864649e-13, 1.e-13),
          (1.0454568 , 8.58324407e-14, 1.e-13),
          (1.04609377, 3.64159481e-13, 1.e-13),
          (1.04673075, 1.32323051e-13, 1.e-13),
          (1.04736772, 2.38120456e-13, 1.e-13),
          (1.0480047 , 1.67463119e-13, 1.e-13),
          (1.04864168, 2.68398002e-13, 1.e-13),
          (1.04927865, 2.70872084e-13, 1.e-13),
          (1.04991563, 4.49884622e-13, 1.e-13),
          (1.05055261, 2.90386076e-13, 1.e-13),
          (1.05118958, 1.84278016e-13, 1.e-13),
          (1.05182656, 1.97502237e-13, 1.e-13),
          (1.05246354, 1.79450524e-13, 1.e-13),
          (1.05310051, 3.16555189e-13, 1.e-13),
          (1.05373749, 2.83794762e-13, 1.e-13),
          (1.05437446, 3.58840671e-13, 1.e-13),
          (1.05501144, 1.01462592e-13, 1.e-13),
          (1.05564842, 2.98397874e-13, 1.e-13),
          (1.05628539, 3.26516193e-13, 1.e-13),
          (1.05692237, 1.01659088e-13, 1.e-13),
          (1.05755935, 3.04582978e-13, 1.e-13),
          (1.05819632, 3.33097866e-13, 1.e-13),
          (1.0588333 , 1.78090829e-13, 1.e-13),
          (1.05947028, 2.45500165e-13, 1.e-13),
          (1.06010725, 4.97942802e-13, 1.e-13),
          (1.06074423, 4.88389341e-13, 1.e-13),
          (1.06139514, 4.00679570e-13, 1.e-13),
          (1.06203211, 3.34417938e-13, 1.e-13),
          (1.06266909, 1.70919045e-13, 1.e-13),
          (1.06330607, 1.65230117e-13, 1.e-13),
          (1.06394305, 4.36515868e-13, 1.e-13),
          (1.06458002, 2.81471403e-13, 1.e-13),
          (1.065217  , 3.37830819e-13, 1.e-13),
          (1.06585398, 4.27911614e-13, 1.e-13),
          (1.06649096, 2.76036147e-13, 1.e-13),
          (1.06712793, 3.11917183e-13, 1.e-13),
          (1.06776491, 3.31327270e-13, 1.e-13),
          (1.06840189, 1.81340533e-13, 1.e-13),
          (1.06903886, 4.90888931e-13, 1.e-13),
          (1.06967584, 2.67252941e-13, 1.e-13),
          (1.07031282, 2.32996195e-13, 1.e-13),
          (1.07094979, 1.66874857e-13, 1.e-13),
          (1.07158677, 1.53642859e-13, 1.e-13),
          (1.07222375, 3.56233580e-13, 1.e-13),
          (1.07286072, 4.79251782e-13, 1.e-13),
          (1.0734977 , 5.22163418e-13, 1.e-13),
          (1.07413468, 4.41704329e-13, 1.e-13),
          (1.07477165, 3.26611081e-13, 1.e-13),
          (1.07540863, 2.21805842e-13, 1.e-13),
          (1.0760456 , 2.31779499e-13, 1.e-13),
          (1.07668258, 3.57814161e-13, 1.e-13),
          (1.07731955, 4.05631637e-13, 1.e-13),
          (1.07795653, 4.09391098e-15, 1.e-13),
          (1.07860747, 7.48259747e-14, 1.e-13),
          (1.07924445, 3.82162280e-13, 1.e-13),
          (1.07988142, 2.79952022e-13, 1.e-13),
          (1.0805184 , 3.00224870e-13, 1.e-13),
          (1.08115538, 2.80047300e-13, 1.e-13),
          (1.08179235, 3.50226498e-13, 1.e-13),
          (1.08242933, 2.81212596e-13, 1.e-13),
          (1.0830663 , 1.69329891e-13, 1.e-13),
          (1.08370328, 2.98331475e-13, 1.e-13),
          (1.08434026, 2.02522585e-13, 1.e-13),
          (1.08497723, 2.38028432e-13, 1.e-13),
          (1.08561421, 2.94623541e-13, 1.e-13),
          (1.08625118, 1.98378133e-13, 1.e-13),
          (1.08688816, 2.79912249e-13, 1.e-13),
          (1.08752513, 4.76740118e-13, 1.e-13),
          (1.08816211, 3.27518460e-13, 1.e-13),
          (1.08879908, 3.77980941e-13, 1.e-13),
          (1.08943605, 1.56084517e-13, 1.e-13),
          (1.09007303, 4.87805261e-13, 1.e-13),
          (1.09071   , 4.12587606e-13, 1.e-13),
          (1.09134698, 4.41010049e-13, 1.e-13),
          (1.09198395, 3.51925040e-13, 1.e-13),
          (1.09262092, 4.43774334e-13, 1.e-13),
          (1.0932579 , 5.36644863e-13, 1.e-13),
          (1.09389487, 3.53419892e-13, 1.e-13),
          (1.09453184, 3.02046708e-13, 1.e-13),
          (1.09516882, 4.60493155e-13, 1.e-13),
          (1.09580579, 4.85328159e-13, 1.e-13),
          (1.09644276, 4.03150577e-13, 1.e-13),
          (1.09707973, 4.66453043e-13, 1.e-13),
          (1.0977167 , 4.20896813e-13, 1.e-13),
          (1.09835368, 4.34047978e-13, 1.e-13),
          (1.09899065, 2.69152230e-13, 1.e-13),
          (1.09962762, 5.57799040e-13, 1.e-13),
          (1.10026459, 3.75521510e-13, 1.e-13),
          (1.10090156, 1.60157684e-13, 1.e-13),
          (1.10153853, 3.90056351e-13, 1.e-13),
          (1.1021755 , 4.49673205e-13, 1.e-13),
          (1.10281247, 4.17112815e-13, 1.e-13),
          (1.10344944, 5.57487304e-13, 1.e-13),
          (1.10408641, 4.72369144e-13, 1.e-13),
          (1.10472338, 3.83054709e-13, 1.e-13),
          (1.10536035, 4.03284496e-13, 1.e-13),
          (1.10599732, 3.49443909e-13, 1.e-13),
          (1.10663429, 4.14028603e-13, 1.e-13),
          (1.10727126, 2.98529630e-13, 1.e-13),
          (1.10790822, 2.23500643e-13, 1.e-13),
          (1.10854519, 2.72224139e-13, 1.e-13),
          (1.10918216, 2.75031227e-13, 1.e-13),
          (1.10981913, 4.49926698e-13, 1.e-13),
          (1.1104561 , 5.17033445e-13, 1.e-13),
          (1.11109306, 3.77205709e-13, 1.e-13),
          (1.11173003, 5.14777195e-13, 1.e-13),
          (1.112367  , 3.45728148e-13, 1.e-13),
          (1.11300396, 4.78515955e-13, 1.e-13),
          (1.11364093, 4.41022423e-13, 1.e-13),
          (1.11427789, 3.15633798e-13, 1.e-13),
          (1.11491486, 4.60366515e-13, 1.e-13),
          (1.11555182, 4.59537498e-13, 1.e-13),
          (1.11618879, 3.57125795e-13, 1.e-13),
          (1.11682575, 4.71355585e-13, 1.e-13),
          (1.11746272, 5.39477170e-13, 1.e-13),
          (1.11809968, 4.71055690e-13, 1.e-13),
          (1.11873664, 2.58177902e-13, 1.e-13),
          (1.11937361, 1.64687286e-13, 1.e-13),
          (1.12001057, 4.36668862e-13, 1.e-13),
          (1.12064753, 3.92515244e-13, 1.e-13),
          (1.1212845 , 2.27476382e-13, 1.e-13),
          (1.12192146, 3.18172037e-13, 1.e-13),
          (1.12255842, 4.06247783e-13, 1.e-13),
          (1.12319538, 4.13594863e-13, 1.e-13),
          (1.12383234, 3.45983392e-13, 1.e-13),
          (1.1244693 , 4.04505634e-13, 1.e-13),
          (1.12510626, 3.43614649e-13, 1.e-13),
          (1.12574322, 6.68088553e-13, 1.e-13),
          (1.12639424, 7.26797843e-13, 1.e-13),
          (1.1270312 , 1.02647395e-12, 1.e-13),
          (1.12766816, 1.35566790e-12, 1.e-13),
          (1.12830512, 1.11219154e-12, 1.e-13),
          (1.12894208, 7.09701231e-13, 1.e-13),
          (1.12957904, 5.88944366e-13, 1.e-13),
          (1.130216  , 3.44075404e-13, 1.e-13),
          (1.13085296, 4.79117942e-13, 1.e-13),
          (1.13148991, 3.68676437e-13, 1.e-13),
          (1.13212687, 4.17866740e-13, 1.e-13),
          (1.13276383, 3.21985728e-13, 1.e-13),
          (1.13340079, 3.89816289e-13, 1.e-13),
          (1.13403774, 3.65957736e-13, 1.e-13),
          (1.1346747 , 3.33283158e-13, 1.e-13),
          (1.13531166, 3.55083953e-13, 1.e-13),
          (1.13594861, 5.91551296e-13, 1.e-13),
          (1.13658557, 4.47070259e-13, 1.e-13),
          (1.13722252, 5.73471459e-13, 1.e-13),
          (1.13785948, 5.68602253e-13, 1.e-13),
          (1.13849643, 5.00111671e-13, 1.e-13),
          (1.13913339, 4.35416450e-13, 1.e-13),
          (1.13977034, 2.84418065e-13, 1.e-13),
          (1.14040729, 4.52535860e-13, 1.e-13),
          (1.14104425, 5.45833725e-13, 1.e-13),
          (1.1416812 , 4.96246994e-13, 1.e-13),
          (1.14231815, 3.36758488e-13, 1.e-13),
          (1.1429551 , 5.51705227e-13, 1.e-13),
          (1.14359205, 7.45589405e-13, 1.e-13),
          (1.144229  , 6.98371932e-13, 1.e-13),
          (1.14486595, 6.56632122e-13, 1.e-13),
          (1.14551699, 7.82987859e-13, 1.e-13),
          (1.14615394, 6.46901991e-13, 1.e-13),
          (1.14679089, 5.42259047e-13, 1.e-13),
          (1.14742784, 4.51682342e-13, 1.e-13),
          (1.14806479, 4.81228676e-13, 1.e-13),
          (1.14870174, 5.44249697e-13, 1.e-13),
          (1.14933869, 3.04091916e-13, 1.e-13),
          (1.14997564, 4.05739575e-13, 1.e-13),
          (1.15061259, 4.56585692e-13, 1.e-13),
          (1.15124953, 4.88541726e-13, 1.e-13),
          (1.15188648, 5.04249058e-13, 1.e-13),
          (1.15252343, 5.77207197e-13, 1.e-13),
          (1.15316037, 5.67643641e-13, 1.e-13),
          (1.15379732, 7.93678610e-13, 1.e-13),
          (1.15443426, 7.54212908e-13, 1.e-13),
          (1.15507121, 8.45107557e-13, 1.e-13),
          (1.15570815, 8.26016970e-13, 1.e-13),
          (1.1563451 , 8.62169408e-13, 1.e-13),
          (1.15698204, 6.18060482e-13, 1.e-13),
          (1.15761898, 6.24817299e-13, 1.e-13),
          (1.15825592, 5.32213718e-13, 1.e-13),
          (1.15889287, 6.99702682e-13, 1.e-13),
          (1.15952981, 6.52652994e-13, 1.e-13),
          (1.16016675, 5.38442732e-13, 1.e-13),
          (1.16080369, 4.31362150e-13, 1.e-13),
          (1.16144063, 3.40311832e-13, 1.e-13),
          (1.16207757, 4.29430448e-13, 1.e-13),
          (1.16271451, 6.20946174e-13, 1.e-13),
          (1.16335144, 6.21408236e-13, 1.e-13),
          (1.16398838, 6.93829160e-13, 1.e-13),
          (1.16462532, 7.22670083e-13, 1.e-13),
          (1.16526226, 6.57540181e-13, 1.e-13),
          (1.16589919, 6.15419791e-13, 1.e-13),
          (1.16653613, 6.91254856e-13, 1.e-13),
          (1.16717306, 6.55687150e-13, 1.e-13),
          (1.16781   , 9.88001222e-13, 1.e-13),
          (1.16844693, 8.89964926e-13, 1.e-13),
          (1.16908387, 9.15438730e-13, 1.e-13),
          (1.1697208 , 9.79759846e-13, 1.e-13),
          (1.17035773, 9.94234731e-13, 1.e-13),
          (1.17099467, 1.01260039e-12, 1.e-13),
          (1.1716316 , 9.01097130e-13, 1.e-13),
          (1.17226853, 1.06732534e-12, 1.e-13),
          (1.17290546, 8.26004028e-13, 1.e-13),
          (1.17354239, 7.37443931e-13, 1.e-13),
          (1.17417932, 6.34469860e-13, 1.e-13),
          (1.17481625, 6.11196615e-13, 1.e-13),
          (1.17545318, 6.07083641e-13, 1.e-13),
          (1.1760901 , 4.84819533e-13, 1.e-13),
          (1.17672703, 2.52542002e-13, 1.e-13),
          (1.17736396, 3.62636719e-13, 1.e-13),
          (1.17800088, 3.58695834e-13, 1.e-13),
          (1.17863781, 5.30236188e-13, 1.e-13),
          (1.17927474, 5.89884451e-13, 1.e-13),
          (1.17991166, 5.28850538e-13, 1.e-13),
          (1.18054858, 4.87772924e-13, 1.e-13),
          (1.18118551, 6.05768150e-13, 1.e-13),
          (1.18182243, 8.04558113e-13, 1.e-13),
          (1.18245935, 1.15401964e-12, 1.e-13),
          (1.18309628, 8.73469938e-13, 1.e-13),
          (1.1837332 , 8.90579680e-13, 1.e-13),
          (1.18437012, 8.77589475e-13, 1.e-13),
          (1.18500704, 8.13590424e-13, 1.e-13),
          (1.18564396, 8.72015191e-13, 1.e-13),
          (1.18628088, 8.68059519e-13, 1.e-13),
          (1.18691779, 1.07781649e-12, 1.e-13),
          (1.18755471, 8.81699998e-13, 1.e-13),
          (1.18819163, 5.80767481e-13, 1.e-13),
          (1.18882855, 5.71175568e-13, 1.e-13),
          (1.18946546, 5.93353996e-13, 1.e-13),
          (1.19010238, 6.01578988e-13, 1.e-13),
          (1.19073929, 4.78701849e-13, 1.e-13),
          (1.19137621, 7.66148406e-13, 1.e-13),
          (1.19201312, 7.66950918e-13, 1.e-13),
          (1.19265003, 6.60555840e-13, 1.e-13),
          (1.19328694, 7.04460744e-13, 1.e-13),
          (1.19392386, 6.15648398e-13, 1.e-13),
          (1.19456077, 8.09748504e-13, 1.e-13),
          (1.19519768, 6.85802060e-13, 1.e-13),
          (1.19583459, 7.09985663e-13, 1.e-13),
          (1.1964715 , 7.36797096e-13, 1.e-13),
          (1.19710841, 6.76080645e-13, 1.e-13),
          (1.19774531, 6.74077883e-13, 1.e-13),
          (1.19838222, 6.16646818e-13, 1.e-13),
          (1.19903332, 5.78564532e-13, 1.e-13),
          (1.19967022, 3.85148788e-13, 1.e-13),
          (1.20030713, 3.58329469e-13, 1.e-13),
          (1.20094404, 6.88216371e-13, 1.e-13),
          (1.20158094, 2.01044678e-13, 1.e-13),
          (1.20221785, 2.91833933e-13, 1.e-13),
          (1.20285475, 5.08608957e-13, 1.e-13),
          (1.20349165, 6.75650298e-13, 1.e-13),
          (1.20412856, 7.19989477e-13, 1.e-13),
          (1.20476546, 8.48415740e-13, 1.e-13),
          (1.20540236, 6.47505770e-13, 1.e-13),
          (1.20603926, 6.06798682e-13, 1.e-13),
          (1.20667616, 5.65372771e-13, 1.e-13),
          (1.20731306, 6.66720700e-13, 1.e-13),
          (1.20794996, 6.64022075e-13, 1.e-13),
          (1.20858686, 7.96373765e-13, 1.e-13),
          (1.20922375, 7.83601084e-13, 1.e-13),
          (1.20986065, 6.28620782e-13, 1.e-13),
          (1.21049755, 6.65820264e-13, 1.e-13),
          (1.21113444, 8.10991477e-13, 1.e-13),
          (1.21177134, 1.12044211e-12, 1.e-13),
          (1.21240823, 1.23266757e-12, 1.e-13),
          (1.21304512, 1.30867330e-12, 1.e-13),
          (1.21368202, 1.11527540e-12, 1.e-13),
          (1.21431891, 7.02505830e-13, 1.e-13),
          (1.2149558 , 7.58094836e-13, 1.e-13),
          (1.21559269, 8.70156171e-13, 1.e-13),
          (1.21622958, 6.99432686e-13, 1.e-13),
          (1.21686647, 1.02199437e-12, 1.e-13),
          (1.21750336, 8.14122151e-13, 1.e-13),
          (1.21814024, 9.30280485e-13, 1.e-13),
          (1.21877713, 9.36998475e-13, 1.e-13),
          (1.21941402, 8.79586976e-13, 1.e-13),
          (1.22006513, 1.09553431e-12, 1.e-13),
          (1.22070202, 1.08331052e-12, 1.e-13),
          (1.2213389 , 1.15951308e-12, 1.e-13),
          (1.22197579, 1.01063784e-12, 1.e-13),
          (1.22261267, 8.00462840e-13, 1.e-13),
          (1.22324955, 9.45203676e-13, 1.e-13),
          (1.22388643, 8.56253876e-13, 1.e-13),
          (1.22452332, 1.03363840e-12, 1.e-13),
          (1.2251602 , 8.09953287e-13, 1.e-13),
          (1.22579708, 8.30163275e-13, 1.e-13),
          (1.22643396, 8.10837625e-13, 1.e-13),
          (1.22707083, 8.64276105e-13, 1.e-13),
          (1.22770771, 8.32194438e-13, 1.e-13),
          (1.22834459, 9.38323343e-13, 1.e-13),
          (1.22898146, 8.48516739e-13, 1.e-13),
          (1.22961834, 9.24011939e-13, 1.e-13),
          (1.23025521, 7.40206422e-13, 1.e-13),
          (1.23089209, 8.71513488e-13, 1.e-13),
          (1.23152896, 1.02335713e-12, 1.e-13),
          (1.23216583, 1.08035828e-12, 1.e-13),
          (1.23280271, 1.02178728e-12, 1.e-13),
          (1.23343958, 8.96742101e-13, 1.e-13),
          (1.23407645, 7.25233319e-13, 1.e-13),
          (1.23471332, 9.40153242e-13, 1.e-13),
          (1.23535018, 8.89781131e-13, 1.e-13),
          (1.23598705, 7.44040690e-13, 1.e-13),
          (1.23662392, 7.71931994e-13, 1.e-13),
          (1.23726078, 5.98854781e-13, 1.e-13),
          (1.23789765, 9.15759433e-13, 1.e-13),
          (1.23853451, 7.35240220e-13, 1.e-13),
          (1.23917138, 5.97180351e-13, 1.e-13),
          (1.23980824, 5.53652167e-13, 1.e-13),
          (1.2404451 , 5.19108648e-13, 1.e-13),
          (1.24108196, 6.35684304e-13, 1.e-13),
          (1.24171882, 8.64535789e-13, 1.e-13),
          (1.24235568, 5.54112249e-13, 1.e-13),
          (1.24299254, 6.85167108e-13, 1.e-13),
          (1.2436294 , 9.77341773e-13, 1.e-13),
          (1.24426626, 7.49452161e-13, 1.e-13),
          (1.24490311, 7.16886097e-13, 1.e-13),
          (1.24553997, 1.00827328e-12, 1.e-13),
          (1.24617683, 5.48718152e-13, 1.e-13),
          (1.24681368, 7.68007073e-13, 1.e-13),
          (1.24745053, 6.22569841e-13, 1.e-13),
          (1.24808738, 6.85560648e-13, 1.e-13),
          (1.24872424, 1.13240405e-12, 1.e-13),
          (1.24936109, 9.34135506e-13, 1.e-13),
          (1.24999794, 6.59118950e-13, 1.e-13),
          (1.25063478, 6.61413653e-13, 1.e-13),
          (1.25127163, 8.38442593e-13, 1.e-13),
          (1.25190848, 8.00919548e-13, 1.e-13),
          (1.25254533, 8.79331486e-13, 1.e-13),
          (1.25318217, 8.47567667e-13, 1.e-13),
          (1.25381902, 9.14539723e-13, 1.e-13),
          (1.25445586, 9.67988537e-13, 1.e-13),
          (1.2550927 , 8.84173404e-13, 1.e-13),
          (1.25572955, 8.71136028e-13, 1.e-13),
          (1.25636639, 9.17617424e-13, 1.e-13),
          (1.25700323, 7.46035154e-13, 1.e-13),
          (1.25764007, 1.10956686e-12, 1.e-13),
          (1.2582769 , 1.06695331e-12, 1.e-13),
          (1.25891374, 8.98392197e-13, 1.e-13),
          (1.25955058, 7.14786070e-13, 1.e-13),
          (1.26018742, 9.03643173e-13, 1.e-13),
          (1.26082425, 9.52279988e-13, 1.e-13),
          (1.26146108, 8.62454019e-13, 1.e-13),
          (1.26209792, 9.21385679e-13, 1.e-13),
          (1.26273475, 1.11029095e-12, 1.e-13),
          (1.26337158, 8.66299543e-13, 1.e-13),
          (1.26400841, 9.89356609e-13, 1.e-13),
          (1.26464524, 9.28098908e-13, 1.e-13),
          (1.26528207, 9.11408630e-13, 1.e-13),
          (1.2659189 , 8.56994858e-13, 1.e-13),
          (1.26655573, 7.50266908e-13, 1.e-13),
          (1.26719255, 7.39715298e-13, 1.e-13),
          (1.26782938, 7.64548293e-13, 1.e-13),
          (1.2684662 , 1.06161603e-12, 1.e-13),
          (1.26910303, 9.15607191e-13, 1.e-13),
          (1.26973985, 9.27040003e-13, 1.e-13),
          (1.27037667, 8.84990629e-13, 1.e-13),
          (1.27101349, 7.75891150e-13, 1.e-13),
          (1.27165031, 6.32565320e-13, 1.e-13),
          (1.27228713, 9.89772042e-13, 1.e-13),
          (1.27292395, 1.18577974e-12, 1.e-13),
          (1.27356076, 1.04398881e-12, 1.e-13),
          (1.27419758, 8.89956515e-13, 1.e-13),
          (1.27483439, 9.00161996e-13, 1.e-13),
          (1.27547121, 9.74916391e-13, 1.e-13),
          (1.27610802, 8.60085960e-13, 1.e-13),
          (1.27674483, 8.02069755e-13, 1.e-13),
          (1.27738164, 8.87388251e-13, 1.e-13),
          (1.27801846, 1.01524164e-12, 1.e-13),
          (1.27865526, 6.18743023e-13, 1.e-13),
          (1.27929207, 7.38965341e-13, 1.e-13),
          (1.27992888, 7.97536913e-13, 1.e-13),
          (1.28056569, 9.90258419e-13, 1.e-13),
          (1.28120249, 1.17000078e-12, 1.e-13),
          (1.28185364, 1.02648386e-12, 1.e-13),
          (1.28249044, 1.19427100e-12, 1.e-13),
          (1.28312725, 9.84335103e-13, 1.e-13),
          (1.28376405, 9.53841247e-13, 1.e-13),
          (1.28440085, 9.93056464e-13, 1.e-13),
          (1.28503765, 8.53236163e-13, 1.e-13),
          (1.28567445, 8.85119626e-13, 1.e-13),
          (1.28631125, 1.16445369e-12, 1.e-13),
          (1.28694805, 1.22363148e-12, 1.e-13),
          (1.28758485, 1.03096165e-12, 1.e-13),
          (1.28822164, 1.07026760e-12, 1.e-13),
          (1.28885844, 1.12604864e-12, 1.e-13),
          (1.28949523, 1.03368151e-12, 1.e-13),
          (1.29013203, 1.10047147e-12, 1.e-13),
          (1.29076882, 9.57451525e-13, 1.e-13),
          (1.29140561, 8.33634516e-13, 1.e-13),
          (1.2920424 , 1.19444332e-12, 1.e-13),
          (1.29267919, 8.93767231e-13, 1.e-13),
          (1.29331598, 7.54645970e-13, 1.e-13),
          (1.29395276, 7.94192900e-13, 1.e-13),
          (1.29458955, 8.98734498e-13, 1.e-13),
          (1.29522633, 7.98732560e-13, 1.e-13),
          (1.29586312, 7.51720467e-13, 1.e-13),
          (1.2964999 , 9.46332378e-13, 1.e-13),
          (1.29713668, 8.55455579e-13, 1.e-13),
          (1.29777346, 7.69154924e-13, 1.e-13),
          (1.29841024, 1.01897425e-12, 1.e-13),
          (1.29904702, 9.37057926e-13, 1.e-13),
          (1.2996838 , 1.00974654e-12, 1.e-13),
          (1.30032058, 9.35608301e-13, 1.e-13),
          (1.30095735, 1.01986258e-12, 1.e-13),
          (1.30159413, 6.96574722e-13, 1.e-13),
          (1.3022309 , 1.04751479e-12, 1.e-13),
          (1.30286768, 9.26731420e-13, 1.e-13),
          (1.30350445, 9.15015395e-13, 1.e-13),
          (1.30414122, 1.10150972e-12, 1.e-13),
          (1.30477799, 9.72608185e-13, 1.e-13),
          (1.30541476, 7.61942665e-13, 1.e-13),
          (1.30606591, 7.72339569e-13, 1.e-13),
          (1.30670268, 7.84004052e-13, 1.e-13),
          (1.30733944, 9.06393496e-13, 1.e-13),
          (1.30797621, 7.09397767e-13, 1.e-13),
          (1.30861297, 7.64546641e-13, 1.e-13),
          (1.30924974, 8.94010909e-13, 1.e-13),
          (1.3098865 , 8.33916329e-13, 1.e-13),
          (1.31052326, 9.69158778e-13, 1.e-13),
          (1.31116002, 8.08510168e-13, 1.e-13),
          (1.31179678, 9.22004520e-13, 1.e-13),
          (1.31243354, 9.44797741e-13, 1.e-13),
          (1.3130703 , 8.48408068e-13, 1.e-13),
          (1.31370705, 9.63737370e-13, 1.e-13),
          (1.31434381, 8.03723133e-13, 1.e-13),
          (1.31498056, 7.03939344e-13, 1.e-13),
          (1.31561731, 8.77277526e-13, 1.e-13),
          (1.31625406, 8.62186176e-13, 1.e-13),
          (1.31689081, 8.78680019e-13, 1.e-13),
          (1.31752756, 1.04552273e-12, 1.e-13),
          (1.31816431, 9.60897105e-13, 1.e-13),
          (1.31880106, 1.06430740e-12, 1.e-13),
          (1.31943781, 1.16119243e-12, 1.e-13),
          (1.32007455, 1.13166703e-12, 1.e-13),
          (1.32071129, 1.19158977e-12, 1.e-13),
          (1.32134804, 1.20805581e-12, 1.e-13),
          (1.32198478, 1.30714584e-12, 1.e-13),
          (1.32262152, 1.14920939e-12, 1.e-13),
          (1.32325826, 1.10378227e-12, 1.e-13),
          (1.323895  , 1.00761762e-12, 1.e-13),
          (1.32453173, 1.18166792e-12, 1.e-13),
          (1.32516847, 1.26814310e-12, 1.e-13),
          (1.32580521, 1.28366633e-12, 1.e-13),
          (1.32644194, 1.03152899e-12, 1.e-13),
          (1.32707867, 1.02654372e-12, 1.e-13),
          (1.3277154 , 8.35346659e-13, 1.e-13),
          (1.32835213, 8.19012233e-13, 1.e-13),
          (1.32898886, 1.04689069e-12, 1.e-13),
          (1.32962559, 1.04973991e-12, 1.e-13),
          (1.33026232, 1.02657570e-12, 1.e-13),
          (1.33089905, 8.98608670e-13, 1.e-13),
          (1.33153577, 8.31842825e-13, 1.e-13),
          (1.33217249, 1.22400221e-12, 1.e-13),
          (1.33280922, 1.10676448e-12, 1.e-13),
          (1.33344594, 1.13826562e-12, 1.e-13),
          (1.33408266, 1.09218953e-12, 1.e-13),
          (1.33471938, 9.36486095e-13, 1.e-13),
          (1.33535609, 1.22253644e-12, 1.e-13),
          (1.33599281, 9.13110984e-13, 1.e-13),
          (1.33662953, 1.04634183e-12, 1.e-13),
          (1.33726624, 1.20789105e-12, 1.e-13),
          (1.33790295, 1.26122197e-12, 1.e-13),
          (1.33853967, 1.07910170e-12, 1.e-13),
          (1.33917638, 1.17340836e-12, 1.e-13),
          (1.33981309, 9.47190705e-13, 1.e-13),
          (1.3404498 , 1.13123636e-12, 1.e-13),
          (1.3410865 , 1.03837411e-12, 1.e-13),
          (1.34172321, 9.62890581e-13, 1.e-13),
          (1.34235991, 1.19733692e-12, 1.e-13),
          (1.34299662, 1.20627294e-12, 1.e-13),
          (1.34363332, 1.09672658e-12, 1.e-13),
          (1.34427002, 1.18166775e-12, 1.e-13),
          (1.34490672, 1.11828396e-12, 1.e-13),
          (1.34554342, 1.13693025e-12, 1.e-13),
          (1.34618012, 1.29280645e-12, 1.e-13),
          (1.34681682, 1.06980022e-12, 1.e-13),
          (1.34745351, 1.35814459e-12, 1.e-13),
          (1.34809021, 1.07621091e-12, 1.e-13),
          (1.3487269 , 6.26559202e-13, 1.e-13),
          (1.34936359, 9.71435567e-13, 1.e-13),
          (1.35000028, 9.52522870e-13, 1.e-13),
          (1.35063697, 1.07006553e-12, 1.e-13),
          (1.35127366, 1.37496256e-12, 1.e-13),
          (1.35191035, 1.39035489e-12, 1.e-13),
          (1.35254703, 8.66423693e-13, 1.e-13),
          (1.35318372, 8.30276554e-13, 1.e-13),
          (1.3538204 , 1.05544848e-12, 1.e-13),
          (1.35445708, 1.12344669e-12, 1.e-13),
          (1.35509376, 1.15965136e-12, 1.e-13),
          (1.35573044, 1.06483062e-12, 1.e-13),
          (1.35636712, 1.18321238e-12, 1.e-13),
          (1.3570038 , 1.04598282e-12, 1.e-13),
          (1.35764048, 1.12324243e-12, 1.e-13),
          (1.35827715, 9.69551814e-13, 1.e-13),
          (1.35891383, 1.15289971e-12, 1.e-13),
          (1.3595505 , 1.13725717e-12, 1.e-13),
          (1.36018717, 9.41679714e-13, 1.e-13),
          (1.36082384, 9.29132473e-13, 1.e-13),
          (1.36146051, 7.46452464e-13, 1.e-13),
          (1.36209717, 9.77903315e-13, 1.e-13),
          (1.36273384, 1.10213736e-12, 1.e-13),
          (1.36337051, 9.49032055e-13, 1.e-13),
          (1.36400717, 8.62678140e-13, 1.e-13),
          (1.36464383, 1.27600776e-12, 1.e-13),
          (1.36528049, 1.02271550e-12, 1.e-13),
          (1.36591715, 8.82500572e-13, 1.e-13),
          (1.36655381, 1.24856684e-12, 1.e-13),
          (1.36719047, 1.22640803e-12, 1.e-13),
          (1.36782712, 8.73402680e-13, 1.e-13),
          (1.36846378, 9.98561531e-13, 1.e-13),
          (1.36910043, 1.17403622e-12, 1.e-13),
          (1.36973708, 1.00015315e-12, 1.e-13),
          (1.37037374, 1.01594213e-12, 1.e-13),
          (1.37101039, 9.43258296e-13, 1.e-13),
          (1.37164703, 1.17112682e-12, 1.e-13),
          (1.37228368, 1.03856218e-12, 1.e-13),
          (1.37292033, 9.87301224e-13, 1.e-13),
          (1.37355697, 9.36996469e-13, 1.e-13),
          (1.37419361, 9.60100704e-13, 1.e-13),
          (1.37483026, 9.59715416e-13, 1.e-13),
          (1.3754669 , 9.79019099e-13, 1.e-13),
          (1.37610354, 1.07962563e-12, 1.e-13),
          (1.37674017, 8.31787822e-13, 1.e-13),
          (1.37737681, 1.04540979e-12, 1.e-13),
          (1.37801345, 8.60026467e-13, 1.e-13),
          (1.37865008, 1.02023940e-12, 1.e-13),
          (1.37928671, 7.94706793e-13, 1.e-13),
          (1.37992335, 8.26109474e-13, 1.e-13),
          (1.38055998, 8.60370401e-13, 1.e-13),
          (1.38121112, 1.10975329e-12, 1.e-13),
          (1.38184775, 9.13354282e-13, 1.e-13),
          (1.38248438, 8.47944845e-13, 1.e-13),
          (1.38312101, 1.44714337e-12, 1.e-13),
          (1.38375763, 1.31503603e-12, 1.e-13),
          (1.38439425, 1.20363212e-12, 1.e-13),
          (1.38503088, 6.96691237e-13, 1.e-13),
          (1.3856675 , 9.88341785e-13, 1.e-13),
          (1.38630412, 1.03302120e-12, 1.e-13),
          (1.38694073, 8.38949298e-13, 1.e-13),
          (1.38757735, 1.06097795e-12, 1.e-13),
          (1.38821397, 8.48083748e-13, 1.e-13),
          (1.38885058, 1.05704988e-12, 1.e-13),
          (1.38948719, 1.32204097e-12, 1.e-13),
          (1.39012381, 8.97913701e-13, 1.e-13),
          (1.39076042, 1.13397091e-12, 1.e-13),
          (1.39139702, 1.22921786e-12, 1.e-13),
          (1.39203363, 7.58023573e-13, 1.e-13),
          (1.39267024, 9.41891803e-13, 1.e-13),
          (1.39330684, 1.09345972e-12, 1.e-13),
          (1.39394345, 1.10828120e-12, 1.e-13),
          (1.39458005, 1.17248358e-12, 1.e-13),
          (1.39521665, 1.28783066e-12, 1.e-13),
          (1.39585325, 1.20558809e-12, 1.e-13),
          (1.39648985, 1.09493213e-12, 1.e-13),
          (1.39712644, 1.05847797e-12, 1.e-13),
          (1.39776304, 1.18929945e-12, 1.e-13),
          (1.39839963, 1.37758090e-12, 1.e-13),
          (1.39903622, 9.87098667e-13, 1.e-13),
          (1.39967281, 1.14005933e-12, 1.e-13),
          (1.4003094 , 1.11727713e-12, 1.e-13),
          (1.40094599, 8.90115299e-13, 1.e-13),
          (1.40158258, 1.09545796e-12, 1.e-13),
          (1.40221917, 1.09432519e-12, 1.e-13),
          (1.40285575, 1.09527812e-12, 1.e-13),
          (1.40349233, 1.04127303e-12, 1.e-13),
          (1.40412891, 9.72140217e-13, 1.e-13),
          (1.40476549, 9.03609845e-13, 1.e-13),
          (1.40540207, 1.00311023e-12, 1.e-13),
          (1.40603865, 1.01099052e-12, 1.e-13),
          (1.40667522, 1.09415815e-12, 1.e-13),
          (1.4073118 , 1.26392381e-12, 1.e-13),
          (1.40794837, 1.40872835e-12, 1.e-13),
          (1.40858494, 1.46406917e-12, 1.e-13),
          (1.40922151, 1.19953886e-12, 1.e-13),
          (1.40985808, 9.57981081e-13, 1.e-13),
          (1.41050922, 1.09847894e-12, 1.e-13),
          (1.41114579, 1.35403099e-12, 1.e-13),
          (1.41178235, 1.23490859e-12, 1.e-13),
          (1.41241892, 1.14381071e-12, 1.e-13),
          (1.41305548, 1.35290000e-12, 1.e-13),
          (1.41369204, 1.11417851e-12, 1.e-13),
          (1.4143286 , 1.30689152e-12, 1.e-13),
          (1.41496516, 1.00952972e-12, 1.e-13),
          (1.41560172, 9.86333905e-13, 1.e-13),
          (1.41623827, 8.43888232e-13, 1.e-13),
          (1.41687483, 8.88582693e-13, 1.e-13),
          (1.41751138, 1.19119778e-12, 1.e-13),
          (1.41814793, 9.07212282e-13, 1.e-13),
          (1.41878448, 1.03499743e-12, 1.e-13),
          (1.41942103, 1.13177552e-12, 1.e-13),
          (1.42005758, 1.11048255e-12, 1.e-13),
          (1.42069412, 1.48683676e-12, 1.e-13),
          (1.42133067, 1.28035553e-12, 1.e-13),
          (1.42196721, 1.27675060e-12, 1.e-13),
          (1.42260375, 1.28293350e-12, 1.e-13),
          (1.42324029, 1.29120048e-12, 1.e-13),
          (1.42387683, 9.54445968e-13, 1.e-13),
          (1.42451337, 1.17163184e-12, 1.e-13),
          (1.4251499 , 1.24264572e-12, 1.e-13),
          (1.42578644, 1.15768268e-12, 1.e-13),
          (1.42642297, 1.23348484e-12, 1.e-13),
          (1.4270595 , 1.45030695e-12, 1.e-13),
          (1.42769603, 1.25919299e-12, 1.e-13),
          (1.42833256, 1.18950733e-12, 1.e-13),
          (1.42896908, 1.10252556e-12, 1.e-13),
          (1.42960561, 1.01185540e-12, 1.e-13),
          (1.43024213, 1.01721465e-12, 1.e-13),
          (1.43087865, 1.26783126e-12, 1.e-13),
          (1.43151518, 1.04984718e-12, 1.e-13),
          (1.43215169, 9.21372106e-13, 1.e-13),
          (1.43278821, 1.09859842e-12, 1.e-13),
          (1.43342473, 1.42679243e-12, 1.e-13),
          (1.43406124, 1.43471018e-12, 1.e-13),
          (1.43469776, 1.51705059e-12, 1.e-13),
          (1.43533427, 1.17289291e-12, 1.e-13),
          (1.43597078, 1.09981190e-12, 1.e-13),
          (1.43660729, 9.81460962e-13, 1.e-13),
          (1.4372438 , 1.08909781e-12, 1.e-13),
          (1.4378803 , 1.07196742e-12, 1.e-13),
          (1.43851681, 9.57634632e-13, 1.e-13),
          (1.43915331, 1.09889494e-12, 1.e-13),
          (1.43978981, 1.31640406e-12, 1.e-13),
          (1.44042631, 1.25044385e-12, 1.e-13),
          (1.44106281, 1.14196824e-12, 1.e-13),
          (1.4416993 , 1.31891167e-12, 1.e-13),
          (1.4423358 , 1.29474910e-12, 1.e-13),
          (1.44297229, 1.13865618e-12, 1.e-13),
          (1.44360879, 1.28473725e-12, 1.e-13),
          (1.44424528, 1.19980277e-12, 1.e-13),
          (1.44488177, 1.28620453e-12, 1.e-13),
          (1.44551825, 1.12318992e-12, 1.e-13),
          (1.44615474, 1.23979590e-12, 1.e-13),
          (1.44679122, 1.32736836e-12, 1.e-13),
          (1.44742771, 1.47070666e-12, 1.e-13),
          (1.44806419, 1.35141282e-12, 1.e-13),
          (1.44870067, 1.22585894e-12, 1.e-13),
          (1.44933715, 1.55837593e-12, 1.e-13),
          (1.44997362, 9.52491309e-13, 1.e-13),
          (1.4506101 , 1.54855209e-12, 1.e-13),
          (1.45124657, 1.29025682e-12, 1.e-13),
          (1.45188305, 1.08027161e-12, 1.e-13),
          (1.45251952, 1.14187134e-12, 1.e-13),
          (1.45315599, 1.09022166e-12, 1.e-13),
          (1.45379245, 1.29252229e-12, 1.e-13),
          (1.45442892, 9.88965152e-13, 1.e-13),
          (1.45506538, 1.12055557e-12, 1.e-13),
          (1.45570185, 1.16063969e-12, 1.e-13),
          (1.45633831, 1.39526446e-12, 1.e-13),
          (1.45697477, 1.50320645e-12, 1.e-13),
          (1.45761123, 1.21814463e-12, 1.e-13),
          (1.45824768, 1.51711049e-12, 1.e-13),
          (1.45888414, 1.08606273e-12, 1.e-13),
          (1.45952059, 1.48396865e-12, 1.e-13),
          (1.46015704, 1.57185454e-12, 1.e-13),
          (1.46079349, 1.49590666e-12, 1.e-13),
          (1.46142994, 1.55912032e-12, 1.e-13),
          (1.46206639, 1.20336349e-12, 1.e-13),
          (1.46270284, 1.04838505e-12, 1.e-13),
          (1.46333928, 1.15948622e-12, 1.e-13),
          (1.46397572, 1.10423527e-12, 1.e-13),
          (1.46461216, 1.34092609e-12, 1.e-13),
          (1.4652486 , 1.40043122e-12, 1.e-13),
          (1.46588504, 1.53332348e-12, 1.e-13),
          (1.46652148, 1.47538688e-12, 1.e-13),
          (1.46715791, 1.11526209e-12, 1.e-13),
          (1.46779435, 1.01838677e-12, 1.e-13),
          (1.46843078, 1.13285858e-12, 1.e-13),
          (1.46906721, 1.31776474e-12, 1.e-13),
          (1.46970363, 1.39249031e-12, 1.e-13),
          (1.47034006, 1.33155046e-12, 1.e-13),
          (1.47097649, 1.32473241e-12, 1.e-13),
          (1.47161291, 1.24421349e-12, 1.e-13),
          (1.47224933, 1.09745776e-12, 1.e-13),
          (1.47288575, 1.26052514e-12, 1.e-13),
          (1.47352217, 1.17358220e-12, 1.e-13),
          (1.47415859, 1.13640366e-12, 1.e-13),
          (1.474795  , 1.40585733e-12, 1.e-13),
          (1.47543142, 1.37274180e-12, 1.e-13),
          (1.47606783, 1.32244487e-12, 1.e-13),
          (1.47670424, 1.22002663e-12, 1.e-13),
          (1.47734065, 1.52478023e-12, 1.e-13),
          (1.47797705, 8.49829899e-13, 1.e-13),
          (1.47861346, 8.69912100e-13, 1.e-13),
          (1.47924986, 1.00716769e-12, 1.e-13),
          (1.47988627, 9.67983455e-13, 1.e-13),
          (1.48052267, 9.54796774e-13, 1.e-13),
          (1.48115907, 1.16924058e-12, 1.e-13),
          (1.48179546, 1.12130659e-12, 1.e-13),
          (1.48243186, 1.14240787e-12, 1.e-13),
          (1.48306825, 1.07037677e-12, 1.e-13),
          (1.48370465, 1.01109388e-12, 1.e-13),
          (1.48434104, 9.66803754e-13, 1.e-13),
          (1.48497743, 8.81546348e-13, 1.e-13),
          (1.48561381, 1.22181583e-12, 1.e-13),
          (1.4862502 , 1.50122081e-12, 1.e-13),
          (1.48688658, 1.22797532e-12, 1.e-13),
          (1.48752297, 1.00977082e-12, 1.e-13),
          (1.48815935, 1.13071679e-12, 1.e-13),
          (1.48879573, 1.09774952e-12, 1.e-13),
          (1.4894321 , 1.02038104e-12, 1.e-13),
          (1.49006848, 1.32034740e-12, 1.e-13),
          (1.49070486, 1.37054159e-12, 1.e-13),
          (1.49134123, 1.40603068e-12, 1.e-13),
          (1.4919776 , 1.32414375e-12, 1.e-13),
          (1.49261397, 1.17389727e-12, 1.e-13),
          (1.49325034, 1.14937063e-12, 1.e-13),
          (1.4938867 , 9.51599432e-13, 1.e-13),
          (1.49452307, 1.10116941e-12, 1.e-13),
          (1.49515943, 6.02266716e-13, 1.e-13),
          (1.49579579, 1.01800390e-12, 1.e-13),
          (1.49643215, 1.36068642e-12, 1.e-13),
          (1.49706851, 1.61327768e-12, 1.e-13),
          (1.49770486, 1.70599772e-12, 1.e-13),
          (1.49834122, 1.28280676e-12, 1.e-13),
          (1.49897757, 1.39233792e-12, 1.e-13),
          (1.49961392, 1.93031924e-12, 1.e-13),
          (1.50025027, 1.61433449e-12, 1.e-13),
          (1.50088662, 1.68225991e-12, 1.e-13),
          (1.50152296, 1.73203268e-12, 1.e-13),
          (1.50215931, 1.38664397e-12, 1.e-13),
          (1.50279565, 1.35263128e-12, 1.e-13),
          (1.50343199, 1.55284815e-12, 1.e-13),
          (1.50406833, 1.25187655e-12, 1.e-13),
          (1.50470466, 1.58894979e-12, 1.e-13),
          (1.505341  , 1.47103109e-12, 1.e-13),
          (1.50597733, 1.27703119e-12, 1.e-13),
          (1.50661367, 1.35045760e-12, 1.e-13),
          (1.50725   , 1.23183915e-12, 1.e-13),
          (1.50788632, 1.31826562e-12, 1.e-13),
          (1.50852265, 1.14032464e-12, 1.e-13),
          (1.50915898, 1.36898554e-12, 1.e-13),
          (1.5097953 , 1.29778824e-12, 1.e-13),
          (1.51043162, 1.54178653e-12, 1.e-13),
          (1.51108269, 1.31640528e-12, 1.e-13),
          (1.51171901, 1.43025280e-12, 1.e-13),
          (1.51235533, 1.52703511e-12, 1.e-13),
          (1.51299164, 1.89840961e-12, 1.e-13),
          (1.51362796, 2.09021296e-12, 1.e-13),
          (1.51426427, 2.53632560e-12, 1.e-13),
          (1.51490058, 2.34222934e-12, 1.e-13),
          (1.51553689, 1.99346979e-12, 1.e-13),
          (1.51617319, 1.51815994e-12, 1.e-13),
          (1.5168095 , 1.52415709e-12, 1.e-13),
          (1.5174458 , 1.32781394e-12, 1.e-13),
          (1.51808211, 1.57369896e-12, 1.e-13),
          (1.51871841, 1.43656463e-12, 1.e-13),
          (1.5193547 , 1.75341305e-12, 1.e-13),
          (1.519991  , 1.63040710e-12, 1.e-13),
          (1.5206273 , 1.64175747e-12, 1.e-13),
          (1.52126359, 1.12870249e-12, 1.e-13),
          (1.52189988, 1.26284419e-12, 1.e-13),
          (1.52253617, 1.15702637e-12, 1.e-13),
          (1.52317246, 1.32201499e-12, 1.e-13),
          (1.52380874, 1.28824903e-12, 1.e-13),
          (1.52444503, 1.12785183e-12, 1.e-13),
          (1.52508131, 1.24939692e-12, 1.e-13),
          (1.52571759, 1.27359376e-12, 1.e-13),
          (1.52635387, 1.08414560e-12, 1.e-13),
          (1.52699015, 1.11285621e-12, 1.e-13),
          (1.52762642, 1.17977719e-12, 1.e-13),
          (1.5282627 , 9.71634336e-13, 1.e-13),
          (1.52889897, 1.27139940e-12, 1.e-13),
          (1.52953524, 1.45933937e-12, 1.e-13),
          (1.53017151, 1.19836762e-12, 1.e-13),
          (1.53080777, 1.09977714e-12, 1.e-13),
          (1.53144404, 9.92317446e-13, 1.e-13),
          (1.5320803 , 1.03495888e-12, 1.e-13),
          (1.53271656, 9.59652036e-13, 1.e-13),
          (1.53335282, 9.39715501e-13, 1.e-13),
          (1.53398908, 1.36599446e-12, 1.e-13),
          (1.53462534, 1.36675871e-12, 1.e-13),
          (1.53526159, 1.00483237e-12, 1.e-13),
          (1.53589784, 8.00763601e-13, 1.e-13),
          (1.53653409, 1.18986210e-12, 1.e-13),
          (1.53717034, 1.06145328e-12, 1.e-13),
          (1.53780659, 1.16682427e-12, 1.e-13),
          (1.53844283, 9.33398317e-13, 1.e-13),
          (1.53907908, 1.12140787e-12, 1.e-13),
          (1.53971532, 1.24440899e-12, 1.e-13),
          (1.54035156, 1.38371597e-12, 1.e-13),
          (1.54098779, 1.32722825e-12, 1.e-13),
          (1.54162403, 1.04506601e-12, 1.e-13),
          (1.54226026, 1.21540786e-12, 1.e-13),
          (1.5428965 , 1.25822154e-12, 1.e-13),
          (1.54353273, 1.23357918e-12, 1.e-13),
          (1.54416896, 1.24462087e-12, 1.e-13),
          (1.54480518, 1.17091236e-12, 1.e-13),
          (1.54544141, 1.17189826e-12, 1.e-13),
          (1.54607763, 1.22799912e-12, 1.e-13),
          (1.54671385, 1.26349100e-12, 1.e-13),
          (1.54735007, 1.14116150e-12, 1.e-13),
          (1.54798629, 9.15216827e-13, 1.e-13),
          (1.5486225 , 1.09038317e-12, 1.e-13),
          (1.54925872, 1.09204023e-12, 1.e-13),
          (1.54989493, 1.17929431e-12, 1.e-13),
          (1.55053114, 1.07189095e-12, 1.e-13),
          (1.55116735, 1.10160300e-12, 1.e-13),
          (1.55180356, 1.30714609e-12, 1.e-13),
          (1.55243976, 1.08674993e-12, 1.e-13),
          (1.55307596, 1.12619686e-12, 1.e-13),
          (1.55371216, 8.59483945e-13, 1.e-13),
          (1.55434836, 1.03696861e-12, 1.e-13),
          (1.55499938, 1.25600637e-12, 1.e-13),
          (1.55563558, 1.13750033e-12, 1.e-13),
          (1.55627177, 1.00087163e-12, 1.e-13),
          (1.55690797, 1.20189006e-12, 1.e-13),
          (1.55754416, 1.17593754e-12, 1.e-13),
          (1.55818035, 1.25247514e-12, 1.e-13),
          (1.55881653, 1.21967584e-12, 1.e-13),
          (1.55945272, 1.15942427e-12, 1.e-13),
          (1.5600889 , 1.11700380e-12, 1.e-13),
          (1.56072509, 1.01634031e-12, 1.e-13),
          (1.56136126, 1.30761946e-12, 1.e-13),
          (1.56199744, 1.10943341e-12, 1.e-13),
          (1.56263362, 1.48826061e-12, 1.e-13),
          (1.56326979, 1.03365762e-12, 1.e-13),
          (1.56390596, 1.25954092e-12, 1.e-13),
          (1.56454213, 1.51080461e-12, 1.e-13),
          (1.5651783 , 1.46762029e-12, 1.e-13),
          (1.56581447, 1.09939829e-12, 1.e-13),
          (1.56645063, 1.31283882e-12, 1.e-13),
          (1.5670868 , 1.23259023e-12, 1.e-13),
          (1.56772296, 1.42708490e-12, 1.e-13),
          (1.56835912, 1.11107654e-12, 1.e-13),
          (1.56899527, 1.00496210e-12, 1.e-13),
          (1.56963143, 1.10065168e-12, 1.e-13),
          (1.57026758, 1.03963056e-12, 1.e-13),
          (1.57090373, 1.16946998e-12, 1.e-13),
          (1.57153988, 6.62842999e-13, 1.e-13),
          (1.57217603, 1.16077028e-12, 1.e-13),
          (1.57281218, 1.39581717e-12, 1.e-13),
          (1.57344832, 1.14496942e-12, 1.e-13),
          (1.57408446, 1.20224995e-12, 1.e-13),
          (1.5747206 , 1.36282248e-12, 1.e-13),
          (1.57535674, 1.75584858e-12, 1.e-13),
          (1.57599288, 1.18282682e-12, 1.e-13),
          (1.57662901, 1.34593967e-12, 1.e-13),
          (1.57726514, 1.13698736e-12, 1.e-13),
          (1.57790127, 1.04355193e-12, 1.e-13),
          (1.5785374 , 1.03545469e-12, 1.e-13),
          (1.57917353, 1.22806002e-12, 1.e-13),
          (1.57980965, 8.13285982e-13, 1.e-13)],
         dtype=(numpy.record, [('wavelength', '>f8'), ('flux', '>f8'), ('uncertainty', '>f8')]))

Workflow via API calls#

I can do some analysis on the spectrum using the plugins in the GUI. For reproducibility, I can do the same thing from the API, changing the parameters in the plugins programmatically.

# Select a region in the spectrum
sv = specviz.app.get_viewer('spectrum-viewer')
# Region with just line for line analysis
sv.toolbar_active_subset.selected = []
sv.apply_roi(XRangeROI(1.124, 1.131))  
# Region with some continuum for gaussian fit
sv.toolbar_active_subset.selected = []
sv.apply_roi(XRangeROI(1.05, 1.25))  
# Open line analysis plugin
plugin_la = specviz.plugins['Line Analysis']
plugin_la.open_in_tray()
# List what's in the data menu
specviz.data_labels
['spec1d calibrated', 'spec1d masked']
# Input the appropriate spectrum and region
plugin_la.dataset = 'spec1d masked'
plugin_la.spectral_subset = 'Subset 2'
# Input the values for the continuum
plugin_la.continuum = 'Surrounding'
plugin_la.width = 7
WARNING:root:DeprecationWarning: width was replaced by continuum_width in 3.9 and will be removed in a future release
WARNING:root:DeprecationWarning: width was replaced by continuum_width in 3.9 and will be removed in a future release
# Return line analysis results
plugin_la.get_results()
[{'function': 'Line Flux', 'result': ''},
 {'function': 'Equivalent Width', 'result': ''},
 {'function': 'Gaussian Sigma Width', 'result': ''},
 {'function': 'Gaussian FWHM', 'result': ''},
 {'function': 'Centroid', 'result': ''}]
# Open line list plugin
plugin_ll = specviz.plugins['Line Lists']
plugin_ll.open_in_tray()

Developer note
The line list plugin cannot yet be accessed by the notebook. I can do it in the GUI though.

Open line list plugin. Select the SDSS IV line list. Load the Oxygen II lines and Hb. Go back to line analysis plugin and associate the Oxygen II line with the line we just analyzed.

# Open model fitting plugin
plugin_mf = specviz.plugins['Model Fitting']
plugin_mf.open_in_tray()
# Input the appropriate datasets
plugin_mf.dataset = 'spec1d masked'
plugin_mf.spectral_subset = 'Subset 3'
# Input the model components
plugin_mf.create_model_component(model_component='Polynomial1D',
                                 poly_order=2,
                                 model_component_label='P2')
plugin_mf.create_model_component(model_component='Gaussian1D',
                                 model_component_label='G')
plugin_mf.get_model_component('G')
{'model_type': 'Gaussian1D',
 'parameters': {'amplitude': {'value': 9.28889869794063e-13,
   'unit': 'MJy',
   'std': nan,
   'fixed': False},
  'mean': {'value': 1.1695679004508002,
   'unit': 'um',
   'std': nan,
   'fixed': False},
  'stddev': {'value': 0.04850103358252829,
   'unit': 'um',
   'std': nan,
   'fixed': False}}}
plugin_mf.set_model_component('G', 'stddev', 0.001)
plugin_mf.set_model_component('G', 'mean', 1.128)
{'name': 'mean', 'value': 1.128, 'unit': 'um', 'fixed': False}
# Model equation gets populated automatically
plugin_mf.equation = 'P2+G'
# After we run this, we go to the GUI and check that the fit makes sense
plugin_mf.calculate_fit()
(<CompoundModel(c0_0=-0. MJy, c1_0=0. MJy / um, c2_0=-0. MJy / um2, amplitude_1=0. MJy, mean_1=1.12768736 um, stddev_1=0.00080151 um)>,
 <Spectrum1D(flux=[1.804380719259348e-14 ... 1.6159052616114435e-12] MJy (shape=(911,), mean=0.00000 MJy); spectral_axis=<SpectralAxis 
    (observer to target:
       radial_velocity=0.0 km / s
       redshift=0.0)
   [1.00020414 1.0008411  1.00149188 ... 1.5785374  1.57917353 1.57980965] um> (length=911))>)
specviz.get_model_parameters()
{'spec1d masked model': {'c0_0': <Quantity -6.08179136e-12 MJy>,
  'c1_0': <Quantity 8.21432852e-12 MJy / um>,
  'c2_0': <Quantity -2.1153065e-12 MJy / um2>,
  'amplitude_1': <Quantity 8.29375554e-13 MJy>,
  'mean_1': <Quantity 1.12768736 um>,
  'stddev_1': <Quantity 0.00080151 um>}}

Same workflow with specutils (old workflow)#

The same workflow can be achieved using directly the package specutils (which is used under the hood in jdaviz) and using matplotlib for a static visualization.

Fit and substract the continuum#

cont_spec1d = fit_generic_continuum(spec1d_masked)
cont_fit = cont_spec1d(spec1d_masked.spectral_axis)
WARNING: Model is linear in parameters; consider using linear fitting methods. [astropy.modeling.fitting]
WARNING:astropy:Model is linear in parameters; consider using linear fitting methods.
plt.figure(figsize=[10, 6])
plt.plot(spec1d_masked.spectral_axis, spec1d_masked.flux, label="data")
plt.plot(spec1d_masked.spectral_axis, cont_fit, label="modeled continuum")
plt.xlabel("wavelength ({:latex})".format(spec1d_masked.spectral_axis.unit))
plt.ylabel("flux ({:latex})".format(spec1d_masked.flux.unit))
plt.legend()
plt.title("Observed spectrum and fitted continuum")
plt.show()

plt.figure(figsize=[10, 6])
plt.plot(spec1d_masked.spectral_axis, spec1d_masked.uncertainty.array, label="data")
plt.xlabel("wavelength ({:latex})".format(spec1d_masked.spectral_axis.unit))
plt.ylabel("uncertainty ({:latex})".format(spec1d_masked.uncertainty.unit))
plt.legend()
plt.title("Uncertianty of observed spectrum")
plt.show()
../../_images/0d8100324f8f29c30dc240d20ae49a777b4cb84fb54b09596149fe6e9faa4005.png ../../_images/e73a7fe3eda5fc67b8c4ac4f2b468da68fced22d4fd1bc28687e2164a4297f07.png

Creating the continuum-subtracted spectrum#

Specutils will figure out what to do with the uncertainty!

spec1d_sub = spec1d_masked - cont_fit
spec1d_sub
<Spectrum1D(flux=[3.7887960348400625e-14 ... -3.987479504166673e-13] MJy (shape=(911,), mean=0.00000 MJy); spectral_axis=<SpectralAxis 
   (observer to target:
      radial_velocity=0.0 km / s
      redshift=0.0)
  [1.00020414 1.0008411  1.00149188 ... 1.5785374  1.57917353 1.57980965] um> (length=911); uncertainty=StdDevUncertainty)>
plt.figure(figsize=[10, 6])
plt.plot(spec1d_sub.spectral_axis, spec1d_sub.flux, label="data")
plt.xlabel("wavelength ({:latex})".format(spec1d_sub.spectral_axis.unit))
plt.ylabel("flux ({:latex})".format(spec1d_sub.flux.unit))
plt.legend()
plt.title("Continuum-subracted spectrum")
plt.show()

plt.figure(figsize=[10, 6])
plt.plot(spec1d_sub.spectral_axis, spec1d_sub.uncertainty.array, label="data")
plt.xlabel("wavelength ({:latex})".format(spec1d_sub.spectral_axis.unit))
plt.ylabel("uncertainty ({:latex})".format(spec1d_sub.uncertainty.unit))
plt.legend()
plt.title("Uncertainty of continuum-subracted spectrum")
plt.show()
../../_images/0f6fa8be9a2fc835279d4b749f10c11e4af4cd0198ae6f516a748c795619cc9e.png ../../_images/d2e8c556df9dcee3127d8c15c7ed90fb77dc66e0ed47e3a1f5954d677440d2d1.png

Find emission and absorption lines#

lines = find_lines_threshold(spec1d_sub, noise_factor=3)
lines
QTable length=47
line_centerline_typeline_center_index
um
float64str10int64
1.0084985099349837emission13
1.00977244535525emission15
1.1276681596792193emission200
1.167809998569554emission263
1.170994665048726emission268
1.1722685279834808emission270
1.1824593532966197emission286
1.1869177938992066emission293
1.2130451230160508emission334
.........
1.484977426686452absorption761
1.495159428380592absorption777
1.533352822212056absorption837
1.5358978418032327absorption841
1.5384428325297663absorption845
1.547986288624624absorption860
1.5537121640004583absorption869
1.5715398828247746absorption897
1.5798096506465742absorption910

Plot the emission lines on the spectrum.

plt.figure(figsize=[10, 6])
plt.plot(spec1d_sub.spectral_axis, spec1d_sub.flux, label="data")
plt.axvline(lines['line_center'][0].value, color="red", alpha=0.5, label='emission lines')
for line in lines:
    if line['line_type'] == 'emission':
        plt.axvline(line['line_center'].value, color='red', alpha=0.5)
plt.xlabel("wavelength ({:latex})".format(spec1d_sub.spectral_axis.unit))
plt.ylabel("flux ({:latex})".format(spec1d_sub.flux.unit))
plt.legend()
plt.title("Continuum-subtracted spectrum and marked lines using find_lines_threshold")
plt.show()
../../_images/aa4211b6771cf7788c883a85a7f578b6eb6c06fd838cba9fc7a822ac92308e18.png

Work by hand on a single line.

# Define limits for plotting
x_min = 1.1
x_max = 1.16

# Define limits for line region
line_min = 1.124*u.um
line_max = 1.131*u.um
plt.figure(figsize=[10, 6])
plt.plot(spec1d_sub.spectral_axis, spec1d_sub.flux, label="data")
plt.scatter(spec1d_sub.spectral_axis, spec1d_sub.flux, label=None)
plt.axvline(lines['line_center'][0].value, color="red", alpha=0.5, label='[OII]')
for line in lines:
    if line['line_type'] == 'emission':
        plt.axvline(line['line_center'].value, alpha=0.5, color='red')
plt.xlim(x_min, x_max)
plt.xlabel("wavelength ({:latex})".format(spec1d_sub.spectral_axis.unit))
plt.ylabel("flux ({:latex})".format(spec1d_sub.flux.unit))
plt.legend()
plt.title("Continuum-subtracted spectrum zoomed on [OII]")
plt.show()
../../_images/fa41a868db90ae0a363f8d476568004ab3af3e81d2fdc075f41f2cada97b3f79.png

Measure line centroids and fluxes#

# Example with just one line
centroid(spec1d_sub, SpectralRegion(line_min, line_max))
\[1.1276676 \; \mathrm{\mu m}\]
sline = centroid(spec1d_sub, SpectralRegion(line_min, line_max))

plt.figure(figsize=[10, 6])
plt.plot(spec1d_sub.spectral_axis, spec1d_sub.flux, label="data")
plt.scatter(spec1d_sub.spectral_axis, spec1d_sub.flux, label=None)
plt.axvline(sline.value, color='red', label="[OII]")
plt.axhline(0, color='black', label='flux = 0')
plt.xlim(x_min, x_max)
plt.xlabel("wavelength ({:latex})".format(spec1d_sub.spectral_axis.unit))
plt.ylabel("flux ({:latex})".format(spec1d_sub.flux.unit))
plt.legend()
plt.title("Continuum-subtracted spectrum zoomed on [OII]")
plt.show()
../../_images/30622fe2bf9d1aaa335a41b176abd4ec408131e18355b05cb4d9cfb6351d13a9.png
line_flux(spec1d_sub, SpectralRegion(line_min, line_max))  
\[1.4318561 \times 10^{-15} \; \mathrm{MJy\,\mu m}\]

Fit the line with a Gaussian#

g_init = models.Gaussian1D(mean=1.1278909*u.um, stddev=0.001*u.um)
g_fit = fit_lines(spec1d_sub, g_init)
spec1d_fit = g_fit(spec1d_sub.spectral_axis)
g_fit
<Gaussian1D(amplitude=0. MJy, mean=1.12769107 um, stddev=0.00078611 um)>
plt.figure(figsize=[10, 6])
plt.plot(spec1d_sub.spectral_axis, spec1d_sub.flux, label='data')
plt.plot(spec1d_sub.spectral_axis, spec1d_fit, color='darkorange', label='Gaussian fit')
plt.xlim(x_min, x_max)
plt.xlabel("wavelength ({:latex})".format(spec1d_sub.spectral_axis.unit))
plt.ylabel("flux ({:latex})".format(spec1d_sub.flux.unit))
plt.legend()
plt.title('Gaussian fit to the [OII] line')
plt.show()
../../_images/37709c15d492b1fc54f5abb22d5a06f12dea4b30873e08b8334ec508d14fb751.png

Measure the equivalent width of the lines#

This needs the spectrum continuum normalized.

spec1d_norm = spec1d_masked / cont_fit
plt.figure(figsize=[10, 6])
plt.plot(spec1d_norm.spectral_axis, spec1d_norm.flux, label='data')
plt.axhline(1, color='black', label='flux = 1')
plt.xlabel("wavelength ({:latex})".format(spec1d_norm.spectral_axis.unit))
plt.ylabel("flux (normalized)")
plt.xlim(x_min, x_max)
plt.legend()
plt.title("Continuum-normalized spectrum, zoomed on [OII]")
plt.show()

plt.figure(figsize=[10, 6])
plt.plot(spec1d_norm.spectral_axis, spec1d_norm.uncertainty.array, label='data')
plt.xlabel("wavelength ({:latex})".format(spec1d_norm.spectral_axis.unit))
plt.ylabel("uncertainty (normalized)")
plt.xlim(x_min, x_max)
plt.legend()
plt.title("Uncertainty of continuum-normalized spectrum, zoomed on [OII]")
plt.show()
../../_images/00e63f294ff5fb3009fd560d31edef7fbd56040c4a821e848b7845dbdc3e5bd3.png ../../_images/85500bcc4948003ee52d4f1223703b0b6f11c7d194073b37cb180b1a815b51d2.png
equivalent_width(spec1d_norm, regions=SpectralRegion(line_min, line_max))
\[-0.0028555634 \; \mathrm{\mu m}\]

Find the best-fitting template#

It needs a list of templates and the redshift of the observed galaxy. For the templates, I am using a set of model SEDs generated with Bruzual & Charlot stellar population models, emission lines, and dust attenuation as described in Pacifici et al. (2012).

Developer note
Maybe there is a way to speed this up (maybe using astropy model_sets)? This fit is run with 100 models, but ideally, if we want to extract physical parameters from this, we would need at least 10,000 models. A dictionary structure with meaningful keys (which can be, e.g., tuples of the relevant physical parameters) could be better than a list? It could make later analysis much clearer than having to map from the list indices back to the relevant parameters.

templatedir = './mos_spectroscopy/templates/'
# Redshift taken from the Specviz analysis
zz = 2.0256

f_lamb_units = u.erg / u.s / (u.cm**2) / u.AA

templatelist = []
# Run on 30 out of 100 for speed
for i in range(1, 30):
    template_file = "{0}{1:05d}.dat".format(templatedir, i)
    template = ascii.read(template_file)
    temp1d = Spectrum1D(spectral_axis=(template['col1']/1E4)*u.um, flux=template['col2']*f_lamb_units)
    templatelist.append(temp1d)
# Change the units of the observed spectrum to match the template
spec1d_masked_flamb = spec1d_masked.new_flux_unit(f_lamb_units)
# The new_flux_unit function does not change the uncertainty and specviz complains that there is a mismatch
# so we re-add the uncertainty like we did a few cells above
spec1d_masked_flamb_unc = Spectrum1D(spectral_axis=spec1d_masked_flamb.spectral_axis,
                                     flux=spec1d_masked_flamb.flux,
                                     uncertainty=StdDevUncertainty((np.zeros(len(spec1d_masked_flamb.flux)) + 1E-20) * spec1d_masked_flamb.unit))
WARNING: AstropyDeprecationWarning: The new_flux_unit function is deprecated and may be removed in a future version.
        Use with_flux_unit instead. [warnings]
WARNING:astropy:AstropyDeprecationWarning: The new_flux_unit function is deprecated and may be removed in a future version.
        Use with_flux_unit instead.
# Take a look at the observed spectrum and one of the templates at the correct redshift
mean_obs = np.mean(spec1d_masked_flamb_unc.flux)
mean_temp = np.mean(templatelist[0].flux)
temp_for_plot = Spectrum1D(spectral_axis=templatelist[0].spectral_axis * (1.+zz),
                           flux=templatelist[0].flux*mean_obs/mean_temp)

plt.figure(figsize=[10, 6])
plt.plot(spec1d_masked_flamb_unc.spectral_axis, spec1d_masked_flamb_unc.flux, label='data')
plt.plot(temp_for_plot.spectral_axis, temp_for_plot.flux, label='model', alpha=0.6)
plt.xlabel("wavelength ({:latex})".format(spec1d_masked_flamb_unc.spectral_axis.unit))
plt.ylabel("flux (normalized)")
plt.xlim(1.1, 1.7)
plt.ylim(0, 2e-18)
plt.legend()
plt.title("Observed spectrum compared to one template at correct redshift")
plt.show()
../../_images/a483935df6bc356968dcfe12e807508bb78440cb3f061b5364a6c16c6ab23abc.png
tm_results = template_comparison.template_match(observed_spectrum=spec1d_masked_flamb_unc, 
                                                spectral_templates=templatelist, 
                                                resample_method="flux_conserving", 
                                                redshift=zz)
tm_results[0]
<Spectrum1D(flux=[0.0 ... 1.8342620429527654e-22] erg / (Angstrom s cm2) (shape=(11283,), mean=0.00000 erg / (Angstrom s cm2)); spectral_axis=<SpectralAxis 
   (observer to target:
      radial_velocity=240744.80805001882 km / s
      redshift=2.0256)
  [ 0.03046779  0.0307401   0.0310124  ... 29.34832    29.469344
 29.590368  ] um> (length=11283))>
plt.figure(figsize=[10, 6])
plt.plot(spec1d_masked_flamb_unc.spectral_axis, spec1d_masked_flamb_unc.flux, label="data")
plt.plot(tm_results[0].spectral_axis, tm_results[0].flux, color='r', alpha=0.5, label='model')
plt.xlim(1.0, 1.7)
plt.ylim(0, 5e-19)
plt.xlabel("wavelength ({:latex})".format(spec1d_masked_flamb_unc.spectral_axis.unit))
plt.ylabel("flux ({:latex})".format(spec1d_masked_flamb_unc.flux.unit))
plt.legend()
plt.title("Observed spectrum and best-fitting model template")
plt.show()
../../_images/ad0ad71c35561189110f3f66792f8d7382803c6fed363b0eff33fbe1419002ac.png

New instance of Specviz with spectrum and template#

Passing the spectra with different (but compatible) units. Specviz adopts the first and converts the second spectrum appropriately.

specviz_2 = Specviz()
specviz_2.load_data(spec1d_masked, data_label='observed') # This is in MJy
specviz_2.load_data(tm_results[0], data_label='model') # This is in erg/(s cm^2 A)
specviz_2.show()
Space Telescope Logo

Notebook created by Camilla Pacifici (cpacifici@stsci.edu)
Updated on September 14, 2023