Ejemplo n.º 1
0
def make_hc15n_all_lines_fig():
    fit_results_path = os.path.expanduser(
        "~/Documents/Data/Herschel_Science_Archive/IRAS16293/Fit_results")
    list_of_files_15 = glob.glob(fit_results_path + "/HC15N*.fits")
    list_of_spectra_15 = [x for x in list_of_files_15 if 'spectrum.fits' in x]
    list_of_results_15 = [x for x in list_of_files_15 if 'result.fits' in x]

    fig = plt.figure()

    for i, (spectrum_fname, result_fname) in enumerate(
            zip(list_of_spectra_15, list_of_results_15)):

        ax = fig.add_subplot(3, 4, i + 1)

        spectrum_tuple = load_a_spectrum(spectrum_fname)
        result_tuple = load_a_spectrum(result_fname)

        ax.plot(spectrum_tuple[2],
                spectrum_tuple[0],
                'k',
                lw=1,
                drawstyle='steps-mid')
        ax.plot(result_tuple[2], result_tuple[0], 'r', lw=0.75)

        ax.set_xlim(-40, 40)
        ax.set_ylim(-0.05, 0.1)

        line_name_nospace = spectrum_fname.split('/')[-1].rstrip(
            '_spectrum.fits')
        line_name = "HC15N " + line_name_nospace.lstrip("HC15N_")
        ax.text(-38, 0.07, line_name)

    plt.show()
    return fig
def make_c17o_all_lines_fig():
    fit_results_path = os.path.expanduser(
        "~/Documents/Data/Herschel_Science_Archive/IRAS16293/Fit_results")
    list_of_files = glob.glob(fit_results_path + "/C17O*.fits")
    list_of_spectra = [x for x in list_of_files if 'spectrum.fits' in x]
    list_of_results = [x for x in list_of_files if 'result.fits' in x]

    fig = plt.figure()

    for i, (spectrum_fname,
            result_fname) in enumerate(zip(list_of_spectra, list_of_results)):

        ax = fig.add_subplot(3, 4, i + 1)

        spectrum_tuple = load_a_spectrum(spectrum_fname)
        result_tuple = load_a_spectrum(result_fname)

        ax.plot(spectrum_tuple[2],
                spectrum_tuple[0],
                'k',
                lw=1,
                drawstyle='steps-mid')
        ax.plot(result_tuple[2], result_tuple[0], 'r', lw=0.75)

        ax.set_xlim(-12, 18)
        ax.set_ylim(-0.25, 0.75)

        line_name_nospace = spectrum_fname.split('/')[-1].rstrip(
            '_spectrum.fits')
        mol_name, Ju = parse_linestring(
            spectrum_fname.split('/')[-1].rstrip('_spectrum.fits'))
        plottable_string = plottable_latex_string(mol_name, Ju)

        ax.text(-10, 0.6, plottable_string)

    plt.show()

    return fig
Ejemplo n.º 3
0
def make_hcn_h13cn_hc15n_figure(fit_tuple=None):
    fit_results_path = os.path.expanduser(
        "~/Documents/Data/Herschel_Science_Archive/IRAS16293/Fit_results")

    list_of_files = glob.glob(fit_results_path + "/HCN*.fits")
    list_of_files_13 = glob.glob(fit_results_path + "/H13CN*.fits")
    list_of_files_15 = glob.glob(fit_results_path + "/HC15N*.fits")

    fig = plt.figure(figsize=(8.6, 4.8))

    text_params = dict(fontsize=11,
                       family='serif',
                       bbox={
                           'facecolor': 'white',
                           'alpha': 0.6,
                           'edgecolor': 'none'
                       })

    file_list_list = [list_of_files, list_of_files_13, list_of_files_15]

    ylims = [(-0.1, 1), (-0.05, 0.12), (-0.04, 0.08)]
    text_heights = [0.8, 0.09, 0.06]

    for j, file_list in enumerate(file_list_list):

        spectra_list = [x for x in file_list if 'spectrum.fits' in x]
        results_list = [x for x in file_list if 'result.fits' in x]

        for i, (spectrum_fname,
                result_fname) in enumerate(zip(spectra_list, results_list)):

            if i > 4:
                break

            ax = fig.add_subplot(3, 5, i + 1 + 5 * j)
            ax.tick_params(axis='both', labelsize=7)

            spectrum_tuple = load_a_spectrum(spectrum_fname)
            result_tuple = load_a_spectrum(result_fname)
            mol_name, Ju = parse_linestring(
                spectrum_fname.split('/')[-1].rstrip('_spectrum.fits'))

            ax.plot(spectrum_tuple[2],
                    spectrum_tuple[0],
                    'k',
                    lw=0.75,
                    drawstyle='steps-mid')
            result_linestyle = 'r-'

            if fit_tuple is not None:
                # retrieve the relevant fit dict from fit_tuple
                this_fit = [
                    x for x in fit_tuple[j].values()
                    if x['Molecule'] == mol_name and x['Ju'] == Ju
                ][0]
                if this_fit['n_lines'] == 2:

                    result_linestyle = 'C0--'

                    # plot the individual line fits
                    xs = np.arange(-30, 30, 0.1)
                    a = this_fit['t_peak']  # 0.03666304656927235
                    b = this_fit['v_cen']  # 3.67
                    c = this_fit['v_fwhm'] / 2.35482  # 6.45 / 2.35482
                    ys = a * np.exp(-(xs - b)**2 / (2 * c**2))

                    ax.plot(xs, ys, 'r', lw=0.75)

                    a2 = this_fit['t_peak_2']  # 0.35102
                    b2 = this_fit['v_cen_2']  # -4.813
                    c2 = this_fit['v_fwhm_2'] / 2.35482  # 6.062 / 2.35482
                    ys2 = a2 * np.exp(-(xs - b2)**2 / (2 * c2**2))

                    ax.plot(xs, ys2, 'C2', lw=0.75)

            ax.plot(result_tuple[2],
                    result_tuple[0],
                    result_linestyle,
                    lw=0.75)

            ax.set_xlim(-30, 30)
            ax.set_ylim(ylims[j])

            plottable_string = plottable_latex_string(mol_name, Ju)
            ax.text(-25, text_heights[j], plottable_string, **text_params)

            if j != 2:
                ax.tick_params(axis='x', labelbottom='off')
            if i > 0:
                ax.tick_params(axis='y', labelleft='off')
            if i == 0 and j == 2:
                ax.set_xlabel(r"$V_{\rm{lsr}}$ (km s$^{-1}$)", fontsize=8)
                ax.set_ylabel(r"$T_{\rm{mb}}$ (K)", fontsize=8)

    plt.tight_layout(w_pad=0.5, h_pad=0.3)
    plt.show()
    return fig