Commit 2b95e4e4 authored by Henri Payno's avatar Henri Payno
Browse files

add a concatenate util class

parent c8b6d8a5
Pipeline #74454 passed with stages
in 3 minutes and 56 seconds
......@@ -3,3 +3,4 @@ from .nxobject import NXobject # noqa F401
from .nxsample import NXsample # noqa F401
from .nxsource import NXsource # noqa F401
from .nxtomo import NXtomo # noqa F401
from .utils import concatenate # noqa F401
......@@ -30,7 +30,6 @@ __date__ = "03/02/2022"
from functools import partial
from multiprocessing.sharedctypes import Value
from operator import is_not
from silx.utils.proxy import docstring
from silx.io.url import DataUrl
......
......@@ -372,7 +372,6 @@ class NXtomo(NXobject):
nx_tomo.start_time = min(start_times)
nx_tomo.end_time = max(end_times)
sample = NXsample.concatenate(tuple([nx_obj.sample for nx_obj in nx_objects]))
nx_tomo.sample = NXsample.concatenate(
tuple([nx_obj.sample for nx_obj in nx_objects])
)
......
......@@ -32,7 +32,8 @@ import os
from tempfile import TemporaryDirectory
from nxtomomill.nexus.nxdetector import FieldOfView
import pytest
from nxtomomill.nexus.nxtomo import NXtomo
from nxtomomill.nexus import NXtomo
from nxtomomill.nexus import concatenate
from datetime import datetime
from tomoscan.esrf import HDF5TomoScan
from tomoscan.validator import ReconstructionValidator
......@@ -287,7 +288,7 @@ def test_nx_tomo(nexus_path_version):
)
# test concatenation
nx_tomo_concat = NXtomo.concatenate([loaded_nx_tomo, None, loaded_nx_tomo])
nx_tomo_concat = concatenate([loaded_nx_tomo, None, loaded_nx_tomo])
concat_file = os.path.join(folder, "concatenated_nexus_file.hdf5")
nx_tomo_concat.save(
......@@ -318,3 +319,6 @@ def test_nx_tomo(nexus_path_version):
]
),
)
with pytest.raises(TypeError):
concatenate([1, 2])
......@@ -35,6 +35,8 @@ import numpy
import h5py
from silx.io.utils import h5py_read_dataset
from nxtomomill.nexus.nxobject import NXobject
def cast_and_check_array_1D(array, array_name):
if not isinstance(array, (type(None), numpy.ndarray, Iterable)):
......@@ -132,3 +134,12 @@ def get_data(file_path, data_path):
return h5py_read_dataset(h5f[data_path])
else:
return None
def concatenate(nx_objects, **kwargs):
if len(nx_objects) == 0:
return None
else:
if not isinstance(nx_objects[0], NXobject):
raise TypeError("nx_objects are expected to be instances of NXobject")
return type(nx_objects[0]).concatenate(nx_objects=nx_objects, **kwargs)
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