Exemple #1
0
Fichier : spec.py Projet : nhmc/H2
def plotlines(z, ax, atmos=None, lines=None, labels=False, ls="dotted", color="k", trim=False, fontsize=10, **kwargs):
    """ Draw vertical dotted lines showing expected positions of
    absorption and emission lines, given a redshift.

    Parameters
    ----------
    atmos : list of float pairs, or True (None)
      Regions of atmospheric absorption to plot. If True, it uses an
      internal list of regions.
    lines : stuctured array, optional
      If given, it must be a record array with fields 'name' and 'wa'.

    Returns the mpl artists representing the lines.
    """
    if lines is None:
        lines = readtxt(DATAPATH + "linelists/galaxy_lines", names="wa,name,select")
    else:
        lines = np.rec.fromrecords([(l["name"], l["wa"]) for l in lines], names="name,wa")
    autoscale = ax.get_autoscale_on()
    if autoscale:
        ax.set_autoscale_on(False)
    artists = []
    w0, w1 = ax.get_xlim()
    wa = lines.wa * (z + 1)
    if trim:
        c0 = between(wa, w0, w1)
        wa = wa[c0]
        lines = lines[c0]
    artists.append(axvlines(wa, ax=ax, ls=ls, color=color, **kwargs))
    if labels:
        for i in range(3):
            for w, l in zip(wa[i::3], lines[i::3]):
                if not (w0 < w < w1) and trim:
                    continue
                # name = l.name + '%.2f' % l.wa
                name = l.name
                artists.append(
                    puttext(
                        w,
                        0.7 + i * 0.08,
                        name,
                        ax,
                        xcoord="data",
                        alpha=1,
                        fontsize=fontsize,
                        rotation=90,
                        ha="right",
                        color=color,
                    )
                )
    if atmos:
        if atmos == True:
            atmos = None
        artists.append(plotatmos(ax, atmos=atmos))
    if autoscale:
        ax.set_autoscale_on(True)

    return artists
Exemple #2
0
def read_pc_all():
    """ Principle components (eigenvectors of the covariance matrix)
    for Suzuki et al. (2005) QSO spectra from 1020 to 1600 Angstroms.
    """
    path = os.path.abspath(os.path.dirname(__file__))
    filename = path + '/PCAcont/Suzuki05/tab3.txt'
    names = 'wa,mu,musig,e1,e2,e3,e4,e5,e6,e7,e8,e9,e10'
    p = readtxt(filename, skip=23, names=names)
    pc = np.array([p['e%i' % i] for i in range(1, 11)])
    return p.wa, p.mu, pc
Exemple #3
0
def read_pc_all():
    """ Principle components (eigenvectors of the covariance matrix)
    for Suzuki et al. (2005) QSO spectra from 1020 to 1600 Angstroms.
    """
    path =  os.path.abspath(os.path.dirname(__file__))
    filename = path + '/PCAcont/Suzuki05/tab3.txt'
    names = 'wa,mu,musig,e1,e2,e3,e4,e5,e6,e7,e8,e9,e10'
    p = readtxt(filename, skip=23, names=names)
    pc = np.array([p['e%i' % i] for i in range(1, 11)])
    return p.wa, p.mu, pc
Exemple #4
0
Fichier : spec.py Projet : nhmc/H2
def pca_qso_cont(nspec, seed=None, return_weights=False):
    """ Make qso continua using the PCA and weights from N. Suzuki et
    al. 2005 and N. Suzuki 2006.

    Parameters
    ----------
    nspec : int
      Number of spectra to create

    Returns
    -------
    wavelength (shape N), array of spectra [shape (nspec, N)]

    Memory use might be prohibitive for nspec > ~1e4.
    """
    # read the principle components
    filename = DATAPATH + "/PCAcont/Suzuki05/tab3.txt"
    names = "wa,mu,musig,e1,e2,e3,e4,e5,e6,e7,e8,e9,e10"
    co = readtxt(filename, skip=23, names=names)
    # use only the first 7 eigenvetors
    eig = [co["e%i" % i] for i in range(1, 8)]
    # from Suzuki et al 2006.
    csig = np.array([7.563, 3.604, 2.351, 2.148, 1.586, 1.479, 1.137])  # , 0.778, 0.735, 0.673])

    # generate weights for each eigenvector
    if seed is not None:
        np.random.seed(seed)
    weights = []
    for sig in csig:
        temp = np.random.randn(2 * nspec)
        # make sure we don't have any very large deviations from the mean
        temp = temp[np.abs(temp) < 3][:nspec]
        assert len(temp) == nspec
        weights.append(temp * sig)

    # generate nspec continua. loop over pixels
    sp = []
    for i in range(len(co.wa)):
        sp.append(co.mu[i] + np.sum(w * e[i] for w, e in zip(weights, eig)))

    sp = np.transpose(sp)
    if return_weights:
        return co.wa, sp, weights
    else:
        return co.wa, sp
Exemple #5
0
  It contains the values `tc` and `tc50` for each element, where `tc`
  is the condensation temperature in K when condensation begins, and
  `tc50` is the temperature when 50% of the element is left in a
  gaseous state.

"""
import numpy as np
from utilities import get_data_path
from io import readtxt
from collections import OrderedDict

datapath = get_data_path()

Asolar = OrderedDict(
    (t.el, t.A) for t in
    readtxt(datapath + 'abundances/SolarAbundance.txt', readnames=1))

cond_temp = readtxt(datapath +
                    'abundances/CondensationTemperatures.txt',
                    readnames=1, sep='|')

def calc_abund(X, Y, logNX, logNY):
    """ Find the abundance relative to solar given two elements and
    their column densities.

    Parameters
    ----------
    X, Y : str
      Element identifiers (for example 'C', 'Si', 'Mg').
    logNX : array_like, shape (N,)
      log10 of element X column density in cm^-2.