def get_spline_TI(self, list_epsilon, eta, hw, sign_Gamma):
        """
        Compute the interpolated value for TR, using splines, which we assume are already computed.
        """

        # find the index of eta
        i_eta = self.get_i_eta_index(eta)

        # find the indices of closest frequencies in table
        # as well as interpolation coefficients

        i_hw_1, i_hw_2, alpha_1, alpha_2 = self.get_hw_indices_and_interpolation(hw)

        # evaluate spline            
        u = N.real ( list_epsilon )

        re_tuple_1 = (self.list_xi, self.re_TI_spline[i_eta,i_hw_1,:], self.spline_order)
        im_tuple_1 = (self.list_xi, self.im_TI_spline[i_eta,i_hw_1,:], self.spline_order)

        T_I_1 = sign_Gamma*complex(1.,0.)*spleval(re_tuple_1,u)+ complex(0.,1.)*spleval(im_tuple_1,u)

        re_tuple_2 = (self.list_xi, self.re_TI_spline[i_eta,i_hw_2,:], self.spline_order)
        im_tuple_2 = (self.list_xi, self.im_TI_spline[i_eta,i_hw_2,:], self.spline_order)

        T_I_2 = sign_Gamma*complex(1.,0.)*spleval(re_tuple_2,u)+ complex(0.,1.)*spleval(im_tuple_2,u)

        T_I = alpha_1*T_I_1+alpha_2*T_I_2

        return T_I
    def get_spline_SI(self, list_epsilon, sign_Gamma):
        """
        Compute the interpolated value for SR, using splines, which we assume are already computed.
        """
        # evaluate spline            
        u = N.real ( list_epsilon )

        re_tuple = (self.list_xi, self.re_SI_spline, self.spline_order)
        im_tuple = (self.list_xi, self.im_SI_spline, self.spline_order)

        S_I = sign_Gamma*complex(1.,0.)*spleval(re_tuple,u)+ complex(0.,1.)*spleval(im_tuple,u)

        return S_I
Esempio n. 3
0
    def __call__(self, wave):
        if not HAS_SCIPY:
            raise ImportError("To use this function scipy needs to be installed")

        from scipy.interpolate import spleval

        wave_shape = wave.shape
        wave = _process_wave(wave)

        _check_wave(wave, 909.091 * u.angstrom, 6.0 * u.micron)

        res = np.empty_like(wave.__array__(), dtype=np.float64)

        # Analytic function in the UV.
        uvmask = wave < (2700.0 * u.angstrom)
        if np.any(uvmask):
            res[uvmask] = cextinction.f99uv(wave[uvmask].value, self.a_v, self.r_v)

        # Spline in the Optical/IR
        oirmask = ~uvmask
        if np.any(oirmask):
            k = spleval(self._spline, 1.0 / wave[oirmask].to("micron"))
            res[oirmask] = self.a_v / self.r_v * (k + self.r_v)

        return res.reshape(wave_shape)
Esempio n. 4
0
    def __call__(self, wave):
        if not HAS_SCIPY:
            raise ImportError('To use this function scipy needs to be installed')

        from scipy.interpolate import spleval

        wave_shape = wave.shape
        wave = _process_wave(wave)

        _check_wave(wave, 909.091* u.angstrom, 6. * u.micron)

        res = np.empty_like(wave.__array__(), dtype=np.float64)

        # Analytic function in the UV.
        uvmask = wave < (2700. * u.angstrom)
        if np.any(uvmask):
            res[uvmask] = cextinction.f99uv(wave[uvmask].value, self.a_v, self.r_v)

        # Spline in the Optical/IR
        oirmask = ~uvmask
        if np.any(oirmask):
            k = spleval(self._spline, 1. / wave[oirmask].to('micron'))
            res[oirmask] = self.a_v / self.r_v * (k + self.r_v)

        return res.reshape(wave_shape)
Esempio n. 5
0
def splines(x, t, k=3, deriv=0):
    n = len(t) - 1

    I = np.eye(n + k)

    return np.vstack(spleval(
        (t.copy(), I[i], k),
        x,
        deriv=deriv) for i in range(n + k))
  def subsampleInterpolatedFibers(self, quantitiyOfPointsPerfiber):
    if '_interpolate' not in dir():
      raise NotImplementedError('scipy module could not be imported, this operation is not implemented')

    self._quantitiyOfPointsPerfiber = quantitiyOfPointsPerfiber
    self._subsampledFibers = []
    s = _numpy.linspace(0,1,quantitiyOfPointsPerfiber)
    i=0.
    for f in self._fibers:
      i+=1
      tck,u = _interpolate.splprep( f.T )
      self._subsampledFibers.append( _numpy.transpose(_interpolate.spleval(s,tck)))

    self._subsampledFibers = _numpy.array( self._subsampledFibers ) 
    self._interpolated = True
Esempio n. 7
0
    def propagate(self, wave, flux):

        ext = np.empty(len(wave), dtype=np.float)

        # Analytic function in the UV.
        uvmask = wave < 2700.
        if np.any(uvmask):
            a_v = self._parameters[0] * self._r_v
            ext[uvmask] = f99uv(wave[uvmask], a_v, self._r_v)

        # Spline in the Optical/IR
        oirmask = ~uvmask
        if np.any(oirmask):
            k = spleval(self._spline, 1.e4 / wave[oirmask])
            ext[oirmask] = self._parameters[0] * (k + self._r_v)

        trans = 10.**(-0.4 * ext)
        return trans * flux
    def subsampleInterpolatedFibers(self, quantitiyOfPointsPerfiber):
        if '_interpolate' not in dir():
            raise NotImplementedError(
                'scipy module could not be imported, this operation is not implemented'
            )

        self._quantitiyOfPointsPerfiber = quantitiyOfPointsPerfiber
        self._subsampledFibers = []
        s = _numpy.linspace(0, 1, quantitiyOfPointsPerfiber)
        i = 0.
        for f in self._fibers:
            i += 1
            tck, u = _interpolate.splprep(f.T)
            self._subsampledFibers.append(
                _numpy.transpose(_interpolate.spleval(s, tck)))

        self._subsampledFibers = _numpy.array(self._subsampledFibers)
        self._interpolated = True
def upsample(data, factor):
    """
    upsample array of data by a given factor using cubic splines
    array.shape is assumed to be (num_events, num_values_per_event)
    """

    # vpe is values per event
    num_m, num_vpe = data.shape
    # new values appear only between old values, hence the "-1"
    up_num_vpe = (num_vpe - 1) * factor + 1
    axis = arange(0, up_num_vpe, factor)
    up_axis = arange(up_num_vpe)
    #   up_data = zeros((num_m, up_num_vpe))
    #   for i in range(num_m):
    #       up_data[i] = spline(axis, data[i], up_axis)
    splines = splmake(axis, data.T)
    up_data = spleval(splines, up_axis)

    return up_data.T
Esempio n. 10
0
def extinction_fm07(wave, a_v):
    """Fitzpatrick & Massa (2007) extinction model for R_V = 3.1.

    The Fitzpatrick & Massa (2007) [1]_ model, which has a slightly
    different functional form from that of Fitzpatrick (1999) [3]_
    (`extinction_f99`). Fitzpatrick & Massa (2007) claim it is
    preferable, although it is unclear if signficantly so (Gordon et
    al. 2009 [2]_). Defined from 910 A to 6 microns.

    .. note :: This model is not R_V dependent.

    {0}

    References
    ----------
    .. [1] Fitzpatrick, E. L. & Massa, D. 2007, ApJ, 663, 320
    .. [2] Gordon, K. D., Cartledge, S., & Clayton, G. C. 2009, ApJ, 705, 1320
    .. [3] Fitzpatrick, E. L. 1999, PASP, 111, 63
    """
    if not HAS_SCIPY:
        raise ImportError('To use this function scipy needs to be installed')
    from scipy.interpolate import spleval

    wave_shape = wave.shape
    wave = _process_wave(wave)


    _check_wave(wave, 909.091 * u.angstrom, 6.0 * u.micron)
    res = np.empty_like(wave.__array__(), dtype=np.float64)

    # Simple analytic function in the UV
    uvmask = wave < (2700. * u.angstrom)
    if np.any(uvmask):
        res[uvmask] = cextinction.fm07uv(wave[uvmask].value, a_v)
    
    # Spline in the Optical/IR
    oirmask = ~uvmask
    if np.any(oirmask):
        k = spleval(_fm07_spline, (1. / wave[oirmask].to('micron')).value)
        res[oirmask] = a_v / _fm07_r_v * (k + _fm07_r_v)

    return res.reshape(wave_shape)
Esempio n. 11
0
def extinction_fm07(wave, a_v):
    """Fitzpatrick & Massa (2007) extinction model for R_V = 3.1.

    The Fitzpatrick & Massa (2007) [1]_ model, which has a slightly
    different functional form from that of Fitzpatrick (1999) [3]_
    (`extinction_f99`). Fitzpatrick & Massa (2007) claim it is
    preferable, although it is unclear if signficantly so (Gordon et
    al. 2009 [2]_). Defined from 910 A to 6 microns.

    .. note :: This model is not R_V dependent.

    {0}

    References
    ----------
    .. [1] Fitpatrick, E. L. & Massa, D. 2007, ApJ, 663, 320
    .. [2] Gordon, K. D., Cartledge, S., & Clayton, G. C. 2009, ApJ, 705, 1320
    .. [3] Fitzpatrick, E. L. 1999, PASP, 111, 63
    """
    if not HAS_SCIPY:
        raise ImportError('To use this function scipy needs to be installed')
    from scipy.interpolate import spleval

    wave_shape = wave.shape
    wave = _process_wave(wave)


    _check_wave(wave, 909.091 * u.angstrom, 6.0 * u.micron)
    res = np.empty_like(wave.__array__(), dtype=np.float64)

    # Simple analytic function in the UV
    uvmask = wave < (2700. * u.angstrom)
    if np.any(uvmask):
        res[uvmask] = cextinction.fm07uv(wave[uvmask].value, a_v) * wave.unit
    
    # Spline in the Optical/IR
    oirmask = ~uvmask
    if np.any(oirmask):
        k = spleval(_fm07_spline, (1. / wave[oirmask].to('micron')).value)
        res[oirmask] = a_v / _fm07_r_v * (k + _fm07_r_v)

    return res.reshape(wave_shape)
Esempio n. 12
0
def upsample(data, factor):
    """
    upsample array of data by a given factor using cubic splines
    array.shape is assumed to be (num_events, num_values_per_event)
    """


    # vpe is values per event
    num_m, num_vpe = data.shape
    # new values appear only between old values, hence the "-1"
    up_num_vpe = (num_vpe - 1) * factor + 1
    axis = arange(0, up_num_vpe, factor) 
    up_axis = arange(up_num_vpe)
#   up_data = zeros((num_m, up_num_vpe))
#   for i in xrange(num_m):
#       up_data[i] = spline(axis, data[i], up_axis)
    splines = splmake(axis, data.T)
    up_data = spleval(splines, up_axis)

    return up_data.T