Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
Live integration
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Koziej Lab
X-ray Diffraction
PDF
Live integration
Commits
0c58f25a
Commit
0c58f25a
authored
1 month ago
by
Gröne, Tjark Leon Raphael
Browse files
Options
Downloads
Patches
Plain Diff
Update file maxwell_integrate_to_h5.py
parent
57014b2c
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
maxwell_integrate_to_h5.py
+36
-30
36 additions, 30 deletions
maxwell_integrate_to_h5.py
with
36 additions
and
30 deletions
maxwell_integrate_to_h5.py
+
36
−
30
View file @
0c58f25a
...
...
@@ -125,36 +125,44 @@ def integrate_ims_in_dir(path_im, path_int, dtype_im=".tif", dtype_int=".dat"):
subdir_name
=
os
.
path
.
basename
(
os
.
path
.
normpath
(
subdir_path_int
))
results_df
.
to_csv
(
os
.
path
.
join
(
subdir_path_int
,
f
"
{
subdir_name
}
.csv
"
),
index
=
False
)
# Create the HDF5 file
with
h5py
.
File
(
"
output_silx_format.h5
"
,
"
w
"
)
as
f
:
# Create top-level group (e.g., subdir_name)
subdir_grp
=
f
.
create_group
(
subdir_name
)
subdir_grp
.
attrs
[
"
NX_class
"
]
=
np
.
string_
(
"
NXentry
"
)
subdir_grp
.
attrs
[
"
description
"
]
=
np
.
string_
(
subdir_name
)
def
natural_sort_key
(
item
):
return
[
int
(
text
)
if
text
.
isdigit
()
else
text
.
lower
()
for
text
in
re
.
split
(
r
'
(\d+)
'
,
item
[
"
filename
"
])]
results_data
=
sorted
(
results_data
,
key
=
natural_sort_key
)
output_file
=
os
.
path
.
join
(
subdir_path_int
,
f
"
{
subdir_name
}
.h5
"
)
if
os
.
path
.
exists
(
output_file
):
print
(
f
"
File
{
output_file
}
already exists. Removing it to create a new one.
"
)
os
.
remove
(
output_file
)
with
h5py
.
File
(
output_file
,
"
w
"
)
as
f
:
entry
=
f
.
create_group
(
"
entry
"
)
entry
.
attrs
[
"
NX_class
"
]
=
np
.
string_
(
"
NXentry
"
)
entry
.
attrs
[
"
default
"
]
=
np
.
string_
(
"
1.1
"
)
# Optional
for
idx
,
result
in
enumerate
(
results_data
,
start
=
1
):
scan_name
=
f
"
{
idx
}
.1
"
scan_grp
=
subdir_grp
.
create_group
(
scan_name
)
# --- Group-level attributes ---
scan_grp
.
attrs
[
"
NX_class
"
]
=
np
.
string_
(
"
NXentry
"
)
scan_grp
.
attrs
[
"
default
"
]
=
np
.
string_
(
"
measurement
"
)
scan_grp
.
attrs
[
"
plotselect
"
]
=
np
.
string_
(
"
q,I
"
)
# --- Measurement group ---
meas_grp
=
scan_grp
.
create_group
(
"
measurement
"
)
meas_grp
.
attrs
[
"
NX_class
"
]
=
np
.
string_
(
"
NXcollection
"
)
# Datasets: q, I, dI
for
name
in
[
"
q
"
,
"
I
"
,
"
dI
"
]:
data
=
result
[
name
]
meas_grp
.
create_dataset
(
name
,
data
=
data
,
chunks
=
(
min
(
len
(
data
),
1000
),),
dtype
=
'
f8
'
)
# --- Plotselect group ---
plotselect_grp
=
scan_grp
.
create_group
(
"
plotselect
"
)
plotselect_grp
.
attrs
[
"
NX_class
"
]
=
np
.
string_
(
"
NXcollection
"
)
plotselect_grp
.
attrs
[
"
axes
"
]
=
np
.
string_
(
"
q
"
)
plotselect_grp
.
attrs
[
"
signal
"
]
=
np
.
string_
(
"
I
"
)
group_name
=
f
"
{
idx
}
.1
"
g
=
entry
.
create_group
(
group_name
)
g
.
attrs
[
"
NX_class
"
]
=
np
.
string_
(
"
NXentry
"
)
g
.
attrs
[
"
default
"
]
=
np
.
string_
(
"
measurement
"
)
meas
=
g
.
create_group
(
"
measurement
"
)
meas
.
attrs
[
"
NX_class
"
]
=
np
.
string_
(
"
NXdata
"
)
meas
.
attrs
[
"
signal
"
]
=
np
.
string_
(
"
I
"
)
meas
.
attrs
[
"
axes
"
]
=
np
.
string_
(
"
q
"
)
meas
.
attrs
[
"
filename
"
]
=
np
.
string_
(
result
[
"
filename
"
])
# 👈 capture filename
meas
.
attrs
[
"
title
"
]
=
np
.
string_
(
result
[
"
filename
"
])
# (H5Web may show this)
# Store datasets
meas
.
create_dataset
(
"
q
"
,
data
=
result
[
"
q
"
])
meas
.
create_dataset
(
"
I
"
,
data
=
result
[
"
I
"
])
meas
.
create_dataset
(
"
dI
"
,
data
=
result
[
"
dI
"
])
# Optional: add filename as long_name attribute on I
meas
[
"
I
"
].
attrs
[
"
long_name
"
]
=
np
.
string_
(
result
[
"
filename
"
])
print
(
f
"
✅ HDF5 file
'
{
output_file
}
'
created with
{
len
(
results_data
)
}
spectra.
"
)
# # Sort results_data by filename
# def natural_sort_key(item):
# return [int(text) if text.isdigit() else text.lower() for text in re.split(r'(\d+)', item["filename"])]
...
...
@@ -178,8 +186,6 @@ def integrate_ims_in_dir(path_im, path_int, dtype_im=".tif", dtype_int=".dat"):
# },
# }
print
(
f
"
Results for subdirectory
{
subdir_name
}
saved to HDF5 file using h5py.
"
)
# Save to HDF5 file using silx
# hdf5_file_path = os.path.join(subdir_path_int, f"{subdir_name}.h5")
# dicttoh5(hdf5_data, hdf5_file_path, mode="w")
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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