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
1b6b1360
Commit
1b6b1360
authored
Nov 22, 2020
by
myron
Browse files
It works iwth NNM components
parent
af25b46e
Changes
5
Hide whitespace changes
Inline
Side-by-side
XRStools/XRS_swissknife.py
View file @
1b6b1360
...
...
@@ -2725,10 +2725,10 @@ def superR_getVolume_Esynt(mydata):
coefficients
[
iE
,
iv
,
roi_map
[
rk
]]
=
c
yamlname
=
output_prefix
+
"inputforcpp.yaml"
DSname
=
output_prefix
+
"DS.
raw
"
DDname
=
output_prefix
+
"DD.
raw
"
SSname
=
output_prefix
+
"SS.
raw
"
COEFname
=
output_prefix
+
"coefficients.
raw
"
DSname
=
output_prefix
+
"DS.
h5
"
DDname
=
output_prefix
+
"DD.
h5
"
SSname
=
output_prefix
+
"SS.
h5
"
COEFname
=
output_prefix
+
"coefficients.
h5
"
DSname_relative
=
os
.
path
.
basename
(
DSname
)
DDname_relative
=
os
.
path
.
basename
(
DDname
)
...
...
@@ -2736,27 +2736,27 @@ def superR_getVolume_Esynt(mydata):
coeffname_relative
=
os
.
path
.
basename
(
COEFname
)
f
=
open
(
yamlname
,
"w"
)
f
.
write
(
"NE : %d
\n
"
%
NE
)
f
.
write
(
"NV : %d
\n
"
%
NV
)
f
.
write
(
"NROI : %d
\n
"
%
NROI
)
f
.
write
(
"DIMZ : %d
\n
"
%
DIMZ
)
f
.
write
(
"DIMY : %d
\n
"
%
DIMY
)
f
.
write
(
"DIMX : %d
\n
"
%
DIMX
)
#
f.write("NE : %d\n"%NE)
#
f.write("NV : %d\n"%NV)
#
f.write("NROI : %d\n"%NROI)
#
f.write("DIMZ : %d\n"%DIMZ)
#
f.write("DIMY : %d\n"%DIMY)
#
f.write("DIMX : %d\n"%DIMX)
f
.
write
(
"DSname : %s
\n
"
%
DSname_relative
)
f
.
write
(
"DDname : %s
\n
"
%
DDname_relative
)
f
.
write
(
"SSname : %s
\n
"
%
SSname_relative
)
f
.
write
(
"COEFFSname : %s
\n
"
%
coeffname_relative
)
f
.
close
()
coefficients
.
tofile
(
COEFname
)
DS
.
tofile
(
DSname
)
DD
.
tofile
(
DDname
)
SS
.
tofile
(
SSname
)
#
coefficients.tofile(COEFname)
#
DS.tofile(DSname)
#
DD.tofile(DDname)
#
SS.tofile(SSname)
h5py
.
File
(
DSname
+
".h5"
,
"w"
)[
"data"
]
=
DS
.
astype
(
"f"
)
h5py
.
File
(
DDname
+
".h5"
,
"w"
)[
"data"
]
=
DD
.
astype
(
"f"
)
h5py
.
File
(
SSname
+
".h5"
,
"w"
)[
"data"
]
=
SS
.
astype
(
"f"
)
h5py
.
File
(
COEFname
+
".h5"
,
"w"
)[
"data"
]
=
coefficients
.
astype
(
"f"
)
h5py
.
File
(
DSname
,
"w"
)[
"data"
]
=
DS
.
astype
(
"f"
)
h5py
.
File
(
DDname
,
"w"
)[
"data"
]
=
DD
.
astype
(
"f"
)
h5py
.
File
(
SSname
,
"w"
)[
"data"
]
=
SS
.
astype
(
"f"
)
h5py
.
File
(
COEFname
,
"w"
)[
"data"
]
=
coefficients
.
astype
(
"f"
)
...
...
fitcc/frsv.cc
View file @
1b6b1360
...
...
@@ -38,7 +38,7 @@ typedef InputFileNames_struct InputFileNames;
float
*
read_volume
(
std
::
string
fn
,
std
::
vector
<
size_t
>
&
dims
)
{
float
*
result
;
std
::
string
testh5_name
(
fn
+
".h5"
)
;
std
::
string
testh5_name
(
fn
)
;
h5
::
File
test_file
(
testh5_name
,
h5
::
File
::
ReadOnly
);
h5
::
DataSet
test_dataset
=
test_file
.
getDataSet
(
"data"
);
dims
=
test_dataset
.
getDimensions
();
...
...
@@ -52,7 +52,7 @@ float * read_volume(std::string fn, std::vector<size_t> &dims) {
void
save_volume
(
std
::
string
fn
,
float
*
X
,
std
::
vector
<
size_t
>
dims
)
{
std
::
string
testh5_name
(
fn
+
".h5"
)
;
std
::
string
testh5_name
(
fn
)
;
h5
::
File
test_file
(
testh5_name
,
h5
::
File
::
ReadWrite
|
h5
::
File
::
Create
|
h5
::
File
::
Truncate
);
h5
::
DataSet
dataset
=
test_file
.
createDataSet
<
float
>
(
"data"
,
h5
::
DataSpace
(
dims
));
dataset
.
write_raw
(
X
);
...
...
@@ -597,16 +597,10 @@ int main(int argc, char ** argv) {
" -h prints this help
\n
"
" arguments :
\n
"
" input_file : a yaml file containing
\n
"
" NE : 7
\n
"
" NV : 7
\n
"
" NROI : 72
\n
"
" DIMZ : 10
\n
"
" DIMY : 41
\n
"
" DIMX : 241
\n
"
" DSname : test0_DS.raw
\n
"
" DDname : test0_DD.raw
\n
"
" SSname : test0_SS.raw
\n
"
" COEFFSname : coefficients.raw
\n
"
;
" DSname : test0_DS.h5
\n
"
" DDname : test0_DD.h5
\n
"
" SSname : test0_SS.h5
\n
"
" COEFFSname : coefficients.h5
\n
"
;
int
hflag
=
0
;
// char *cvalue = NULL;
...
...
@@ -646,12 +640,6 @@ int main(int argc, char ** argv) {
YAML
::
Node
mockup_config
;
mockup_config
=
YAML
::
LoadFile
(
argv
[
index_input
]);
assert
(
mockup_config
[
"NE"
]
)
;
assert
(
mockup_config
[
"NV"
]
)
;
assert
(
mockup_config
[
"NROI"
]
)
;
assert
(
mockup_config
[
"DIMZ"
]
)
;
assert
(
mockup_config
[
"DIMY"
]
)
;
assert
(
mockup_config
[
"DIMX"
]
)
;
assert
(
mockup_config
[
"DSname"
]
)
;
assert
(
mockup_config
[
"DDname"
]
)
;
assert
(
mockup_config
[
"SSname"
]
)
;
...
...
@@ -764,7 +752,7 @@ int main(int argc, char ** argv) {
printf
(
" iter %d %e
\n
"
,
iter
,
merit
);
}
pb
.
save
(
X
,
"solution.
raw
"
);
pb
.
save
(
X
,
"solution.
h5
"
);
pb
.
setFreeFacts
(
ffacts
,
X
)
;
...
...
@@ -775,7 +763,7 @@ int main(int argc, char ** argv) {
printf
(
" set ok
\n
"
);
}
pb
.
save
(
X
,
"solution.
raw
"
);
pb
.
save
(
X
,
"solution.
h5
"
);
}
nonregressions/volumes/test2/batch_extraction_esynth1.py
View file @
1b6b1360
# newfactors e' gia pronto , dopo verifica fuzionalita di roi_sel in ximages
import
numpy
as
np
import
h5py
import
glob
...
...
@@ -87,6 +85,45 @@ def extract_sample_givenrois(
process_input
(
inputstring
,
exploit_slurm_mpi
=
0
)
def
InterpInfo_Esynt_components
(
cenom
,
energy_exp_grid
=
None
,
custom_ene_list
=
None
):
components
=
h5py
.
File
(
"components.h5"
,
"r"
)[
"components"
]
[()]
info_dict
=
{}
for
i_interval
in
range
(
len
(
components
)):
info_dict
[
str
(
i_interval
)]
=
{}
info_dict
[
str
(
i_interval
)][
"E"
]
=
custom_ene_list
[
i_interval
]
info_dict
[
str
(
i_interval
)][
"coefficients"
]
=
{}
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
):
info_dict
[
str
(
i_interval
)][
"coefficients"
][
str
(
i_n
)
][
str
(
roi_num
)
]
=
0
for
ic
in
range
(
len
(
components
)):
for
i_interval
in
range
(
len
(
custom_ene_list
)
-
1
):
cE1
=
custom_ene_list
[
i_interval
]
cE2
=
custom_ene_list
[
i_interval
+
1
]
for
i_ene
,
t_ene
in
enumerate
(
energy_exp_grid
)
:
for
roi_num
,
de
in
enumerate
(
cenom
):
if
t_ene
+
de
<
cE1
or
t_ene
+
de
>
cE2
:
continue
alpha
=
(
cE2
-
(
t_ene
+
de
)
)
/
(
cE2
-
cE1
)
info_dict
[
str
(
ic
)][
"coefficients"
][
str
(
i_ene
)
][
str
(
roi_num
)
]
+=
alpha
*
components
[
ic
][
i_interval
]
info_dict
[
str
(
ic
)][
"coefficients"
][
str
(
i_ene
)
][
str
(
roi_num
)
]
+=
(
1
-
alpha
)
*
components
[
ic
][
i_interval
+
1
]
return
info_dict
def
InterpInfo_Esynt
(
cenom
,
energy_exp_grid
=
None
,
custom_ene_list
=
None
):
info_dict
=
{
"energy_exp_grid"
:
list
(
energy_exp_grid
),
"de_list"
:
list
(
cenom
)}
...
...
@@ -155,6 +192,27 @@ def InterpInfo_Esynt( cenom , energy_exp_grid = None, custom_ene_list = Non
self
.
interp_file
=
interp_file
self
.
source
=
source
self
.
cenom
=
cenom
# interpolation_infos_file = "interpolation_infos.json"
# info_dict={}
# for i in range(NC):
# dizio = {}
# info_dict[str(i)] = {"coefficients":dizio}
# c = model.components_[i]
# np = len(c)
# for j in range(np):
# dizio[str(j)] = float(c[j])
# json.dump(info_dict,open( interpolation_infos_file,"w"), indent=4)
def
interpola_Esynt
(
self
,
roi_sel
=
roi_sel
):
print
(
" ECCO I DATI "
)
...
...
@@ -163,7 +221,6 @@ def InterpInfo_Esynt( cenom , energy_exp_grid = None, custom_ene_list = Non
info_dict
=
{}
for
i_intervallo
in
range
(
len
(
self
.
custom_ene_list
)):
info_dict
[
str
(
i_intervallo
)]
=
{}
info_dict
[
str
(
i_intervallo
)][
"E"
]
=
self
.
custom_ene_list
[
i_intervallo
]
...
...
@@ -171,7 +228,6 @@ def InterpInfo_Esynt( cenom , energy_exp_grid = None, custom_ene_list = Non
for
t_vn
,
t_sn
,
t_ene
in
list
(
zip
(
self
.
volum_list
,
self
.
scan_num_list
,
self
.
ene_list
)):
info_dict
[
str
(
i_intervallo
)][
"coefficients"
][
t_vn
]
=
{}
for
i_intervallo
in
range
(
len
(
self
.
custom_ene_list
)
-
1
):
cE1
=
self
.
custom_ene_list
[
i_intervallo
]
cE2
=
self
.
custom_ene_list
[
i_intervallo
+
1
]
...
...
@@ -297,7 +353,7 @@ 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
,
679
1
])
energy_custom_grid
=
np
.
array
([
6745.0
,
6754.0
,
6755.5
,
6756.2
,
6757.5
,
6759.3
,
6762.5
,
6770.0
,
679
2
])
energy_exp_grid
=
h5py
.
File
(
datadir
+
(
filename_template
%
1
)
+
".nxs"
,
"r"
)[
"/root.spyc.config1d_RIXS_0024/scan_data/actuator_1_1"
][()]
...
...
@@ -347,7 +403,8 @@ interpolation_infos_file = "interpolation_infos.json"
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( 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
)
...
...
nonregressions/volumes/test2/colletta.py
0 → 100644
View file @
1b6b1360
from
numpy
import
*
import
h5py
f
=
h5py
.
File
(
"results/extracted.h5"
,
"r"
)
res
=
[
[
0
for
i
in
range
(
9
)
]
for
r
in
range
(
5
)]
for
ie
in
range
(
9
):
he
=
f
[
"E%d"
%
ie
]
for
iscan
in
range
(
19
):
for
ir
in
range
(
4
):
m
=
he
[
"Scan%d/%02d/matrix"
%
(
iscan
,
ir
)][()]
res
[
ir
+
1
][
ie
]
+=
m
.
sum
()
h5py
.
File
(
"plot.h5"
,
"w"
)[
"plot"
]
=
array
(
res
)
R
=
array
(
res
)
R
[
0
,:]
=
array
(
[
6745.981087876128
,
6754.004616913128
,
6755.549616942595
,
6756.206827194552
,
6757.550552579804
,
6759.304498100658
,
6762.542644309955
,
6770.0295586460825
,
6790.5063595030115
])
savetxt
(
"plot.txt"
,
R
.
T
)
nonregressions/volumes/test2/extract_components.py
0 → 100644
View file @
1b6b1360
from
h5py
import
*
from
sklearn.decomposition
import
NMF
from
pylab
import
*
import
json
NC
=
3
model
=
NMF
(
n_components
=
NC
,
init
=
'random'
,
random_state
=
0
,
max_iter
=
200
)
d
=
File
(
"solution.h5"
,
"r"
)
[
"data"
][()]
d
.
shape
=
9
,
-
1
W
=
model
.
fit_transform
(
d
.
T
)
for
i
in
range
(
NC
):
plot
(
model
.
components_
[
i
])
show
()
File
(
"components.h5"
,
"w"
)[
"components"
]
=
model
.
components_
interpolation_infos_file
=
"interpolation_infos.json"
info_dict
=
{}
for
i
in
range
(
NC
):
dizio
=
{}
info_dict
[
str
(
i
)]
=
{
"coefficients"
:
dizio
}
c
=
model
.
components_
[
i
]
np
=
len
(
c
)
for
j
in
range
(
np
):
dizio
[
str
(
j
)]
=
float
(
c
[
j
])
json
.
dump
(
info_dict
,
open
(
interpolation_infos_file
,
"w"
),
indent
=
4
)
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