Beispiel #1
0
    def _getChannelColor(self, seriesIndx, channelIndx):
        """Returns the channel color (from the parsed metadata) for
        a given channel in a given series."
        """

        if self._DEBUG:
            self._logger.info("Trying to find seriesIndx = " + \
                               str(seriesIndx) + " in seriesIndices = " + \
                               str(self._seriesIndices))

        # Get the position in the seriesIndices list
        indx = self._seriesIndices.index(int(seriesIndx))

        # Get the metadata for the requested series
        metadata = self._allSeriesMetadata[indx]

        if self._DEBUG:
            self._logger.info("Trying to find channel color for channel " + \
                               str(channelIndx))

        # Get the metadata
        key = "channelColor" + str(channelIndx)
        color = metadata[key]

        if color is not None:
            color = color.split(",")
            R = int(float(color[0]))
            G = int(float(color[1]))
            B = int(float(color[2]))
        else:
            if channelIndx == 0:
                R = 255
                G = 0
                B = 0
            elif channelIndx == 1:
                R = 0
                G = 255
                B = 0
            elif channelIndx == 2:
                R = 0
                G = 0
                B = 255
            else:
                R = random.randint(0, 255)
                G = random.randint(0, 255)
                B = random.randint(0, 255)

        # Work around an issue if all color components are 0
        if R == G == B == 0:
            R = 255
            G = 255
            B = 255
            self._logger.info(
                "Color changed from (0, 0, 0) to (255, 255, 255)")

        # Create the ChannelColorRGB object
        colorRGB = ChannelColorRGB(R, G, B)

        # Return it
        return colorRGB
Beispiel #2
0
    def _getChannelColor(self, seriesIndx, channelIndx):
        """Returns the channel color (from the parsed metadata) for
        a given channel in a given series."
        """

        # Get the metadata for the requested series
        metadata = self._allSeriesMetadata[seriesIndx]

        # Try extracting the color for the given series and channel
        try:
            color = metadata["channelColor" + str(channelIndx)]

        except KeyError:
            err = "MICROSCOPYSINGLEDATASETCONFIG::_getChannelColor(): " + \
            "Could not extract channel color for channel " + \
             str(channelIndex) + " and series " + str(seriesIndx) + \
            " from metadata."
            self._logger.error(err)
            raise (err)

        # Try extracting the color for current channel
        colorComponents = color.split(",")
        assert (len(colorComponents) == 4)
        try:
            R = int(float(colorComponents[0]))
            G = int(float(colorComponents[1]))
            B = int(float(colorComponents[2]))
        except:
            err = "MICROSCOPYSINGLEDATASETCONFIG::_getChannelColor(): " + \
            "Could not extract color with index " + str(channelIndx)
            self._logger.error(err)
            raise (err)

        if self._DEBUG:
            self._logger.info("Color extracted from metadata: (R = " + str(R) +
                              ", G = " + str(G) + ", B = " + str(B) + ")")

        # Work around an issue if all color components are 0
        if R == G == B == 0:
            R = 255
            G = 255
            B = 255
            self._logger.info(
                "Color changed from (0, 0, 0) to (255, 255, 255)")

        # Create the ChannelColorRGB object
        colorRGB = ChannelColorRGB(R, G, B)

        return colorRGB
    def _getChannelColor(self, seriesIndx, channelIndx):
        """Returns the channel color (from the parsed metadata) for
        a given channel in a given series."
        """

        # Get the metadata for the requested series
        metadata = self._allSeriesMetadata[seriesIndx]

        # Try extracting the color for the given series and channel
        try:
            color = metadata["channelColor" + str(channelIndx)]

        except KeyError:
            err = "MICROSCOPYSINGLEDATASETCONFIG::createChannel(): " + \
            "Could not extract channel color for channel " + \
             str(channelIndex) + " and series " + str(seriesIndx) + \
            " from metadata."
            self._logger.error(err)
            raise (err)

        # Try extracting the color for current channel
        colorComponents = color.split(",")
        assert (len(colorComponents) == 4)
        try:
            R = int(float(colorComponents[0]))
            G = int(float(colorComponents[1]))
            B = int(float(colorComponents[2]))
        except:
            err = "MICROSCOPYSINGLEDATASETCONFIG::createChannel(): " + \
            "Could not extract color with index " + str(channelIndx)
            self._logger.error(err)
            raise (err)

        # Create the ChannelColorRGB object
        colorRGB = ChannelColorRGB(R, G, B)

        return colorRGB
    def _getChannelColor(self, seriesIndx, channelIndx):
        """Returns the channel color (from the parsed metadata) for
        a given channel in a given series."
        """

        # Get the position in the seriesIndices list
        indx = self._seriesIndices.index(int(seriesIndx))

        # Get the metadata for the requested series
        metadata = self._allSeriesMetadata[indx]

        # Get the metadata
        try:
            key = "channelColor" + str(channelIndx)
            color = metadata[key]
        except:
            color = None

        if color is not None:
            color = color.split(",")
            R = int(255 * float(color[0]))
            G = int(255 * float(color[1]))
            B = int(255 * float(color[2]))
        else:

            # If there is only one channel in the whole dataset,
            # we make it gray value
            if len(self._channelNames) == 1:
                # Fall back to gray
                R = 255
                G = 255
                B = 255
            else:
                # Fall back to default colors
                if channelIndx == 0:
                    R = 255
                    G = 0
                    B = 0
                elif channelIndx == 1:
                    R = 0
                    G = 255
                    B = 0
                elif channelIndx == 2:
                    R = 0
                    G = 0
                    B = 255
                elif channelIndx == 3:
                    R = 255
                    G = 255
                    B = 0
                elif channelIndx == 4:
                    R = 255
                    G = 0
                    B = 255
                elif channelIndx == 5:
                    R = 0
                    G = 255
                    B = 255
                elif channelIndx == 7:
                    R = 255
                    G = 255
                    B = 255
                else:
                    R = random.randint(0, 255)
                    G = random.randint(0, 255)
                    B = random.randint(0, 255)

        # Work around an issue if all color components are 0
        if R == G == B == 0:
            R = 255
            G = 255
            B = 255
            self._logger.info(
                "Color changed from (0, 0, 0) to (255, 255, 255)")

        # Create the ChannelColorRGB object
        colorRGB = ChannelColorRGB(R, G, B)

        # Return it
        return colorRGB