From 0f23e23ee5330b28d37e54587fb48c9c7aee3ecc Mon Sep 17 00:00:00 2001 From: Stuart Mumford Date: Fri, 23 Feb 2024 16:41:51 +0000 Subject: [PATCH] Make changes for datasets with only one file This is towards fixing VBI single shot mosaics --- dkist/io/dask_utils.py | 7 +++++-- dkist/io/file_manager.py | 5 ++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/dkist/io/dask_utils.py b/dkist/io/dask_utils.py index feb8a3fb..c66d4d13 100644 --- a/dkist/io/dask_utils.py +++ b/dkist/io/dask_utils.py @@ -23,6 +23,8 @@ def stack_loader_array(loader_array, chunksize): # If the chunksize sin't specified then use the whole array shape chunksize = chunksize or loader_array.flat[0].shape + if loader_array.size == 1: + return tuple(loader_to_dask(loader_array, chunksize))[0] if len(loader_array.shape) == 1: return da.stack(loader_to_dask(loader_array, chunksize)) stacks = [] @@ -38,10 +40,11 @@ def loader_to_dask(loader_array, chunksize): This is done so that an explicit ``meta=`` argument can be provided to prevent loading data from disk. """ - - if len(loader_array.shape) != 1: + if loader_array.size != 1 and len(loader_array.shape) != 1: raise ValueError("Can only be used on one dimensional arrays") + loader_array = np.atleast_1d(loader_array) + # The meta argument to from array is used to determine properties of the # array, such as dtype. We explicitly specify it here to prevent dask # trying to auto calculate it by reading from the actual array on disk. diff --git a/dkist/io/file_manager.py b/dkist/io/file_manager.py index dbe7a23d..fe05c581 100644 --- a/dkist/io/file_manager.py +++ b/dkist/io/file_manager.py @@ -56,7 +56,7 @@ def _output_shape_from_ref_array(shape, loader_array) -> Tuple[int]: if shape[0] == 1: shape = shape[1:] - if len(loader_array) == 1: + if loader_array.size == 1: return shape else: return tuple(list(loader_array.shape) + list(shape)) @@ -99,8 +99,7 @@ def __init__( self._basepath = None self.basepath = basepath # Use the setter to convert to a Path self.chunksize = chunksize - - self._fileuri_array = np.array(fileuris) + self._fileuri_array = np.atleast_1d(np.array(fileuris)) loader_array = np.empty_like(self._fileuri_array, dtype=object) for i, fileuri in enumerate(self._fileuri_array.flat):