Skip to content

Commit

Permalink
Merge pull request #161 from henrypinkard/main
Browse files Browse the repository at this point in the history
fix 8 bit bug
  • Loading branch information
henrypinkard authored Jun 18, 2024
2 parents f3f6589 + b11bb88 commit 2e8851a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion python/ndstorage/_version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version_info = (0, 1, 5)
version_info = (0, 1, 6)
__version__ = ".".join(map(str, version_info))
2 changes: 2 additions & 0 deletions python/ndstorage/ndtiff_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ def _bytes_per_image_pixels(self, pixels, rgb):
return len(pixels)
elif isinstance(pixels, np.ndarray) and pixels.dtype == np.uint16:
return pixels.size * 2
elif isinstance(pixels, np.ndarray) and pixels.dtype == np.uint8:
return pixels.size
else:
raise RuntimeError("unknown pixel type")

Expand Down
28 changes: 28 additions & 0 deletions python/ndstorage/test/writing_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,34 @@ def test_write_full_dataset(test_data_path):
assert np.all(read_image == pixels)
assert dataset.read_metadata(**axes) == {'time_metadata': time}

def test_write_full_dataset_8_bit(test_data_path):
"""
Write an NDTiff dataset and read it back in, testing pixels and metadata
"""
full_path = os.path.join(test_data_path, 'test_write_full_dataset')
dataset = NDTiffDataset(full_path, summary_metadata={}, writable=True)

image_height = 256
image_width = 256
images = []
for time in range(10):
pixels = np.ones(image_height * image_width, dtype=np.uint16).reshape((image_height, image_width)) * time
images.append(pixels)
for time in range(10):
axes = {'time': time}
dataset.put_image(axes, images[time], {'time_metadata': time})

dataset.finish()

# read the file back in
dataset = NDTiffDataset(full_path)
for time in range(10):
pixels = np.ones(image_height * image_width, dtype=np.uint8).reshape((image_height, image_width)) * time
axes = {'time': time}
read_image = dataset.read_image(**axes)
assert np.all(read_image == pixels)
assert dataset.read_metadata(**axes) == {'time_metadata': time}

def test_write_full_dataset_RAM():
dataset = NDRAMDataset()

Expand Down

0 comments on commit 2e8851a

Please sign in to comment.