{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"![alt text][logo]\n",
"\n",
"[logo]: https://github.com/legolason/PyQSOFit/blob/master/pyqsofit/QSOFit_logo.png?raw=true\n",
"\n",
"\n",
"# PyQSOFit\n",
"\n",
"\n",
"PyQSOFit is a flexible tool to decompose quasar spectra. It was originally translated from [Yue Shen](http://quasar.astro.illinois.edu/)'s IDL qsofit code, but not exactly the same. With this program, people can get the information of quasar continuum and emission lines, e.g., continuum slope, line FWHM, line dispersion, EW, peak, etc. The main flows of this code are:\n",
"\n",
"1) We decompose the host galaxy and quasar component with the PCA method if needed\n",
"2) We fit the continuum with several components (Power-Law, Polynomial, Fe II, Balmer Continuum) using some line free windows\n",
"3) We fit line complexes one by one, including H$\\alpha$, H$\\beta$, Mg II, C III], CIV and Ly$\\alpha$ complex. In each complex, broad and narrow Gaussian profiles are used to fit different emission lines. \n",
"\n",
"For the details, you can read [Shen et al. (2015)](http://adsabs.harvard.edu/abs/2018arXiv181001447S), [Guo et al. (2018)](http://adsabs.harvard.edu/abs/2018arXiv180904610G) and Wang et al.(2018, in prepration)\n",
"\n",
"\n",
"## Installation and Requirements\n",
"\n",
"To install this code, just download and install it with ``pip``:\n",
"\n",
"``git clone https://github.com/legolason/PyQSOFit``
\n",
"``cd PyQSOFit``
\n",
"``python -m pip install .``
\n",
"\n",
"\n",
"This code was tested Python 3.9. These packages are __required__, but should have been installed automatically during the step above:\n",
"\n",
"1) [Numpy](http://www.numpy.org/)
\n",
"2) [Scipy](https://www.scipy.org/)
\n",
"3) [Astropy](http://www.astropy.org/)
\n",
"4) [PyAstronomy](https://pyastronomy.readthedocs.io/en/latest/pyaCDoc/installingPyA.html)
\n",
"5) [LMFIT](https://lmfit.github.io/lmfit-py/)
\n",
"6) [Sfdmap2](https://github.com/AmpelAstro/sfdmap2): a fork of sfdmap, as the original repository is no longer maintained. Dust reddening map from [Schlegel et al. (2008)](http://www.adsabs.harvard.edu/abs/1998ApJ...500..525S)
\n",
"\n",
"These packages are __optional__. They are not installed automatically but must be installed for parameter uncertainty estimates:\n",
"\n",
"1) [emcee](https://emcee.readthedocs.io/en/stable/)
\n",
"2) [pandas](https://pandas.pydata.org/)
\n",
"3) [corner](https://corner.readthedocs.io/en/latest/)
\n",
"\n",
"If using pPXF to get the host component (`use_ppxf=True`),\n",
"\n",
"1) [pPXF](https://pypi.org/project/ppxf/)\n",
"\n",
"Eigenspectra of galaxy and quasar from Yip et al. [(2004a)](http://adsabs.harvard.edu/abs/2004AJ....128..585Y), [(2004b)](http://adsabs.harvard.edu/abs/2004AJ....128.2603Y)\n",
"and Optical/UV Fe II templates are included in this package. We suggest that install python through [anaconda](https://www.anaconda.com/), which incorporates most packages you need. \n",
"\n",
"## Key features\n",
"1) Fit the whole spectra input or fit each line locally using ``wave_range`` parameter\n",
"2) Parameter uncertaianties can be computed for each parameter. The uncertainties from least-squares fitting is usually not robust, so we do not output those as default results (but the user still can read out this errors through ``lmfit.params``). The best way to calculate the error is using MCMC. In previous versions of the code, we used a Monte Carlo resampling method, which perturbs the flux based on the input error. Computing parameter uncertainties will take longer, but in practice we found that MCMC is not significantly slower than the resampling method and MCMC probably gives more reliable parameter uncertainties and covariances. \n",
"3) A 3rd order polynomial component accounts for dust reddening if any.\n",
"4) Iterative sigma clipping can be used to clean the spectrum for absorbed continuum fitting. \n",
"5) One can block serval ranges on the spectrum for bad S/N ratio pixels or absorption lines.\n",
"6) The code directly saves out the properties of emission lines, e.g., FWHM, line dispersion, EW, Peak, line flux for the broad components and continuum luminosity at 1350, 3000, 5100A.\n",
"7) One can remove the bad pixels caused by the cosmic ray or the sky. \n",
"8) Host/QSO decompisition using built-in PCA method or pPXF.\n",
"\n",
"\n",
"\n",
"## Possible future updates\n",
"1) Option for using Gauss-Hermite profile to fit the emission lines.
\n",
"2) Simultaneously fit several epochs for the same source since the time domain era is coming.
\n",
"3) Add functions to fit the absorption lines.
\n",
"4) Produce more secondary parameters from spectral fitting.
\n",
"5) Speed up the code by e.g., choosing better initial conditions (especially for the continuum and narrow-line flux normalizations).
\n",
"6) Option for automatically determining the number of broad emission line components to include in a fit using e.g., BIC. This will take longer to execute initially but might make the MCMC sampling faster and fits more reliable if fewer components are used, especially for low S/N or BAL quasar spectra.
\n",
"7) Improved integration with pPXF, specutils, etc.
\n",
"8) Better code documentation.
\n",
"\n",
"\n",
"## Authors\n",
"[Hengxiao Guo](https://hengxiaoguo.wixsite.com/hengxiaoguo), hengxiaoguo AT gmail.com (SHAO)
\n",
"[Yue Shen](http://quasar.astro.illinois.edu/), shenyue AT illinois.edu (UIUC)
\n",
"Shu Wang, wangshukiaa AT pku.edu.cn (Seoul National University)
\n",
"[Colin J. Burke](https://burke86.github.io/), colinjb2 AT illinois.edu (UIUC)
\n",
"[Wenke Ren](https://github.com/WenkeRen/), rwk AT mail.ustc.edu.cn (USTC)
\n",
"\n",
"\n",
"## Acknowledgement\n",
"If our code makes your life easier, it would be appreciated to cite us:
\n",
"1) [Guo, H., Shen, Y., Wang, S. 2018, ascl:1809.008](https://ui.adsabs.harvard.edu/abs/2018ascl.soft09008G/abstract)\n",
"2) [Shen, Y. et al., ApJS, 241, 34S](http://adsabs.harvard.edu/abs/2018arXiv181001447S)\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"ExecuteTime": {
"end_time": "2023-11-24T07:52:00.489911Z",
"start_time": "2023-11-24T07:51:53.989171Z"
}
},
"outputs": [],
"source": [
"%matplotlib inline\n",
"import glob, os, sys, timeit\n",
"import matplotlib\n",
"import numpy as np\n",
"\n",
"sys.path.append('../')\n",
"from pyqsofit.PyQSOFit import QSOFit\n",
"from astropy.io import fits\n",
"from astropy.table import Table\n",
"import matplotlib.pyplot as plt\n",
"import warnings\n",
"\n",
"warnings.filterwarnings(\"ignore\")\n",
"\n",
"QSOFit.set_mpl_style()"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"ExecuteTime": {
"end_time": "2023-07-26T07:26:19.759721Z",
"start_time": "2023-07-26T07:26:19.757178Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"5.3.1\n",
"1.2.1\n",
"2.0.0\n",
"3.1.4\n"
]
}
],
"source": [
"# Show the versions so we know what works\n",
"import astropy\n",
"import lmfit\n",
"import pyqsofit\n",
"\n",
"print(astropy.__version__)\n",
"print(lmfit.__version__)\n",
"print(pyqsofit.__version__)\n",
"\n",
"import emcee # optional, for MCMC\n",
"\n",
"print(emcee.__version__)\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"ExecuteTime": {
"end_time": "2023-07-26T07:26:19.761253Z",
"start_time": "2023-07-26T07:26:19.759443Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['/Users/wenke/data/20230710CodeRefine/20230710PyQSOFit/pyqsofit']\n"
]
}
],
"source": [
"print(pyqsofit.__path__)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Detailed Usage\n",
"\n",
"## 1. Fit type 1 QSO\n",
"\n",
"__Step 1: Set up the model input parameters__
\n",
"Firstly, run the script below to produce the line list file, qsopar.fits, containing lines and their constraints, which will be needed in the following fitting program. From this file, you can change some specific parameters to suit your requirements, e.g., fitting range, line width, tie line center, tie line sigma, etc. If you want to fit extra lines, please append it to corresponding complex. Note that our line wavelength and sigma in the list are in Ln scale, like Lnlambda, Lnsigma. "
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"ExecuteTime": {
"end_time": "2023-07-26T07:26:19.763305Z",
"start_time": "2023-07-26T07:26:19.761202Z"
}
},
"outputs": [],
"source": [
"path_ex = '.' #os.path.join(pyqsofit.__path__[0], '..', 'example')\n",
"\n",
"# create a header\n",
"hdr0 = fits.Header()\n",
"hdr0['Author'] = 'Hengxiao Guo'\n",
"primary_hdu = fits.PrimaryHDU(header=hdr0)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"ExecuteTime": {
"end_time": "2023-07-26T07:26:19.774519Z",
"start_time": "2023-07-26T07:26:19.764295Z"
},
"pycharm": {
"is_executing": true
}
},
"outputs": [],
"source": [
"\"\"\"\n",
"In this table, we specify the priors / initial conditions and boundaries for the line fitting parameters.\n",
"\"\"\"\n",
"\n",
"line_priors = np.rec.array([\n",
" (6564.61, 'Ha', 6400, 6800, 'Ha_br', 2, 0.0, 0.0, 1e10, 5e-3, 0.004, 0.05, 0.015, 0, 0, 0, 0.05, 1),\n",
" (6564.61, 'Ha', 6400, 6800, 'Ha_na', 1, 0.0, 0.0, 1e10, 1e-3, 5e-4, 0.00169, 0.01, 1, 1, 0, 0.002, 1),\n",
" (6549.85, 'Ha', 6400, 6800, 'NII6549', 1, 0.0, 0.0, 1e10, 1e-3, 2.3e-4, 0.00169, 5e-3, 1, 1, 1, 0.001, 1),\n",
" (6585.28, 'Ha', 6400, 6800, 'NII6585', 1, 0.0, 0.0, 1e10, 1e-3, 2.3e-4, 0.00169, 5e-3, 1, 1, 1, 0.003, 1),\n",
" (6718.29, 'Ha', 6400, 6800, 'SII6718', 1, 0.0, 0.0, 1e10, 1e-3, 2.3e-4, 0.00169, 5e-3, 1, 1, 2, 0.001, 1),\n",
" (6732.67, 'Ha', 6400, 6800, 'SII6732', 1, 0.0, 0.0, 1e10, 1e-3, 2.3e-4, 0.00169, 5e-3, 1, 1, 2, 0.001, 1),\n",
"\n",
" (4862.68, 'Hb', 4640, 5100, 'Hb_br', 2, 0.0, 0.0, 1e10, 5e-3, 0.004, 0.05, 0.01, 0, 0, 0, 0.01, 1),\n",
" (4862.68, 'Hb', 4640, 5100, 'Hb_na', 1, 0.0, 0.0, 1e10, 1e-3, 2.3e-4, 0.00169, 0.01, 1, 1, 0, 0.002, 1),\n",
" (4960.30, 'Hb', 4640, 5100, 'OIII4959c', 1, 0.0, 0.0, 1e10, 1e-3, 2.3e-4, 0.00169, 0.01, 1, 1, 0, 0.002, 1),\n",
" (5008.24, 'Hb', 4640, 5100, 'OIII5007c', 1, 0.0, 0.0, 1e10, 1e-3, 2.3e-4, 0.00169, 0.01, 1, 1, 0, 0.004, 1),\n",
" (4960.30, 'Hb', 4640, 5100, 'OIII4959w', 1, 0.0, 0.0, 1e10, 3e-3, 2.3e-4, 0.004, 0.01, 2, 2, 0, 0.001, 1),\n",
" (5008.24, 'Hb', 4640, 5100, 'OIII5007w', 1, 0.0, 0.0, 1e10, 3e-3, 2.3e-4, 0.004, 0.01, 2, 2, 0, 0.002, 1),\n",
" #(4687.02, 'Hb', 4640, 5100, 'HeII4687_br', 1, 0.0, 0.0, 1e10, 5e-3, 0.004, 0.05, 0.005, 0, 0, 0, 0.001, 1),\n",
" #(4687.02, 'Hb', 4640, 5100, 'HeII4687_na', 1, 0.0, 0.0, 1e10, 1e-3, 2.3e-4, 0.00169, 0.005, 1, 1, 0, 0.001, 1),\n",
"\n",
" #(3934.78, 'CaII', 3900, 3960, 'CaII3934' , 2, 0.0, 0.0, 1e10, 1e-3, 3.333e-4, 0.00169, 0.01, 99, 0, 0, -0.001, 1),\n",
"\n",
" #(3728.48, 'OII', 3650, 3800, 'OII3728', 1, 0.0, 0.0, 1e10, 1e-3, 3.333e-4, 0.00169, 0.01, 1, 1, 0, 0.001, 1),\n",
"\n",
" #(3426.84, 'NeV', 3380, 3480, 'NeV3426', 1, 0.0, 0.0, 1e10, 1e-3, 3.333e-4, 0.00169, 0.01, 0, 0, 0, 0.001, 1),\n",
" #(3426.84, 'NeV', 3380, 3480, 'NeV3426_br', 1, 0.0, 0.0, 1e10, 5e-3, 0.0025, 0.02, 0.01, 0, 0, 0, 0.001, 1),\n",
"\n",
" (2798.75, 'MgII', 2700, 2900, 'MgII_br', 2, 0.0, 0.0, 1e10, 5e-3, 0.004, 0.05, 0.015, 0, 0, 0, 0.05, 1),\n",
" (2798.75, 'MgII', 2700, 2900, 'MgII_na', 1, 0.0, 0.0, 1e10, 1e-3, 5e-4, 0.00169, 0.01, 1, 1, 0, 0.002, 1),\n",
"\n",
" (1908.73, 'CIII', 1700, 1970, 'CIII_br', 2, 0.0, 0.0, 1e10, 5e-3, 0.004, 0.05, 0.015, 99, 0, 0, 0.01, 1),\n",
" #(1908.73, 'CIII', 1700, 1970, 'CIII_na', 1, 0.0, 0.0, 1e10, 1e-3, 5e-4, 0.00169, 0.01, 1, 1, 0, 0.002, 1),\n",
" #(1892.03, 'CIII', 1700, 1970, 'SiIII1892', 1, 0.0, 0.0, 1e10, 2e-3, 0.001, 0.015, 0.003, 1, 1, 0, 0.005, 1),\n",
" #(1857.40, 'CIII', 1700, 1970, 'AlIII1857', 1, 0.0, 0.0, 1e10, 2e-3, 0.001, 0.015, 0.003, 1, 1, 0, 0.005, 1),\n",
" #(1816.98, 'CIII', 1700, 1970, 'SiII1816', 1, 0.0, 0.0, 1e10, 2e-3, 0.001, 0.015, 0.01, 1, 1, 0, 0.0002, 1),\n",
" #(1786.7, 'CIII', 1700, 1970, 'FeII1787', 1, 0.0, 0.0, 1e10, 2e-3, 0.001, 0.015, 0.01, 1, 1, 0, 0.0002, 1),\n",
" #(1750.26, 'CIII', 1700, 1970, 'NIII1750', 1, 0.0, 0.0, 1e10, 2e-3, 0.001, 0.015, 0.01, 1, 1, 0, 0.001, 1),\n",
" #(1718.55, 'CIII', 1700, 1900, 'NIV1718', 1, 0.0, 0.0, 1e10, 2e-3, 0.001, 0.015, 0.01, 1, 1, 0, 0.001, 1),\n",
"\n",
" (1549.06, 'CIV', 1500, 1700, 'CIV_br', 2, 0.0, 0.0, 1e10, 5e-3, 0.004, 0.05, 0.015, 0, 0, 0, 0.05, 1),\n",
" # (1549.06, 'CIV', 1500, 1700, 'CIV_na', 1, 0.0, 0.0, 1e10, 1e-3, 5e-4, 0.00169, 0.01, 1, 1, 0, 0.002, 1),\n",
" #(1640.42, 'CIV', 1500, 1700, 'HeII1640', 1, 0.0, 0.0, 1e10, 1e-3, 5e-4, 0.00169, 0.008, 1, 1, 0, 0.002, 1),\n",
" #(1663.48, 'CIV', 1500, 1700, 'OIII1663', 1, 0.0, 0.0, 1e10, 1e-3, 5e-4, 0.00169, 0.008, 1, 1, 0, 0.002, 1),\n",
" #(1640.42, 'CIV', 1500, 1700, 'HeII1640_br', 1, 0.0, 0.0, 1e10, 5e-3, 0.0025, 0.02, 0.008, 1, 1, 0, 0.002, 1),\n",
" #(1663.48, 'CIV', 1500, 1700, 'OIII1663_br', 1, 0.0, 0.0, 1e10, 5e-3, 0.0025, 0.02, 0.008, 1, 1, 0, 0.002, 1),\n",
"\n",
" #(1402.06, 'SiIV', 1290, 1450, 'SiIV_OIV1', 1, 0.0, 0.0, 1e10, 5e-3, 0.002, 0.05, 0.015, 1, 1, 0, 0.05, 1),\n",
" #(1396.76, 'SiIV', 1290, 1450, 'SiIV_OIV2', 1, 0.0, 0.0, 1e10, 5e-3, 0.002, 0.05, 0.015, 1, 1, 0, 0.05, 1),\n",
" #(1335.30, 'SiIV', 1290, 1450, 'CII1335', 1, 0.0, 0.0, 1e10, 2e-3, 0.001, 0.015, 0.01, 1, 1, 0, 0.001, 1),\n",
" #(1304.35, 'SiIV', 1290, 1450, 'OI1304', 1, 0.0, 0.0, 1e10, 2e-3, 0.001, 0.015, 0.01, 1, 1, 0, 0.001, 1),\n",
"\n",
" (1215.67, 'Lya', 1150, 1290, 'Lya_br', 3, 0.0, 0.0, 1e10, 5e-3, 0.002, 0.05, 0.02, 0, 0, 0, 0.05, 1),\n",
" (1240.14, 'Lya', 1150, 1290, 'NV1240', 1, 0.0, 0.0, 1e10, 2e-3, 0.001, 0.01, 0.005, 0, 0, 0, 0.002, 1),\n",
" # (1215.67, 'Lya', 1150, 1290, 'Lya_na', 1, 0.0, 0.0, 1e10, 1e-3, 5e-4, 0.00169, 0.01, 0, 0, 0, 0.002, 1),\n",
" ],\n",
"\n",
" formats='float32, a20, float32, float32, a20, int32, float32, float32, float32, float32, float32, float32, float32, int32, int32, int32, float32, int32',\n",
" names=' lambda, compname, minwav, maxwav, linename, ngauss, inisca, minsca, maxsca, inisig, minsig, maxsig, voff, vindex, windex, findex, fvalue, vary')\n",
"\n",
"# Header\n",
"hdr1 = fits.Header()\n",
"hdr1['lambda'] = 'Vacuum Wavelength in Ang'\n",
"hdr1['minwav'] = 'Lower complex fitting wavelength range'\n",
"hdr1['maxwav'] = 'Upper complex fitting wavelength range'\n",
"hdr1['ngauss'] = 'Number of Gaussians for the line'\n",
"\n",
"# Can be set to negative for absorption lines if you want\n",
"hdr1['inisca'] = 'Initial guess of line scale [flux]'\n",
"hdr1['minsca'] = 'Lower range of line scale [flux]'\n",
"hdr1['maxsca'] = 'Upper range of line scale [flux]'\n",
"\n",
"hdr1['inisig'] = 'Initial guess of linesigma [lnlambda]'\n",
"hdr1['minsig'] = 'Lower range of line sigma [lnlambda]'\n",
"hdr1['maxsig'] = 'Upper range of line sigma [lnlambda]'\n",
"\n",
"hdr1['voff '] = 'Limits on velocity offset from the central wavelength [lnlambda]'\n",
"hdr1['vindex'] = 'Entries w/ same NONZERO vindex constrained to have same velocity'\n",
"hdr1['windex'] = 'Entries w/ same NONZERO windex constrained to have same width'\n",
"hdr1['findex'] = 'Entries w/ same NONZERO findex have constrained flux ratios'\n",
"hdr1['fvalue'] = 'Relative scale factor for entries w/ same findex'\n",
"\n",
"hdr1['vary'] = 'Whether or not to vary the parameter (set to 0 to fix the line parameter to initial values)'\n",
"\n",
"# Save line info\n",
"hdu1 = fits.BinTableHDU(data=line_priors, header=hdr1, name='line_priors')"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"\"\"\"\n",
"In this table, we specify the windows and priors / initial conditions and boundaries for the continuum fitting parameters.\n",
"\"\"\"\n",
"\n",
"conti_windows = np.rec.array([\n",
" (1150., 1170.), \n",
" (1275., 1290.),\n",
" (1350., 1360.),\n",
" (1445., 1465.),\n",
" (1690., 1705.),\n",
" (1770., 1810.),\n",
" (1970., 2400.),\n",
" (2480., 2675.),\n",
" (2925., 3400.),\n",
" (3775., 3832.),\n",
" (4000., 4050.),\n",
" (4200., 4230.),\n",
" (4435., 4640.),\n",
" (5100., 5535.),\n",
" (6005., 6035.),\n",
" (6110., 6250.),\n",
" (6800., 7000.),\n",
" (7160., 7180.),\n",
" (7500., 7800.),\n",
" (8050., 8150.), # Continuum fitting windows (to avoid emission line, etc.) [AA]\n",
" ], \n",
" formats = 'float32, float32',\n",
" names = 'min, max')\n",
"\n",
"hdu2 = fits.BinTableHDU(data=conti_windows, name='conti_windows')\n",
"\n",
"conti_priors = np.rec.array([\n",
" ('Fe_uv_norm', 0.0, 0.0, 1e10, 1), # Normalization of the MgII Fe template [flux]\n",
" ('Fe_uv_FWHM', 3000, 1200, 18000, 1), # FWHM of the MgII Fe template [AA]\n",
" ('Fe_uv_shift', 0.0, -0.01, 0.01, 1), # Wavelength shift of the MgII Fe template [lnlambda]\n",
" ('Fe_op_norm', 0.0, 0.0, 1e10, 1), # Normalization of the Hbeta/Halpha Fe template [flux]\n",
" ('Fe_op_FWHM', 3000, 1200, 18000, 1), # FWHM of the Hbeta/Halpha Fe template [AA]\n",
" ('Fe_op_shift', 0.0, -0.01, 0.01, 1), # Wavelength shift of the Hbeta/Halpha Fe template [lnlambda]\n",
" ('PL_norm', 1.0, 0.0, 1e10, 1), # Normalization of the power-law (PL) continuum f_lambda = (lambda/3000)^-alpha\n",
" ('PL_slope', -1.5, -5.0, 3.0, 1), # Slope of the power-law (PL) continuum\n",
" ('Blamer_norm', 0.0, 0.0, 1e10, 1), # Normalization of the Balmer continuum at < 3646 AA [flux] (Dietrich et al. 2002)\n",
" ('Balmer_Te', 15000, 10000, 50000, 1), # Te of the Balmer continuum at < 3646 AA [K?]\n",
" ('Balmer_Tau', 0.5, 0.1, 2.0, 1), # Tau of the Balmer continuum at < 3646 AA\n",
" ('conti_a_0', 0.0, None, None, 1), # 1st coefficient of the polynomial continuum\n",
" ('conti_a_1', 0.0, None, None, 1), # 2nd coefficient of the polynomial continuum\n",
" ('conti_a_2', 0.0, None, None, 1), # 3rd coefficient of the polynomial continuum\n",
" # Note: The min/max bounds on the conti_a_0 coefficients are ignored by the code,\n",
" # so they can be determined automatically for numerical stability.\n",
" ],\n",
"\n",
" formats = 'a20, float32, float32, float32, int32',\n",
" names = 'parname, initial, min, max, vary')\n",
"\n",
"hdr3 = fits.Header()\n",
"hdr3['ini'] = 'Initial guess of line scale [flux]'\n",
"hdr3['min'] = 'FWHM of the MgII Fe template'\n",
"hdr3['max'] = 'Wavelength shift of the MgII Fe template'\n",
"\n",
"hdr3['vary'] = 'Whether or not to vary the parameter (set to 0 to fix the continuum parameter to initial values)'\n",
"\n",
"\n",
"hdu3 = fits.BinTableHDU(data=conti_priors, header=hdr3, name='conti_priors')"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"ExecuteTime": {
"end_time": "2023-07-26T07:26:19.811255Z",
"start_time": "2023-07-26T07:26:19.778494Z"
}
},
"outputs": [],
"source": [
"\"\"\"\n",
"In this table, we allow user to customized some key parameters in our result measurements.\n",
"\"\"\"\n",
"\n",
"measure_info = Table(\n",
" [\n",
" [[1350, 1450, 3000, 4200, 5100]],\n",
" [[\n",
" # [2240, 2650], \n",
" [4435, 4685],\n",
" ]]\n",
" ],\n",
" names=([\n",
" 'cont_loc',\n",
" 'Fe_flux_range'\n",
" ]),\n",
" dtype=([\n",
" 'float32',\n",
" 'float32'\n",
" ])\n",
")\n",
"hdr4 = fits.Header()\n",
"hdr4['cont_loc'] = 'The wavelength of continuum luminosity in results'\n",
"hdr4['Fe_flux_range'] = 'Fe emission wavelength range calculated in results'\n",
"\n",
"hdu4 = fits.BinTableHDU(data=measure_info, header=hdr4, name='measure_info')\n",
"\n",
"hdu_list = fits.HDUList([primary_hdu, hdu1, hdu2, hdu3, hdu4])\n",
"hdu_list.writeto(os.path.join(path_ex, 'qsopar.fits'), overwrite=True)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"__Print the table:__"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"ExecuteTime": {
"end_time": "2023-07-26T07:26:19.817254Z",
"start_time": "2023-07-26T07:26:19.789297Z"
}
},
"outputs": [
{
"data": {
"text/html": [
"
lambda | compname | minwav | maxwav | linename | ngauss | inisca | minsca | maxsca | inisig | minsig | maxsig | voff | vindex | windex | findex | fvalue | vary |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
float32 | bytes20 | float32 | float32 | bytes20 | int32 | float32 | float32 | float32 | float32 | float32 | float32 | float32 | int32 | int32 | int32 | float32 | int32 |
6564.61 | Ha | 6400.0 | 6800.0 | Ha_br | 2 | 0.0 | 0.0 | 10000000000.0 | 0.005 | 0.004 | 0.05 | 0.015 | 0 | 0 | 0 | 0.05 | 1 |
6564.61 | Ha | 6400.0 | 6800.0 | Ha_na | 1 | 0.0 | 0.0 | 10000000000.0 | 0.001 | 0.0005 | 0.00169 | 0.01 | 1 | 1 | 0 | 0.002 | 1 |
6549.85 | Ha | 6400.0 | 6800.0 | NII6549 | 1 | 0.0 | 0.0 | 10000000000.0 | 0.001 | 0.00023 | 0.00169 | 0.005 | 1 | 1 | 1 | 0.001 | 1 |
6585.28 | Ha | 6400.0 | 6800.0 | NII6585 | 1 | 0.0 | 0.0 | 10000000000.0 | 0.001 | 0.00023 | 0.00169 | 0.005 | 1 | 1 | 1 | 0.003 | 1 |
6718.29 | Ha | 6400.0 | 6800.0 | SII6718 | 1 | 0.0 | 0.0 | 10000000000.0 | 0.001 | 0.00023 | 0.00169 | 0.005 | 1 | 1 | 2 | 0.001 | 1 |
6732.67 | Ha | 6400.0 | 6800.0 | SII6732 | 1 | 0.0 | 0.0 | 10000000000.0 | 0.001 | 0.00023 | 0.00169 | 0.005 | 1 | 1 | 2 | 0.001 | 1 |
4862.68 | Hb | 4640.0 | 5100.0 | Hb_br | 2 | 0.0 | 0.0 | 10000000000.0 | 0.005 | 0.004 | 0.05 | 0.01 | 0 | 0 | 0 | 0.01 | 1 |
4862.68 | Hb | 4640.0 | 5100.0 | Hb_na | 1 | 0.0 | 0.0 | 10000000000.0 | 0.001 | 0.00023 | 0.00169 | 0.01 | 1 | 1 | 0 | 0.002 | 1 |
4960.3 | Hb | 4640.0 | 5100.0 | OIII4959c | 1 | 0.0 | 0.0 | 10000000000.0 | 0.001 | 0.00023 | 0.00169 | 0.01 | 1 | 1 | 0 | 0.002 | 1 |
5008.24 | Hb | 4640.0 | 5100.0 | OIII5007c | 1 | 0.0 | 0.0 | 10000000000.0 | 0.001 | 0.00023 | 0.00169 | 0.01 | 1 | 1 | 0 | 0.004 | 1 |
4960.3 | Hb | 4640.0 | 5100.0 | OIII4959w | 1 | 0.0 | 0.0 | 10000000000.0 | 0.003 | 0.00023 | 0.004 | 0.01 | 2 | 2 | 0 | 0.001 | 1 |
5008.24 | Hb | 4640.0 | 5100.0 | OIII5007w | 1 | 0.0 | 0.0 | 10000000000.0 | 0.003 | 0.00023 | 0.004 | 0.01 | 2 | 2 | 0 | 0.002 | 1 |
2798.75 | MgII | 2700.0 | 2900.0 | MgII_br | 2 | 0.0 | 0.0 | 10000000000.0 | 0.005 | 0.004 | 0.05 | 0.015 | 0 | 0 | 0 | 0.05 | 1 |
2798.75 | MgII | 2700.0 | 2900.0 | MgII_na | 1 | 0.0 | 0.0 | 10000000000.0 | 0.001 | 0.0005 | 0.00169 | 0.01 | 1 | 1 | 0 | 0.002 | 1 |
1908.73 | CIII | 1700.0 | 1970.0 | CIII_br | 2 | 0.0 | 0.0 | 10000000000.0 | 0.005 | 0.004 | 0.05 | 0.015 | 99 | 0 | 0 | 0.01 | 1 |
1549.06 | CIV | 1500.0 | 1700.0 | CIV_br | 2 | 0.0 | 0.0 | 10000000000.0 | 0.005 | 0.004 | 0.05 | 0.015 | 0 | 0 | 0 | 0.05 | 1 |
1215.67 | Lya | 1150.0 | 1290.0 | Lya_br | 3 | 0.0 | 0.0 | 10000000000.0 | 0.005 | 0.002 | 0.05 | 0.02 | 0 | 0 | 0 | 0.05 | 1 |
1240.14 | Lya | 1150.0 | 1290.0 | NV1240 | 1 | 0.0 | 0.0 | 10000000000.0 | 0.002 | 0.001 | 0.01 | 0.005 | 0 | 0 | 0 | 0.002 | 1 |