Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
Hdf5 maps handling
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Container Registry
Operate
Terraform modules
Monitor
Incidents
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ilaria Carlomagno
Hdf5 maps handling
Commits
d67eaeca
Commit
d67eaeca
authored
1 month ago
by
Ilaria Carlomagno
Browse files
Options
Downloads
Patches
Plain Diff
Added comment in the hdf5 file
parent
06e200f0
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
reshape-cut-rotate_working.py
+45
-45
45 additions, 45 deletions
reshape-cut-rotate_working.py
with
45 additions
and
45 deletions
reshape-cut-rotate_working.py
+
45
−
45
View file @
d67eaeca
...
...
@@ -33,7 +33,8 @@ def cut_reshape(in_file, out_fold):
with
h5py
.
File
(
in_file
,
'
r
'
)
as
f
:
move_ver
=
False
comment_line
=
''
for
run
in
f
.
keys
():
date_str
=
'
Run%Y%m%d %H%M%S
'
# the first part of the string contains date and time of acquisition
...
...
@@ -42,8 +43,8 @@ def cut_reshape(in_file, out_fold):
sample_name
=
run
[
19
:]
new_map
=
'
./
'
+
NEW_FOLDER
+
sample_name
+
date_acq
.
strftime
(
'
_%Y-%m-%d_%H-%M-%S
'
)
print
(
"
Sample_name: %s.
"
%
sample_name
)
print
(
date_acq
.
strftime
(
'
\t
Acquisition time: %d/%m/%Y - %H:%M:%S.
'
))
print
(
"
Sample_name: %s.
"
%
sample_name
)
print
(
date_acq
.
strftime
(
'
\t
Acquisition time: %d/%m/%Y - %H:%M:%S.
'
))
try
:
x
=
f
[
run
+
PATH_SCALAR
+
"
/X
"
][...]
...
...
@@ -59,7 +60,7 @@ def cut_reshape(in_file, out_fold):
# The following section fixes this issue. The output file will be shown
# in the correct orientation on PyMCA.
try
:
x
,
y
,
move_ver
=
orientation
(
x
,
y
)
x
,
y
,
move_ver
=
orientation
(
x
,
y
)
except
ValueError
:
print
(
'
\t
x x x x x x x x x x x x x x x x x x x x x x x x
'
)
print
(
'
\t
x Size not valid for map. Please check file. x
'
)
...
...
@@ -85,6 +86,7 @@ def cut_reshape(in_file, out_fold):
row
=
shape_x
col
=
math
.
floor
(
valid_pixels
/
shape_x
)
new_map
+=
'
_rot
'
comment_line
+=
'
This map has been rotated.
\n
'
else
:
col
=
shape_y
row
=
math
.
floor
(
valid_pixels
/
shape_y
)
...
...
@@ -93,50 +95,49 @@ def cut_reshape(in_file, out_fold):
print
(
'
!
\t
Valid pixels = %s out of %s
'
%
(
valid_pixels
,
shape_x
*
shape_y
))
if
not
beam_lost
:
print
(
'
\t
Incomplete map collection found.
'
)
comment_line
+=
'
Incomplete map collection found
'
print
(
'
\t
New map shape: (%d, %d)
'
%
(
row
,
col
))
new_map
+=
'
_cut
'
if
(
row
*
col
==
shape_x
*
shape_y
):
print
(
'
\t
No cutting, just reshaping.
\n
'
)
comment_line
+=
'
This map was not cut. Only reshaping has been done.
'
print
(
'
\t
New map shape: (%d, %d)
'
%
(
row
,
col
))
new_map
+=
'
.h5
'
with
h5py
.
File
(
new_map
,
'
w
'
)
as
fout
:
final_points
=
row
*
col
my_comment
=
'
Test_ciao !!
'
fout
.
create_dataset
(
"
Comments
"
,
data
=
my_comment
)
# Reshaping TransientVectorData
for
vectorData
in
f
[
run
+
PATH_VECTOR
].
keys
():
v
=
f
[
run
+
PATH_VECTOR
+
"
/
"
+
vectorData
][...]
v
=
v
[
0
:
final_points
]
v
=
v
.
reshape
(
row
,
col
,
v
.
shape
[
-
1
])
fout
=
h5py
.
File
(
new_map
,
'
w
'
)
final_points
=
row
*
col
fout
.
create_dataset
(
"
Comments
"
,
data
=
comment_line
)
# Reshaping TransientVectorData
for
vectorData
in
f
[
run
+
PATH_VECTOR
].
keys
():
v
=
f
[
run
+
PATH_VECTOR
+
"
/
"
+
vectorData
][...]
v
=
v
[
0
:
final_points
]
v
=
v
.
reshape
(
row
,
col
,
v
.
shape
[
-
1
])
# the rotation of the map is done here:
if
move_ver
:
v
=
np
.
rot90
(
v
,
-
1
,
axes
=
(
1
,
0
))
fout
.
create_dataset
(
run
+
"
/Detector_data/
"
+
vectorData
,
data
=
v
,
compression
=
"
gzip
"
,
shuffle
=
True
)
# Reshaping TransientScalarData:')
for
scalarData
in
f
[
run
+
PATH_SCALAR
].
keys
():
if
scalarData
in
AcceptedList
:
s
=
f
[
run
+
PATH_SCALAR
+
"
/
"
+
scalarData
][...]
s
=
s
[
0
:
final_points
]
if
s
.
shape
[
0
]
==
final_points
:
s
=
s
.
reshape
(
row
,
col
)
# the rotation of the map is done here:
if
move_ver
:
v
=
np
.
rot90
(
v
,
-
1
,
axes
=
(
1
,
0
))
fout
.
create_dataset
(
run
+
"
/Detector_data/
"
+
vectorData
,
data
=
v
,
compression
=
"
gzip
"
,
shuffle
=
True
)
# Reshaping TransientScalarData:')
for
scalarData
in
f
[
run
+
PATH_SCALAR
].
keys
():
if
scalarData
in
AcceptedList
:
s
=
f
[
run
+
PATH_SCALAR
+
"
/
"
+
scalarData
][...]
s
=
s
[
0
:
final_points
]
if
s
.
shape
[
0
]
==
final_points
:
s
=
s
.
reshape
(
row
,
col
)
if
move_ver
:
s
=
np
.
rot90
(
s
,
-
1
,
axes
=
(
1
,
0
))
fout
.
create_dataset
(
run
+
"
/Motor_positions/
"
+
scalarData
,
data
=
s
)
# Reshaping Positioners (i.e. motor position before map collection)
for
motor_position
in
f
[
run
+
POSITIONERS
].
keys
():
p
=
f
[
run
+
POSITIONERS
+
"
/
"
+
motor_position
][...]
fout
.
create_dataset
(
run
+
"
/Starting_positions/
"
+
motor_position
,
data
=
p
)
s
=
np
.
rot90
(
s
,
-
1
,
axes
=
(
1
,
0
))
fout
.
create_dataset
(
run
+
"
/Motor_positions/
"
+
scalarData
,
data
=
s
)
# Reshaping Positioners (i.e. motor position before map collection)
for
motor_position
in
f
[
run
+
POSITIONERS
].
keys
():
p
=
f
[
run
+
POSITIONERS
+
"
/
"
+
motor_position
][...]
fout
.
create_dataset
(
run
+
"
/Starting_positions/
"
+
motor_position
,
data
=
p
)
####################################################################
...
...
@@ -161,15 +162,14 @@ def run():
if
len
(
file_list
)
==
0
:
print
(
"
\t
-> Can
'
t do much with 0 files! Sorry!
"
)
print
(
"
\t
-> Move the maps in the same folder as the program and try again!
"
)
print
(
"
\t
-> Move the maps in the same folder as the program and try again!
"
)
else
:
print
(
"
\t
-> All the files mentioned above will be cut and reshaped.
"
)
print
(
"
\t
-> Don
'
t worry: overwriting raw data is not an option. ;)
\n
"
)
print
(
"
\t
-> Don
'
t worry: overwriting raw data is not an option. ;)
\n
"
)
if
not
os
.
path
.
exists
(
out_path
):
os
.
makedirs
(
out_path
)
os
.
makedirs
(
out_path
)
for
filename
,
i
in
zip
(
file_list
,
range
(
len
(
file_list
))):
filename
=
filename
[
2
:]
cut_reshape
(
filename
,
out_path
)
...
...
@@ -178,4 +178,4 @@ def run():
print
(
'
\t
Have a nice day.
\n
'
)
if
__name__
==
"
__main__
"
:
run
()
\ No newline at end of file
run
()
This diff is collapsed.
Click to expand it.
Preview
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!
Save comment
Cancel
Please
register
or
sign in
to comment