本文整理汇总了Python中Timer.Timer.end方法的典型用法代码示例。如果您正苦于以下问题:Python Timer.end方法的具体用法?Python Timer.end怎么用?Python Timer.end使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Timer.Timer
的用法示例。
在下文中一共展示了Timer.end方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: runGrid
# 需要导入模块: from Timer import Timer [as 别名]
# 或者: from Timer.Timer import end [as 别名]
def runGrid(passCount, filename='lists/binaries2.dat'):
'''
Wrapper function to run the binary mofel fitting grid.
:param passCount: [in] The maximum amount of passes to run on the grid
:param filename: [in] The filename of the file containing a list of targets field and APOGEE ID's to use
'''
timer = Timer()
timer.start()
# Prep Grid
locationIDs, apogeeIDs = np.loadtxt(filename, unpack=True, delimiter=',', dtype=str)
targetCount = len(locationIDs)
gridParams = [GridParam(locationIDs[i], apogeeIDs[i]) for i in range(targetCount)]
minimizedVisitParams = [np.array([]) for i in range(targetCount)]
# Use past results
# checkPreviousData(gridParams)
grid(passCount, gridParams, minimizedVisitParams)
writeGridToFile(gridParams)
for i in range(len(minimizedVisitParams)):
filename = 'lists/chi2/' + minimizedVisitParams[i][0].locationID + '/' + minimizedVisitParams[i][0].apogeeID + '.lis'
if not os.path.exists('lists/chi2/' + minimizedVisitParams[i][0].locationID + '/'):
os.makedirs('lists/chi2/' + minimizedVisitParams[i][0].locationID + '/')
writeGridToFile(minimizedVisitParams[i], filename=filename)
print('Total run time: ' + str(round(timer.end(), 2)) + str('s'))
示例2: grid
# 需要导入模块: from Timer import Timer [as 别名]
# 或者: from Timer.Timer import end [as 别名]
def grid(passCount, gridParams, minimizedVisitParams):
'''
The binary model fitting grid. This function will fit the targets of the following parameters:
1) Teff of component A
2) Teff of component B
3) Flux Ratio of component B
4) Relative Heliocentric Velocity of Component A
5) Relative Heliocentric Velocity of Component B
After chi2 minimization of the above parameters, the parameters used to get the minimized chi2 value is written into
lists/chi2.lis. The other parameters that were tested on the grid and their corresponding chi2 values can be found
in lists/chi2/FIELD_ID/2M_ID.lis.
:param passCount: [in] The amount of maximum amount of passes the grid will go through
:param gridParams: [in/out] The list of GridParams that contain the targets fitting data (built in runGrid)
:param minimizedVisitParams: [out] All the visits with the minimized chi2 parameters
'''
targetCount = len(gridParams)
tpass = Timer()
tpassSum = 0.0
for j in range(passCount):
tpass.start()
print('-------------PASS ' + str(j+1) + '/' + str(passCount) + '-------------')
ttarget = Timer()
ttargetSum = 0.0
for i in range(targetCount):
locationID = gridParams[i].locationID
apogeeID = gridParams[i].apogeeID
badheader, header = apread.apStar(locationID, apogeeID, ext=0, header=True)
nvisits = header['NVISITS']
print('Fitting: ' + locationID + ', ' + apogeeID + ', nvisits: ' + str(nvisits))
print('On target: ' + str(i+1) + '/' + str(targetCount))
ttarget.start()
gridParams[i], minimizedVisitParams[i] = bg.targetGrid(gridParams[i], minimizedVisitParams[i], plot=False)
temp = ttarget.end()
ttargetSum+= temp
print('Target run time: ' + str(round(temp, 2)) + str('s'))
temp = tpass.end()
tpassSum+= temp
print('Pass run time: ' + str(round(temp, 2)) + str('s'))
print('Average target run time: ' + str(round(ttargetSum/targetCount, 2)) + str('s'))
print('Average pass run time: ' + str(round(tpassSum/passCount, 2)) + str('s'))
示例3: range
# 需要导入模块: from Timer import Timer [as 别名]
# 或者: from Timer.Timer import end [as 别名]
for i in range(3):
if procs[i].is_alive() == False:
badheader, header = apread.apStar(locationIDs[i], apogeeIDs[i], ext=0, header=True, dr='13')
nvisits = header['NVISITS']
visitSum+= timers[i].end() / nvisits
if procs[0].is_alive() == False and procs[1].is_alive() == False and procs[2].is_alive() == False:
running = False
time.sleep(2)'''
timer = Timer()
visitSum = 0.0
for i in range(targetCount):
badheader, header = apread.apStar(locationIDs[i], apogeeIDs[i], ext=0, header=True, dr='13')
nvisits = header['NVISITS']
timer.start()
runTarget(targets[i])
visitSum+= timer.end() / nvisits
print(visitSum)
print('avg visit time:', visitSum/targetCount)
'''
done=4
print('------------Target ' + str(done + 1) + '/' + str(targetCount) + ' ------------')
while targetQueue.empty() == False:
# runTarget(targetQueue.get_nowait())
for i in range(4):
if procs[i].is_alive() == False:
del(procs[i])
if targetQueue.empty() == False:
procs.append(Process(target=runTarget, args=(targetQueue.get_nowait(),)))
procs[3].start()
done+=1
示例4: targetGrid
# 需要导入模块: from Timer import Timer [as 别名]
# 或者: from Timer.Timer import end [as 别名]
def targetGrid(gridParam, minimizedVisitParams, plot=True):
'''
The grid tests against ranging effective temperatures for both stars and the flux ratio of the
secondary component. This is done by target.
:param gridParam: [in/out] The GridParam of the target
:param gridRes: [out] The visits that have the same paramters as the minimized chi2 visit
:param plot: [in] If true makes plots to see intermediate steps (default=True)
'''
locationID = gridParam.locationID
apogeeID = gridParam.apogeeID
badheader, header = apread.apStar(locationID, apogeeID, ext=0, header=True)
specs = apread.apStar(locationID, apogeeID, ext=1, header=False)
specerrs = apread.apStar(locationID, apogeeID, ext=2, header=False)
nvisits = header['NVISITS']
# chi2 = np.full((nvisits, nrangeTeffA, nrangeTeffB, nrangeFluxRatio), -1.)
#chi2 = np.full((nvisits, nrangeTeffA, nrangeTeffB, nrangeFluxRatio, nrangeRVA, nrangeRVB), -1.)
ipg = ferre.Interpolator(lib='GK')
ipf = ferre.Interpolator(lib='F')
# Create file to store all the chi2 values
path = 'lists/all_chi2/' + str(locationID) + '/'
if not os.path.exists(path):
os.makedirs(path)
fn = open(path + apogeeID + '.lis', 'w')
fn.write(gridParam.toStringHeader())
timer = Timer()
timeSum = 0.0
allChi2 = []
visitGridParamsBuffer = []
for visit in range(1, nvisits + 1):
timer.start()
if (nvisits != 1):
spec = specs[1+visit]
specerr = specerrs[1+visit]
else:
spec = specs
specerr = specerrs
if (len(minimizedVisitParams) == 0):
gridParam = GridParam(locationID, apogeeID)
gridParam.constructParams()
gridParam.getRVs(visit)
else:
gridParam = minimizedVisitParams[visit - 1]
visitGridParamsBuffer.append(gridParam)
# Prepare grid ranges
rangeTeffA = np.arange(gridParam.minTeffA, gridParam.maxTeffA, gridParam.teffStepA)
rangeTeffB = np.arange(gridParam.minTeffB, gridParam.maxTeffB, gridParam.teffStepB)
rangeFluxRatio = np.arange(gridParam.minFluxRatio, gridParam.maxFluxRatio, gridParam.fluxStep)
rangeRVA = np.arange(gridParam.minRVA, gridParam.maxRVA, gridParam.rvAStep)
rangeRVB = np.arange(gridParam.minRVB, gridParam.maxRVB, gridParam.rvBStep)
nrangeTeffA = len(rangeTeffA)
nrangeTeffB = len(rangeTeffB)
nrangeFluxRatio = len(rangeFluxRatio)
nrangeRVA =len(rangeRVA)
nrangeRVB =len(rangeRVB)
chi2 = np.full((nrangeTeffA, nrangeTeffB, nrangeFluxRatio, nrangeRVA, nrangeRVB), -1.)
print('Visit: ' + str(visit) ,'Grid dimensions: ' + str(chi2.shape))
# Prep Spectra
aspec= np.reshape(spec,(1, len(spec)))
aspecerr= np.reshape(specerr,(1, len(specerr)))
cont= spec / continuum.fit(aspec, aspecerr, type='aspcap')[0]
conterr = specerr / continuum.fit(aspec, aspecerr, type='aspcap')[0]
shiftedSpec = bm.shiftFlux(cont, header['VHELIO' + str(visit)])
# Run grid
for i in range(nrangeTeffA):
gridParam.modelParamA.teff = rangeTeffA[i]
componentA = bm.genComponent(gridParam.modelParamA, ipf, ipg)
for j in range(nrangeTeffB):
gridParam.modelParamB.teff = rangeTeffB[j]
componentB = bm.genComponent(gridParam.modelParamB, ipf, ipg)
for k in range(nrangeFluxRatio):
gridParam.modelParamB.fluxRatio = rangeFluxRatio[k]
componentBR = componentB * rangeFluxRatio[k]
for l in range(nrangeRVA):
gridParam.modelParamA.rv = rangeRVA[l]
componentAS = bm.shiftFlux(componentA, rangeRVA[l])
for m in range(nrangeRVB):
gridParam.modelParamB.rv = rangeRVB[m]
componentBS = bm.shiftFlux(componentBR, rangeRVB[m])
binaryFlux = bm.combineFlux(componentAS, componentBS)
chi2[i][j][k][l][m] = calcChi2(binaryFlux, shiftedSpec, conterr) / (len(binaryFlux) - 5.0)
gridParam.chi2 = chi2[i][j][k][l][m]
fn.write(gridParam.toString())
if (plot is True):
restLambda = splot.apStarWavegrid()
BinPlot.plotDeltaVCheck(locationID, apogeeID, visit,
[ [ restLambda, binaryFlux, 'blue', 'model' ],
[ restLambda, cont, 'orange', 'unshifted' ],
[ restLambda, shiftedSpec, 'green', 'shifted' ]],
[gridParam.modelParamA.teff,gridParam.modelParamB.teff, gridParam.modelParamB.fluxRatio],
'Delta V Shift', folder='grid_deltaVCheck')
timeSum+=timer.end()
#.........这里部分代码省略.........
示例5: range
# 需要导入模块: from Timer import Timer [as 别名]
# 或者: from Timer.Timer import end [as 别名]
for visit in range(1, nvisits):
if (nvisits != 1):
ccf = data['CCF'][0][1 + visit]
else:
ccf = data['CCF'][0]
max1, max2 = getMaxPositions(ccf, ranger)
r = []
for cut in range(20):
r.append(calcR(ccf, cut*10, (401 - (cut * 10))))
if r < 1.0:
if recorded is False:
recorded = True
interestingTargets.append([locationID, apogeeID, "r"])
if str(max2) != 'none':
if recorded is False:
recorded = True
interestingTargets.append([locationID, apogeeID, ranger])
positions.append([max1, max2, r])
reportPositions(locationID, apogeeID, ranger, positions)
recordTargets(interestingTargets, ranger, 'interestingTargets')
recordTargets(skippedTargets, ranger, 'skippedTargets')
print("done", t.current())
t.end()