diff --git a/python/ndtiff/_version.py b/python/ndtiff/_version.py index 8c788f9..dc4ad5d 100644 --- a/python/ndtiff/_version.py +++ b/python/ndtiff/_version.py @@ -1,2 +1,2 @@ -version_info = (2, 2, 0) +version_info = (2, 2, 1) __version__ = ".".join(map(str, version_info)) diff --git a/python/ndtiff/nd_tiff_current.py b/python/ndtiff/nd_tiff_current.py index 0df2cfc..a4875fc 100644 --- a/python/ndtiff/nd_tiff_current.py +++ b/python/ndtiff/nd_tiff_current.py @@ -626,7 +626,7 @@ def close(self): def _read_one_image(self, block_id, axes_to_stack=None, axes_to_slice=None, stitched=False, rgb=False): # a function that reads in one chunk of data - axes = {key: block_id[i] for i, key in enumerate(axes_to_stack.keys())} + axes = {key: axes_to_stack[key][block_id[i]] for i, key in enumerate(axes_to_stack.keys())} if stitched: # Combine all rows and cols into one stitched image # get spatial layout of position indices diff --git a/python/ndtiff/test/data_loading_test.py b/python/ndtiff/test/data_loading_test.py index f44a96d..a1839a8 100644 --- a/python/ndtiff/test/data_loading_test.py +++ b/python/ndtiff/test/data_loading_test.py @@ -108,5 +108,77 @@ def test_v3_2_no_magellan_explore_no_channels(test_data_path): dataset = Dataset(data_path) assert(np.sum(np.array(dataset.as_array(stitched=True)[0])) > 0) +def test_labeled_positions(test_data_path): + """ + This dataset was acquired with the following events: + events = [ + {'axes': {'position': 'Pos2'}, 'x': 0, 'y': 0}, + {'axes': {'position': 'Pos0'}, 'x': 0, 'y': 1}, + {'axes': {'position': 'Pos1'}, 'x': 0, 'y': 2} + ] + Further, images at position ('Pos2', 'Pos0', 'Pos1') have (0, 0) pixels + equal to (0, 1, 2). + + Here we test that the axis and image order of the dataset is as expected. + """ + + data_path = os.path.join(test_data_path, 'v3', 'labeled_positions_1') + position_names = ('Pos2', 'Pos0', 'Pos1') + + dataset = Dataset(data_path) + data = np.asarray(dataset.as_array()) + + # ndtiff sorts the dataset axes. Check that the position axis is correctly + # sorted + assert dataset.axes['position'] == set(('Pos0', 'Pos1', 'Pos2')) + + # Check that the image metadata includes the position name + for position_name in position_names: + metadata = dataset.read_metadata(position=position_name) + assert metadata['PositionName'] == position_name + + # Check that data is in the ('Pos0', 'Pos1', 'Pos2') order + pixel_00 = (1, 2, 0) + for idx, image in enumerate(data): + assert image[0, 0] == pixel_00[idx] + +def test_unordered_z_axis(test_data_path): + """ + This dataset was acquired with the following events: + + events1 = [{'axes': {'z': z_idx}, 'z': z_idx} for z_idx in range(10)] + events2 = [{'axes': {'z': z_idx}, 'z': z_idx} for z_idx in range(-10, 0)] + + and the following image process hook function: + + def fun(image, metadata): + if not hasattr(fun, "idx"): + fun.idx = 0 + + image[0, 0] = np.uint16(fun.idx) + + fun.idx += 1 + + return image, metadata + + Here we test that the axis and image order of the dataset is as expected. + """ + + data_path = os.path.join(test_data_path, 'v3', 'unordered_z_1') + acquisition_z_axis = list(range(10)) + list(range(-10, 0)) + sorting_index = np.argsort(acquisition_z_axis) + sorted_z_axis = np.sort(acquisition_z_axis) + + dataset = Dataset(data_path) + data = np.asarray(dataset.as_array()) + + # ndtiff sorts the dataset axes. Check that the position axis is correctly + # sorted + assert dataset.axes['z'] == set(sorted_z_axis) + + # Check that data is in the sorted(acquisition_z_axis) order + pixel_00 = sorting_index + for idx, image in enumerate(data): + assert image[0, 0] == pixel_00[idx] diff --git a/test_data/v3/labeled_positions_1/NDTiff.index b/test_data/v3/labeled_positions_1/NDTiff.index new file mode 100644 index 0000000..c465fb8 Binary files /dev/null and b/test_data/v3/labeled_positions_1/NDTiff.index differ diff --git a/test_data/v3/labeled_positions_1/labeled_positions_NDTiffStack.tif b/test_data/v3/labeled_positions_1/labeled_positions_NDTiffStack.tif new file mode 100644 index 0000000..33c198e Binary files /dev/null and b/test_data/v3/labeled_positions_1/labeled_positions_NDTiffStack.tif differ diff --git a/test_data/v3/unordered_z_1/NDTiff.index b/test_data/v3/unordered_z_1/NDTiff.index new file mode 100644 index 0000000..1314efd Binary files /dev/null and b/test_data/v3/unordered_z_1/NDTiff.index differ diff --git a/test_data/v3/unordered_z_1/unordered_z_NDTiffStack.tif b/test_data/v3/unordered_z_1/unordered_z_NDTiffStack.tif new file mode 100644 index 0000000..6548035 Binary files /dev/null and b/test_data/v3/unordered_z_1/unordered_z_NDTiffStack.tif differ