display sequence will now allow the loading of sequences with missing frames

Sequences with missing frames are not uncommon in the raw images that were collected at soleil. I beleive that these missing frames are caused by the sequence captures that are stopped, resting in missing frames at the end compared to what was planned....

fixes #10
This commit is contained in:
Guillaume Raffy 2022-01-26 22:25:42 +01:00
parent 2acff0f175
commit 4932427663
3 changed files with 41 additions and 11 deletions

View File

@ -7,7 +7,7 @@ TEMP_PATH:=$(shell echo ~/work/lipase/tmp)
TESTS_OUTPUT_DATA_PATH:=$(TEMP_PATH) TESTS_OUTPUT_DATA_PATH:=$(TEMP_PATH)
LIB_SRC_FILES=$(shell find ./src/lipase -name "*.py") LIB_SRC_FILES=$(shell find ./src/lipase -name "*.py")
PLUGINS_SRC_FILES=$(shell find ./src/ij-plugins -name "*.py") PLUGINS_SRC_FILES=$(shell find ./src/ij-plugins -name "*.py")
LIPASE_VERSION=1.10 LIPASE_VERSION=1.11
BUILD_ROOT_PATH:=$(TEMP_PATH)/build BUILD_ROOT_PATH:=$(TEMP_PATH)/build
PACKAGE_FILE_PATH=$(BUILD_ROOT_PATH)/lipase-$(LIPASE_VERSION).zip PACKAGE_FILE_PATH=$(BUILD_ROOT_PATH)/lipase-$(LIPASE_VERSION).zip

View File

@ -28,6 +28,19 @@ class DacMetadata(object):
return channels[channel_index]["Name"] return channels[channel_index]["Name"]
class MissingImageFile(Exception):
def __init__(self, sequence_id, frame_index, slice_index, channel_index):
self.sequence_id = sequence_id
self.frame_index= frame_index
self.slice_index = slice_index
self.channel_index = channel_index
super(MissingImageFile, self).__init__(self, 'missing image file')
def __str__(self):
return 'the image file for sequence "%s" frame %d, slice %d and channel %d is missing' % (self.sequence_id, self.frame_index, self.slice_index, self.channel_index)
class Sequence(object): class Sequence(object):
"""A sequence of images stored in micro manager format """A sequence of images stored in micro manager format
""" """
@ -121,7 +134,10 @@ class Sequence(object):
''' '''
assert frame_index < self.num_frames assert frame_index < self.num_frames
assert channel_index < self.num_channels assert channel_index < self.num_channels
frame_info = self.mmm['FrameKey-%d-%d-%d' % (frame_index, channel_index, slice_index)] try:
frame_info = self.mmm['FrameKey-%d-%d-%d' % (frame_index, channel_index, slice_index)]
except KeyError as e:
raise MissingImageFile(sequence_id=self.id, frame_index=frame_index, slice_index=slice_index, channel_index=channel_index)
rel_file_path = frame_info['FileName'] rel_file_path = frame_info['FileName']
return os.path.join(self.get_root_path(), rel_file_path) return os.path.join(self.get_root_path(), rel_file_path)
@ -192,8 +208,13 @@ class Sequence(object):
for frame_index in selected_frames: for frame_index in selected_frames:
for slice_index in selected_slices: for slice_index in selected_slices:
for channel_index in selected_channel_indices: for channel_index in selected_channel_indices:
image = IImageEngine.get_instance().load_image(self.get_image_file_path(channel_index=channel_index, frame_index=frame_index, slice_index=slice_index)) try:
stack.set_image(image=image, channel_index=channel_index, frame_index=frame_index, slice_index=slice_index) image_file_path = self.get_image_file_path(channel_index=channel_index, frame_index=frame_index, slice_index=slice_index)
image = IImageEngine.get_instance().load_image(image_file_path)
stack.set_image(image=image, channel_index=channel_index, frame_index=frame_index, slice_index=slice_index)
except MissingImageFile as e:
logger.warn('%s. As a result, the hyperstack will be black at this frame' % str(e))
# logger.warn('the image file for sequence "%s" frame %d, slice %d and channel %d is missing. As a result, the hyperstack will be black at this frame' % (self.id, frame_index, slice_index, channel_index))
return stack return stack
def find_dirs_containing_file(file_name, root_dir): def find_dirs_containing_file(file_name, root_dir):

View File

@ -1,15 +1,20 @@
import os
from ij import IJ, ImagePlus # pylint: disable=import-error from ij import IJ, ImagePlus # pylint: disable=import-error
import re import re
from .. import logger
from ..catalog import MissingImageFile
def open_sequence_as_hyperstack(sequence): def open_sequence_as_hyperstack(sequence):
hyperstack = IJ.createHyperStack(sequence.id, sequence.width, sequence.height, sequence.num_channels, sequence.num_slices, sequence.num_frames, sequence.num_bits_per_pixels) hyperstack = IJ.createHyperStack(sequence.id, sequence.width, sequence.height, sequence.num_channels, sequence.num_slices, sequence.num_frames, sequence.num_bits_per_pixels)
for channel_index in range(sequence.num_channels): for channel_index in range(sequence.num_channels):
for frame_index in range(sequence.num_frames): for frame_index in range(sequence.num_frames):
slice_index = 0 slice_index = 0
src_image_file_path = sequence.get_image_file_path(channel_index=channel_index, frame_index=frame_index) try:
# print(src_image_file_path) src_image_file_path = sequence.get_image_file_path(channel_index=channel_index, frame_index=frame_index)
src_image = IJ.openImage(src_image_file_path) src_image = IJ.openImage(src_image_file_path)
except MissingImageFile as e:
logger.warn('%s. As a result, the hyperstack will be black at this frame' % str(e))
#logger.warn('the image file for frame %d and channel %d is missing. As a result, the hyperstack will be black at this frame' % (frame_index, channel_index))
# print(src_image.getProperties()) # print(src_image.getProperties())
hyperstack.setPositionWithoutUpdate(channel_index + 1, slice_index + 1, frame_index + 1) hyperstack.setPositionWithoutUpdate(channel_index + 1, slice_index + 1, frame_index + 1)
hyperstack.setProcessor(src_image.getProcessor()) hyperstack.setProcessor(src_image.getProcessor())
@ -23,9 +28,13 @@ def open_sequence_as_stack(sequence, channel_id):
hyperstack = IJ.createHyperStack(sequence.id, sequence.width, sequence.height, 1, sequence.num_slices, sequence.num_frames, sequence.num_bits_per_pixels) hyperstack = IJ.createHyperStack(sequence.id, sequence.width, sequence.height, 1, sequence.num_slices, sequence.num_frames, sequence.num_bits_per_pixels)
for frame_index in range(sequence.num_frames): for frame_index in range(sequence.num_frames):
slice_index = 0 slice_index = 0
src_image_file_path = sequence.get_image_file_path(channel_index=channel_index, frame_index=frame_index) try:
# print(src_image_file_path) src_image_file_path = sequence.get_image_file_path(channel_index=channel_index, frame_index=frame_index)
src_image = IJ.openImage(src_image_file_path) # print(src_image_file_path)
src_image = IJ.openImage(src_image_file_path)
except MissingImageFile as e:
logger.warn('%s. As a result, the hyperstack will be black at this frame' % str(e))
# logger.warn('the image file for frame %d and channel %d is missing. As a result, the hyperstack will be black at this frame' % (frame_index, channel_index))
# print(src_image.getProperties()) # print(src_image.getProperties())
hyperstack.setPositionWithoutUpdate(channel_index + 1, slice_index + 1, frame_index + 1) hyperstack.setPositionWithoutUpdate(channel_index + 1, slice_index + 1, frame_index + 1)
hyperstack.setProcessor(src_image.getProcessor()) hyperstack.setProcessor(src_image.getProcessor())