def add_channelfn(self, can_remove=True): '''Add another image channel can_remove - true if we are allowed to remove this channel ''' group = cps.SettingsGroup() self.channels.append(group) #Check which cellprofiler image we are in the group #(each channel translates to a single cellprofiler image) cpimg_index = 0 for channel in self.channels: if id(channel) == id(group): break cpimg_index += 1 group.append("divider", cps.Divider(line=True)) group.append("cpimage_name", cps.ImageNameProvider( 'Image name', default_cpimage_name(cpimg_index))) channel_numbers = [ str(x) for x in range(0, max(10, len(self.channels)+2)) ] group.append("channel_number", cps.Choice( "Channel number:", channel_numbers, channel_numbers[len(self.channels)-1], doc = """(Used only for multichannel images) The channels of a multichannel image are numbered starting from 0 (zero). Each channel is a greyscale image, acquired using different illumination sources and/or optics. Use this setting to pick the channel to associate with the image or images you load from OMERO.""")) group.can_remove = can_remove if can_remove: group.append("remover", cps.RemoveSettingButton( "Remove this channel", "Remove channel", self.channels, group))
def add_channelfn(self, can_remove=True): '''Add another image channel can_remove - true if we are allowed to remove this channel ''' group = cps.SettingsGroup() self.channels.append(group) # Check which cellprofiler image we are in the group # (each channel translates to a single cellprofiler image) cpimg_index = 0 for channel in self.channels: if id(channel) == id(group): break cpimg_index += 1 group.append("divider", cps.Divider(line=True)) group.append("cpimage_name", cps.ImageNameProvider( 'Image name', default_cpimage_name(cpimg_index))) channel_numbers = [ str(x) for x in range(0, max(10, len(self.channels) + 2))] group.append("channel_number", cps.Choice( "Channel number:", channel_numbers, channel_numbers[len(self.channels) - 1], doc="""(Used only for multichannel images) The channels of a multichannel image are numbered starting from 0 (zero). Each channel is a greyscale image, acquired using different illumination sources and/or optics. Use this setting to pick the channel to associate with the image or images you load from OMERO.""")) group.can_remove = can_remove if can_remove: group.append("remover", cps.RemoveSettingButton( "Remove this channel", "Remove channel", self.channels, group))
def load_channels(self): '''Add and set channels based on an image from omero ''' try: self.create_omero_gateway() id = int(self.omero_object_id.value) if self.omero_object == MS_IMAGE: omero_image = self.omero_gateway.getImage(id) elif self.omero_object == MS_DATASET: images_from_dataset = self.get_images_from_dataset(id, 1) if len(images_from_dataset) == 0: omero_image = None else: omero_image = images_from_dataset[0] elif self.omero_object == MS_PLATE: wells_from_plate = self.get_wells_from_plate(id, 1) if len(wells_from_plate) == 0: omero_image = None else: omero_well = wells_from_plate[0] omero_image = omero_well.getWellSample(0).getImage() if omero_image is None: # Don't say plate or dataset not found as they might still exist but do not have # images attached to them. Another reason for not being able to find images is # because the omero account used does not have permissions to retrieve the image # or images. raise RuntimeError("No image found for %s with id %d" % (self.omero_object, id)) omero_image_id = omero_image.getId().getValue() pixels = self.omero_gateway.getPixelsFromImage(omero_image_id)[0] #The pixels doesn't have all the (logical) channels #because of lazy loading. So the pixels is requested #again, but in a way to get the channels as well. pixels = self.omero_gateway.getPixels(pixels.getId().getValue()) #repopulate channels based on the retrieved pixels. #note: cannot say self.channels=[] because the channel_count #is associated with the object self.channels refers to. for channel in self.channels[:]: self.channels.remove(channel) omero_channels = [channel for channel in pixels.iterateChannels()] number_of_channels = pixels.getSizeC().getValue() for channel_number in range(0, number_of_channels): omero_channel = omero_channels[ channel_number].getLogicalChannel() #load default cpimage name in case the logical channel name # cannot be retrieved. e.g. when the logical channel name is null try: omero_channel_name = omero_channel.getName().getValue( ).strip() except: omero_channel_name = default_cpimage_name(channel_number) self.add_channelfn(channel_number != 0) self.channels[-1].cpimage_name.set_value(omero_channel_name) self.channels[-1].channel_number.set_value(str(channel_number)) #Close the session just in case the user decides not to run #the pipeline. self.omero_client.closeSession() self.omero_client = None wx.MessageBox( "Retrieved %d channel(s) from OMERO" % number_of_channels, "", wx.ICON_INFORMATION) except: wx.MessageBox(traceback.format_exc(limit=0), "Exception", wx.ICON_ERROR)
def load_channels(self): '''Add and set channels based on an image from omero ''' try: self.create_omero_gateway() id = int(self.omero_object_id.value) if self.omero_object == MS_IMAGE: omero_image = self.omero_gateway.getImage(id) elif self.omero_object == MS_DATASET: images_from_dataset = self.get_images_from_dataset(id, 1) if len(images_from_dataset) == 0: omero_image = None else: omero_image = images_from_dataset[0] elif self.omero_object == MS_PLATE: wells_from_plate = self.get_wells_from_plate(id, 1) if len(wells_from_plate) == 0: omero_image = None else: omero_well = wells_from_plate[0] omero_image = omero_well.getWellSample(0).getImage() if omero_image is None: # Don't say plate or dataset not found as they might still exist but do not have # images attached to them. Another reason for not being able to find images is # because the omero account used does not have permissions to retrieve the image # or images. raise RuntimeError("No image found for %s with id %d"%(self.omero_object,id)) omero_image_id = omero_image.getId().getValue() pixels = self.omero_gateway.getPixelsFromImage(omero_image_id)[0] #The pixels doesn't have all the (logical) channels #because of lazy loading. So the pixels is requested #again, but in a way to get the channels as well. pixels = self.omero_gateway.getPixels(pixels.getId().getValue()) #repopulate channels based on the retrieved pixels. #note: cannot say self.channels=[] because the channel_count #is associated with the object self.channels refers to. for channel in self.channels[:]: self.channels.remove(channel) omero_channels = [channel for channel in pixels.iterateChannels()] number_of_channels = pixels.getSizeC().getValue() for channel_number in range(0, number_of_channels): omero_channel = omero_channels[channel_number].getLogicalChannel() #load default cpimage name in case the logical channel name # cannot be retrieved. e.g. when the logical channel name is null try: omero_channel_name = omero_channel.getName().getValue().strip() except: omero_channel_name = default_cpimage_name(channel_number) self.add_channelfn(channel_number != 0) self.channels[-1].cpimage_name.set_value(omero_channel_name) self.channels[-1].channel_number.set_value(str(channel_number)) #Close the session just in case the user decides not to run #the pipeline. self.omero_client.closeSession() self.omero_client = None wx.MessageBox("Retrieved %d channel(s) from OMERO"%number_of_channels, "", wx.ICON_INFORMATION) except: wx.MessageBox(traceback.format_exc(limit=0), "Exception", wx.ICON_ERROR);