def compareGrid(specFlag, globals): Te_MIN = globals.TE_MIN Te_MAX = globals.TE_MAX ne_MAX = globals.NE_MAX ne_MIN = globals.NE_MIN data = Data() data.loadData(1110328120) ps = data.getPolySegData(3,0) fitPolySeg(ps) print "Init density: ", ps.ne0, " Init temp: ", ps.Te0 maxProb = 0 ps.ne0 = -1 ps.Te0 = -1 gridPts = 10.0 gridsearch = zeros((gridPts,gridPts)) i = 0 for Te in logspace(log10(Te_MIN), log10(Te_MAX), gridPts): j = 0 for ne in logspace(log10(ne_MIN), log10(ne_MAX), gridPts): Nphotons = specPhotons(ne, Te, ps, specFlag) prob = - calcModelProbability(ps, globals, Nphotons) gridsearch[i,j] = prob if prob > maxProb: maxProb = prob ps.ne0 = ne ps.Te0 = Te j += 1 i += 1 return gridsearch, maxProb, ps
def compareGrid(specFlag): from ..globals import global_settings #call global variables Te_MIN; Te_MAX; NE_STEPS; TE_STEPS; # Saturation levels ACQIRIS_MIN; ACQIRIS_MAX; STRUCK_MIN; STRUCK_MAX; # Laser wavelength LASER_LAM; # Logbook quality LOGBOOK_TRUE; LOGBOOK_UNSURE; globals = init_globals() Te_MIN = globals[0];Te_MAX = globals[1]; NE_STEPS = globals[2]; TE_STEPS = globals[3]; ACQUIRIS_MIN = globals[4]; ACQUIRIS_MAX = globals[5]; STRUCK_MIN = globals[6]; STRUCK_MAX = globals[7]; LASER_LAM = globals[8]; LOGBOOK_TRUE = globals[9]; LOGBOOK_UNSURE = globals[10] #global_settings.init_globals() data = Data() data.loadData(1110328120) ps = data.getPolySegData(3,0) fitPolySeg(ps) print "Init density: ", ps.ne0, " Init temp: ", ps.Te0 maxProb = 0 ps.ne0 = -1 ps.Te0 = -1 gridPts = 10.0 gridsearch = zeros((gridPts,gridPts)) i = 0 for Te in logspace(log10(Te_MIN), log10(Te_MAX), gridPts): j = 0 for ne in logspace(log10(ne_MIN), log10(ne_MAX), gridPts): Nphotons = specPhotons(ne, Te, ps, specFlag) prob = - calcModelProbability(ps, Nphotons) gridsearch[i,j] = prob if prob > maxProb: maxProb = prob ps.ne0 = ne ps.Te0 = Te j += 1 i += 1 return gridsearch, maxProb, ps
def fitShot(shotNum, specFlag = "tsc", numProcs = None, burstLen = 0): """This function fits an entire shot. This version will use up to the number of detected processors on the machine if the multiprocessing module is installed. The multiprocessing module is a standard part of python 2.6, and has been backported to 2.5: http://code.google.com/p/python-multiprocessing/ Parameters: shotNum -- The shot number to fit. For example 1070814040. numProcs -- The number of processes to create. Defaults to the number of CPUs in the machine. burstLen -- For culling of extra Fast Thomson laser diode pulses Default of 0 acts like old system, keeping all pulses Any other value n will cause laser diode to skip pulses ~200 us after n pulses before looking for next burst """ from globals import init_globals glob = init_globals() Te_MIN = glob[0] Te_MAX = glob[1] NE_STEPS = glob[2] TE_STEPS = glob[3] ACQIRIS_MIN = glob[4] ACQIRIS_MAX = glob[5] STRUCK_MIN = glob[6] STRUCK_MAX = glob[7] LASER_LAM = glob[8] LOGBOOK_TRUE = glob[9] LOGBOOK_UNSURE = glob[10] #Load data from Data import Data data = Data() try: data.loadData(shotNum) except Exception, ex: print "Failed to fit shot:", ex return None
def fitShot(shotNum, specFlag = "tsc", numProcs = None, burstLen = 0): """This function fits an entire shot. This version will use up to the number of detected processors on the machine if the multiprocessing module is installed. The multiprocessing module is a standard part of python 2.6, and has been backported to 2.5: http://code.google.com/p/python-multiprocessing/ Parameters: shotNum -- The shot number to fit. For example 1070814040. numProcs -- The number of processes to create. Defaults to the number of CPUs in the machine. burstLen -- For culling of extra Fast Thomson laser diode pulses Default of 0 acts like old system, keeping all pulses Any other value n will cause laser diode to skip pulses ~200 us after n pulses before looking for next burst """ data = Data() try: data.loadData(shotNum) except Exception, ex: print "Failed to fit shot:", ex return None
def test_compile(): # a function to call each spectral calculation one time to make sure they have all # been compiled properly before using them on a fit (JDL has indicated that trying # to run an inline function for the first time with multiple processors going plays # havoc with the compiler) data = Data() data.loadData(1110328120) ps = data.getPolySegData(3,0) calcAmpOffset(ps) calcVoltageFromRawData(ps) calc_t0(ps) calcTransMask(ps) calcNumPhotons(ps) filterChans(ps) calcScatteringAngle(ps) calcLambdaArray(ps) ne = 45000.0 Te = 300.0 dist = cold2o_Spec(ps, Te) NP_cold2o = ne * ps.calib.deltaLam * dot(ps.trans_Bayes, dist) dist = selden_Spec(ps, Te) NP_selden = ne * ps.calib.deltaLam * dot(ps.trans_Bayes, dist) dist = selden_old(ps, Te) NP_selden_old = (ne/1500000) * ps.calib.deltaLam * dot(ps.trans_Bayes, dist) prob_cold2o = calcModelProbability(ps, NP_cold2o) prob_selden = calcModelProbability(ps, NP_selden) prob_selden_old = calcModelProbability(ps, NP_selden_old) return prob_cold2o, prob_selden, prob_selden_old