Exemplo n.º 1
0
def __resid(pars, ncoefs=1, knots=None, order=3, irbkg=1, nfft=2048,
            kraw=None, mu=None, kout=None, ftwin=1, chi_std=None, **kws):

    coefs = [getattr(pars, FMT_COEF % i) for i in range(ncoefs)]
    bkg, chi = spline_eval(kraw, mu, knots, coefs, order, kout)
    if chi_std is not None:
        chi = chi - chi_std
    return realimag(xafsft_fast(chi*ftwin, nfft=nfft)[:irbkg])
Exemplo n.º 2
0
    def apply(self, chi, eps_scale=False, all_kweights=True, **kws):
        """apply transform, returns real/imag components
        eps_scale: scale by appropriaat epsilon_k or epsilon_r
        """
        # print 'this  is transform apply ', len(chi), chi[5:10], kws
        for key, val in kws.items():
            if key == 'kw': key = 'kweight'
            setattr(self, key, val)

        all_kweights = all_kweights and isinstance(self.kweight, Iterable)
        # print 'fit space = ', self.fitspace
        if self.fitspace == 'k':
            if all_kweights:
                return np.concatenate([chi * self.k_[:len(chi)]**kw for kw in self.kweight])
            else:
                return chi * self.k_[:len(chi)]**self.kweight
        elif self.fitspace in ('r', 'q'):
            self.make_karrays()
            out = []
            if all_kweights:
                # print 'Apply -- use all kweights ', self.kweight
                chir = [self.fftf(chi, kweight=kw) for kw in self.kweight]
                eps_r = self.epsilon_r
            else:
                chir = [self.fftf(chi)]
                eps_r = [self.epsilon_r]
            if self.fitspace == 'r':
                irmin = int(0.01 + self.rmin/self.rstep)
                irmax = min(self.nfft/2,  int(1.01 + self.rmax/self.rstep))
                for i, chir_ in enumerate(chir):
                    if eps_scale:
                        chir_ = chir_ /(eps_r[i])
                    out.append( realimag(chir_[irmin:irmax]))
            else:
                chiq = [self.ffti(self.r_, c) for c in chir]
                iqmin = int(0.01 + self.kmin/self.kstep)
                iqmax = min(self.nfft/2,  int(1.01 + self.kmax/self.kstep))
                for chiq_ in chiq:
                    out.append( realimag(chiq[iqmin:iqmax]))
            return np.concatenate(out)
Exemplo n.º 3
0
def __resid(pars,
            knots=None,
            order=3,
            irbkg=1,
            nfft=2048,
            kraw=None,
            mu=None,
            kout=None,
            ftwin=1,
            **kws):
    coefs = [p.value for p in pars.values()]
    bkg, chi = spline_eval(kraw, mu, knots, coefs, order, kout)
    return realimag(xafsft_fast(chi * ftwin, nfft=nfft)[:irbkg])
Exemplo n.º 4
0
    def apply(self, k, chi, **kws):
        """apply filter"""
        
        for key, val in kws:
            if key == 'kweight': key = 'kw'
            setattr(self, key, val)

        if self.fitspace == 'k':
            return chi * k**self.kw
        elif self.fitspace in ('r', 'q'):
          
            k_ = self.kstep * arange(self.nfft, dtype='float64')
            r_ = self.rstep * arange(self.nfft, dtype='float64')
            chir = self.fft(k_, chi)
            if self.fitspace == 'r':
                irmin = index_of(r_, self.rmin)
                irmax = min(self.nfft/2,  1 + index_of(r_, self.rmax))
                return realimag(chir[irmin:irmax])
            else:
                chiq = self.ifft(r_, chir)
                iqmin = index_of(k_, self.kmin)
                iqmax = min(self.nfft/2,  1 + index(k_, self.kmax))
                return realimag(chiq[ikmin:ikmax])
Exemplo n.º 5
0
    def apply(self, k, chi, **kws):
        """apply filter"""

        for key, val in kws:
            if key == 'kweight': key = 'kw'
            setattr(self, key, val)

        if self.fitspace == 'k':
            return chi * k**self.kw
        elif self.fitspace in ('r', 'q'):

            k_ = self.kstep * arange(self.nfft, dtype='float64')
            r_ = self.rstep * arange(self.nfft, dtype='float64')
            chir = self.fft(k_, chi)
            if self.fitspace == 'r':
                irmin = index_of(r_, self.rmin)
                irmax = min(self.nfft / 2, 1 + index_of(r_, self.rmax))
                return realimag(chir[irmin:irmax])
            else:
                chiq = self.ifft(r_, chir)
                iqmin = index_of(k_, self.kmin)
                iqmax = min(self.nfft / 2, 1 + index(k_, self.kmax))
                return realimag(chiq[ikmin:ikmax])
Exemplo n.º 6
0
    def _estimate_noise(self, chi, rmin=15.0, rmax=25.0, all_kweights=True):
        """estimage noice from high r"""
        # print 'Estimate Noise!! ', rmin, self.transform.rmin
        self.make_karrays()

        save = self.rmin, self.rmax, self.fitspace

        all_kweights = all_kweights and isinstance(self.kweight, Iterable)
        if all_kweights:
            chir = [self.fftf(chi, kweight=kw) for kw in self.kweight]
        else:
            chir = [self.fftf(chi)]
        irmin = int(0.01 + rmin/self.rstep)
        irmax = min(self.nfft/2,  int(1.01 + rmax/self.rstep))
        highr = [realimag(chir_[irmin:irmax]) for chir_ in chir]
        # get average of window function value, we will scale eps_r scale by this
        ikmin = index_of(self.k_, self.kmin)
        ikmax = index_of(self.k_, self.kmax)
        kwin_ave = self.kwin[ikmin:ikmax].sum()/(ikmax-ikmin)

        eps_r = [(sqrt((chi*chi).sum() / len(chi)) / kwin_ave) for chi in highr]
        eps_k = []
        # use Parseval's theorem to convert epsilon_r to epsilon_k,
        # compensating for kweight
        if all_kweights:
            kweights = self.kweight[:]
        else:
            kweights = [self.kweight]
        for i, kw in enumerate(kweights):
            w = 2 * kw + 1
            scale = sqrt((2*pi*w)/(self.kstep*(self.kmax**w - self.kmin**w)))
            eps_k.append(scale*eps_r[i])


        self.rmin, self.rmax, self.fitspace = save

        self.n_idp  = 2*(self.rmax-self.rmin)*(self.kmax-self.kmin)/pi
        self.epsilon_k = eps_k
        self.epsilon_r = eps_r
        if len(eps_r) == 1:
            self.epsilon_k = eps_k[0]
            self.epsilon_r = eps_r[0]
Exemplo n.º 7
0
def __resid(pars, knots=None, order=3, irbkg=1, nfft=2048,
            kraw=None, mu=None, kout=None, ftwin=1, **kws):
    coefs = [p.value for p in pars.values()]
    bkg, chi = spline_eval(kraw, mu, knots, coefs, order, kout)
    return realimag(xafsft_fast(chi*ftwin, nfft=nfft)[:irbkg])