Example #1
0
    def _postAnalyze(self):
        """_postAnalyze doc..."""

        ratios = []

        for name, curve in DictUtils.iter(self.data):
            segments = curve.segments

            for i in ListUtils.rangeOn(segments):
                segment = segments[i]
                segmentLine = segment.line

                # If this is an extrapolated segment, use the length from the neighboring segment
                # instead of the artificial length of this segment.
                if segment == segments[0]:
                    segmentLine = segments[i + 1].line
                elif segment == segments[-1]:
                    segmentLine = segments[i - 1].line

                for pairData in segment.pairs:
                    projectionLine = pairData["line"]
                    ratios.append(100.0 * projectionLine.length.raw / segmentLine.length.raw)

        h = Histogram(
            data=ratios,
            binCount=50,
            xLabel="Projection/Stride Ratio (%)",
            title="Relative Stride to Projection Length Ratios",
        )
        h.shaveDataToXLimits()
        self._paths.append(h.save(path=self.getTempFilePath(extension="pdf")))

        self.mergePdfs(self._paths, "Curve-Projection.pdf")
Example #2
0
    def _histogramTrackwaySparseness(self, label, values):
        """ Creates a histogram for each trackway entry in the values list. """

        path        = self.getTempFilePath(extension='pdf')
        h           = Histogram(data=values, isLog=True)
        h.xLimits   = [0, 200]
        h.binCount  = 20
        h.xLabel    = 'Relative Sparseness (%)'
        h.title     = 'Trackway Sparseness (%s)' % label

        h.shaveDataToXLimits()
        h.save(path=path)
        return path
Example #3
0
    def _histogramSeriesSparseness(self, label, values):
        """_histogramSeriesSparseness doc..."""

        path        = self.getTempFilePath(extension='pdf')
        h           = Histogram(data=values, isLog=True)
        h.xLimits   = [0, 200]
        h.binCount  = 20
        h.xLabel    = 'Relative Sparseness (%)'
        h.title     = 'Track Series Sparseness (%s)' % label

        h.shaveDataToXLimits()
        h.save(path=path)
        return path
Example #4
0
    def _processCurveDeviations(self, key, label):
        """_processCurveDeviations doc..."""

        d = [data['deviations'][key]
                for k, data in DictUtils.iter(self.trackwaysData)]
        dCurved = []
        dStraight = []
        for item in d:
            if item < 1.0:
                dStraight.append(item)
            else:
                dCurved.append(min(10.0, item))

        plot = Histogram(
            data=dCurved,
            title='%s Trackway Deviations' % label,
            xLabel='Trackway Index')
        self._paths.insert(0, plot.save(self.getTempFilePath(extension='pdf')))

        d = [(index, d[index]) for index in ListUtils.rangeOn(d)]
        dCurved = []
        dStraight = []
        for item in d:
            if item[-1] < 1.0:
                dStraight.append(item)
            else:
                dCurved.append((item[0], min(10.0, item[1])) )

        self.logger.write('%s Trackways: %s/%s (%s%%)' % (
            label,
            len(dCurved),
            len(dCurved) + len(dStraight),
            100.0*len(dCurved)/(len(dCurved) + len(dStraight)) ))

        plot = MultiScatterPlot(
            {'data':dStraight, 'color':'blue'},
            {'data':dCurved, 'color':'red'},
            title='%s Trackway Deviations' % label,
            xLabel='Trackway Index',
            yLabel='Fractional Deviation')
        self._paths.insert(1, plot.save(self.getTempFilePath(extension='pdf')))
Example #5
0
    def _plotTrackwayGauges(self, points, color, unit, heading):

        histData = []
        for p in points:
            histData.append(p.yValue.value)

        plot = Histogram(
            data=histData,
            title='%s Trackway Gauges' % heading,
            xLabel='Averaged Trackway Gauge (%s)' % unit,
            yLabel='Frequency',
            color=color)
        self._paths.insert(0, plot.save(self.getTempFilePath(extension='pdf')))

        plot = ScatterPlot(
            data=ListUtils.sortObjectList(points, 'y', inPlace=True),
            title='%s Trackway Gauges' % heading,
            xLabel='Trackway Pes Count (#)',
            yLabel='Averaged Trackway Gauge (%s)' % unit,
            color=color)
        self._paths.insert(0, plot.save(self.getTempFilePath(extension='pdf')))
Example #6
0
    def _processAspectRatios(self):
        """_processAspectRatios doc..."""
        aspects    = []
        pesAspects = []
        manAspects = []

        for entry in self.entries:
            value = entry['aspect'].value
            aspects.append(value)
            if entry['track'].pes:
                pesAspects.append(value)
            else:
                manAspects.append(value)

        self.logger.write('%s\nASPECT RATIO' % ('='*80))
        self.logger.write('Total: %s' %
            NumericUtils.getMeanAndDeviation(aspects).label)
        self.logger.write('Pes: %s' %
            NumericUtils.getMeanAndDeviation(pesAspects).label)
        self.logger.write('Manus: %s' %
            NumericUtils.getMeanAndDeviation(manAspects).label)

        h = Histogram(data=aspects, color='green')
        h.title = 'Aspect Ratios'
        h.yLabel = 'Count'
        h.xLabel = 'Aspect Ratio (width/length)'
        self._paths.append(h.save(self.getTempFilePath(extension='pdf')))

        h = Histogram(data=pesAspects, color='green')
        h.title = 'Aspect Ratios (Pes)'
        h.yLabel = 'Count'
        h.xLabel = 'Aspect Ratio (width/length)'
        self._paths.append(h.save(self.getTempFilePath(extension='pdf')))

        h = Histogram(data=manAspects, color='green')
        h.title = 'Aspect Ratios (Manus)'
        h.yLabel = 'Count'
        h.xLabel = 'Aspect Ratio (width/length)'
        self._paths.append(h.save(self.getTempFilePath(extension='pdf')))
    def _postAnalyze(self):
        h = Histogram(
            data=self._uncs,
            binCount=80,
            xLimits=(0, max(*self._uncs)),
            color="r",
            title="Distribution of Rotational Uncertainties",
            xLabel="Uncertainty Value (degrees)",
            yLabel="Frequency",
        )
        p1 = h.save(self.getTempFilePath(extension="pdf"))

        h.isLog = True
        h.title += " (log)"
        p2 = h.save(self.getTempFilePath(extension="pdf"))

        self.mergePdfs([p1, p2], self.getPath("Rotational-Uncertainty-Distribution.pdf"))

        average = NumericUtils.getMeanAndDeviation(self._uncs)
        self.logger.write("Average rotational uncertainty: %s" % average.label)

        # -------------------------------------------------------------------------------------------
        # FIND LARGE UNCERTAINTY TRACKS
        largeUncertaintyCount = 0
        drawing = None
        sitemap = None

        # If track uncertainty is 2x average, add that track to the spreadsheet and map overlay
        for t in self._tracks:

            # if the tracksite has changed, save previous map and make a new one
            if sitemap != t.trackSeries.trackway.sitemap:

                # save the last site map drawing (if there was one)
                if drawing:
                    drawing.save()

                # then start a new drawing for this new site map
                sitemap = t.trackSeries.trackway.sitemap

                fileName = "%s-%s-ROTATION_UNC.svg" % (sitemap.name, sitemap.level)
                path = self.getPath(self.DRAWING_FOLDER_NAME, fileName, isFile=True)
                drawing = CadenceDrawing(path, sitemap)

                # create a group to be instanced for the spreadsheet values
                drawing.createGroup("rect1")
                # create a rectangle of 100x100 cm that is to be scaled by fractional meters
                drawing.rect((0, 0), 100, 100, scene=True, groupId="rect1")

                # create another group to be instanced for the mapped values.
                drawing.createGroup("rect2")
                # create a rectangle of 100x100 cm that is to be scaled by fractional meters
                drawing.rect((0, 0), 100, 100, scene=True, groupId="rect2")

                # and place a grid and the federal coordinates in the drawing file
                drawing.grid()
                drawing.federalCoordinates()

            # now examine the positional uncertainties for this track
            rotation = t.rotationAngle.valueDegrees
            if rotation.uncertainty <= 2.0 * average.uncertainty:

                # then just indicate that this track has low uncertainty
                self._drawLowUncertaintyMarker(drawing, t)

                # label this track green
                # drawing.text(
                #     t.name,
                #     (t.x - 20, t.z),
                #     scene=True,
                #     stroke='green',
                #     stroke_width='0.25',
                #     font_size='8px',
                #     font_family='Arial')
                continue

            # else, since the uncertainty is high, first write that track in the spreadsheet
            largeUncertaintyCount += 1
            self._largeUncCsv.createRow(uid=t.uid, fingerprint=t.fingerprint, r=rotation.label)

            # if either the measured width or length is 0, mark with a yellow disk with red outline
            if t.rotationMeasured == 0:
                drawing.circle(
                    (t.x, t.z),
                    100 * (t.widthUncertainty + t.lengthUncertainty) / 2.0,
                    scene=True,
                    fill="yellow",
                    stroke="red",
                )

                # drawing.text(
                #     t.name,
                #     (t.x - 20, t.z),
                #     scene=True,
                #     stroke='black',
                #     stroke_width='0.25',
                #     font_size='6px',
                #     font_family='Arial')
                continue

            self._drawHighUncertaintyMarker(drawing, t)

            # label this track with red
            # drawing.text(
            #     t.name,
            #     (t.x - 20, t.z),
            #     scene=True,
            #     stroke='red',
            #     stroke_width='0.25',
            #     font_size='6px',
            #     font_family='Arial')

        # and close off with a final save of the drawing file
        if drawing:
            drawing.save()

        self.logger.write(
            "%s Tracks with large rotational uncertainties found (%s%%)"
            % (
                largeUncertaintyCount,
                NumericUtils.roundToOrder(100.0 * float(largeUncertaintyCount) / float(len(self._tracks)), -1),
            )
        )

        self._largeUncCsv.save()
        self._tracks = []
    def _postAnalyze(self):
        h = Histogram(
            data=self._uncs,
            binCount=80,
            xLimits=(0, max(*self._uncs)),
            color='r',
            title='Distribution of Spatial (X, Z) Uncertainties',
            xLabel='Uncertainty Value (m)',
            yLabel='Frequency')
        p1 = h.save(self.getTempFilePath(extension='pdf'))

        h.isLog = True
        h.title += ' (log)'
        p2 = h.save(self.getTempFilePath(extension='pdf'))

        self.mergePdfs([p1, p2], self.getPath('Spatial-Uncertainty-Distribution.pdf'))

        average = NumericUtils.getMeanAndDeviation(self._uncs)
        self.logger.write('Average spatial uncertainty: %s' % average.label)

        #-------------------------------------------------------------------------------------------
        # FIND LARGE UNCERTAINTY TRACKS
        largeUncertaintyCount = 0
        drawing = None
        sitemap = None

        # If track uncertainty is 2x average, add that track to the spreadsheet and map overlay
        for t in self._tracks:

            # if the tracksite has changed, save previous map and make a new one
            if sitemap != t.trackSeries.trackway.sitemap:

                # save the last site map drawing (if there was one)
                if drawing:
                    drawing.save()

                # then start a new drawing for this new site map
                sitemap = t.trackSeries.trackway.sitemap

                fileName = sitemap.name + "_" + sitemap.level + '_uncertainty.svg'
                path = self.getPath(self.DRAWING_FOLDER_NAME, fileName, isFile=True)
                drawing = CadenceDrawing(path, sitemap)

                # create a group to be instanced for the spreadsheet values
                drawing.createGroup('rect1')
                # create a rectangle of 100x100 cm that is to be scaled by fractional meters
                drawing.rect((0, 0), 100, 100, scene=True, groupId='rect1')

                # create another group to be instanced for the mapped values.
                drawing.createGroup('rect2')
                # create a rectangle of 100x100 cm that is to be scaled by fractional meters
                drawing.rect((0, 0), 100, 100, scene=True, groupId='rect2')

                # and place a grid and the federal coordinates in the drawing file
                drawing.grid()
                drawing.federalCoordinates()

            # now examine the positional uncertainties for this track
            x = t.xValue
            z = t.zValue

            if x.uncertainty > 0.15 or z.uncertainty > 0.15:
                # s = '%s%s %s%s: %s %s'% (
                #     t.site, t.level, t.trackwayType, t.trackwayNumber, t.name, t.uid)
                # print('%s:  (%s and %s)' % (s, x.uncertainty, z.uncertainty))
                print('%s\t%s' % (t.uid, t.fingerprint))

            if max(x.uncertainty, z.uncertainty) <= 2.0*average.uncertainty:
                # then just indicate that this track has low uncertainty
                self._drawLowUncertaintyMarker(drawing, t)
                # label this track with green
                drawing.text(
                    t.name,
                    (t.x - 20, t.z),
                    scene=True,
                    stroke='green',
                    stroke_width='0.25',
                    font_size='8px',
                    font_family='Arial')
                continue

            # else, since the uncertainty is high, first write that track in the spreadsheet
            largeUncertaintyCount += 1
            self._largeUncCsv.createRow(
                uid=t.uid,
                fingerprint=t.fingerprint,
                x=x.label,
                z=z.label)

            # if either the measured width or length is 0, mark with a yellow disk with red outline
            if t.widthMeasured == 0 or t.lengthMeasured == 0:
                drawing.circle(
                    (t.x, t.z),
                    100*(t.widthUncertainty + t.lengthUncertainty)/2.0,
                    scene=True,
                    fill='yellow',
                    stroke='red')
                drawing.text(
                    t.name,
                    (t.x - 20, t.z),
                    scene=True,
                    stroke='black',
                    stroke_width='0.25',
                    font_size='6px',
                    font_family='Arial')
                continue

            self._drawHighUncertaintyMarker(drawing, t)

            # label this track with red
            drawing.text(
                t.name,
                (t.x - 20, t.z),
                scene=True,
                stroke='red',
                stroke_width='0.25',
                font_size='6px',
                font_family='Arial')
#
#             # draw this track indicating it has high uncertainty
#             drawing.use(
#                     'rect1',
#                     (t.x, t.z),
#                     scene=True,
#                     rotation=t.rotation,
#                     opacity='0.5',
#                     scale=t.widthMeasured,
#                     scaleY=t.lengthMeasured,
#                     fill='red',
#                     stroke='red')
#
#             # draw the map dimensions with an outline gray rectangle
#             drawing.use(
#                     'rect2',
#                     (t.x, t.z),
#                     scene=True,
#                     rotation=t.rotation,
#                     scale=t.width,
#                     scaleY=t.length,
#                     fill='none',
#                     stroke='gray')

        # and close off with a final save of the drawing file
        if drawing:
            drawing.save()


        self.logger.write('%s Tracks with large spatial uncertainties found (%s%%)' % (
            largeUncertaintyCount, NumericUtils.roundToOrder(
                100.0*float(largeUncertaintyCount)/float(len(self._tracks)), -1) ))

        self._largeUncCsv.save()
        self._tracks = []