realspec0[i*69:(i+1)*69] /= f else: realspec0[i*69:len(test_lam)] /=f # ~ ~ ~ ~ ~ ~ Initial Conditions ~ ~ ~ ~ ~ ~ # #startarr = np.array([2.5, 1.03, .01, -3.95*10**(-7),0.011079,816.9,.05,.05,.05,.05,.05]) #tau,norm,sig,dxm,dxb,dxc,amps (in fraction of 1, amp of central) low = np.array([2.4,1.01,.008,-3.96*10**-7,.010,816.85,0,0,0,0,0]) high = np.array([2.6,1.04,.02,-3.94*10**-7,0.013,816.95,.1,.1,.1,.1,.1]) #chi_ev = [0] #watch evolution of minf #~ ~ ~ ~ ~ ~ ~ ~ Run NLOPT ~ ~ ~ ~ ~ ~ ~ opt = nlopt.opt(nlopt.GN_CRS2_LM,len(startarr)) #GN_CRS2_LM, MLSL(_LDS),GN_ESCH opt.set_lower_bounds(low) opt.set_upper_bounds(high) opt.set_min_objective(lambda x,grad: tapafunc(x,realspec0,spec,pixels,test_lam,nsat,chi_ev)) opt.set_stopval(.0001) opt.set_maxeval(nit) starttime = time.time() #time function print 'NLOPT stuff is starting now' x = opt.optimize(startarr) elapsedtime = time.time() - starttime minf = opt.last_optimum_value() print x print minf print elapsedtime, ' seconds' # ~ ~ ~ ~ Plot Results ~ ~ ~ ~ ~ ~ # lambd = x[3] * pixels**2 + x[4] * pixels + x[5] plt.figure()
############################### #Import functions import calib_fxns reload(calib_fxns) from calib_fxns import gaussian, sumgaus, tapafunc, binres ########################### ############################################ #~ ~ ~ ~ ~ ~ ~ ~ Run NLOPT ~ ~ ~ ~ ~ ~ ~ opt = nlopt.opt(nlopt.GN_CRS2_LM, len(startarr)) #GN_CRS2_LM, MLSL(_LDS),GN_ESCH opt.set_lower_bounds(lowarr) opt.set_upper_bounds(higharr) opt.set_min_objective( lambda x, grad: tapafunc(x, realspec, spec, pixels, test_lam, nsat, chi_ev, xx_smalls, lo_inds, hi_inds)) #opt.add_inequality_constraint(lambda x,grad: ampconstraint(x,2,1,nsat), 1e-8) #only for certain algorithms opt.set_stopval(.0001) opt.set_maxeval(nit) starttime = time.time() #time function ####################################### print 'NLOPT stuff is starting now' x = opt.optimize(startarr) elapsedtime = time.time() - starttime minf = opt.last_optimum_value() x print minf print elapsedtime, ' seconds' ####################################
# ############################### #Import functions import calib_fxns reload(calib_fxns) from calib_fxns import gaussian,sumgaus,tapafunc,binres ########################### ############################################ #~ ~ ~ ~ ~ ~ ~ ~ Run NLOPT ~ ~ ~ ~ ~ ~ ~ opt = nlopt.opt(nlopt.GN_CRS2_LM,len(startarr)) #GN_CRS2_LM, MLSL(_LDS),GN_ESCH opt.set_lower_bounds(lowarr) opt.set_upper_bounds(higharr) opt.set_min_objective(lambda x,grad: tapafunc(x,realspec,spec,pixels,test_lam, nsat,chi_ev,xx_smalls,lo_inds,hi_inds)) #opt.add_inequality_constraint(lambda x,grad: ampconstraint(x,2,1,nsat), 1e-8) #only for certain algorithms opt.set_stopval(.0001) opt.set_maxeval(nit) starttime = time.time() #time function ####################################### print 'NLOPT stuff is starting now' x = opt.optimize(startarr) elapsedtime = time.time() - starttime minf = opt.last_optimum_value() x print minf print elapsedtime, ' seconds' ####################################
else: realspec0[i * 69:len(test_lam)] /= f # ~ ~ ~ ~ ~ ~ Initial Conditions ~ ~ ~ ~ ~ ~ # #startarr = np.array([2.5, 1.03, .01, -3.95*10**(-7),0.011079,816.9,.05,.05,.05,.05,.05]) #tau,norm,sig,dxm,dxb,dxc,amps (in fraction of 1, amp of central) low = np.array([2.4, 1.01, .008, -3.96 * 10**-7, .010, 816.85, 0, 0, 0, 0, 0]) high = np.array( [2.6, 1.04, .02, -3.94 * 10**-7, 0.013, 816.95, .1, .1, .1, .1, .1]) #chi_ev = [0] #watch evolution of minf #~ ~ ~ ~ ~ ~ ~ ~ Run NLOPT ~ ~ ~ ~ ~ ~ ~ opt = nlopt.opt(nlopt.GN_CRS2_LM, len(startarr)) #GN_CRS2_LM, MLSL(_LDS),GN_ESCH opt.set_lower_bounds(low) opt.set_upper_bounds(high) opt.set_min_objective(lambda x, grad: tapafunc(x, realspec0, spec, pixels, test_lam, nsat, chi_ev)) opt.set_stopval(.0001) opt.set_maxeval(nit) starttime = time.time() #time function print 'NLOPT stuff is starting now' x = opt.optimize(startarr) elapsedtime = time.time() - starttime minf = opt.last_optimum_value() print x print minf print elapsedtime, ' seconds' # ~ ~ ~ ~ Plot Results ~ ~ ~ ~ ~ ~ # lambd = x[3] * pixels**2 + x[4] * pixels + x[5] plt.figure()