Commit 00233a02 authored by myron's avatar myron
Browse files

restructuring the volume extraction and xrs_swissknife

parent 23322b8e
This diff is collapsed.
...@@ -2164,7 +2164,7 @@ class read_id20: ...@@ -2164,7 +2164,7 @@ class read_id20:
self.scans = {} # was a dictionary before self.scans = {} # was a dictionary before
if absfilename is not None: if absfilename is not None:
if not os.path.isfile(absfilename): if not os.path.isfile(absfilename):
raise Exception('IOError! No such file, please check filename.') raise Exception('IOError! No such file %s, please check filename.' % absfilename )
self.path = os.path.split(absfilename)[0] + '/' self.path = os.path.split(absfilename)[0] + '/'
self.filename = os.path.split(absfilename)[1] self.filename = os.path.split(absfilename)[1]
if not edfName: if not edfName:
......
...@@ -3,46 +3,64 @@ import h5py ...@@ -3,46 +3,64 @@ import h5py
import glob import glob
import json import json
import os import os
import h5py
BATCH_PARALLELISM = 4 BATCH_PARALLELISM = 4
import os import os
def main(): def main():
peaks_shifts = File("peaks_positions_for_analysers.h5","w")["peaks_positions"] peaks_shifts = h5py.File("peaks_positions_for_analysers.h5","r")["peaks_positions"][()]
assert( len(peaks_shifts) == 72)) assert( len(peaks_shifts) == 72)
Enominal = np.median(peak_shifts) os.system("xz -dk mask.h5.xz")
peak_shifts-= Enominal Enominal = np.median(peaks_shifts)
peaks_shifts-= Enominal
datadir = "/data/id20/inhouse/data/run3_20/run3_es949" datadir = "/data/id20/inhouse/data/run3_20/run3_es949"
os.system("mkdir results") os.system("mkdir results")
roi_target_path = "results/myrois.h5:/ROIS" roi_target_path = "results/myrois.h5:/ROIS"
filter_path : "mask.h5:/FILTER_MASK/filter" # roi_target_path = "rr.h5:/extracted/ROI_AS_SELECTED"
roi_scan_num = 246 filter_path = "mask.h5:/FILTER_MASK/filter"
roi_scan_num = [245,246,247]
first_scan_num = 651 first_scan_num = 651
Ydim = 25 Ydim = 25
Zdim = 10 Zdim = 10
Edim = 7 Edim = 7
monitorcolumn = "izero/0.000001" monitor_column = "izero/0.000001"
signals_target_file = "results/signals.h5" signals_target_file = "results/signals.h5"
interpolated_signals_target_file = "results/interpolated_signals.h5" interpolated_signals_target_file = "results/interpolated_signals.h5"
extracted_reference_target_file = "results/reference.h5"
reference_scan_list = [245, 246, 247]
# If reference_clip is not None, then a smaller part of the reference scan is considered
# This may be usefule to obtain smaller volumes containing the interesting part
# The used reference scan will the correspond to the positions from reference_clip[0] to reference_clip[1]-1 included
###########
# reference_clip = None
reference_clip = [ 90, 180 ]
## in the reference scan for each position there is a spot with a maximum. We set zero the background which is further than
## such radius from the maximum
isolate_spot_by = 6
steps_to_do = { steps_to_do = {
"do_step_make_roi": False, "do_step_make_roi": False,
"do_step_interpolation": True,
"do_step_sample_extraction": False, "do_step_sample_extraction": False,
"do_step_interpolation": False,
"do_extract_reference_scan": True,
"do_step_make_reference": False, "do_step_make_reference": False,
"do_step_scalar_products": False, "do_step_scalar_products": False,
"do_step_finalise_for_fit": True "do_step_finalise_for_fit": False
} }
...@@ -60,8 +78,13 @@ def main(): ...@@ -60,8 +78,13 @@ def main():
Edim = Edim , Edim = Edim ,
monitor_column = monitor_column, monitor_column = monitor_column,
signals_target_file = signals_target_file signals_target_file = signals_target_file,
interpolated_signals_target_file = interpolated_signals_target_file interpolated_signals_target_file = interpolated_signals_target_file,
reference_scan_list = reference_scan_list,
reference_clip = reference_clip,
extracted_reference_target_file = extracted_reference_target_file ,
isolate_spot_by = isolate_spot_by
) )
...@@ -88,28 +111,58 @@ def process_input(s, go=0, exploit_slurm_mpi = 0, stop_omp = False): ...@@ -88,28 +111,58 @@ def process_input(s, go=0, exploit_slurm_mpi = 0, stop_omp = False):
def select_rois( datadir = None, roi_scan_num=None, roi_target_path = None, filter_path = None): def select_rois( datadir = None, roi_scan_num=None, roi_target_path = None, filter_path = None):
if np.isscalar(roi_scan_num):
scans = [roi_scan_num]
else:
scans = list(roi_scan_num)
inputstring = """ inputstring = """
create_rois: create_rois:
expdata : {expdata} expdata : {expdata}
scans : [{roi_scan_num}] scans : {scans}
roiaddress : {roi_target_path} roiaddress : {roi_target_path}
filter_path : {filter_path} filter_path : {filter_path}
""".format( """.format(
expdata = os.path.join( datadir, "/hydra"), expdata = os.path.join( datadir, "hydra"),
roi_scan_num = roi_scan_num, scans = scans,
roi_target_path = roi_target_path, roi_target_path = roi_target_path,
filter_path = filter_path filter_path = filter_path
) )
process_input( inputstring, exploit_slurm_mpi = 0 ) process_input( inputstring, exploit_slurm_mpi = 0 )
extract_sample_givenrois( def get_reference( roi_path = None,
datadir = None,
reference_scan_num=None,
monitor_column = None,
extracted_reference_target_file = None,
isolate_spot_by = None,
):
signal_path = extracted_reference_target_file + ":/"
inputstring = """
loadscan_2Dimages :
expdata : {expdata}
roiaddress : {roi_path}
monitor_column : {monitor_column}
scan_interval : [{reference_scan_num},{reference_scan_num_plus1} ]
signaladdress : {signal_path}
isolateSpot : {isolate_spot_by}
save_also_roi : True
sumto1D : 0
energycolumn : 'stx'
"""
s=inputstring.format(
exp_data = os.path.join( datadir, "hydra"),
reference_scan_num = reference_scan_num,
reference_scan_num_plus1 = reference_scan_num+1,
monitor_column = monitor_column,
roi_path = roi_path, roi_path = roi_path,
Start = first_scan_num , isolate_spot_by = isolate_spot_by,
End = (first_scan_num + Zdim * Edim ) , signal_path = signal_path
Thickness = Zdim
) )
process_input( s , exploit_slurm_mpi = 1)
def extract_sample_givenrois( def extract_sample_givenrois(
...@@ -118,8 +171,8 @@ def extract_sample_givenrois( ...@@ -118,8 +171,8 @@ def extract_sample_givenrois(
Start = None, Start = None,
End = None, End = None,
Thickness = None , Thickness = None ,
monitor_columns = None, monitor_column = None,
signals_target_file = None signals_target_file = None,
): ):
for start in range(Start,End, Thickness): for start in range(Start,End, Thickness):
...@@ -137,43 +190,42 @@ def extract_sample_givenrois( ...@@ -137,43 +190,42 @@ def extract_sample_givenrois(
monitor_column : {monitor_column} monitor_column : {monitor_column}
sumto1D : 0 sumto1D : 0
""".format( """.format(
expdata = os.path.join( datadir, "/hydra"), expdata = os.path.join( datadir, "hydra"),
roi_path = roi_path, roi_path = roi_path,
start = start, start = start,
end = end, end = end,
monitor_column = monitor_column, monitor_column = monitor_column,
signal_path = signal_path signal_path = signal_path
) )
process_input(s, exploit_slurm_mpi = 1) process_input(inputstring, exploit_slurm_mpi = 1)
def interpolate( peaks_shifts, interp_file_str, interp_file_target_str):
interp_file = h5py.File( interp_file_str ,"r+")
interp_file_target = h5py.File( interp_file_target_str ,"r+")
class interpolate( peaks_shifts, interp_file, interp_file_target):
volum_list = list(interp_file.keys()) volum_list = list(interp_file.keys())
scan_num_list = np.array([ int( t.split("_") [1]) for t in volum_list]) scan_num_list = np.array([ int( t.split("_") [1]) for t in volum_list])
ene_list = np.array([ interp_file[vn]["scans"]["Scan%03d"%sn ]["motorDict"]["energy"].value for vn,sn in zip(volum_list, scan_num_list ) ]) ene_list = np.array([ interp_file[vn]["scans"]["Scan%03d"%sn ]["motorDict"]["energy"].value for vn,sn in zip(volum_list, scan_num_list ) ])
print ( " ecco la scannumlist " , scan_num_list) print ( " ecco la scannumlist " , scan_num_list)
print (" ecco ene_list", ene_list) print (" ecco ene_list", ene_list)
order = np.argsort( ene_list ) order = np.argsort( ene_list )
ene_list = ene_list [order] ene_list = ene_list [order]
scan_num_list = scan_num_list [order] scan_num_list = scan_num_list [order]
volum_list = [ volum_list [ii] for ii in order ] volum_list = [ volum_list [ii] for ii in order ]
print ( " ECCO I DATI ")
print ( ene_list )
print ( cenom )
# raise # raise
for t_vn, t_sn, t_ene in list(zip(volum_list, scan_num_list, ene_list ))[0:]: for t_vn, t_sn, t_ene in list(zip(volum_list, scan_num_list, ene_list ))[0:]:
rois_coeffs={} rois_coeffs={}
for roi_num, de in enumerate( cenom ): for roi_num, de in enumerate( peaks_shifts ):
print ( roi_num, "===== " , t_ene+de , ene_list .min() , t_ene+de , ene_list .max() ) print ( roi_num, "===== " , t_ene+de , ene_list .min() , t_ene+de , ene_list .max() )
if t_ene+de < ene_list .min() or t_ene+de > ene_list .max(): if t_ene+de < ene_list .min() or t_ene+de > ene_list .max():
continue continue
...@@ -194,9 +246,6 @@ class interpolate( peaks_shifts, interp_file, interp_file_target): ...@@ -194,9 +246,6 @@ class interpolate( peaks_shifts, interp_file, interp_file_target):
print ( " for reinterpolation of ", t_vn ," interpolation scheme is the following ", rois_coeffs) print ( " for reinterpolation of ", t_vn ," interpolation scheme is the following ", rois_coeffs)
interp_file_target.require_group(target)
fscans = interp_file[ t_vn ]["scans"] fscans = interp_file[ t_vn ]["scans"]
keys_list = list( fscans.keys() ) keys_list = list( fscans.keys() )
print ( " keylist ", keys_list) print ( " keylist ", keys_list)
...@@ -270,8 +319,14 @@ def tools_sequencer( peaks_shifts = None, ...@@ -270,8 +319,14 @@ def tools_sequencer( peaks_shifts = None,
##################################################### #####################################################
## can be left to None, will be set to the used target ## can be left to None, will be set to the used target
roi_path = None, roi_path = None,
signals_file = None signals_file = None,
interpolated_signals_file = None interpolated_signals_file = None,
reference_clip = None,
isolate_spot_by = None,
reference_scan_list = None,
extracted_reference_target_file = None ,
) : ) :
...@@ -286,8 +341,7 @@ def tools_sequencer( peaks_shifts = None, ...@@ -286,8 +341,7 @@ def tools_sequencer( peaks_shifts = None,
select_rois(datadir = datadir , select_rois(datadir = datadir ,
roi_scan_num = roi_scan_num , roi_scan_num = roi_scan_num ,
roi_target_path = roi_target_path, roi_target_path = roi_target_path,
filter_path = filter_path, filter_path = filter_path
signals_target_file = signals_target_file
) )
if(steps_to_do["do_step_sample_extraction"]): if(steps_to_do["do_step_sample_extraction"]):
...@@ -296,14 +350,62 @@ def tools_sequencer( peaks_shifts = None, ...@@ -296,14 +350,62 @@ def tools_sequencer( peaks_shifts = None,
datadir = datadir, datadir = datadir,
Start = first_scan_num , Start = first_scan_num ,
End = (first_scan_num + Zdim * Edim ) , End = (first_scan_num + Zdim * Edim ) ,
Thickness = Zdim Thickness = Zdim,
monitor_column = monitor_column, monitor_column = monitor_column,
signals_target_file = signals_target_file signals_target_file = signals_target_file
) )
if(steps_to_do["do_step_interpolation"]): if(steps_to_do["do_step_interpolation"]):
os.system("cp {signals_file} {interpolated_signals_target_file}".format(signals_file=signals_file, interpolated_signals_target_file =interpolated_signals_target_file) ) os.system("cp {signals_file} {interpolated_signals_target_file}".format(signals_file=signals_file, interpolated_signals_target_file =interpolated_signals_target_file) )
Interpolate( peaks_shift , signals_file , interpolated_signals_target_file ) interpolate( peaks_shifts , signals_file , interpolated_signals_target_file )
if(steps_to_do["do_extract_reference_scan"]): # of course we need the REFERENCE SCAN
for reference_scan_num in reference_scan_list:
get_reference( datadir = datadir,
monitor_column = monitor_column,
extracted_reference_target_file = extracted_reference_target_file,
isolate_spot_by = isolate_spot_by,
reference_scan_num = reference_scan_num
)
# for other in other_rois_for_ref:
# os.system("cp roi_%d.h5 roi_%d.h5"%(roi_scann, other) )
# if reference_clip is not None:
# clip1, clip2= reference_clip
# ftarget = h5py.File( "roi_%d.h5" % roi_scann ,"r+")
# target_group = ftarget["extracted/ROI_AS_SELECTED/calibration_scan/scans/Scan%03d"% roi_scann ]
# for k in target_group.keys():
# if k != "motorDict":
# print(" SHRINKING scan for ROI %s in file roi_%d.h5 " %( k, roi_scann ))
# for dsn in ["matrix", "monitor", "xscale"]:
# mat = target_group[k][dsn][()]
# del target_group[k][dsn]
# target_group[k][dsn] = mat[clip1:clip2]
# ftarget.close()
# for other in other_rois_for_ref:
# get_reference(roi_scan_num=other)
# ftarget = h5py.File( "roi_%d.h5" % roi_scann ,"r+")
# fsource = h5py.File( "roi_%d.h5" % other , "r")
# source_group = fsource["extracted/ROI_AS_SELECTED/calibration_scan/scans/Scan%03d"% other ]
# target_group = ftarget["extracted/ROI_AS_SELECTED/calibration_scan/scans/Scan%03d"% roi_scann ]
# for k in target_group.keys():
# if k != "motorDict":
# print(" ADDING data for ROI %s from file roi_%d.h5 " %( k, other ))
# mat = source_group[k]["matrix"][()]
# if clip1 is not None:
# mat = mat[clip1:clip2]
# target_group[k]["matrix"][:] += mat
# print( " SUCCESS ")
main()
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