def pinpointMinima(self): """ Pinpoint the exact positions of local minima within the scope of each smoothed local minimum. 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 minium m in the interval ( center(m_n-1, m_n), center(m_n, m_n+1) ) for each n in (0, smoothed local minimum, -1) """ from itertools import compress localminima = MessageAnalyzer.localMinima( self.values) # List[idx], List[min] allovermin = min(localminima[1]) minSmsk = [ True if e < self._sensitivity * allovermin else False for e in localminima[1] ] lminAO = [0] + list(compress(localminima[0], minSmsk)) + [len(self._message.data)] lminMed = (numpy.round(numpy.ediff1d(lminAO) / 2) + lminAO[:-1]).astype(int) bclmins = [ medl + numpy.argmin(self.bitcongruences[medl:medr]) for medl, medr in zip(lminMed[:-1], lminMed[1:]) ] return bclmins
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
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()
def pinpointMinima(self): """ Pinpoint the exact positions of local minima within the scope of each smoothed local minimum. The exact position is looked for in self.bitcongruences. :return: One exact local minium m in the interval ( center(m_n-1, m_n), center(m_n, m_n+1) ) for each n in (0, smoothed local minimum, -1) """ localminima = MessageAnalyzer.localMinima( self.values) # List[idx], List[min] # localmaxima = MessageAnalyzer.localMaxima(self.values) # List[idx], List[max] # for lminix in range(len(localminima)): # localminima[lminix] lminAO = [0] + localminima[0] + [len(self._message.data)] lminMed = (numpy.round(numpy.ediff1d(lminAO) / 2) + lminAO[:-1]).astype(int) bclmins = [ medl + numpy.argmin(self.bitcongruences[medl:medr]) for medl, medr in zip(lminMed[:-1], lminMed[1:]) ] return bclmins