Example #1
0
    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'

    # # Load the data
    results_dict = sr.loadConfData(results_file, group_variables=False)

    for j, ssp_lib in enumerate(ssp_lib_list):

        section_label = f'{ssp_lib}_FADO'
        section_results = results_dict[section_label]

        row_data = []
        for column, param_code in dict_ref.items():
            param_value = section_results[param_code]
            row_data.append(param_value)
        row_data[0] = ssp_lib

        pdf.addTableRow(row_data, last_row=False, rounddig=2)

    pdf.table.add_hline()
    pdf.generate_pdf(table_file)
Example #2
0
        param_value = (np.mean(trace), np.std(trace))
        if param == 'Teff':
            param_entry = r'${:.0f}\pm{:.0f}$'.format(param_value[0],
                                                      param_value[1])
        else:
            param_entry = r'${:.2f}\pm{:.2f}$'.format(param_value[0],
                                                      param_value[1])
        row_data[4] = param_entry

        # Bayesian Direct method + HII-CHI-mistry
        if outputDirectHIIchemDb.is_file():
            model_fit = sr.load_MC_fitting(outputDirectHIIchemDb)
            trace = model_fit['trace'][param]
            param_value = (np.mean(trace), np.std(trace))
            if param == 'Teff':
                param_entry = r'${:.0f}\pm{:.0f}$'.format(
                    param_value[0], param_value[1])
            else:
                param_entry = r'${:.2f}\pm{:.2f}$'.format(
                    param_value[0], param_value[1])
            row_data[5] = param_entry

        pdf.addTableRow(row_data,
                        color_background='background',
                        color_font='foreground')

pdf.table.add_hline()

table_file = tables_folder / f'photo-ionization_param_comparison'
pdf.generate_pdf(table_file, clean_tex=False)
Example #3
0
    wave_rest, flux, header = sr.import_fits_data(fitsFolder/fitsFile, 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], lineLogFolder / lineLogFile, normFlux=flux_norm)

    # Measure line fluxes
    idcs_lines = ~lm.linesDF.index.str.contains('_b')
    obsLines = lm.linesDF.loc[idcs_lines].index.values

    # Equivalent width Hbeta
    eqw_Hbeta, eqwErr_Hbeta = lm.linesDF.loc['H1_4861A', 'eqw'], lm.linesDF.loc['H1_4861A', 'eqw_err']
    eqw_entry = r'${:0.2f}$ $\pm$ ${:0.2f}$'.format(eqw_Hbeta, eqwErr_Hbeta)

    # 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
    halphaRatio_entry = r'${:0.2f}$'.format(halpha_norm)
    colorGrade = colorChooser(halpha_norm, 2.86)
    RatioComparison = r'\textcolor{{{}}}{{{}}}'.format(colorGrade, halphaRatio_entry)

    # Reddening coefficient
    rc = pn.RedCorr(R_V=3.4, law='G03 LMC')
    rc.setCorr(obs_over_theo=halpha_norm/2.86, wave1=6563., wave2=4861.)
    cHbeta_entry = r'${:0.2f}$'.format(rc.cHbeta)
    pdf.addTableRow([objName, eqw_entry, cHbeta_entry, RatioComparison], last_row=True if file_address == addressList[-1] else False)

# Generate the table
pdf.generate_pdf(clean_tex=True)
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()
pdf.generate_pdf(tables_folder/'posteriors_table', clean_tex=True)

    cHbeta = r'${:0.2f}\,\pm\,{:0.2f}$'.format(cHbeta[0], cHbeta[1])
    eqw_Hbeta = r'${}\,\pm\,{}$'.format(f'{eqw:0.0f}', f'{eqw_err:0.0f}')
    F_Hbeta = r'${}$'.format(
        f'{linesDF_i.loc["H1_4861A", "intg_flux"] / normFlux:0.3f}')

    print(linesDF_i.loc["H1_4861A", "intg_flux"], normFlux,
          linesDF_i.loc["H1_4861A", "intg_flux"] / normFlux)
    # eqw_Hbeta = f'{linesDF_i.loc["H1_4861A", "eqw"]:0.2f}'
    # F_Hbeta = f'{linesDF_i.loc["H1_4861A", "intg_flux"]/normFlux:0.2f}'

    cHbeta_row[2 + j] = pylatex.MultiColumn(2,
                                            align='c',
                                            data=pylatex.NoEscape(cHbeta))
    eqwHbeta_row[2 + j] = pylatex.MultiColumn(2,
                                              align='c',
                                              data=pylatex.NoEscape(eqw_Hbeta))
    FHbeta_row[2 + j] = pylatex.MultiColumn(2,
                                            align='c',
                                            data=pylatex.NoEscape(F_Hbeta))

pdf.addTableRow(cHbeta_row)
pdf.addTableRow(eqwHbeta_row)
pdf.addTableRow(FHbeta_row, last_row=True)

# Save the pdf table
print(f'-- Saving table at: {pdfTableFile}')
try:
    pdf.generate_pdf(pdfTableFile, clean_tex=False)
except:
    print('-- PDF compilation failure')
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]
        row[2] = objData['RA']
        row[3] = objData['DEC']
        row[4] = objData['z']
        row[5] = f'{objData["grism_b"]}, {objData["grism_r"]}'
        # row[5] = f'{objData["grism_b"]} (blue), {objData["grism_r"]}(red)'
        row[6] = r'${}\times{}s$'.format(objData["exp_number"],
                                         objData["exp_time"])
        row[7] = r'$\approx {}$'.format(objData["seeing"])
        row[8] = f'{objData["standard_blue"]}, {objData["standard_red"]}'
        # row[8] = f'{objData["standard_blue"]} (blue), {objData["standard_red"]}(red)'
        # row[9] = f'{objData["night_type"]} night'

        pdf.addTableRow(row, last_row=False)

pdf.table.add_hline()
pdf.generate_pdf(tables_folder / 'night_log')
                lineInt, lineIntErr = np.array(measurements_dict[section][lineLabel], dtype=float)
                lineFlux, lineFluxErr = lineInt / np.power(10, cHbeta[0] * flambda), lineIntErr / np.power(10, cHbeta[0] * flambda)
                row_data[3] = r'${:.3f}\pm{:.3f}$'.format(lineFlux, lineFluxErr)
                row_data[3] += percent_func(obsFlux, lineFlux)

            section = f'HII_Tef_fit_C17_bb_Teff_30-90_pp.dat_{cycle}_sed'
            if lineLabel in measurements_dict[section]:
                lineInt, lineIntErr = np.array(measurements_dict[section][lineLabel], dtype=float)
                lineFlux, lineFluxErr = lineInt / np.power(10, cHbeta[0] * flambda), lineIntErr / np.power(10, cHbeta[0] * flambda)
                row_data[4] = r'${:.3f}\pm{:.3f}$'.format(lineFlux, lineFluxErr)
                row_data[4] += percent_func(obsFlux, lineFlux)

            if lineLabel in flux_tensor_dict:
                lineFlux, lineFluxErr = np.mean(flux_tensor_dict[lineLabel]), np.std(flux_tensor_dict[lineLabel])
                row_data[5] = r'${:.3f}\pm{:.3f}$'.format(lineFlux, lineFluxErr)
                row_data[5] += percent_func(obsFlux, lineFlux)

            if lineLabel in srPlus_lineLabels:
                i_line = sr_lineLabels.index(lineLabel)
                row_data[6] = r'${:.3f}\pm{:.3f}$'.format(mean_plus_line_values[i_line], std_plus_line_values[i_line])
                row_data[6] += percent_func(obsFlux, mean_plus_line_values[i_line])

            pdf.addTableRow(row_data, last_row=False)

        pdf.table.add_hline()

        table_file = tables_folder/f'{obj}_lineFlux_fit_comparison'
        pdf.generate_pdf(table_file, clean_tex=True)


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():
    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()
pdf.generate_pdf(tables_folder / 'atomic_data', clean_tex=False)
    nebCompFile = objFolder / f'{obj}{ext}_NebFlux_{cycle}.txt'
    run_ref = f'{obj}{ext}_{cycle}'
    objSSP_outputFile = starlight_folder / 'Output' / f'{obj}{ext}_it2.slOutput'

    # Starlight wrapper
    sw = SSPsynthesizer()

    # Data output
    results_dict = sr.loadConfData(results_file, group_variables=False)
    stellar_fit_dict = results_dict[f'Starlight_run_it2']
    stellar_Wave, obj_input_flux, stellar_flux, fit_output = sw.load_starlight_output(
        objSSP_outputFile)

    if stellar_fit_dict['A_V_stellarr'] == 0:
        stellar_fit_dict['A_V_stellarr'] = 0.0

    row_data = [
        objRefNames[i],
        np.round(stellar_fit_dict['Galaxy_mass_Current'], 2),
        np.round(stellar_fit_dict['Galaxy_mass_Percentbelow20Myr'], 2),
        np.round(stellar_fit_dict['A_V_stellarr'], 2),
        np.round(stellar_fit_dict['cHbeta_stellar'], 2),
        np.round(stellar_fit_dict['SN'], 2),
        np.round(stellar_fit_dict['Chi2'], 2)
    ]

    pdf.addTableRow(row_data, last_row=False, rounddig=2)

pdf.table.add_hline()
pdf.generate_pdf(pdfTableFile)
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]

        # row[0] = objData['SDSS_label']
        row[0] = r'\href{{{}}}{{{}}}'.format(
            objData['SDSS_website'].replace('&', '\&'), objData['SDSS_label'])
        row[1] = objRef[i]
        row[2] = objData['RA']
        row[3] = objData['DEC']
        row[4] = objData['z']
        row[5] = f'{objData["grism_b"]}, {objData["grism_r"]}'
        # row[5] = f'{objData["grism_b"]} (blue), {objData["grism_r"]}(red)'
        row[6] = r'${}\times{}s$'.format(objData["exp_number"],
                                         objData["exp_time"])
        row[7] = r'$\approx {}$'.format(objData["seeing"])
        row[8] = f'{objData["standard_blue"]}, {objData["standard_red"]}'
        # row[8] = f'{objData["standard_blue"]} (blue), {objData["standard_red"]}(red)'
        # row[9] = f'{objData["night_type"]} night'

        # pdf.addTableRow(NoEscape(r'\rowcolor{background}'), last_row=False)
        pdf.addTableRow(row, last_row=False, color_font='foreground')

pdf.table.add_hline()
pdf.generate_pdf(tables_folder / 'night_log_dark', clean_tex=False)