main change: worked to avoid memory leaks trough view of original big array and iminuit object
This commit is contained in:
parent
a2c508fa5d
commit
6457520442
24
alignment.py
24
alignment.py
|
@ -77,7 +77,7 @@ kw_2dplot = dict(
|
|||
cmap = cmap
|
||||
)
|
||||
|
||||
fit_ret = collections.namedtuple("fit_ret",["fit_result","init_pars","final_pars",\
|
||||
fit_ret = collections.namedtuple("fit_ret",["init_pars","final_pars",\
|
||||
"final_transform1","final_transform2","im1","im2","E","p1","p1_sum","p2","p2_sum","fom","ratio","tneeded"] )
|
||||
|
||||
def calcFOM(p1,p2,ratio):
|
||||
|
@ -268,22 +268,21 @@ def loadAlignment(fname):
|
|||
def unravel_results(res,nSaveImg='all'):
|
||||
final_pars = dict()
|
||||
# res[0].fit_result is a list if we are trying to unravel retult from getShots
|
||||
if isinstance(res[0].fit_result,list):
|
||||
parnames = res[0].fit_result[0].parameters
|
||||
if isinstance(res[0].init_pars,list):
|
||||
parnames = res[0].init_pars[0].get_keys()
|
||||
else:
|
||||
parnames = res[0].fit_result.parameters
|
||||
parnames = res[0].init_pars.keys()
|
||||
final_pars = dict()
|
||||
init_pars = dict()
|
||||
for n in parnames:
|
||||
final_pars[n] = np.hstack( [r.final_pars[n] for r in res])
|
||||
init_pars[n] = np.hstack( [r.init_pars[n] for r in res])
|
||||
im1 = np.asarray( [r.im1 for r in res])
|
||||
im2 = np.asarray( [r.im2 for r in res])
|
||||
im1 = np.asarray( [r.im1 for r in res if r.im1.shape[0] != 0])
|
||||
im2 = np.asarray( [r.im2 for r in res if r.im2.shape[0] != 0])
|
||||
if nSaveImg != 'all':
|
||||
im1 = im1[:nSaveImg]
|
||||
im2 = im2[:nSaveImg]
|
||||
im1 = im1[:nSaveImg].copy(); # copy is necessary to free the original memory
|
||||
im2 = im2[:nSaveImg].copy(); # of original array
|
||||
return fit_ret(
|
||||
fit_result = [r.fit_result for r in res],
|
||||
init_pars = init_pars,
|
||||
final_pars = final_pars,
|
||||
final_transform1 = [r.final_transform1 for r in res],
|
||||
|
@ -439,7 +438,6 @@ def transformIminuit(im1,im2,init_transform=dict(),show=False,verbose=True,zeroT
|
|||
idx = p1>np.nanmax(p1)/10.
|
||||
fom = calcFOM(p1,p2,r)
|
||||
return fit_ret(
|
||||
fit_result = imin,
|
||||
init_pars = init_params,
|
||||
final_pars = final_params,
|
||||
final_transform1 = t1,
|
||||
|
@ -581,9 +579,9 @@ def doShots(imgs1,imgs2,initpars,nJobs=16,doFit=False,returnBestTransform=False,
|
|||
(joblib.delayed(doShot)(imgs1[i],imgs2[i],initpars,doFit=doFit) for i in range(N))
|
||||
res = unravel_results(pool,nSaveImg=nSaveImg)
|
||||
if returnBestTransform:
|
||||
idx = np.argmin( res.fom );
|
||||
print("FOM for best alignment %.2f"%res.fom[fom])
|
||||
return res,res.final_transform1[idx]
|
||||
idx = np.nanargmin( res.fom );
|
||||
print("FOM for best alignment %.2f"%res.fom[idx])
|
||||
return res,pool[idx].final_pars
|
||||
else:
|
||||
return res
|
||||
# out = collections.OrderedDict( enumerate(pool) )
|
||||
|
|
Loading…
Reference in New Issue