def smooth_in_section(xx, data, deviation, order): f = fitting(xx, data) f.fitting(order) for index in range(len(xx)): if data[index] - f.val[index] > deviation * f.ER2: data[index] = f.val[index] + deviation * f.ER2 elif f.val[index] - data[index] > deviation * f.ER2: data[index] = f.val[index] - deviation * f.ER2
def fit_to_powerlow(self): """Fitting method to calcurate the fractal dimension of DLA cluster.""" def fit_func(parameter0, R_g, Narr): """Fitting function: Narr ~ R_{g}^{D}""" log = np.log c1 = parameter0[0] c2 = parameter0[1] residual = log(Narr) - c1 - c2*log(R_g) return residual def fitted(R, c1, D): return np.exp(c1)*(R**D) fitting(self.R_g, self.Narr, fit_func, [0.1, 1.7], fitted, xlabel=r'$R_{g}$', ylabel=r'$N$', param_to_show={'D': 1} )
def main(N): def fit_func(parameter, Tarr, sigma_T): """Fitting function: sigma ~ T^{H}""" log = np.log c1 = parameter[0] c2 = parameter[1] residual = log(sigma_T) - c1 - c2*log(Tarr) return residual def fitted(T, c1, H): return np.exp(c1)*(T**H) # Create brownian motion and calcurate deviations for each T Tarr, sigma_T = calc_hurst(brownian_curve_1d(N, plot=True), plot=True) # Fitting fitting(Tarr, sigma_T, fit_func, [0.1, 0.5], fitted, xlabel=r'$T$', ylabel=r'$\sigma_{x}$', param_to_show={'D': 1} )
inp_date = input('最初の日付, 最後の日付(カンマ区切りでyymmdd形式) >> ').split(',') # カンマ区切りでリストの要素として拾う inp_date_nospace = [i.strip() for i in inp_date] # リスト各要素の両端の空白を削除 for da in tqdm(pd.date_range(*inp_date_nospace)): randate = da.strftime('%Y%m%d') print(''' ___________________________________ 次の年月日のファイルをfittingします。 ''') print(randate) for fitfile in tqdm(glob.glob(param['in'] + randate + '*')): data = np.loadtxt(fitfile) # load text data as array if not len(data): continue # dataが空なら次のループ fitRtn = fitting.fitting(fitfile, plot_switch=plot) # fitting.pyへフルパス渡す SNResult.update(fitRtn[0]) # fittingを行い、結果をSNResultに貯める powerResult.update(fitRtn[1]) # fittingを行い、結果をpowerResultに貯める # print('') # print('Now Fitting...', fitfile[-19:]) # print('Write to SN...', list(fitRtn[0].values())[0]) # print('Write to Power...', list(fitRtn[1].values())[0]) # __WRITEING__________________________ ''' for文の中でc.editCSVを行うと 逐一書き込むので処理の最中にctrl+Cで中断できるが (しかもfinallyステート内で最後に書き込みを行わせる) 逐一ファイルの読み込みを行うので、 csvファイルが巨大になっていくごとにc.editCSVの処理に時間がかかる