Commit daeda96a authored by myron's avatar myron
Browse files

restructured

parent 1b6b1360
......@@ -4,11 +4,90 @@ import h5py
import glob
import json
BATCH_PARALLELISM = 1
import os
def main():
peaks_shifts = np.array(
[ 6471.983002,
6471.318152,
6470.612314,
6471.217828,
])
Enominal = 6470.6
peaks_shifts -= Enominal
datadir = "/data/scisofttmp/mirone/Loic1/data/"
filter_path = datadir + "../mask.h5:/filter"
filename_template = "HC-D_2Dmap_%04d"
data_path_template = datadir + filename_template + ".nxs:/root.spyc.config1d_RIXS_0024/scan_data/data_03"
monitor_path_template = datadir + filename_template +"_monitor.hd5:/monitor"
# energy_custom_grid = np.array([6746.0,6754.0,6755.5,6756.2,6757.5,6759.3,6762.5,6770.0,6790.5])
energy_custom_grid = np.array([6744.0,6754.0,6755.5,6756.2,6757.5,6759.3,6762.5,6770.0,6792])
energy_exp_grid = h5py.File( datadir +(filename_template%1)+".nxs" ,"r")["/root.spyc.config1d_RIXS_0024/scan_data/actuator_1_1"][()]
scan_interval = [1,476] # from 1 to 475 included
scans_to_use_for_roi = list(range(1,20))
Ydim = 25
Zdim = 19
Edim = 9
roi_target_path = "results/myrois.h5:/ROIS"
reference_target_file = "results/response.h5"
signals_target_file = "results/extracted.h5"
scalarprods_target_file = "results/scalar_prods.h5"
steps_to_do = {
"do_step_make_roi": False,
"do_step_make_reference": False,
"do_step_sample_extraction": False,
"do_step_scalar_products": False,
"do_step_interpolation_coefficients": True,
"do_step_finalise_for_fit": True
}
# use_custom_components = None
use_custom_components = "components.h5"
tools_sequencer( peaks_shifts = peaks_shifts ,
datadir = datadir ,
filter_path = filter_path ,
filename_template = filename_template ,
data_path_template = data_path_template ,
energy_custom_grid = energy_custom_grid ,
energy_exp_grid = energy_exp_grid ,
monitor_path_template = monitor_path_template ,
scan_interval = scan_interval ,
scans_to_use_for_roi = scans_to_use_for_roi ,
Ydim = Ydim ,
Zdim = Zdim ,
Edim = Edim ,
roi_target_path = roi_target_path ,
reference_target_file = reference_target_file ,
signals_target_file = signals_target_file ,
scalarprods_target_file = scalarprods_target_file ,
steps_to_do = steps_to_do,
use_custom_components = use_custom_components
)
def process_input(s, go=0, exploit_slurm_mpi = 0, stop_omp = False):
open("input_tmp_%d.par"%go, "w").write(s)
background_activator = ""
......@@ -18,14 +97,18 @@ def process_input(s, go=0, exploit_slurm_mpi = 0, stop_omp = False):
prefix=""
if stop_omp:
prefix = prefix +"export OMP_NUM_THREADS=1 ;"
if ( exploit_slurm_mpi==0 ):
os.system(prefix +"mpirun -n 1 XRS_swissknife input_tmp_%d.par %s"%(go, background_activator))
comando = (prefix +"mpirun -n 1 XRS_swissknife input_tmp_%d.par %s"%(go, background_activator))
elif ( exploit_slurm_mpi>0 ):
os.system(prefix + "mpirun XRS_swissknife input_tmp_%d.par %s"%(go, background_activator) )
comando = (prefix + "mpirun XRS_swissknife input_tmp_%d.par %s"%(go, background_activator) )
else:
os.system(prefix + "mpirun -n %d XRS_swissknife input_tmp_%d.par %s"%(abs( exploit_slurm_mpi ), go, background_activator) )
comando = (prefix + "mpirun -n %d XRS_swissknife input_tmp_%d.par %s"%(abs( exploit_slurm_mpi ), go, background_activator) )
res = os.system( comando )
assert (res==0) , " something went wrong running command : " + comando
def select_rois( data_path_template=None, filter_path=None, roi_target_path=None, scans_to_use=None ):
......@@ -87,9 +170,9 @@ def extract_sample_givenrois(
def InterpInfo_Esynt_components(cenom , energy_exp_grid = None, custom_ene_list = None ):
def InterpInfo_Esynt_components(peaks_shifts , energy_exp_grid = None, custom_ene_list = None, custom_components = None ):
components = h5py.File("components.h5","r")["components"] [()]
components = h5py.File( custom_components ,"r")["components"] [()]
info_dict = {}
......@@ -100,7 +183,7 @@ def InterpInfo_Esynt_components(cenom , energy_exp_grid = None, custom_ene_li
for i_n in range(len(energy_exp_grid)):
info_dict[str(i_interval)]["coefficients" ][ str(i_n) ]={}
for roi_num, de in enumerate( cenom ):
for roi_num, de in enumerate( peaks_shifts ):
info_dict[str(i_interval)]["coefficients" ][ str(i_n) ][ str(roi_num) ] = 0
......@@ -111,10 +194,10 @@ def InterpInfo_Esynt_components(cenom , energy_exp_grid = None, custom_ene_li
cE2 = custom_ene_list[ i_interval+1 ]
for i_ene, t_ene in enumerate( energy_exp_grid) :
for roi_num, de in enumerate( cenom ):
for roi_num, de in enumerate( peaks_shifts ):
if t_ene+de < cE1 or t_ene+de > cE2:
continue
alpha = (cE2-(t_ene+de) )/(cE2-cE1)
alpha = (cE2-(t_ene+de) )/(cE2+cE1)
info_dict[str(ic)]["coefficients" ][ str(i_ene) ][ str(roi_num) ] += alpha * components[ic][ i_interval ]
......@@ -124,9 +207,9 @@ def InterpInfo_Esynt_components(cenom , energy_exp_grid = None, custom_ene_li
return info_dict
def InterpInfo_Esynt( cenom , energy_exp_grid = None, custom_ene_list = None):
def InterpInfo_Esynt( peaks_shifts , energy_exp_grid = None, custom_ene_list = None):
info_dict = {"energy_exp_grid":list(energy_exp_grid), "de_list": list(cenom)}
info_dict = {"energy_exp_grid":list(energy_exp_grid), "de_list": list(peaks_shifts)}
N_custom = len(custom_ene_list)
N_data = len( energy_exp_grid )
......@@ -139,7 +222,7 @@ def InterpInfo_Esynt( cenom , energy_exp_grid = None, custom_ene_list = Non
for i_n in range(len(energy_exp_grid)):
info_dict[str(i_interval)]["coefficients" ][ str(i_n) ]={}
for roi_num, de in enumerate( cenom ):
for roi_num, de in enumerate( peaks_shifts ):
info_dict[str(i_interval)]["coefficients" ][ str(i_n) ][ str(roi_num) ] = 0
......@@ -150,7 +233,7 @@ def InterpInfo_Esynt( cenom , energy_exp_grid = None, custom_ene_list = Non
for i_ene, t_ene in enumerate( energy_exp_grid) :
for roi_num, de in enumerate( cenom ):
for roi_num, de in enumerate( peaks_shifts ):
if t_ene+de < cE1 or t_ene+de > cE2:
continue
alpha = (cE2-(t_ene+de) )/(cE2-cE1)
......@@ -162,7 +245,7 @@ def InterpInfo_Esynt( cenom , energy_exp_grid = None, custom_ene_list = Non
def __init__(self, cenom, interp_file, source, custom_ene_list = None):
def __init__(self, peaks_shifts, interp_file, source, custom_ene_list = None):
volum_list = list(interp_file[source].keys())
scan_num_list = np.array([ int( t.split("_") [1]) for t in volum_list])
......@@ -191,13 +274,7 @@ def InterpInfo_Esynt( cenom , energy_exp_grid = None, custom_ene_list = Non
self.interp_file=interp_file
self.source= source
self.cenom=cenom
self.peaks_shifts=peaks_shifts
# interpolation_infos_file = "interpolation_infos.json"
......@@ -217,7 +294,7 @@ def InterpInfo_Esynt( cenom , energy_exp_grid = None, custom_ene_list = Non
def interpola_Esynt(self, roi_sel=roi_sel ):
print ( " ECCO I DATI ")
print ( self.ene_list )
print ( self.cenom )
print ( self.peaks_shifts )
info_dict = {}
......@@ -232,7 +309,7 @@ def InterpInfo_Esynt( cenom , energy_exp_grid = None, custom_ene_list = Non
cE1 = self.custom_ene_list[ i_intervallo ]
cE2 = self.custom_ene_list[ i_intervallo+1 ]
for t_vn, t_sn, t_ene in list(zip(self.volum_list, self.scan_num_list, self.ene_list ))[0:]:
for roi_num, de in enumerate( self.cenom ):
for roi_num, de in enumerate( self.peaks_shifts ):
if roi_num not in roi_sel:
continue
if t_ene+de < cE1 or t_ene+de > cE2:
......@@ -331,101 +408,93 @@ def reshuffle( volumefile = "volumes.h5", nick = None ):
## THE FOLLOWING PART IS THE RELEVANT ONE
cenom = np.array(
[ 6471.983002,
6471.318152,
6470.612314,
6471.217828,
])
Enominal = 6470.6
cenom -= Enominal
def tools_sequencer( peaks_shifts = None,
datadir = None,
filter_path = None,
filename_template = None,
data_path_template = None,
energy_custom_grid = None,
energy_exp_grid = None,
monitor_path_template = None,
scan_interval = None,
scans_to_use_for_roi = None,
Ydim = None,
Zdim = None,
Edim = None,
roi_target_path = None,
reference_target_file = None,
signals_target_file = None,
scalarprods_target_file = None,
steps_to_do = None,
use_custom_components = None
) :
datadir = "/data/scisofttmp/mirone/Loic1/data/"
filter_path = datadir + "../mask.h5:/filter"
filename_template = "HC-D_2Dmap_%04d"
data_path_template = datadir + filename_template + ".nxs:/root.spyc.config1d_RIXS_0024/scan_data/data_03"
monitor_path_template = datadir + filename_template +"_monitor.hd5:/monitor"
# energy_custom_grid = np.array([6746.0,6754.0,6755.5,6756.2,6757.5,6759.3,6762.5,6770.0,6790.5])
energy_custom_grid = np.array([6745.0,6754.0,6755.5,6756.2,6757.5,6759.3,6762.5,6770.0,6792])
energy_exp_grid = h5py.File( datadir +(filename_template%1)+".nxs" ,"r")["/root.spyc.config1d_RIXS_0024/scan_data/actuator_1_1"][()]
if(steps_to_do["do_step_make_roi"]): # ROI selection and reference scan
select_rois( data_path_template = data_path_template, filter_path = filter_path, roi_target_path = roi_target_path, scans_to_use=scans_to_use_for_roi )
roi_path = roi_target_path
scan_interval = [1,476] # from 1 to 475 included
scans_to_use_for_roi = list(range(1,20))
first_scan_n = 1
if(steps_to_do["do_step_make_reference"]):
get_reference( roi_path = roi_path , reference_target_file = reference_target_file )
reference_file = reference_target_file
Ydim = 25
Zdim = 19
Edim = 9
roi_target_path = "results/myrois.h5:/ROIS"
reference_target_file = "results/response.h5"
signals_target_file = "results/extracted.h5"
scalarprods_target_file = "results/scalar_prods.h5"
if(steps_to_do["do_step_sample_extraction"]): # SAMPLE extraction
extract_sample_givenrois(
roi_path = roi_path ,
data_path_template = data_path_template ,
monitor_path_template = monitor_path_template ,
scan_interval = scan_interval ,
Ydim = Ydim ,
Zdim = Zdim ,
Edim = Edim ,
signals_target_file = signals_target_file
)
signals_file = signals_target_file
if(0): # ROI selection and reference scan
select_rois( data_path_template = data_path_template, filter_path = filter_path, roi_target_path = roi_target_path, scans_to_use=scans_to_use_for_roi )
roi_path = roi_target_path
if(0):
get_reference( roi_path = roi_path , reference_target_file = reference_target_file )
reference_file = reference_target_file
if(steps_to_do["do_step_scalar_products"]):
os.system("rm %s"%scalarprods_target_file)
for iE in range(Edim) :
get_scalars( iE = iE,
signals_file = signals_file,
reference_file = reference_file,
target_file = scalarprods_target_file
)
if(0): # SAMPLE extraction
extract_sample_givenrois(
roi_path = roi_path ,
data_path_template = data_path_template ,
monitor_path_template = monitor_path_template ,
scan_interval = scan_interval ,
Ydim = Ydim ,
Zdim = Zdim ,
Edim = Edim ,
signals_target_file = signals_target_file
)
signals_file = signals_target_file
scalarprods_file = scalarprods_target_file
interpolation_infos_file = "interpolation_infos.json"
interpolation_infos_file = "interpolation_infos.json"
if(steps_to_do["do_step_interpolation_coefficients"]): # INTERPOLATION ESYNTH
if use_custom_components is None:
info_dict = InterpInfo_Esynt( peaks_shifts ,
energy_exp_grid = energy_exp_grid,
custom_ene_list = energy_custom_grid
)
else:
info_dict = InterpInfo_Esynt_components( peaks_shifts,
energy_exp_grid = energy_exp_grid,
custom_ene_list = energy_custom_grid,
custom_components = use_custom_components
)
json.dump(info_dict,open( interpolation_infos_file,"w"), indent=4)
if(1): # INTERPOLATION ESYNTH
# info_dict = InterpInfo_Esynt( cenom , energy_exp_grid = energy_exp_grid, custom_ene_list = energy_custom_grid )
info_dict = InterpInfo_Esynt_components( cenom , energy_exp_grid = energy_exp_grid, custom_ene_list = energy_custom_grid )
json.dump(info_dict,open( interpolation_infos_file,"w"), indent=4)
if(0):
os.system("rm %s"%scalarprods_target_file)
for iE in range(Edim) :
get_scalars( iE = iE,
signals_file = signals_file,
reference_file = reference_file,
target_file = scalarprods_target_file
)
scalarprods_file = scalarprods_target_file
# ### ESYNTH
if(1):
get_volume_Esynt( scalarprods_file = scalarprods_file,
interpolation_file = interpolation_infos_file)
# ### ESYNTH
if(steps_to_do["do_step_finalise_for_fit"]):
get_volume_Esynt( scalarprods_file = scalarprods_file,
interpolation_file = interpolation_infos_file)
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