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]
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])
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])