Commit e21eed00 authored by Alessandro Mirone's avatar Alessandro Mirone
Browse files

preparing XES non regression test

parent 908fae88
......@@ -704,12 +704,13 @@ def calculate_recenterings(mydata):
h5B = h5B_f[bariB_groupname]
offs = {}
chiavi = filterRoiList(h5A.keys())
chiavi = filterRoiList(h5A.keys(), prefix="")
for c in chiavi:
bA = h5A[c]["barix"].value + h5A[c]["cornerpos"][:][1]
bB = h5B[c]["barix"].value + h5B[c]["cornerpos"][:][1]
bAy = h5A[c]["bariy"].value + h5A[c]["cornerpos"][:][0]
bBy = h5B[c]["bariy"].value + h5B[c]["cornerpos"][:][0]
bA = h5A[c]["barix"][()] + h5A[c]["cornerpos"][:][1]
bB = h5B[c]["barix"][()] + h5B[c]["cornerpos"][:][1]
bAy = h5A[c]["bariy"][()] + h5A[c]["cornerpos"][:][0]
bBy = h5B[c]["bariy"][()] + h5B[c]["cornerpos"][:][0]
offs[c] = [[bBy, bAy ],[bB,bA]]
if h5B_f is not h5A_f:
......@@ -1033,7 +1034,7 @@ def loadscan_2Dimages(mydata):
h5f = h5py.File(recenterings_filename,"r")
h5 = h5f[recenterings_groupname]
recenterings= {}
chiavi = filterRoiList(h5.keys())
chiavi = filterRoiList(h5.keys(), prefix="")
for c in chiavi:
recenterings[int(c)]= h5[c][:]
if recenterings[int(c)].shape == (2,2):
......@@ -1103,6 +1104,8 @@ def loadscan_2Dimages(mydata):
h5f = h5py.File(recenterings_confirmed_filename,"w")
h5 = h5f.require_group(recenterings_confirmed_groupname)
for c in chiavi:
if c in h5:
del h5[c]
h5[c] = reader.recenterings[int(c)]
h5f.flush()
h5f.close()
......@@ -1436,6 +1439,10 @@ def extract_spectra(mydata):
references = {}
h5f = h5py.File(reference_file,"r" )
if reference_groupname not in h5f:
raise ValueError("Key %s not present in file %s"%(reference_groupname, reference_file) )
h5 = h5f[reference_groupname]
print( " FILTRO ", list(h5.keys()) )
rois_keys = filterRoiList(h5.keys(),prefix="")
......@@ -1451,27 +1458,29 @@ def extract_spectra(mydata):
for k in rois_keys:
if deconvolve:
mm = h5[k]["matrix"][:]
mm[np.isnan(mm)] = 0.0
else:
mm = None
print(reference_file, reference_groupname, list(h5[k].keys() ) )
zscale = h5[k]["xscale"].value*1000.0
zscale = h5[k]["xscale"][()]*1000.0
mask = h5rois["ROI%02d"%int(k)]["mask"][:]
cummask = np.cumsum(mask,axis=0)
mask[cummask<=zmargin]=0
mask[(cummask.max(axis=0) -cummask)<zmargin]=0
oggetto_line = None
if "line" in h5[k]:
nref = h5[k]["nref"].value
rebinned = h5[k][ optical_response_name ].value
nref = h5[k]["nref"][()]
rebinned = h5[k][ optical_response_name ][()]
s0,s1 = rebinned.shape
rebinned = np.reshape(rebinned, [ s0//nref, nref, s1//nref, nref ] )//nref
rebinned = (rebinned.sum(axis=3)).sum(axis=1)
dico_line = {"line" : h5[k]["line"].value * np.array([1.0/nref,1.0]),
"Xintercept" : h5[k]["Xintercept"].value,
"Yintercept" : h5[k]["Yintercept"].value,
"Xslope" : h5[k]["Xslope"].value,
"Yslope" : h5[k]["Yslope"].value,
"nref" : h5[k]["nref"].value,
dico_line = {"line" : h5[k]["line"][()] * np.array([1.0/nref,1.0]),
"Xintercept" : h5[k]["Xintercept"][()],
"Yintercept" : h5[k]["Yintercept"][()],
"Xslope" : h5[k]["Xslope"][()],
"Yslope" : h5[k]["Yslope"][()],
"nref" : h5[k]["nref"][()],
"optical_response" : rebinned,
"weight_by_response" : weight_by_response
}
......@@ -1497,9 +1506,9 @@ def extract_spectra(mydata):
print( " scan_name " , scan_name)
h5 = h5_sample_group[scan_name]
scan_energy_0 = h5["motorDict/energy"].value
scan_energy_0 = h5["motorDict/energy"][()]
print(" ROISKEYS ", rois_keys )
denominator = h5[ rois_keys[0] ]["monitor"].value/(float(h5[ rois_keys[0] ]["monitor_divider"].value))
denominator = h5[ rois_keys[0] ]["monitor"][()]/(float(h5[ rois_keys[0] ]["monitor_divider"][()]))
for k in rois_keys:
print( " KKKKK " , k)
......@@ -1568,7 +1577,8 @@ error_{key} : the errors fo scan {key}
E0_{key} : the monocromator energy for scan {key}
""").format(key=str(ene0_key))
for lab in [envar,spvar,ervar,E0var , "python_plot_spectra_byline" , "README", "python_plot_spectra_byfit" , "python_plot_convergency" ]:
for lab in [envar,spvar,ervar,E0var , "python_plot_spectra_byline" , "README", "python_plot_spectra_byfit" , "python_plot_convergency",
"spectraByFit_"+str(ene0_key),"fit_errList_"+str(ene0_key),"sintesi_"+str(ene0_key) ]:
if lab in h5k:
del h5k[lab]
......@@ -1586,9 +1596,9 @@ E0_{key} : the monocromator energy for scan {key}
if niter:
h5k["spectraByFit_"+str(ene0_key)] = myres[ene0_key][k]["spectraByFit"]
h5k["spectraByFit_"+str(ene0_key)] = myres[ene0_key][k]["spectraByFit"][()]
h5k["fit_errList_"+str(ene0_key)] = myres[ene0_key][k]["fit_errList"]
h5k["sintesi_"+str(ene0_key)] = myres[ene0_key][k]["sintesi"]
h5k["sintesi_"+str(ene0_key)] = myres[ene0_key][k]["sintesi"][()]
plotfit_string+="ax.plot(self.energies_%s -self.E0_%s,self.spectraByFit_%s, label=\"spectra %f\")\n"%(ene0_key,ene0_key,ene0_key,enbyscan[ene0_key])
plotconv_string+="ax.plot(self.fit_errList%s)\n"%(ene0_key)
......
......@@ -71,7 +71,7 @@ if SHOW_LOADED_FILES :
def dump_on_file_list(filename):
f = open("list_of_used_files.txt","a")
f.write( filename )
f.write( filename+"\n")
f.close()
......@@ -162,6 +162,9 @@ def PyMcaSpecRead_my(filename,nscan):
"""
Returns data, counter-names, and EDF-files using PyMCA.
"""
if SHOW_LOADED_FILES:
dump_on_file_list(filename)
sf = SpecIO.Specfile(filename)
scan = sf.select(str(nscan))
data = scan.data()
......@@ -180,6 +183,9 @@ def SilxSpecRead( filename, nscan ):
"""
Returns data, motors, counter-names, and labels using Silx.
"""
if SHOW_LOADED_FILES:
dump_on_file_list(filename)
nscan -= 1
sf = SpecFile( filename )
data = sf.data( nscan )
......@@ -219,6 +225,9 @@ def PyMcaEdfRead(fname):
"""
Returns the EDF-data using PyMCA.
"""
if SHOW_LOADED_FILES:
dump_on_file_list(fname)
data = EdfIO.EdfFile(fname,"r").GetData(0)
return data
......@@ -226,6 +235,9 @@ def FabioEdfRead(fname):
"""
Returns the EDF-data using FabIO.
"""
if SHOW_LOADED_FILES:
dump_on_file_list(fname)
return fabio.edfimage.EdfImage().read(fname).data
def ReadScanFromFile(fname):
......@@ -347,7 +359,9 @@ def ReadEdfImages_my(ccdcounter, path, EdfPrefix, EdfName, EdfPostfix):
for m in range(len(ccdcounter)):
ccdnumber = ccdcounter[m]
fname = path + EdfPrefix + EdfName + "%04d" % ccdnumber + EdfPostfix
if SHOW_LOADED_FILES : print( " LEGGO ", fname)
if SHOW_LOADED_FILES :
dump_on_file_list(fname)
print( " LEGGO ", fname)
edfmats[m,:,:] = myEdfRead(fname)
return edfmats
......@@ -364,7 +378,10 @@ def ReadEdfImages_PyMca(ccdcounter, path, EdfPrefix, EdfName, EdfPostfix):
for m in range(len(ccdcounter)):
ccdnumber = ccdcounter[m]
fname = path + EdfPrefix + EdfName + "%04d" % ccdnumber + EdfPostfix
if SHOW_LOADED_FILES : print( " LEGGO ", fname)
if SHOW_LOADED_FILES :
dump_on_file_list(fname)
print( " LEGGO ", fname)
edfmats[m,:,:] = PyMcaEdfRead(fname)
return edfmats
......
......@@ -160,6 +160,10 @@ class oneD_imaging(xrs_read.read_id20):
print( " ENERGIA adesso " , tmp.sum())
print( " ENERGIA prima " ,edfmats[:,roixinds,roiyinds] .sum())
#
# When recentering.shape ==(2,2) it contains the previously measure (bari_Y, bari_X) of the reference scan ( with the reference ROI) in the first column
# while the second columns is the previously measured baricenter of the sample scan ( with the sample ROI).
# The goal now is to have a shift ( confirmed shift) which brings the sample baricenter ( with the reference ROI) over the scan baricenter
if self.recenterings[ii].shape ==(2,2):
dimz,dimy,dimx = tmp.shape
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment