Skip to content
Snippets Groups Projects
Commit 6a7aa2ee authored by Gröne, Tjark Leon Raphael's avatar Gröne, Tjark Leon Raphael
Browse files

Update file maxwell_integrate_to_h5.py

parent 9a7361d2
No related branches found
No related tags found
No related merge requests found
......@@ -16,6 +16,7 @@ from watchdog.events import PatternMatchingEventHandler
from multiprocessing.pool import ThreadPool as Pool
import pandas as pd
from silx.io.dictdump import h5todict, dicttoh5
import re
......@@ -123,26 +124,184 @@ 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)
# 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"])]
results_data = sorted(results_data, key=natural_sort_key)
# Prepare data for HDF5 file using silx
hdf5_data = {
subdir_name: {
"@NX_class": "NXroot",
"@NX_class": "NXentry",
"description": f"{subdir_name}",
"files": [
{
"name": f"{idx}.1",
"path": f"/{idx}.1",
"attributes": [
{
"name": "NX_class",
"shape": [],
"type": {
"class": "String",
"charSet": "UTF-8",
"strPad": "null-terminated"
},
"value": "NXentry"
},
{
"name": "default",
"shape": [],
"type": {
"class": "String",
"charSet": "UTF-8",
"strPad": "null-terminated"
},
"value": "measurement"
},
{
"name": "plotselect",
"shape": [],
"type": {
"class": "String",
"charSet": "UTF-8",
"strPad": "null-terminated"
},
"value": "q,I"
}
],
"kind": "group",
"children": [
{
"name": "measurement",
"path": f"/{idx}.1/measurement",
"attributes": [
{
"name": "NX_class",
"shape": [],
"type": {
"class": "String",
"charSet": "UTF-8",
"strPad": "null-terminated"
},
"value": "NXcollection"
}
# Sort results_data by filename
results_data = sorted(results_data, key=lambda x: x["filename"].lower())
for idx, result in enumerate(results_data, start=1):
group_name = f"{idx}.1"
hdf5_data[subdir_name][group_name] = {
"@NX_class": "NXentry",
"description": os.path.basename(result["filename"]),
"measurements": {
"@NX_class": "NXcollection",
"q": result["q"].tolist(),
"I": result["I"].tolist(),
"dI": result["dI"].tolist()
],
"kind": "group",
"children": [
{
"name": "q",
"path": f"/{idx}.1/measurement/q",
"attributes": [],
"kind": "dataset",
"shape": [len(result["q"])],
"type": {
"class": "Float",
"endianness": "little-endian",
"size": 64
},
"chunks": [min(len(result["q"]), 1000)],
"filters": [],
"rawType": {
"signed": False,
"type": 1,
"vlen": False,
"littleEndian": True,
"size": 8,
"total_size": len(result["q"])
},
"value": result["q"]
},
{
"name": "I",
"path": f"/{idx}.1/measurement/I",
"attributes": [],
"kind": "dataset",
"shape": [len(result["I"])],
"type": {
"class": "Float",
"endianness": "little-endian",
"size": 64
},
"chunks": [min(len(result["I"]), 1000)],
"filters": [],
"rawType": {
"signed": False,
"type": 1,
"vlen": False,
"littleEndian": True,
"size": 8,
"total_size": len(result["I"])
},
"value": result["I"]
},
{
"name": "dI",
"path": f"/{idx}.1/measurement/dI",
"attributes": [],
"kind": "dataset",
"shape": [len(result["dI"])],
"type": {
"class": "Float",
"endianness": "little-endian",
"size": 64
},
"chunks": [min(len(result["dI"]), 1000)],
"filters": [],
"rawType": {
"signed": False,
"type": 1,
"vlen": False,
"littleEndian": True,
"size": 8,
"total_size": len(result["dI"])
},
"value": result["dI"]
}
]
},
{
"name": "plotselect",
"path": f"/{idx}.1/plotselect",
"attributes": [
{
"name": "NX_class",
"shape": [],
"type": {
"class": "String",
"charSet": "UTF-8",
"strPad": "null-terminated"
},
"value": "NXcollection"
},
{
"name": "axes",
"shape": [1],
"type": {
"class": "String",
"charSet": "UTF-8",
"strPad": "null-terminated"
},
"value": "q"
},
{
"name": "signal",
"shape": [],
"type": {
"class": "String",
"charSet": "UTF-8",
"strPad": "null-terminated"
},
"value": "I"
}
],
"kind": "group"
}
]
}
for idx, result in enumerate(results_data, start=1)
]
}
}
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment