Exemple #1
0
 def bin_shift_and_tilt_spline(self, order, singlebin, binSize, multiple, shift, sigma, slope, offset, minuit, **kwargs):
     """trying to smooth, interpolate, and integrate the fit."""
     mask = self.Orders[order]['mask']
     ok = reduce(np.logical_and, [self.Orders[order][binSize][singlebin]['ok'], mask])
     iok = self.Orders[order][binSize][singlebin]['iok']
     iow = self.Orders[order]['iow'][iok]
     iof = self.Orders[order]['iof'][iok]
     wav = self.Orders[order]['wav'][ok]
     flx = self.Orders[order]['flx'][ok]
     err = self.Orders[order]['err'][ok]
     con = self.Orders[order]['con'][ok]
     pix = self.Orders[order]['pix'][ok]
     overflx = multiple * slope_to_array(slope,
                                         wav + shift,
                                         interp.interp_spline(wav + shift,
                                                              iow,
                                                              convolve.convolve_constant_dv(iow,
                                                                                            iof,
                                                                                            vfwhm=sigma)
                                                              )
                                         ) + offset
     chi_square = np.sum((overflx - flx/con)**2 / (err/con)**2)
     if minuit == 0:
         return chi_square
     else:
         return chi_square, wav, flx/con, err/con, pix, overflx
Exemple #2
0
 def bin_shift_and_tilt_spline(self, order, singlebin, binSize, multiple,
                               shift, sigma, slope, offset, minuit,
                               **kwargs):
     """trying to smooth, interpolate, and integrate the fit."""
     mask = self.Orders[order]['mask']
     ok = reduce(np.logical_and,
                 [self.Orders[order][binSize][singlebin]['ok'], mask])
     iok = self.Orders[order][binSize][singlebin]['iok']
     iow = self.Orders[order]['iow'][iok]
     iof = self.Orders[order]['iof'][iok]
     wav = self.Orders[order]['wav'][ok]
     flx = self.Orders[order]['flx'][ok]
     err = self.Orders[order]['err'][ok]
     con = self.Orders[order]['con'][ok]
     pix = self.Orders[order]['pix'][ok]
     overflx = multiple * slope_to_array(
         slope,
         interp.interp_spline(
             wav + shift, iow,
             convolve.convolve_constant_dv(iow, iof, vfwhm=sigma))) + offset
     chi_square = np.sum((overflx - flx / con)**2 / (err / con)**2)
     if minuit == 0:
         return chi_square
     else:
         return chi_square, wav, flx / con, err / con, pix, overflx
Exemple #3
0
def readLSF(grating, dw_new=None):
    """ Read the COS line spread function, optionally interpolated to
    a new pixel width.

    Parameters
    ----------
    grating : str, {'G130M', 'G160M', 'NUV'}
      Either 'NUV' for all near UV gratings, or the name of the far UV
      COS grating.
    dw_new : float
      The new pixel width in Angstroms.  Default is `None`, which
      returns the original LSF.

    Returns
    -------
    LSF, wa : ndarrays of shape (N,)
      The new LSF and the wavelength offsets from the line centre.
    """

    # see if we've already calculated it
    try:
        #print grating, dw, 'cached!'
        return cacheLSF[grating, dw_new]
    except KeyError:
        pass

    oldLSF = readtxt(datapath + '/LSF/%s.txt' % grating, readnames=1)

    dw_orig = dict(G130M=0.00997, G160M=0.01223, NUV=0.390)

    wa0 = oldLSF.relpix * dw_orig[grating]
    if dw_new is None:
        return oldLSF, wa0

    t = np.arange(0, wa0[-1], dw_new)
    wa1 = np.concatenate([-t[::-1][:-1], t])

    wavs = oldLSF.dtype.names[1:]
    newLSF = []
    for w in wavs:
        newLSF.append(interp_spline(wa1, wa0, oldLSF[w]))

    t = np.arange(len(wa1) // 2 + 1)
    newpix = np.concatenate([-t[::-1][:-1], t])
    #import pdb; pdb.set_trace()
    newLSF = np.rec.fromarrays([newpix] + newLSF, names=oldLSF.dtype.names)

    cacheLSF[grating, dw_new] = newLSF, wa1
    return newLSF, wa1
Exemple #4
0
def readLSF(grating, dw_new=None):
    """ Read the COS line spread function, optionally interpolated to
    a new pixel width.

    Parameters
    ----------
    grating : str, {'G130M', 'G160M', 'NUV'}
      Either 'NUV' for all near UV gratings, or the name of the far UV
      COS grating.
    dw_new : float
      The new pixel width in Angstroms.  Default is `None`, which
      returns the original LSF.

    Returns
    -------
    LSF, wa : ndarrays of shape (N,)
      The new LSF and the wavelength offsets from the line centre.
    """

    # see if we've already calculated it
    try:
        #print grating, dw, 'cached!'
        return cacheLSF[grating, dw_new]
    except KeyError:
        pass
    
    oldLSF = readtxt(datapath + '/LSF/%s.txt' % grating, readnames=1)

    dw_orig = dict(G130M=0.00997, G160M=0.01223, NUV=0.390)

    wa0 = oldLSF.relpix * dw_orig[grating]
    if dw_new is None:
        return oldLSF, wa0

    t = np.arange(0, wa0[-1], dw_new)
    wa1 = np.concatenate([-t[::-1][:-1], t])

    wavs = oldLSF.dtype.names[1:]
    newLSF = []
    for w in wavs:
        newLSF.append(interp_spline(wa1, wa0, oldLSF[w]))
        
    t = np.arange(len(wa1)//2 + 1)
    newpix = np.concatenate([-t[::-1][:-1], t])
    #import pdb; pdb.set_trace()
    newLSF = np.rec.fromarrays([newpix] + newLSF, names=oldLSF.dtype.names)

    cacheLSF[grating, dw_new] = newLSF, wa1
    return newLSF, wa1
Exemple #5
0
 def order_shift_and_scale_spline(self, order, multiple, shift, sigma, slope, offset, minuit, **kwargs):
     """trying to smooth, interpolate, and integrate the fit."""
     mask = self.Orders[order]['mask']
     iow = self.Orders[order]['iow']
     iof = self.Orders[order]['iof']
     wav = self.Orders[order]['wav'][mask]
     flx = self.Orders[order]['flx'][mask]
     err = self.Orders[order]['err'][mask]
     con = self.Orders[order]['con'][mask]
     pix = self.Orders[order]['pix'][mask]
     overflx = multiple * slope_to_array(slope, interp.interp_spline(wav + shift, iow, convolve.convolve_constant_dv(iow, iof, vfwhm=sigma))) + offset        
     chi_square = np.sum((overflx - flx/con)**2 / (err/con)**2) 
     if minuit == 0:
         return chi_square
     else:
         return chi_square, wav, flx/con, err/con, pix, overflx
Exemple #6
0
 def order_shift_and_scale_spline(self, order, multiple, shift, sigma,
                                  slope, offset, minuit, **kwargs):
     """trying to smooth, interpolate, and integrate the fit."""
     mask = self.Orders[order]['mask']
     iow = self.Orders[order]['iow']
     iof = self.Orders[order]['iof']
     wav = self.Orders[order]['wav'][mask]
     flx = self.Orders[order]['flx'][mask]
     err = self.Orders[order]['err'][mask]
     con = self.Orders[order]['con'][mask]
     pix = self.Orders[order]['pix'][mask]
     overflx = multiple * slope_to_array(
         slope,
         interp.interp_spline(
             wav + shift, iow,
             convolve.convolve_constant_dv(iow, iof, vfwhm=sigma))) + offset
     chi_square = np.sum((overflx - flx / con)**2 / (err / con)**2)
     if minuit == 0:
         return chi_square
     else:
         return chi_square, wav, flx / con, err / con, pix, overflx
Exemple #7
0
    # Faucher-Giguere 2009
    gamma_HI = 0.861e-12
    print 'gamma HeII'
    for eta in 30, 100, 200:
        print eta, "{:.3g}".format(0.43 * gamma_HI / eta)
    
    prefix = "/Users/ncrighton/Projects/MPIA_QSO_LBG/Cloudy/J0004/comp1"
    names = sorted(glob(prefix + "/uvb_k0?/*tilted*tbl"))

    for n in names:
        #if 'k00' not in n and 'k04' not in n and 'k06' not in n:
        #    continue
        print n
        T = Table.read(n, format='ascii')
        # energy and log10jnu
        if 0:
            x = np.log10(T['energy'])
            x1 = np.arange(x[0], x[-1], 0.1*(x[1]-x[0]))
            from barak.interp import interp_spline
            y1 = interp_spline(x1, x, T['log10jnu'])
            jnu = 10**y1
            gamHeII = find_gamma(10**x1, jnu, Z=2)
            gamHI = find_gamma(10**x1, jnu, Z=1)
        else:
            jnu = 10**T['log10jnu']
            gamHeII = find_gamma(T['energy'], jnu, Z=2)
            gamHI = find_gamma(T['energy'], jnu, Z=1)
        print 'HeII {:.3g}'.format(gamHeII*1e-12)
        print 'HI {:.3g}'.format(gamHI*1e-12)

Exemple #8
0
    # Faucher-Giguere 2009
    gamma_HI = 0.861e-12
    print 'gamma HeII'
    for eta in 30, 100, 200:
        print eta, "{:.3g}".format(0.43 * gamma_HI / eta)

    prefix = "/Users/ncrighton/Projects/MPIA_QSO_LBG/Cloudy/J0004/comp1"
    names = sorted(glob(prefix + "/uvb_k0?/*tilted*tbl"))

    for n in names:
        #if 'k00' not in n and 'k04' not in n and 'k06' not in n:
        #    continue
        print n
        T = Table.read(n, format='ascii')
        # energy and log10jnu
        if 0:
            x = np.log10(T['energy'])
            x1 = np.arange(x[0], x[-1], 0.1 * (x[1] - x[0]))
            from barak.interp import interp_spline
            y1 = interp_spline(x1, x, T['log10jnu'])
            jnu = 10**y1
            gamHeII = find_gamma(10**x1, jnu, Z=2)
            gamHI = find_gamma(10**x1, jnu, Z=1)
        else:
            jnu = 10**T['log10jnu']
            gamHeII = find_gamma(T['energy'], jnu, Z=2)
            gamHI = find_gamma(T['energy'], jnu, Z=1)
        print 'HeII {:.3g}'.format(gamHeII * 1e-12)
        print 'HI {:.3g}'.format(gamHI * 1e-12)