def test_add_measurement(self):
        result = measurements.add([self.measurement_1, self.measurement_2])
        expected_values = [a + b for a, b in zip(self.measurement_1[1],
                                                 self.measurement_2[1])]
        expected_errors = [math.sqrt(a**2 + b**2)
                           for a, b in zip(self.measurement_1[2],
                                           self.measurement_2[2])]

        self.assertEqual(range(10), result[0])
        self.assertEqual(expected_values, result[1])
        self.assertEqual(expected_errors, result[2])
    def test_double_measurement(self):
        expected_1 = [range(10),
                      [2*m for m in self.measurement_1[1]],
                      [math.sqrt(2*(m**2)) for m in self.measurement_1[2]]]

        result_1 = measurements.add([self.measurement_1, self.measurement_1])

        self.assertEqual(expected_1[0], result_1[0])
        self.assertEqual(expected_1[1], result_1[1])
        for e, r in zip(expected_1[2], result_1[2]):
            self.assertAlmostEqual(e, r)

        expected_2 = [range(10),
                      [2*m for m in self.measurement_2[1]],
                      [math.sqrt(2*(m**2)) for m in self.measurement_2[2]]]

        result_2 = measurements.add([self.measurement_2, self.measurement_2])

        self.assertEqual(expected_2[0], result_2[0])
        self.assertEqual(expected_2[1], result_2[1])
        for e, r in zip(expected_2[2], result_2[2]):
            self.assertAlmostEqual(e, r)
Exemple #3
0
    def test_add_measurement(self):
        result = measurements.add([self.measurement_1, self.measurement_2])
        expected_values = [
            a + b for a, b in zip(self.measurement_1[1], self.measurement_2[1])
        ]
        expected_errors = [
            math.sqrt(a**2 + b**2)
            for a, b in zip(self.measurement_1[2], self.measurement_2[2])
        ]

        self.assertEqual(range(10), result[0])
        self.assertEqual(expected_values, result[1])
        self.assertEqual(expected_errors, result[2])
Exemple #4
0
    def test_double_measurement(self):
        expected_1 = [
            range(10), [2 * m for m in self.measurement_1[1]],
            [math.sqrt(2 * (m**2)) for m in self.measurement_1[2]]
        ]

        result_1 = measurements.add([self.measurement_1, self.measurement_1])

        self.assertEqual(expected_1[0], result_1[0])
        self.assertEqual(expected_1[1], result_1[1])
        for e, r in zip(expected_1[2], result_1[2]):
            self.assertAlmostEqual(e, r)

        expected_2 = [
            range(10), [2 * m for m in self.measurement_2[1]],
            [math.sqrt(2 * (m**2)) for m in self.measurement_2[2]]
        ]

        result_2 = measurements.add([self.measurement_2, self.measurement_2])

        self.assertEqual(expected_2[0], result_2[0])
        self.assertEqual(expected_2[1], result_2[1])
        for e, r in zip(expected_2[2], result_2[2]):
            self.assertAlmostEqual(e, r)
    def perform(self, run, target):
        results = [run.analyses[self.analysis_name]]
        if self.secondary_name:
            results.append(run.analyses[self.secondary_name])

        times, values, errors = measurements.add(results)

        i = bisect.bisect_left(times, self.time)
        if not self.average:
            value = values[i]
        else:
            value = numpy.mean(values[i:])

        value -= self.subtract_first
        value *= self.scale_by
        value /= self.divide_by
        target.value = value
    def perform(self, run, target):
        results = [run.analyses[self.analysis_name]]
        if self.secondary_name:
            results.append(run.analyses[self.secondary_name])

        times, values, errors = measurements.add(results)

        i = bisect.bisect_left(times, self.time)
        if not self.average:
            value = values[i]
        else:
            value = numpy.mean(values[i:])

        value -= self.subtract_first
        value *= self.scale_by
        value /= self.divide_by
        target.value = value
 def unnormalized_measurement(self, run):
     analyses = run.analyses
     measurements = []
     for name, weight in self.weights.iteritems():
         measurements.append(_measurements.scale(analyses[name], weight))
     return _measurements.add(measurements)