Commit f75892d8 authored by payno's avatar payno
Browse files

Merge branch 'add_use_file_lock' into '0.3'

[h5_to_nx] set HDF5_USE_FILE_LOCKING environment variable to prevent corruption

See merge request !23
parents 71e07b36 d0e7d628
Pipeline #31969 passed with stage
in 20 seconds
......@@ -6,6 +6,7 @@ Change Log
* h5_to_nx:
* add set-param option to let the user define some parameters values like energy if he knows it is missing (and avoid asking him n times).
* io: add management of hdf5 files from tomoscan.io.HDF5File
0.3.1: 2020/08/19
-----------------
......
......@@ -49,6 +49,7 @@ from nxtomomill.settings import (EDF_DARK_NAMES, EDF_MOTOR_MNE, EDF_MOTOR_POS,
EDF_X_TRANS, EDF_Y_TRANS, EDF_Z_TRANS)
from collections import namedtuple
from tomoscan.unitsystem import metricsystem
from tomoscan.io import HDF5File
import os
import typing
import h5py
......@@ -133,8 +134,7 @@ def edf_to_nx(scan: EDFTomoScan, output_file: str, file_extension: str,
_logger.info("Output file will be " + fileout_h5)
DARK_ACCUM_FACT = True
with h5py.File(fileout_h5, "w") as h5d:
os.environ["HDF5_USE_FILE_LOCKING"] = "TRUE"
with HDF5File(fileout_h5, "w") as h5d:
proj_urls = scan.get_proj_urls(scan=scan.path)
for dark_to_find in file_keys.dark_names:
......@@ -541,8 +541,7 @@ def h5_to_nx(input_file_path: str, output_file: str, single_file:bool,
plugins = []
res = []
with h5py.File(input_file_path, 'r') as h5d:
os.environ["HDF5_USE_FILE_LOCKING"] = "FALSE"
with HDF5File(input_file_path, 'r') as h5d:
groups = list(h5d.keys())
groups.sort(key=float)
# step 1: deduce acquisitions
......@@ -613,8 +612,7 @@ def h5_to_nx(input_file_path: str, output_file: str, single_file:bool,
# if split files create a master file with link to those entries
if single_file is False:
_logger.info('create link in %s' % output_file)
with h5py.File(output_file, 'a') as master_file:
os.environ["HDF5_USE_FILE_LOCKING"] = "TRUE"
with HDF5File(output_file, 'a') as master_file:
mf_entry = 'entry' + str(i_acquisition).zfill(4)
link_file = os.path.relpath(en_output_file, os.path.dirname(output_file))
master_file[mf_entry] = h5py.ExternalLink(link_file,
......@@ -643,8 +641,7 @@ def _get_entry_type(entry: h5py.Group, scan_titles) -> typing.Union[None, Acquis
def get_bliss_tomo_entries(input_file_path, scan_titles):
"""Util function. Used by tomwer for example"""
with h5py.File(input_file_path, 'r') as h5d:
os.environ["HDF5_USE_FILE_LOCKING"] = "FALSE"
with HDF5File(input_file_path, 'r') as h5d:
acquisitions = []
for group_name in h5d.keys():
......@@ -812,8 +809,7 @@ class _Acquisition:
# first retrieve the data and create some virtual dataset.
self._preprocess_frames(input_file_path)
with h5py.File(output_file, 'a') as h5_file:
os.environ["HDF5_USE_FILE_LOCKING"] = "TRUE"
with HDF5File(output_file, 'a') as h5_file:
entry = h5_file.require_group(data_path)
entry.attrs["NX_class"] = u"NXentry"
entry.attrs["definition"] = u"NXtomo"
......
......@@ -2,4 +2,4 @@ silx
h5py
numpy
fabio
tomoscan >= 0.3
\ No newline at end of file
tomoscan >= 0.3.2
\ No newline at end of file
......@@ -189,7 +189,7 @@ def get_project_configuration(dry_run):
"numpy",
"silx",
"h5py",
"tomoscan >= 0.3",
"tomoscan >= 0.3.2",
]
setup_requires = ["setuptools",]
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment