Esempio n. 1
0
def plot_mir_set(
    ax,
    starnames,
    extra_off_val=0.0,
    plam4=True,
    norm_wave_range=[6.0, 10.0] * u.micron,
    col_vals=["b", "g", "r", "m", "c", "y"],
    ann_xvals=[35.0, 42.0] * u.micron,
    ann_wave_range=[9.0, 15.0] * u.micron,
    ann_rot=5.0,
    ann_offset=0.2,
    fontsize=12,
    path="/home/kgordon/Python_git/extstar_data/",
    subpath="DAT_files/",
):
    """
    Plot a set of spectra
    """
    n_col = len(col_vals)
    for i in range(len(starnames)):
        stardata = StarData(subpath + starnames[i] + ".dat", path=path, use_corfac=True)

        stardata.plot(
            ax,
            mlam4=True,
            norm_wave_range=norm_wave_range,
            yoffset=extra_off_val + 0.5 * i,
            yoffset_type="add",
            pcolor=col_vals[i % n_col],
            annotate_key="IRS",
            annotate_wave_range=ann_wave_range,
            annotate_text=starnames[i] + " " + stardata.sptype,
            fontsize=fontsize,
            annotate_rotation=ann_rot,
            annotate_yoffset=ann_offset,
        )
Esempio n. 2
0
    mpl.rc("lines", linewidth=1)
    mpl.rc("axes", linewidth=2)
    mpl.rc("xtick.major", width=2)
    mpl.rc("xtick.minor", width=2)
    mpl.rc("ytick.major", width=2)
    mpl.rc("ytick.minor", width=2)

    # setup the plot
    fig, ax = plt.subplots(figsize=(13, 10))

    # plot the bands and all spectra for this star
    # plot all the spectra on the same plot
    for k, cstarname in enumerate(starnames):
        fstarname, file_path = get_full_starfile(cstarname)
        starobs = StarData(fstarname, path=file_path)
        starobs.plot(ax, norm_wave_range=[0.2, 0.3] * u.micron, yoffset=2**k)

    # finish configuring the plot
    ax.set_yscale("log")
    ax.set_xscale("log")
    ax.set_xlabel(r"$\lambda$ [$\mu m$]", fontsize=1.3 * fontsize)
    ax.set_ylabel(r"$F(\lambda)$ [$ergs\ cm^{-2}\ s\ \AA$]",
                  fontsize=1.3 * fontsize)
    ax.tick_params("both", length=10, width=2, which="major")
    ax.tick_params("both", length=5, width=1, which="minor")

    # use the whitespace better
    fig.tight_layout()

    # plot or save to a file
    save_str = "_spec"
Esempio n. 3
0
    half_num = len(starnames) // 2 + 1
    col_vals = ["b", "g", "c"]
    n_cols = len(col_vals)
    for k, cstarname in enumerate(starnames):
        fstarname, file_path = get_full_starfile(cstarname)
        starobs = StarData(fstarname, path=file_path)
        if k // half_num > 0:
            yoff = 2.5**(k - half_num)
        else:
            yoff = 2.5**k
        starobs.plot(
            ax[k // half_num],
            norm_wave_range=[0.2, 0.3] * u.micron,
            yoffset=yoff,
            pcolor=col_vals[k % n_cols],
            annotate_key="IUE",
            annotate_wave_range=[0.25, 0.27] * u.micron,
            annotate_text=cstarname,
            annotate_rotation=-10.,
            annotate_yoffset=0.0,
            fontsize=12,
        )
        print(cstarname)

    # finish configuring the plot
    for i in range(2):
        ax[i].set_xlim(0.1, 0.325)
        ylim = ax[i].get_ylim()
        ax[i].set_ylim(1e-1, ylim[1])
        ax[i].set_xscale("linear")
        ax[i].set_yscale("log")
        ax[i].set_xlabel(r"$\lambda$ [$\mu m$]", fontsize=1.3 * fontsize)
Esempio n. 4
0
def plot_multi_spectra(
    starlist,
    path,
    mlam4=False,
    HI_lines=False,
    range=None,
    norm_range=None,
    spread=False,
    exclude=[],
    log=False,
    class_offset=True,
    text_offsets=[],
    text_angles=[],
    pdf=False,
    outname="all_spec.pdf",
):
    """
    Plot the observed band and spectral data of multiple stars in the same plot

    Parameters
    ----------
    starlist : list of strings
        List of stars for which to plot the spectrum

    path : string
        Path to the data files

    mlam4 : boolean [default=False]
        Whether or not to multiply the flux F(lambda) by lambda^4 to remove the Rayleigh-Jeans slope

    HI_lines : boolean [default=False]
        Whether or not to indicate the HI-lines in the plot

    range : list of 2 floats [default=None]
        Wavelength range to be plotted (in micron) - [min,max]

    norm_range : list of 2 floats [default=None]
        Wavelength range to use to normalize the data (in micron)- [min,max]

    spread : boolean [default=False]
        Whether or not to spread the spectra out by adding a vertical offset to each spectrum

    exclude : list of strings [default=[]]
        List of data type(s) to exclude from the plot (e.g., IRS)

    log : boolean [default=False]
        Whether or not to plot the wavelengths on a log-scale

    class_offset : boolean [default=True]
        Whether or not to add an extra offset between main sequence and giant stars (only relevant when spread=True; this only works when the stars are sorted by spectral class, i.e. first the main sequence and then the giant stars)

    text_offsets : list of floats [default=[]]
        List of the same length as starlist with offsets for the annotated text

    text_angles : list of integers [default=[]]
        List of the same length as starlist with rotation angles for the annotated text

    pdf : boolean [default=False]
        Whether or not to save the figure as a pdf file

    outname : string [default="all_spec.pdf"]
        Name for the output pdf file

    Returns
    -------
    Figure with band data points and spectra of multiple stars
    """
    # plotting setup for easier to read plots
    fontsize = 18
    font = {"size": fontsize}
    plt.rc("font", **font)
    plt.rc("lines", linewidth=1)
    plt.rc("axes", linewidth=2)
    plt.rc("xtick.major", width=2)
    plt.rc("xtick.minor", width=2)
    plt.rc("ytick.major", width=2)
    plt.rc("ytick.minor", width=2)

    # create the plot
    fig, ax = plt.subplots(figsize=(15, len(starlist) * 1.25))
    colors = plt.get_cmap("tab10")

    if norm_range is not None:
        norm_range = norm_range * u.micron

    # set default text offsets and angles
    if text_offsets == []:
        text_offsets = np.full(len(starlist), 0.2)
    if text_angles == []:
        text_angles = np.full(len(starlist), 10)

    for i, star in enumerate(starlist):
        # read in all bands and spectra for this star
        starobs = StarData("%s.dat" % star.lower(), path=path, use_corfac=True)

        # spread out the spectra if requested
        # add extra whitespace when the luminosity class changes from main sequence to giant
        if spread:
            extra_off = 0
            if "V" not in starobs.sptype and class_offset:
                extra_off = 1
            yoffset = extra_off + 0.5 * i
        else:
            yoffset = 0

        # determine where to add the name of the star and its spectral type
        # find the shortest plotted wavelength, and give preference to spectral data when available
        exclude2 = []
        if "BAND" in starobs.data.keys() and len(starobs.data.keys()) > 1:
            exclude2 = ["BAND"]
        (waves, fluxes,
         flux_uncs) = starobs.get_flat_data_arrays(starobs.data.keys() -
                                                   (exclude + exclude2))
        if range is not None:
            waves = waves[waves >= range[0]]
        min_wave = waves[0]
        # find out which data type corresponds with this wavelength
        for data_type in starobs.data.keys():
            if data_type in exclude:
                continue
            used_waves = starobs.data[data_type].waves[
                starobs.data[data_type].npts > 0]
            if min_wave in used_waves.value:
                ann_key = data_type
        ann_range = [min_wave, min_wave] * u.micron

        # plot the spectrum
        starobs.plot(
            ax,
            pcolor=colors(i % 10),
            norm_wave_range=norm_range,
            mlam4=mlam4,
            exclude=exclude,
            yoffset=yoffset,
            yoffset_type="add",
            annotate_key=ann_key,
            annotate_wave_range=ann_range,
            annotate_text=star.upper() + "  " + starobs.sptype,
            annotate_yoffset=text_offsets[i],
            annotate_rotation=text_angles[i],
            annotate_color=colors(i % 10),
        )

    # plot HI-lines if requested
    if HI_lines:
        plot_HI(path, ax)

    # zoom in on a specific region if requested
    if range is not None:
        zoom(ax, range)
        outname = outname.replace(".pdf", "_zoom.pdf")

    # finish configuring the plot
    if not spread:
        ax.set_yscale("log")
    if log:
        ax.set_xscale("log")
    ax.set_xlabel(r"$\lambda$ [$\mu m$]", fontsize=1.5 * fontsize)
    ylabel = r"$F(\lambda)$"

    if norm_range is not None:
        if norm_range[0].unit == "micron":
            units = r"$\mu m$"
        else:
            units = norm_range[0].unit
        ylabel += "/$F$(" + str(int(np.mean(norm_range).value)) + units + ")"
    else:
        ylabel += r" [$ergs\ cm^{-2}\ s^{-1}\ \AA^{-1}$]"
    if mlam4:
        ylabel = r"$\lambda^4$" + ylabel.replace("]", r" $\mu m^4$]")
        outname = outname.replace("spec", "spec_mlam4")
    if spread:
        ylabel += " + offset"
    ax.set_ylabel(ylabel, fontsize=1.5 * fontsize)
    ax.tick_params("both", length=10, width=2, which="major")
    ax.tick_params("both", length=5, width=1, which="minor")

    # show the figure or save it to a pdf file
    if pdf:
        fig.savefig(path + outname, bbox_inches="tight")
    else:
        plt.show()

    # return the figure and axes for additional manipulations
    return fig, ax
Esempio n. 5
0
def plot_spectrum(
    star,
    path,
    mlam4=False,
    HI_lines=False,
    range=None,
    norm_range=None,
    exclude=[],
    pdf=False,
):
    """
    Plot the observed band and spectral data of a star

    Parameters
    ----------
    star : string
        Name of the star for which to plot the spectrum

    path : string
        Path to the data files

    mlam4 : boolean [default=False]
        Whether or not to multiply the flux F(lambda) by lambda^4 to remove the Rayleigh-Jeans slope

    HI_lines : boolean [default=False]
        Whether or not to indicate the HI-lines in the plot

    range : list of 2 floats [default=None]
        Wavelength range to be plotted (in micron) - [min,max]

    norm_range : list of 2 floats [default=None]
        Wavelength range to use to normalize the data (in micron)- [min,max]

    exclude : list of strings [default=[]]
        List of data type(s) to exclude from the plot (e.g., IRS)

    pdf : boolean [default=False]
        Whether or not to save the figure as a pdf file

    Returns
    -------
    Figure with band data points and spectrum
    """
    # plotting setup for easier to read plots
    fontsize = 18
    font = {"size": fontsize}
    plt.rc("font", **font)
    plt.rc("lines", linewidth=1)
    plt.rc("axes", linewidth=2)
    plt.rc("xtick.major", width=2)
    plt.rc("xtick.minor", width=2)
    plt.rc("ytick.major", width=2)
    plt.rc("ytick.minor", width=2)

    # create the plot
    fig, ax = plt.subplots(figsize=(13, 10))

    # read in and plot all bands and spectra for this star
    starobs = StarData("%s.dat" % star.lower(), path=path, use_corfac=True)
    if norm_range is not None:
        norm_range = norm_range * u.micron
    starobs.plot(ax, norm_wave_range=norm_range, mlam4=mlam4, exclude=exclude)

    # plot HI-lines if requested
    if HI_lines:
        plot_HI(path, ax)

    # define the output name
    outname = star.lower() + "_spec.pdf"

    # zoom in on a specific region if requested
    if range is not None:
        zoom(ax, range)
        outname = outname.replace(".pdf", "_zoom.pdf")

    # finish configuring the plot
    ax.set_xscale("log")
    ax.set_yscale("log")
    ax.set_title(star.upper(), fontsize=50)
    ax.set_xlabel(r"$\lambda$ [$\mu m$]", fontsize=1.5 * fontsize)
    if mlam4:
        ax.set_ylabel(
            r"$F(\lambda)\ \lambda^4$ [$ergs\ cm^{-2}\ s^{-1}\ \AA^{-1}\ \mu m^4$]",
            fontsize=1.5 * fontsize,
        )
        outname = outname.replace("spec", "spec_mlam4")
    else:
        ax.set_ylabel(
            r"$F(\lambda)$ [$ergs\ cm^{-2}\ s^{-1}\ \AA^{-1}$]",
            fontsize=1.5 * fontsize,
        )
    ax.tick_params("both", length=10, width=2, which="major")
    ax.tick_params("both", length=5, width=1, which="minor")

    # show the figure or save it to a pdf file
    if pdf:
        fig.savefig(path + outname, bbox_inches="tight")
        plt.close()
    else:
        plt.show()
Esempio n. 6
0
    fontsize = 18
    font = {'size': fontsize}
    mpl.rc('font', **font)
    mpl.rc('lines', linewidth=1)
    mpl.rc('axes', linewidth=2)
    mpl.rc('xtick.major', width=2)
    mpl.rc('xtick.minor', width=2)
    mpl.rc('ytick.major', width=2)
    mpl.rc('ytick.minor', width=2)

    # setup the plot
    fig, ax = plt.subplots(figsize=(13, 10))

    # plot the bands and all spectra for this star
    import astropy.units as u
    starobs.plot(ax, mlam4=True, norm_wave_range=[10., 20.] * u.micron)

    # finish configuring the plot
    ax.set_yscale('log')
    ax.set_xscale('log')
    ax.set_xlabel('$\lambda$ [$\mu m$]', fontsize=1.3 * fontsize)
    ax.set_ylabel('$F(\lambda)$ [$ergs\ cm^{-2}\ s\ \AA$]',
                  fontsize=1.3 * fontsize)
    ax.tick_params('both', length=10, width=2, which='major')
    ax.tick_params('both', length=5, width=1, which='minor')

    # use the whitespace better
    fig.tight_layout()

    # plot or save to a file
    save_str = '_spec'