Esempio n. 1
0
    def pinpointMaxima(self):
        """
        Pinpoint the exact positions of local maxima within the scope of each smoothed local maximum.
        The exact position is looked for in self.bitcongruences.
        Only those extrema of the smoothed graph are taken into account which are above the sensitivity threshold.

        :return: One exact local maximum m in the interval ( center(m_n-1, m_n), center(m_n, m_n+1) )
            for each n in (0, smoothed local maximum, -1)
        """
        from itertools import compress

        localmaxima = MessageAnalyzer.localMaxima(
            self.values)  # List[idx], List[max]
        allovermax = max(localmaxima[1])
        maxSmsk = [
            True if e > self._sensitivity * allovermax else False
            for e in localmaxima[1]
        ]
        lmaxAO = [0] + list(compress(localmaxima[0],
                                     maxSmsk)) + [len(self._message.data)]
        lmaxMed = (numpy.round(numpy.ediff1d(lmaxAO) / 2) +
                   lmaxAO[:-1]).astype(int)
        bclmaxs = [
            medl + numpy.argmax(self.bitcongruences[medl:medr])
            for medl, medr in zip(lmaxMed[:-1], lmaxMed[1:])
        ]
        return bclmaxs
Esempio n. 2
0
 def extrema(self) -> List[Tuple[int, bool]]:
     """
     :return: all extrema of the smoothed bcd, each described by a tuple of its index and bool (min is False)
     """
     bcdNR = self.values
     lmin = MessageAnalyzer.localMinima(bcdNR)
     lmax = MessageAnalyzer.localMaxima(bcdNR)
     nrExtrema = sorted([(i, False) for i in lmin[0]] + [(i, True)
                                                         for i in lmax[0]],
                        key=lambda k: k[0])
     return nrExtrema
Esempio n. 3
0
    def plotSubfigs(self, analysisResults: List[List[float]], subfigName: List[str]=None,
                    compareValue: List[List[float]]=None, fieldEnds: List[List[int]]=None,
                    markextrema: bool=False,
                    resultsLabel: str=None, compareLabel: str=None, fieldEndMarks: bool=True):
        """
        Plot different aspects about analysis results.

        :param analysisResults: The results of a message analyzer for each message.
        :param subfigName: Titles for each subplot.
        :param compareValue: Values to plot for comparison for each message.
        :param fieldEnds: True field ends to plot for reference to each message.
        :param markextrema: If set, plot the local extrema of the analysis results.
        :param resultsLabel: Label for the results.
        :param compareLabel: Label for the compare values.
        :param fieldEndMarks: Mark the field ends with dots on the graph
        """

        # xshift=1  # shift to the right by one, since we want to see the value for x at position x+1
        self.plotInEachAx(analysisResults,
                          linestyle=MessagePlotter.STYLE_ALTMAINLINE \
                              if not resultsLabel else dict(MessagePlotter.STYLE_ALTMAINLINE,
                                                            label=resultsLabel)
                          )
        if markextrema:
            self.scatterInEachAx([MessageAnalyzer.localMinima(values) for values in analysisResults])
            self.scatterInEachAx([MessageAnalyzer.localMaxima(values) for values in analysisResults])

        if compareValue:
            self.plotInEachAx(compareValue,
                              linestyle=MessagePlotter.STYLE_COMPARELINE \
                                  if not compareLabel else dict(MessagePlotter.STYLE_COMPARELINE,
                                                                label=compareLabel)
                              )

        if fieldEnds:
            self.fieldmarkersInEachAx(fieldEnds)
            if fieldEndMarks:
                try:
                    self.scatterInEachAx(
                        [ (fe[:-1], [ar[endbyte] for endbyte in fe[:-1] ])
                          for fe, ar in zip(fieldEnds, analysisResults) ],
                        marker='.'
                    )
                except IndexError:
                    print('Error: Dissector field index and message are contradicting. Field ends could not be marked.\n'
                          'Check dissector and message.')

        if subfigName:
            self.nameEachAx(subfigName)

        if resultsLabel or compareLabel:
            plt.legend()