当前位置: 首页>>代码示例>>Python>>正文


Python NumericUtils.NumericUtils类代码示例

本文整理汇总了Python中pyaid.number.NumericUtils.NumericUtils的典型用法代码示例。如果您正苦于以下问题:Python NumericUtils类的具体用法?Python NumericUtils怎么用?Python NumericUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了NumericUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __unicode__

    def __unicode__(self):
        isPy2 = bool(sys.version < '3')

        return '<%s (%s, %s)>' % (
            self.__class__.__name__,
            NumericUtils.toValueUncertainty(self.x, self.xUnc, asciiLabel=isPy2).label,
            NumericUtils.toValueUncertainty(self.y, self.yUnc, asciiLabel=isPy2).label)
开发者ID:sernst,项目名称:PyAid,代码行数:7,代码来源:PositionValue2D.py

示例2: test_isNumber

 def test_isNumber(self):
     """test_isNumber doc..."""
     self.assertTrue(NumericUtils.isNumber(1.234))
     self.assertTrue(NumericUtils.isNumber(100))
     self.assertTrue(NumericUtils.isNumber(-24))
     self.assertFalse(NumericUtils.isNumber('12'))
     self.assertFalse(NumericUtils.isNumber(self))
开发者ID:sernst,项目名称:PyAid,代码行数:7,代码来源:Test_NumericUtils.py

示例3: _adjustPositionForward

    def _adjustPositionForward(self, pair, maxOffset =1.0e8):
        """_adjustPositionForward doc..."""

        delta = 0.001
        segment = pair['segment']
        offset = segment.offset + pair['distance']

        while maxOffset <= (offset + delta) or NumericUtils.equivalent(maxOffset, offset + delta):
            delta *= 0.5

        point = pair['line'].start.clone()
        segment.line.adjustPointAlongLine(point, delta, inPlace=True)
        dist = segment.line.start.distanceTo(point).raw

        if not NumericUtils.equivalent(pair['distance'] + delta, dist, machineEpsilonFactor=1000.0):
            self.stage.logger.write([
                '[ERROR]: Forward adjust failure in CurveSeries.adjustPositionForward',
                'TRACK: %s [%s]' % (pair['track'].fingerprint, pair['track'].uid),
                'EXPECTED: %s' % (pair['distance'] + delta),
                'ACTUAL: %s' % dist,
                'DELTA: %s' % delta])

        pair['line'].start.copyFrom(point)

        track = pair['track']
        pair['distance'] = dist

        if not self.saveToAnalysisTracks:
            return

        at = track.getAnalysisPair(self.stage.analysisSession)
        at.curvePosition = segment.offset + dist
        at.segmentPosition = dist
开发者ID:sernst,项目名称:Cadence,代码行数:33,代码来源:CurveSeries.py

示例4: _calculateDeviation

    def _calculateDeviation(
            self, track, value, uncertainty, highMeasuredUncertainty, measured,
            prefix, label
    ):
        if not measured:
            return None

        out = dict()

        measuredUncertainty = measured*(
            0.12 if highMeasuredUncertainty else 0.06)

        v = NumericUtils.toValueUncertainty(value, uncertainty)
        mv = NumericUtils.toValueUncertainty(measured, measuredUncertainty)
        unc = math.sqrt(v.uncertainty**2 + mv.uncertainty**2)

        deviation = v.value - mv.value
        out['%sDev' % prefix] = deviation/measured

        try:
            out['%sDelta' % prefix] = abs(deviation)/unc
        except ZeroDivisionError:
            self.logger.write([
                '[ERROR]: Track without %s uncertainty' % label,
                'TRACK: %s (%s)' % (track.fingerprint, track.uid) ])
            raise

        return out
开发者ID:sernst,项目名称:Cadence,代码行数:28,代码来源:LengthWidthStage.py

示例5: _resolveSpatialCoincidences

    def _resolveSpatialCoincidences(self, pair):
        """ Correct for cases where projected prints reside at the same spatial location on the
            curve series by adjusting one of the tracks projection position slightly. """

        segment = pair['segment']

        try:
            nextSegment = self.segments[self.segments.index(segment) + 1]
            nextOffset = nextSegment.offset
        except Exception:
            nextOffset = 1.0e8

        # Adjust a pair print if it resides at the same position as its curve series track
        if NumericUtils.equivalent(pair['distance'], 0.0):
            self._adjustPositionForward(pair, nextOffset)

        try:
            # Retrieve the next pair track in the segment if one exists
            nextPair = segment.pairs[segment.pairs.index(pair) + 1]
        except Exception:
            return

        pDist = pair['distance']
        npDist = nextPair['distance']

        # Adjust pair tracks that reside at the same spatial position
        if npDist <= pDist or NumericUtils.equivalent(pDist, npDist):
            self._adjustPositionForward(nextPair, nextOffset)
开发者ID:sernst,项目名称:Cadence,代码行数:28,代码来源:CurveSeries.py

示例6: print_track

def print_track(track, aSession):
    """

    @param track:
    @param aSession:
    @return:
    """

    limb_id = "{}{}".format("l" if track.left else "r", "p" if track.pes else "m")

    print(track.echoForVerification())
    print(
        "        size: (%s, %s) | field (%s, %s)"
        % (track.width, track.length, track.widthMeasured, track.lengthMeasured)
    )

    aTrack = track.getAnalysisPair(aSession)
    print(
        "        curve[#%s -> %s]: %s (%s)"
        % (
            aTrack.curveIndex,
            aTrack.curveSegment,
            NumericUtils.roundToSigFigs(aTrack.segmentPosition, 4),
            NumericUtils.roundToSigFigs(aTrack.curvePosition, 4),
        )
    )
    print("        snapshot: {}\n".format(DictUtils.prettyPrint(track.snapshotData)))

    return dict(limb_id=limb_id, track=track, aTrack=aTrack)
开发者ID:sernst,项目名称:Cadence,代码行数:29,代码来源:trackwayPrinter.py

示例7: project

    def project(self, track, data =None):
        """ Tests the specified segment and modifies the data dictionary with the results of the
            test if it was successful. """

        data = self._initializeData(data, track)

        position = track.positionValue
        debugItem = {'TRACK':self.track.fingerprint if self.track else 'NONE'}
        debugData = {}
        data['debug'].append({'print':debugItem, 'data':debugData})

        # Make sure the track resides in a generally forward direction relative to
        # the direction of the segment. The prevents tracks from matching from behind.
        angle = self.line.angleBetweenPoint(position)
        if abs(angle.degrees) > 100.0:
            debugItem['CAUSE'] = 'Segment position angle [%s]' % angle.prettyPrint
            return

        # Calculate the closest point on the line segment. If the point and line are not
        # properly coincident, the testPoint will be None and the attempt should be aborted.
        testPoint = self.line.closestPointOnLine(position, contained=True)
        if not testPoint:
            debugItem['CAUSE'] = 'Not aligned to segment'
            return

        testLine = LineSegment2D(testPoint, position.clone())

        # Make sure the test line intersects the segment line at 90 degrees, or the
        # value is invalid.
        angle = testLine.angleBetweenPoint(self.line.end)
        if not NumericUtils.equivalent(angle.degrees, 90.0, 2.0):
            debugItem['CAUSE'] = 'Projection angle [%s]' % angle.prettyPrint
            debugData['testLine'] = testLine
            debugData['testPoint'] = testPoint
            return

        # Skip if the test line length is greater than the existing test line
        length = data.get('projectionLength', 1.0e10)
        if testLine.length.raw > length:
            debugItem['CAUSE'] = 'Greater length [%s > %s]' % (
                NumericUtils.roundToSigFigs(length, 5),
                NumericUtils.roundToSigFigs(testLine.length.raw, 5) )
            debugData['testLine'] = testLine
            debugData['testPoint'] = testPoint
            return

        # Populate the projection values if the projection was successful
        p  = testPoint.clone()
        # p.xUnc = position.xUnc
        # p.yUnc = position.yUnc
        data['segment'] = self
        data['projectionLength'] = position.distanceTo(p).raw
        data['line'] = LineSegment2D(p, position)

        data['distance'] = self.line.start.distanceTo(p).raw
        debugData['distance'] = data['distance']

        return data
开发者ID:sernst,项目名称:Cadence,代码行数:58,代码来源:CurveProjectionSegment.py

示例8: _postAnalyze

    def _postAnalyze(self):
        """_postAnalyze doc..."""
        self._csv.save()

        meanDiff = NumericUtils.getMeanAndDeviation(self._diffs)
        self.logger.write('Rotation %s' % meanDiff.label)

        self._paths.append(self._makePlot(
            label='Rotation Differences',
            data=self._diffs,
            histRange=[-180, 180]))

        self._paths.append(self._makePlot(
            label='Rotation Differences',
            data=self._diffs,
            histRange=[-180, 180],
            isLog=True))

        circs    = []
        circsUnc = []
        diffs    = []
        diffsUnc = []
        entries  = self.owner.getStage('lengthWidth').entries

        for entry in entries:
            track = entry['track']
            if track.uid not in self.deviations:
                # Skip those tracks with no deviation value (solo tracks)
                continue

            diffDeg = self.deviations[track.uid]
            diffs.append(abs(diffDeg.value))
            diffsUnc.append(diffDeg.uncertainty)

            # Compute the circularity of the track from its aspect ratio. If
            # the aspect is less than or equal to 1.0 use the aspect value
            # directly. However, if the value is greater than one, take the
            # reciprocal so that large and small aspect ratios can be compared
            # equally.
            aspect = entry['aspect']
            if aspect.value > 1.0:
                a = 1.0/aspect.raw
                aspect = NumericUtils.toValueUncertainty(a, a*(aspect.rawUncertainty/aspect.raw))

            circs.append(abs(aspect.value - 1.0))
            circsUnc.append(aspect.uncertainty)

        pl = self.plot
        self.owner.createFigure('circular')
        pl.errorbar(x=circs, y=diffs, xerr=circsUnc, yerr=diffsUnc, fmt='.')
        pl.xlabel('Aspect Circularity')
        pl.ylabel('Rotation Deviation')
        pl.title('Rotation Deviation and Aspect Circularity')
        self._paths.append(self.owner.saveFigure('circular'))

        self.mergePdfs(self._paths)
        self._paths = []
开发者ID:sernst,项目名称:Cadence,代码行数:57,代码来源:RotationStage.py

示例9: test_weightedAverage

    def test_weightedAverage(self):
        """ doc... """
        values = [
            NumericUtils.toValueUncertainty(11.0, 1.0),
            NumericUtils.toValueUncertainty(12.0, 1.0),
            NumericUtils.toValueUncertainty(10.0, 3.0) ]

        result = NumericUtils.weightedAverage(*values)

        self.assertEqual(result.value, 11.4, 'Value Match')
        self.assertEqual(result.uncertainty, 0.7, 'Value Match')
开发者ID:sernst,项目名称:PyAid,代码行数:11,代码来源:Test_NumericUtils.py

示例10: test_toValueUncertainty

    def test_toValueUncertainty(self):
        """test_toValueUncertainty doc..."""
        value = NumericUtils.toValueUncertainty(math.pi, 0.00456)
        self.assertEqual(value.value, 3.142, 'Values do not match %s' % value.label)
        self.assertEqual(value.uncertainty, 0.005, 'Uncertainties do not match %s' % value.label)

        value = NumericUtils.toValueUncertainty(100.0*math.pi, 42.0)
        self.assertEqual(value.value, 310.0, 'Values do not match %s' % value.label)
        self.assertEqual(value.uncertainty, 40.0, 'Uncertainties do not match %s' % value.label)

        value = NumericUtils.toValueUncertainty(0.001*math.pi, 0.000975)
        self.assertEqual(value.value, 0.003, 'Values do not match %s' % value.label)
        self.assertEqual(value.uncertainty, 0.001, 'Uncertainties do not match %s' % value.label)
开发者ID:sernst,项目名称:PyAid,代码行数:13,代码来源:Test_NumericUtils.py

示例11: makePlot

def makePlot(label, tracks):
    tracks = tracks.copy()

    xBounds = [
        NumericUtils.roundToOrder(tracks.length.min() - 0.05, -1, math.floor),
        NumericUtils.roundToOrder(tracks.length.max() + 0.05, -1, math.ceil)]
    yBounds = [
        NumericUtils.roundToOrder(tracks.width.min() - 0.05, -1, math.floor),
        NumericUtils.roundToOrder(tracks.width.max() + 0.05, -1, math.ceil)]

    fig = plotlyTools.make_subplots(
        rows=1, cols=2,
        subplot_titles=('Length vs Width','Aspect Ratios'),
        print_grid=False)

    traces = []
    for site in tracks.site.unique():
        color = PlotConfigs.SITE_SPECS[site]['color']
        siteSlice = tracks[tracks.site == site]
        traces.append(plotlyGraph.Scatter(
            name=site,
            mode='markers',
            xaxis='x1', yaxis='y1',
            marker=plotlyGraph.Marker(color=color),
            x=siteSlice.length,
            y=siteSlice.width))

        traces.append(plotlyGraph.Box(
            name=site,
            y=siteSlice.length/siteSlice.width,
            marker=plotlyGraph.Marker(color=color),
            xaxis='x2', yaxis='y2'))

    fig['data'] += plotlyGraph.Data(traces)
    fig['layout'].update(
        title='%s Length & Width by Tracksite' % label,
        xaxis1=plotlyGraph.XAxis(
            title='Length (m)',
            range=xBounds,
            autorange=False ),
        yaxis1=plotlyGraph.YAxis(
            title='Width (m)',
            range=yBounds,
            autorange=False ))

    url = plotly.plot(
        filename='A16/%s-Length-Width' % label,
        figure_or_data=fig,
        auto_open=False)
    print('PLOT[%s]:' % label, PlotlyUtils.toEmbedUrl(url))
开发者ID:sernst,项目名称:Cadence,代码行数:50,代码来源:BasicFigures.py

示例12: _processGaugeData

    def _processGaugeData(self, bundle, trackway, data):
        pesCount = bundle.leftPes.count + bundle.rightPes.count
        record = {'name':trackway.name, 'count':pesCount}

        gaugeData = data['gauges']

        try:
            value = NumericUtils.getWeightedMeanAndDeviation(gaugeData.abs)
            record['abs'] = value.value
            record['absUnc'] = value.uncertainty
            self._trackwayGauges.abs.append((pesCount, value))
        except ZeroDivisionError:
            return

        widthValue = NumericUtils.getWeightedMeanAndDeviation(gaugeData.width)
        record['width'] = widthValue.value
        record['widthUnc'] = widthValue.uncertainty
        self._trackwayGauges.width.append((pesCount, widthValue))

        if gaugeData.pace:
            value = NumericUtils.getWeightedMeanAndDeviation(gaugeData.pace)
            record['pace'] = value.value
            record['paceUnc'] = value.uncertainty
            self._trackwayGauges.pace.append((pesCount, value))
        else:
            record['pace'] = ''
            record['paceUnc'] = ''

        if gaugeData.stride:
            value = NumericUtils.getWeightedMeanAndDeviation(gaugeData.stride)
            record['stride'] = value.value
            record['strideUnc'] = value.uncertainty
            self._trackwayGauges.stride.append((pesCount, value))
        else:
            record['stride'] = ''
            record['strideUnc'] = ''

        self._trackwayCsv.addRow(record)

        plot = ScatterPlot(
            data=data['points'],
            title='%s Width-Normalized Gauges (%s)' % (trackway.name, widthValue.label),
            xLabel='Track Position (m)',
            yLabel='Gauge (AU)')
        self._paths.append(plot.save(self.getTempFilePath(extension='pdf')))

        analysisTrackway = trackway.getAnalysisPair(self.analysisSession)
        analysisTrackway.simpleGauge = widthValue.raw
        analysisTrackway.simpleGaugeUnc = widthValue.rawUncertainty
开发者ID:sernst,项目名称:Cadence,代码行数:49,代码来源:SimpleGaugeStage.py

示例13: _drawMeasuredWidth

    def _drawMeasuredWidth(self, track, drawing):
        if NumericUtils.equivalent(track.widthMeasured, 0.0):
            return

        if track.uid in self.trackDeviations:
            data = self.trackDeviations[track.uid]
            if data['wSigma'] > 2.0:
                strokeWidth = 3.0
                color = 'red'
            else:
                strokeWidth = 1.0
                color = 'green'
        else:
            strokeWidth = 1.0
            color = 'green'

        w   = 100*track.widthMeasured
        rot = math.radians(track.rotation)
        x1  = w/2.0
        x2  = -w/2.0

        drawing.line(
             (track.x + x1*math.cos(rot), track.z - x1*math.sin(rot)),
             (track.x + x2*math.cos(rot), track.z - x2*math.sin(rot)),
             scene=True,
             stroke=color,
             stroke_width=strokeWidth)
开发者ID:sernst,项目名称:Cadence,代码行数:27,代码来源:DrawLengthWidthStage.py

示例14: _drawMeasuredLength

    def _drawMeasuredLength(self, track, drawing):
        if NumericUtils.equivalent(track.lengthMeasured, 0.0):
            return

        if track.uid in self.trackDeviations:
            data = self.trackDeviations[track.uid]
            if data['lSigma'] > 2.0:
                  strokeWidth = 3.0
                  color = 'red'
            else:
                strokeWidth = 1.0
                color = 'green'
        else:
            strokeWidth = 1.0
            color = 'green'

        l   = 100*track.lengthMeasured
        rot = math.radians(track.rotation)
        z1  = track.lengthRatio*l
        z2  = z1 - l

        drawing.line(
             (track.x + z1*math.sin(rot), track.z + z1*math.cos(rot)),
             (track.x + z2*math.sin(rot), track.z + z2*math.cos(rot)),
             scene=True,
             stroke=color,
             stroke_width=strokeWidth)
开发者ID:sernst,项目名称:Cadence,代码行数:27,代码来源:DrawLengthWidthStage.py

示例15: rawLabel

 def rawLabel(self):
     if self._asciiLabels:
         return self.asciiRawLabel
     return '%s %s %s' % (
         NumericUtils.roundToSigFigs(self.raw, 6),
         StringUtils.unichr(0x00B1),
         self.uncertainty)
开发者ID:sernst,项目名称:PyAid,代码行数:7,代码来源:ValueUncertainty.py


注:本文中的pyaid.number.NumericUtils.NumericUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。