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
Branches
No related tags found
No related merge requests found
...@@ -16,6 +16,7 @@ from watchdog.events import PatternMatchingEventHandler ...@@ -16,6 +16,7 @@ from watchdog.events import PatternMatchingEventHandler
from multiprocessing.pool import ThreadPool as Pool from multiprocessing.pool import ThreadPool as Pool
import pandas as pd import pandas as pd
from silx.io.dictdump import h5todict, dicttoh5 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"): ...@@ -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)) 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) 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 # Prepare data for HDF5 file using silx
hdf5_data = { hdf5_data = {
subdir_name: { 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 "kind": "group",
results_data = sorted(results_data, key=lambda x: x["filename"].lower()) "children": [
{
for idx, result in enumerate(results_data, start=1): "name": "q",
group_name = f"{idx}.1" "path": f"/{idx}.1/measurement/q",
hdf5_data[subdir_name][group_name] = { "attributes": [],
"@NX_class": "NXentry", "kind": "dataset",
"description": os.path.basename(result["filename"]), "shape": [len(result["q"])],
"measurements": { "type": {
"@NX_class": "NXcollection", "class": "Float",
"q": result["q"].tolist(), "endianness": "little-endian",
"I": result["I"].tolist(), "size": 64
"dI": result["dI"].tolist() },
"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 register or to comment