cc = ((rms-rms_o)>=0.0) & (t<5.0) fc = np.zeros(rms.size) fc[cc] = (rms-rms_o)[cc] #b = B-5.0 #b[b<=0] = 0.0 b = B #+++++++++++++++++++++++++++++++++++++++++++++++++++++++ tau_o, bp = 3.0, -0.1 # LIBRES q, off, bo = -5.53, 0.64, 10.0 # FIJOS p = Parameters() p.add('q', value=-5.53, vary=False) p.add('tau', value=3.0, vary=False) p.add('off', value=0.64, vary=False) p.add('bp', value=-0.1, vary=False) p.add('bo', value=10.0, vary=False) TAUs = np.linspace(2.5, 12.0, 50) BPs = np.linspace(-0.5, 0.0, 50) for p['tau'].value in TAUs: for p['bp'].value in BPs: fit = ff.fit_forbush([t, fc, crs, b], [tau_o, q, off, bp, bo]) diff = fit.residuals(p) #print diff #diff = ff.nCR2([t, rms, B], tau, q, off, bp, bo)
cc = ((rms - rms_o) >= 0.0) & (t < 5.0) fc = np.zeros(rms.size) fc[cc] = (rms - rms_o)[cc] #tau = 3.0 #ncr = nCR2([t, fc], tau, q) #++++++++++++++++++++++++++++++++++++++++++++++++ figura fig = figure(1, figsize=(6, 4)) ax0 = fig.add_subplot(111) ax1 = ax0.twinx() #--- plot der ax1.plot(t[1:-1], fc[1:-1], c='gray') tau_o, q, off = 5., -6., 0.1 #2.0, -400.0 fit = ff.fit_forbush([t, fc, crs], [tau_o, q, off]) fit.make_fit() print fit.par #ncr = nCR2([t, fc], tau, q) """ #--- plot izq ax0.plot(t, ncr, label='$\\tau=%2.2g$'%tau) ax0.plot(t, crs, '-o', c='k', ms=3) ax0.axhline(y=0.0, c='g') ax0.axvline(x=0, ls='--', c='gray', lw=3) ax0.axvline(x=1, ls='--', c='gray', lw=3) ax0.axvline(x=4, ls='--', c='gray', lw=3) ax0.legend() ax0.grid() ax0.set_xlim(-2,+7)
tau = Lim(0.1, 5., n=nbin) q = Lim(-20., -0.1, n=nbin) off = Lim(0., 1., n=nbin) bp = Lim(-1., 0., n=nbin) bo = Lim(0., 20., n=nbin) #--- slice object rranges = ( slice(tau.min, tau.max, tau.delta()), slice(q.min, q.max, q.delta()), slice(off.min, off.max, off.delta()), slice(bp.min, bp.max, bp.delta()), slice(bo.min, bo.max, bo.delta()), ) #--- start && run the fitter data = np.array([t, fc, crs, b]) fit = ff.fit_forbush(data, [tau_, q_, off_, bp_, bo_]) fit.make_fit_brute(rranges) print fit.par #--- output en hdf5 fo = h5(fname_out, 'w') for pname in fit.par.keys(): fo[pname] = fit.par[pname] #--- guardamos la grilla de exploracion fo['grids/tau'] = [tau.min, tau.max, tau.delta(), tau.n] fo['grids/q'] = [q.min, q.max, q.delta(), q.n] fo['grids/off'] = [off.min, off.max, off.delta(), off.n] fo['grids/bp'] = [bp.min, bp.max, bp.delta(), bp.n] fo['grids/bo'] = [bo.min, bo.max, bo.delta(), bo.n] #------------------
b = B _tau = np.linspace(*pa.seed_tau) _q = np.linspace(*pa.seed_q) _off = np.linspace(*pa.seed_off) _bp = np.linspace(*pa.seed_bp) _bo = np.linspace(*pa.seed_bo) #tau_o, q, off = 3., -6., 0.1 #2.0, -400.0 #bp, bo = -0.1, 10.0 data = np.array([t, fc, crs, b]) _fit, it = [], 0 all_seeds = list(itertools.product(_tau, _q, _off, _bp, _bo)) for tau_o, q, off, bp, bo in all_seeds: print " it, total: ", it + 1, len(all_seeds) _fit += [ff.fit_forbush(data, [tau_o, q, off, bp, bo])] _fit[it].make_fit(monit=True) it += 1 MinRes = np.array([_fit[i].resid for i in range(len(_fit))]) ind = find(MinRes.min() == MinRes) for i in ind: print _fit[i].niter print _fit[i].par #sys.exit(0) #print fit.par """ tau, bp = 2.36, 0.0 q, off, bo = -9.373, 0.89, 16.15 """