'_treatedlinesLog.txt') tableLogAddress = str(file_address).replace('.fits', '_treatedlinesLog') figureLogAddress = str(file_address).replace('.fits', '_treatedlinesLog.png') # Set and crop the wavelength wave_rest, flux, header = sr.import_fits_data(file_address, instrument='SDSS') idx_wave = (wave_rest >= obsData['sample_data']['wmin_array']) & ( wave_rest <= obsData['sample_data']['wmax_array']) # Load line measurer object lm = sr.LineMesurer(wave_rest[idx_wave], flux[idx_wave] / fluxNorm, linesDF_address=linesLogAddress) pdf = PdfPrinter() # Measure line fluxes idcs_lines = ~lm.linesDF.index.str.contains('_b') obsLines = lm.linesDF.loc[idcs_lines].index.values pdf.create_pdfDoc(tableLogAddress, pdf_type='table') pdf.pdf_insert_table(tableHeaders) flux_Hbeta = lm.linesDF.loc['H1_4861A', 'intg_flux'] for lineLabel in obsLines: label_entry = lm.linesDF.loc[lineLabel, 'latexLabel'] eqw, eqwErr = lm.linesDF.loc[lineLabel, 'eqw'], lm.linesDF.loc[lineLabel,
'DirectMethod_fitSigma', 'DirectMethod_difPercentage', 'HIICHImistry_Spherical_fitFlux', 'HIICHImistry_Spherical_fitSigma', 'HIICHImistry_Spherical_difPercentage', 'HIICHImistry_PlaneParallel_fitFlux', 'HIICHImistry_PlaneParallel_fitSigma', 'HIICHImistry_PlaneParallel_difPercentage', 'BayesHIICHImistry_fitFlux', 'BayesHIICHImistry_fitSigma', 'BayesHIICHImistry_difPercentage', 'DirectMethod-BayesHIICHImistry_fitFlux', 'DirectMethod-BayesHIICHImistry_fitSigma', 'DirectMethod-BayesHIICHImistry_difPercentage' ] tableDF = pd.DataFrame(columns=txt_headers) pdf = PdfPrinter() pdf.create_pdfDoc(pdf_type=None) pdf.pdf_insert_table(table_headers, addfinalLine=True) for i, lineLabel in enumerate(tableLines): row_data = ['-'] * len(table_headers) row_txt = ['-'] * (len(txt_headers)) row_data[0] = latexLabel_array[i] obsFlux, obsErr = objLinesDF.loc[ lineLabel, 'obsFlux'], objLinesDF.loc[lineLabel, 'obsFluxErr'] row_data[1] = r'${:.3f}\pm{:.3f}$'.format(obsFlux, obsErr) row_txt[0], row_txt[1] = f'{obsFlux:.3f}', f'{obsErr:.3f}'
traces_param.append(param) traces_param = np.array(traces_param) obj_Results = {} traces = fit_results['trace'] for trace_code in traces_param: trace_array = traces[trace_code] mean_value = np.mean(trace_array) std_dev = np.std(trace_array) obj_Results[trace_code] = (mean_value, std_dev) sample_Results[obj] = obj_Results # Generate the table pdf = PdfPrinter() pdf.create_pdfDoc(pdf_type=None) pdf.pdf_insert_table(['Parameter', 'SHOC148', 'GP101157', 'GP121903']) for i, param in enumerate(rows): row_data = ['-'] * 4 row_data[0] = latex_labels[param] for j, obj in enumerate(objList[:3]): param_mean, param_std = sample_Results[obj][param] if param == 'logU': param_formated = r'${:.2f}\pm{:.2f}$'.format(param_mean, param_std) elif param != 'He2': round_n = 0 if param_mean > 10 else 2 param_formated = r'${}\pm{}$'.format(
def table_line_fluxes(table_address, db_dict, combined_dict={}, file_type='table'): # Table headers headers = [ 'Line', 'Observed flux', 'Mean', 'Standard deviation', 'Median', r'$16^{th}$ $percentil$', r'$84^{th}$ $percentil$', r'$Difference\,\%$' ] # Create containers tableDF = pd.DataFrame(columns=headers[1:]) pdf = PdfPrinter() pdf.create_pdfDoc(pdf_type=file_type) pdf.pdfDoc.append( NoEscape('\definecolor{background}{rgb}{0.169, 0.169, 0.169}')) pdf.pdfDoc.append( NoEscape('\definecolor{foreground}{rgb}{0.702, 0.780, 0.847}')) pdf.pdfDoc.append(NoEscape(r'\arrayrulecolor{foreground}')) pdf.pdf_insert_table(headers, color_font='foreground', color_background='background') # Input data inputLabels = db_dict['Input_data']['lineLabels_list'] inFlux, inErr = db_dict['Input_data']['inputFlux_array'], db_dict[ 'Input_data']['inputErr_array'] # Output data flux_matrix = db_dict['trace']['calcFluxes_Op'] mean_line_values = flux_matrix.mean(axis=0) std_line_values = flux_matrix.std(axis=0) median_line_values = np.median(flux_matrix, axis=0) p16th_line_values = np.percentile(flux_matrix, 16, axis=0) p84th_line_values = np.percentile(flux_matrix, 84, axis=0) # Array wih true error values for flux diff_Percentage = np.round((1 - (median_line_values / inFlux)) * 100, 2) diff_Percentage = list(map(str, diff_Percentage)) ion_array, wave_array, latexLabel_array = label_decomposition( inputLabels, combined_dict=combined_dict) for i in range(inFlux.size): # label = label_formatting(inputLabels[i]) row_i = [ latexLabel_array[i], inFlux[i], mean_line_values[i], std_line_values[i], median_line_values[i], p16th_line_values[i], p84th_line_values[i], diff_Percentage[i] ] pdf.addTableRow( row_i, last_row=False if inputLabels[-1] != inputLabels[i] else True, color_font='foreground', color_background='background') tableDF.loc[inputLabels[i]] = row_i[1:] pdf.generate_pdf(table_address) # Save the table as a dataframe. with open(f'{table_address}.txt', 'wb') as output_file: string_DF = tableDF.to_string() output_file.write(string_DF.encode('UTF-8'))
# Import the observation data obsData = sr.loadConfData('D:/Pycharm Projects/vital_tests/astro/data/SDSS/flux_comparison.ini', group_variables=False) linesFile = Path('D:/Pycharm Projects/spectra-synthesizer/src/specsiser/literature_data/lines_data.xlsx') linesDb = pd.read_excel(linesFile, sheet_name=0, header=0, index_col=0) data_folder = Path(obsData['file_information']['data_folder']) fileList = list_files(data_folder, '.fits') addressList = list(data_folder / file for file in fileList) flux_norm = obsData['sample_data']['norm_flux'] tableHeaders = [r'Object name', r'$EW(H\beta)$ $(\AA)$', r'$c(H\beta)$', r'$F(H\alpha)/F(H\beta)$'] scaleTable = 1000.0 fitsFolder, fitsFile = addressList[0].parent, addressList[0].name sampleFolder, tableName = fitsFolder/'sample_data', 'sample_properties' pdf = PdfPrinter() pdf.create_pdfDoc(sampleFolder / tableName, pdf_type='table') pdf.pdf_insert_table(tableHeaders) # Analyse the spectrum for i, file_address in enumerate(addressList): # Open lineslog fitsFolder, fitsFile = file_address.parent, file_address.name lineLogFolder, lineLogFile = fitsFolder/'flux_analysis', fitsFile.replace('.fits', '_linesLog.txt') pdfLogFolder, pdfLogFile = fitsFolder / 'flux_analysis', fitsFile.replace('.fits', '_linesLog') objName = fitsFile.replace('.fits', '') print(f'- {i}: {objName}') # Set and crop the wavelength
r'$\chi^2$': 'CHI2_RED', r'$T_{e} (K)$': 'TELECTRO', r'$n_{e} (cm^{-3})$': 'DELECTRO', r'$A_{V, neb}$': 'GNEBULAR', r'$A_{V, \star}$': 'GEXTINCT', 'Mass ever formed': 'LOGMEAVE', 'Mass presently availabled': 'LOGMEAVE', 'Mass > 1 Myr': 'LOGPEAVE' } row_headers = list(dict_ref.keys()) tables_folder = Path(obsData['file_information']['tables_folder']) for i, obj in enumerate(objList): pdf = PdfPrinter() row_object = [''] * len(row_headers) row_object[5] = obj pdf.create_pdfDoc(pdf_type='table') pdf.pdf_insert_table(row_object, addfinalLine=False) pdf.table.add_hline() pdf.addTableRow(row_headers, last_row=False, rounddig=2) pdf.table.add_hline() # Declare input files objFolder = resultsFolder / f'{obj}' results_file = objFolder / f'{obj}_{ext}_measurements.txt' # Declare output file table_file = tables_folder / f'{obj}_FadoFitting'
# Establish files location objName = obsData['file_information']['object_list'][i] fitsFolder, fitsFile = file_address.parent, file_address.name lineLogFolder, lineLogFile = fitsFolder / 'flux_analysis', fitsFile.replace( '.fits', '_linesLog.txt') pdfTableFolder, pdfTableFile = fitsFolder / 'flux_analysis', fitsFile.replace( '.fits', '_linesTable') txtTableFolder, txtTableFile = fitsFolder / 'flux_analysis', fitsFile.replace( '.fits', '_linesTable.txt') print(f'-{objName}') # Load line measuerer object lm = sr.LineMesurer(linesDF_address=lineLogFolder / lineLogFile) pdf = PdfPrinter() tableDF = pd.DataFrame(columns=tableHeaders[1:]) # Measure line fluxes idcs_lines = ~lm.linesDF.index.str.contains('_b') obsLines = lm.linesDF.loc[idcs_lines].index.values # Measure line fluxes pdf.create_pdfDoc(pdfTableFolder / pdfTableFile, pdf_type='table') pdf.pdf_insert_table(tableHeaders) # Normalizing flux flux_Halpha = lm.linesDF.loc['H1_6563A', 'gauss_flux'] flux_Hbeta = lm.linesDF.loc['H1_4861A', 'intg_flux'] halpha_norm = flux_Halpha / flux_Hbeta
refernList = obsData['file_information']['refName_list'] resultsFolder = Path(obsData['file_information']['results_folder']) tables_folder = Path('/home/vital/Dropbox/Astrophysics/Seminars/UniVapo 2021/') ext = 'BR' cycle = 'it3' table_headers = [ 'Galaxy', 'Parameter', r'\makecell{\textsc{HII-CHI-mistry: } \\ Spherical}', r'\makecell{\textsc{HII-CHI-mistry: } \\ Plane-Parallel}', r'\makecell{Bayesian \textsc{HII-CHI-mistry: } \\ Plane-Parallel}', r'\makecell{Bayesian \\ Direct Method + \textsc{HII-CHI-mistry} \\ Plane-Parallel}' ] pdf = PdfPrinter() pdf.create_pdfDoc(pdf_type='table') pdf.pdfDoc.append( pylatex.NoEscape('\definecolor{background}{rgb}{0.169, 0.169, 0.169}')) pdf.pdfDoc.append( pylatex.NoEscape('\definecolor{foreground}{rgb}{0.702, 0.780, 0.847}')) pdf.pdf_insert_table(table_headers, addfinalLine=True, color_background='background', color_font='foreground') for i, obj in enumerate(objList[:3]): objFolder = resultsFolder / f'{obj}' results_file = objFolder / f'{obj}_{ext}_measurements.txt' lineLog_file = objFolder / f'{obj}_{ext}_linesLog_{cycle}.txt'
from src.specsiser.data_printing import PdfPrinter, latex_labels from pylatex import NoEscape atomic_data_dict = {'T_low': r'$Normal(\mu=15,000K,\sigma=5000K)$', 'T_high': r'$Normal(\mu=15,000K,\sigma=5000K)$', 'n_e': r'$HalfCauchy(\mu=2.0,\sigma=0)$', 'cHbeta': r'$HalfCauchy(\mu=2.0,\sigma=0)$', 'log(X_i+)': r'$Normal(\mu=5,\sigma=5)$', 'log(He1r)': r'$Normal(\mu=0,\sigma=3)$', 'log(He2r)': r'$Normal(\mu=0,\sigma=3)$', 'Teff': r'$Uniform(min=30,000K, max=90,000K)$', 'logU': r'$Uniform(min=-4.0, max=-1.0K)$'} tables_folder = Path('/home/vital/Dropbox/Astrophysics/Seminars/UniVapo 2021/') pdf = PdfPrinter() pdf.create_pdfDoc(pdf_type='table') pdf.pdfDoc.append(NoEscape('\definecolor{background}{rgb}{0.169, 0.169, 0.169}')) pdf.pdfDoc.append(NoEscape('\definecolor{foreground}{rgb}{0.702, 0.780, 0.847}')) pdf.pdfDoc.append(NoEscape(r'\arrayrulecolor{foreground}')) pdf.pdf_insert_table(['Parameter', 'Prior distribution'], addfinalLine=True, color_font='foreground', color_background='background') for ion, params in atomic_data_dict.items(): ion_label = latex_labels[ion] row = [ion_label, params] pdf.addTableRow(row, last_row=False, color_font='foreground', color_background='background') pdf.table.add_hline()
scaleTable = 1000 pdfTableFile, txtTableFile = tables_folder / f'sample_emission_lines', tables_folder / f'sample_emission_lines.txt' table_header_format = 'lccccccc' row_headers = [ '', '', pylatex.MultiColumn(2, align='c', data=objSubList[0].upper()), pylatex.MultiColumn(2, align='c', data=objSubList[1].upper()), pylatex.MultiColumn(2, align='c', data=objSubList[2].upper()) ] row_subHeaders = [ 'Line label', r'$f_{\lambda}$', r'$F(\lambda)$', r'$I(\lambda)$', r'$F(\lambda)$', r'$I(\lambda)$', r'$F(\lambda)$', r'$I(\lambda)$' ] # Table heading pdf = PdfPrinter() pdf.create_pdfDoc(pdf_type='table') pdf.pdf_insert_table(row_headers, table_format=table_header_format, addfinalLine=False) # pdf.table.add_hline(3, 4, cmidruleoption='l{10pt}r{2pt}') # pdf.table.add_hline(5, 6) # pdf.table.add_hline(7, 8) pdf.addTableRow(row_subHeaders, last_row=True) # Table body for i, linelabel in enumerate(tableDF.index): # Line reference if (tableDF.loc[linelabel, 'blended_label'] == 'None') or ('_m' in linelabel): label_ref = tableDF.loc[linelabel, 'latexLabel']
conf_file_address = '../../../papers/gtc_greenpeas/gtc_greenpeas_data.ini' obsData = sr.loadConfData(conf_file_address, objList_check=True, group_variables=False) objList = obsData['file_information']['object_list'] objRef = obsData['file_information']['refName_list'] tables_folder = Path(obsData['file_information']['tables_folder']) table_headers = {} table_headers = [ 'SDSS ID', 'Label', 'R.A', 'DEC', 'z', '$Grisms^{1}$', '$T_{exp}$', 'Seeing', r'Standard stars$^{2}$' ] pdf = PdfPrinter() pdf.create_pdfDoc(pdf_type=None) pdf.pdf_insert_table(table_headers, addfinalLine=True) for i, obj in enumerate(objList): if i < 3: row = ['-'] * len(table_headers) objData = obsData[obj] # row[0] = objData['SDSS_label'] row[0] = r'\href{{{}}}{{{}}}'.format( objData['SDSS_website'].replace('&', '\&'), objData['SDSS_label']) print(row[0]) row[1] = objRef[i]
resultsFolder = Path(obsData['file_information']['results_folder']) tables_folder = Path(obsData['file_information']['tables_folder']) ext = 'BR' cycle = 'it3' table_headers = ['Galaxy', 'Parameter', r'\makecell{\textsc{HII-CHI-mistry: } \\ Spherical}', r'\makecell{\textsc{HII-CHI-mistry: } \\ Plane-Parallel}', r'\makecell{Bayesian \textsc{HII-CHI-mistry: } \\ Plane-Parallel}', r'\makecell{Bayesian \\ Direct Method + \textsc{HII-CHI-mistry} \\ Plane-Parallel}' ] pdf = PdfPrinter() pdf.create_pdfDoc(pdf_type=None) pdf.pdf_insert_table(table_headers, addfinalLine=True) for i, obj in enumerate(objList[:3]): objFolder = resultsFolder / f'{obj}' results_file = objFolder / f'{obj}_{ext}_measurements.txt' lineLog_file = objFolder / f'{obj}_{ext}_linesLog_{cycle}.txt' outputPiDb = objFolder / f'{obj}_{ext}_pI_fitting_{cycle}.db' outputDirectHIIchemDb = objFolder / f'{obj}_{ext}_Direct-Teff-logU_{cycle}.db' results_dict = sr.loadConfData(results_file, group_variables=False) for j, param in enumerate(('Teff', 'logU')):
base_DF.loc[line] = lm.linesDF.loc[line] #Sort the data objectList = list(df_dict.keys()) objectList.sort() base_DF.sort_values(by=['wavelength'], inplace=True) idcsLines = ~base_DF.index.str.contains('_b') lineList = base_DF.loc[idcsLines].index.values # Print the data for lineLabel in lineList: sampleFolder, tableName = fitsFolder / 'sample_data' / 'properties_by_line', f'{lineLabel}_fluxes' pdf = PdfPrinter() pdf.create_pdfDoc(sampleFolder / tableName, pdf_type='table') refarenceTable = base_DF.loc[lineLabel, 'latexLabel'] print(refarenceTable) tableHeaders = [ refarenceTable, '$EW(\AA)$', '$F(\lambda)$', '$I(\lambda)$', r'$c(H\beta)$' ] pdf.pdf_insert_table(tableHeaders) for obj in objectList: objDF = df_dict[obj] if lineLabel in objDF.index:
'Kaufman \& Sugar (1986); Galav\'is et al. (1995)' ], 'Ar4': ['Ramsbottom \& Bell (1997)', 'Mendoza \& Zeippen (1982)'], 'Cl3': ['Butler \& Zeippen (1989)', 'Mendoza (1983)'], 'Fe3': ['Zhang (1996)', 'Quinet (1996), Johansson et al. (2000)'], 'Ni3': ['Bautista (2001)', 'Bautista (2001)'] } tables_folder = Path('/home/vital/Dropbox/Astrophysics/Seminars/UniVapo 2021/') table_headers = [ 'SDSS ID', 'Label', 'R.A', 'DEC', 'z', '$Grisms^{1}$', '$T_{exp}$', 'Seeing', r'Standard stars$^{2}$' ] pdf = PdfPrinter() pdf.create_pdfDoc(pdf_type='table') pdf.pdfDoc.append( NoEscape('\definecolor{background}{rgb}{0.169, 0.169, 0.169}')) pdf.pdfDoc.append( NoEscape('\definecolor{foreground}{rgb}{0.702, 0.780, 0.847}')) pdf.pdfDoc.append(NoEscape(r'\arrayrulecolor{foreground}')) pdf.pdf_insert_table( ['Ion', 'Collision Strengths', 'Transition probabilities'], addfinalLine=True, color_font='foreground', color_background='background') for ion, params in atomic_data_dict.items():
conf_file_address = '../../../papers/gtc_greenpeas/gtc_greenpeas_data.ini' obsData = sr.loadConfData(conf_file_address, objList_check=True, group_variables=False) objList = obsData['file_information']['object_list'] objRef = obsData['file_information']['refName_list'] tables_folder = Path('/home/vital/Dropbox/Astrophysics/Seminars/UniVapo 2021/') table_headers = {} table_headers = [ 'SDSS ID', 'Label', 'R.A', 'DEC', 'z', '$Grisms^{1}$', '$T_{exp}$', 'Seeing', r'Standard stars$^{2}$' ] pdf = PdfPrinter() pdf.create_pdfDoc(pdf_type='table') pdf.pdfDoc.append( NoEscape('\definecolor{background}{rgb}{0.169, 0.169, 0.169}')) pdf.pdfDoc.append( NoEscape('\definecolor{foreground}{rgb}{0.702, 0.780, 0.847}')) pdf.pdfDoc.append(NoEscape(r'\arrayrulecolor{foreground}')) pdf.pdf_insert_table(table_headers, addfinalLine=True, color_font='foreground') for i, obj in enumerate(objList): if i < 3: row = ['-'] * len(table_headers) objData = obsData[obj]