Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ixstools
xrstools
Commits
d7574d9a
Commit
d7574d9a
authored
Dec 01, 2020
by
myron
Browse files
reorganised reference extration
parent
79cb683a
Changes
2
Hide whitespace changes
Inline
Side-by-side
XRStools/XRS_swissknife.py
View file @
d7574d9a
...
...
@@ -193,10 +193,10 @@ from XRStools import reponse_percussionelle
def
check_allowed
(
mydata
,
allowed_keys
)
:
def
check_allowed
_keys
(
mydata
,
allowed_keys
)
:
for
k
in
mydata
.
keys
():
if
not
k
in
allowed_keys
:
raise
ValueError
(
(
" key "
+
str
(
k
)
+
" not in allowed keys :"
:
+
str
(
allowed_keys
))
)
raise
ValueError
(
(
" key "
+
str
(
k
)
+
" not in allowed keys :"
+
str
(
allowed_keys
))
)
def
dump_anydict_as_map
(
anydict
):
yaml
.
add_representer
(
anydict
,
_represent_dictorder
)
...
...
@@ -880,7 +880,7 @@ def loadscan_2Dimages(mydata):
#
"""
allowed_keys
=
[
"roiaddress"
,
'monitorcolumn'
,
'recenterings'
,
'recenterings_confirmed'
,
'energycolumn'
,
'edfName'
,
'isolateSpot'
,
"expdata"
,
"scan_interval"
,
"signaladdress"
,
"save_also_roi"
,
'sumto1D'
,]
allowed_keys
=
[
"roiaddress"
,
'monitorcolumn'
,
'recenterings'
,
'recenterings_confirmed'
,
'energycolumn'
,
'edfName'
,
'isolateSpot'
,
"expdata"
,
"scan_interval"
,
"
scan_list"
,
"
signaladdress"
,
"save_also_roi"
,
'sumto1D'
,]
check_allowed_keys
(
mydata
,
allowed_keys
)
...
...
@@ -964,12 +964,23 @@ def loadscan_2Dimages(mydata):
recenterings
=
recenterings
)
reader
.
set_roiObj
(
roiob
)
scan_interval
=
mydata
[
"scan_interval"
]
print
(
" LOAD "
)
todo_list
=
[]
ninterval
=
len
(
scan_interval
)
//
2
for
i
in
range
(
ninterval
):
todo_list
=
todo_list
+
list
(
range
(
int
(
scan_interval
[
2
*
i
]),
int
(
scan_interval
[
2
*
i
+
1
]))
)
# *scan_interval[2*i :2*i+2])
if
"scan_interval"
in
mydata
:
scan_interval
=
mydata
[
"scan_interval"
]
ninterval
=
len
(
scan_interval
)
//
2
for
i
in
range
(
ninterval
):
todo_list
=
todo_list
+
list
(
range
(
int
(
scan_interval
[
2
*
i
]),
int
(
scan_interval
[
2
*
i
+
1
]))
)
# *scan_interval[2*i :2*i+2])
else
:
scan_list
=
mydata
[
"scan_list"
]
for
i
in
scan_list
:
todo_list
=
todo_list
+
[
int
(
i
)]
mytodo
=
np
.
array_split
(
todo_list
,
nprocs
)
[
myrank
]
print
(
mytodo
)
...
...
@@ -4146,7 +4157,7 @@ swissknife_operations={
"superR_getVolume_Esynt"
:
superR_getVolume_Esynt
,
"calculate_recenterings"
:
calculate_recenterings
,
"extract_spectra"
:
extract_spectra
,
"sum_scans2maps"
:
sum_scans2maps
,
#
"sum_scans2maps" : sum_scans2maps,
# "XRSprediction" : XRSprediction,
# "Fourc_extraction" : Fourc_extraction,
# "Hydra_extraction" : Hydra_extraction,
...
...
nonregressions/volumes/interpola_1/batch_extraction_esynth1.py
View file @
d7574d9a
...
...
@@ -22,7 +22,8 @@ def main():
roi_target_path
=
"results/myrois.h5:/ROIS"
# roi_target_path = "rr.h5:/extracted/ROI_AS_SELECTED"
filter_path
=
"mask.h5:/FILTER_MASK/filter"
filter_path
=
"mask.h5:/FILTER_MASK/filter"
roi_scan_num
=
[
245
,
246
,
247
]
first_scan_num
=
651
...
...
@@ -55,9 +56,8 @@ def main():
"do_step_make_roi"
:
False
,
"do_step_sample_extraction"
:
False
,
"do_step_interpolation"
:
False
,
"do_extract_reference_scan"
:
True
,
"do_extract_reference_scan"
:
False
,
"do_step_make_reference"
:
False
,
"do_step_scalar_products"
:
False
,
"do_step_finalise_for_fit"
:
False
...
...
@@ -129,14 +129,14 @@ def select_rois( datadir = None, roi_scan_num=None, roi_target_path = None, fil
filter_path
=
filter_path
)
process_input
(
inputstring
,
exploit_slurm_mpi
=
0
)
def
get_reference
(
roi_path
=
None
,
datadir
=
None
,
reference_scan_
num
=
None
,
reference_scan_
list
=
None
,
monitor_column
=
None
,
extracted_reference_target_file
=
None
,
isolate_spot_by
=
None
,
isolate_spot_by
=
None
):
signal_path
=
extracted_reference_target_file
+
":/"
...
...
@@ -144,9 +144,9 @@ def get_reference( roi_path = None,
loadscan_2Dimages :
expdata : {expdata}
roiaddress : {roi_path}
monitor
_
column : {monitor_column}
scan_
interval
:
[
{reference_scan_
num},{reference_scan_num_plus1
}
]
signaladdress :
{signal_path}
monitorcolumn : {monitor_column}
scan_
list
: {reference_scan_
list
}
signaladdress :
"{extracted_reference_target_file}:/references"
isolateSpot : {isolate_spot_by}
save_also_roi : True
...
...
@@ -154,15 +154,15 @@ def get_reference( roi_path = None,
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
,
expdata
=
os
.
path
.
join
(
datadir
,
"hydra"
),
reference_scan_list
=
reference_scan_list
,
monitor_column
=
monitor_column
,
roi_path
=
roi_path
,
isolate_spot_by
=
isolate_spot_by
,
signal_path
=
signal_path
signal_path
=
signal_path
,
extracted_reference_target_file
=
extracted_reference_target_file
)
process_input
(
s
,
exploit_slurm_mpi
=
1
)
process_input
(
s
,
exploit_slurm_mpi
=
0
)
def
extract_sample_givenrois
(
...
...
@@ -229,7 +229,7 @@ def interpolate( peaks_shifts, interp_file_str, interp_file_target_str):
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
():
continue
print
(
" CONTINUO "
,
t_ene
+
de
,
ene_list
.
min
()
,
ene_list
.
max
()
)
i0
=
np
.
searchsorted
(
ene_list
,
t_ene
+
de
)
-
1
...
...
@@ -362,50 +362,48 @@ def tools_sequencer( peaks_shifts = None,
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
)
get_
reference
(
datadir
=
datadir
,
roi_path
=
roi_path
,
monitor_column
=
monitor_column
,
extracted_reference_target_file
=
extracted_reference_target_file
,
isolate_spot_by
=
isolate_spot_by
,
reference_scan_
list
=
reference_scan_
list
)
# 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:
if
reference_clip
is
not
None
:
#
clip1, clip2= reference_clip
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 ")
ftarget
=
h5py
.
File
(
extracted_reference_target_file
,
"r+"
)
for
roi_scann
in
reference_scan_list
:
target_group
=
ftarget
[
"references/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
()
ftarget
=
h5py
.
File
(
extracted_reference_target_file
,
"r+"
)
ftarget
[
"references/scans/ScansSum"
]
=
ftarget
[
"references/scans/Scan%03d"
%
reference_scan_list
[
0
]
]
for
other
in
reference_scan_list
[
1
:]:
source_group
=
ftarget
[
"references/scans/Scan%03d"
%
other
]
target_group
=
ftarget
[
"references/scans/ScansSum"
]
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"
][()]
target_group
[
k
][
"matrix"
][:]
+=
mat
ftarget
.
close
()
main
()
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment