def _calculateAverageSpacing(cls, series):
        """ Determines the average spacing of the tracks in the track series for use as a
            comparative measure of sparseness to the other track series in the trackway. If the
            series is not ready or does not have a sufficient number of tracks, this method will
            return None.

            :param: series | TrackSeries
                The series on which to determine the average spacing.

            :return: ValueUncertainty
                A value uncertainty instance that represents the average spacing of the series,
                or None if it's the calculation is aborted. """

        if not series.isReady:
            # Skip trackways with invalid series
            return None

        tracks = series.tracks
        if not tracks or len(tracks) < 2:
            # Ignore series with less than two tracks
            return None

        length = 0.0
        uncs    = []

        for i in ListUtils.range(len(tracks) - 1):
            line = LineSegment2D(
                start=tracks[i].positionValue,
                end=tracks[i + 1].positionValue)
            spacing = line.length
            length += spacing.value
            uncs.append(spacing.uncertainty)

        unc = NumericUtils.sqrtSumOfSquares(*uncs)

        return NumericUtils.toValueUncertainty(
            value=length/float(len(tracks)),
            uncertainty=unc/float(len(tracks)) )
Exemple #2
0
 def test_sqrtSumOfSquares(self):
     """test_sqrtSumOfSquares doc..."""
     self.assertEqual(1.0, NumericUtils.sqrtSumOfSquares(-1.0))
     self.assertEqual(math.sqrt(2), NumericUtils.sqrtSumOfSquares(1.0, 1.0))
     self.assertEqual(math.sqrt(4.25),
                      NumericUtils.sqrtSumOfSquares(2.0, 0.5))
Exemple #3
0
 def test_sqrtSumOfSquares(self):
     """test_sqrtSumOfSquares doc..."""
     self.assertEqual(1.0, NumericUtils.sqrtSumOfSquares(-1.0))
     self.assertEqual(math.sqrt(2), NumericUtils.sqrtSumOfSquares(1.0, 1.0))
     self.assertEqual(math.sqrt(4.25), NumericUtils.sqrtSumOfSquares(2.0, 0.5))