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