Skip to content
Snippets Groups Projects
Commit cb9efb9c authored by payno's avatar payno
Browse files

[patch-nx] add an option embed to include dataset not in the file

parent 8b795fab
No related branches found
No related tags found
1 merge request!40[patch-nx] add an option embed to include dataset not in the file
Pipeline #37558 passed
......@@ -191,6 +191,12 @@ def main(argv):
help="Define the set of frames to be mark as alignment. "
"" + _INFO_FRAME_INPUT,
)
parser.add_argument(
"--embed-data",
default=False,
action="store_true",
help="Embed data from url in the file if not already inside",
)
options = parser.parse_args(argv[1:])
......@@ -271,6 +277,7 @@ def main(argv):
flats_start=flat_start_url,
darks_end=darks_end_url,
flats_end=flat_end_url,
embed_data=options.embed_data,
logger=_logger,
)
......
......@@ -45,6 +45,7 @@ import logging
import h5py
from collections.abc import Iterable
from silx.utils.enum import Enum as _Enum
import uuid
class ImageKey(_Enum):
......@@ -221,6 +222,7 @@ def add_dark_flat_nx_file(
flats_end: typing.Union[None, numpy.ndarray, DataUrl] = None,
extras: typing.Union[None, dict] = None,
logger: typing.Union[None, logging.Logger] = None,
embed_data: bool = True,
):
"""
This will get all data from entry@input_file and patch them with provided
......@@ -269,6 +271,8 @@ def add_dark_flat_nx_file(
* `rotation_angle`
:type extras: Union[None, dict]
:param Union[None, logging.Logger] logger: object for logs
:param bool embed_data: if True then each external data will be copy
under a 'duplicate_data' folder
"""
from nxtomomill.converter import ImageKey # avoid cyclic import
......@@ -283,6 +287,28 @@ def add_dark_flat_nx_file(
"{keys}".format(key=key, keys=valid_extra_keys)
)
if embed_data is True:
def embed_url(url):
if not isinstance(url, DataUrl):
return url
elif url.file_path() == file_path:
return url
else:
embed_data_path = "/".join(("/duplicate_data", str(uuid.uuid1())))
with cwd_context():
os.chdir(os.path.dirname(os.path.abspath(file_path)))
with HDF5File(file_path, "a") as h5s:
h5s[embed_data_path] = get_data(url)
return DataUrl(
file_path=file_path, data_path=embed_data_path, scheme="silx"
)
darks_start = embed_url(darks_start)
darks_end = embed_url(darks_end)
flats_start = embed_url(flats_start)
flats_end = embed_url(flats_end)
# !!! warning: order of dark / flat treatments import
data_names = "flats_start", "darks_end", "flats_end", "darks_start"
datas = flats_start, darks_end, flats_end, darks_start
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment