Exemplo n.º 1
0
    def test_vector_operations_with_exceptions(self):
        iv1 = IntVector()
        iv1.append(1)
        iv1.append(2)
        iv1.append(3)

        iv2 = IntVector()
        iv2.append(4)
        iv2.append(5)

        dv1 = DoubleVector()
        dv1.append(0.5)
        dv1.append(0.75)
        dv1.append(0.25)

        # Size mismatch
        with self.assertRaises(ValueError):
            iv3 = iv1 + iv2

        # Size mismatch
        with self.assertRaises(ValueError):
            iv3 = iv1 * iv2

        # Type mismatch
        with self.assertRaises(TypeError):
            iv1 += dv1

        # Type mismatch
        with self.assertRaises(TypeError):
            iv1 *= dv1
Exemplo n.º 2
0
    def loadVector(self, plot_block_data, fs, report_step, realization_number):
        """
        @type plot_block_data: PlotBlockData
        @type fs: EnkfFs
        @type report_step: int
        @type realization_number: int
        @rtype PlotBlockVector
        """
        config_node = self.__obs_vector.getConfigNode()

        is_private_container = (
            config_node.getImplementationType() == ErtImplType.CONTAINER)
        data_node = EnkfNode(config_node, private=is_private_container)

        node_id = NodeId(report_step, realization_number)

        if data_node.tryLoad(fs, node_id):
            block_obs = self.getBlockObservation(report_step)

            data = DoubleVector()
            for index in range(len(block_obs)):
                value = block_obs.getData(data_node.valuePointer(), index,
                                          node_id)
                data.append(value)
            data.permute(self.__permutation_vector)

            plot_block_vector = PlotBlockVector(realization_number, data)
            plot_block_data.addPlotBlockVector(plot_block_vector)
Exemplo n.º 3
0
    def test_vector_operations_with_exceptions(self):
        iv1 = IntVector()
        iv1.append(1)
        iv1.append(2)
        iv1.append(3)

        iv2 = IntVector()
        iv2.append(4)
        iv2.append(5)

        dv1 = DoubleVector()
        dv1.append(0.5)
        dv1.append(0.75)
        dv1.append(0.25)

        # Size mismatch
        with self.assertRaises(ValueError):
            iv3 = iv1 + iv2

        # Size mismatch
        with self.assertRaises(ValueError):
            iv3 = iv1 * iv2

        # Type mismatch
        with self.assertRaises(TypeError):
            iv1 += dv1

        # Type mismatch
        with self.assertRaises(TypeError):
            iv1 *= dv1
Exemplo n.º 4
0
    def test_element_sum(self):
        dv = DoubleVector()
        iv = IntVector()
        for i in range(10):
            dv.append(i + 1)
            iv.append(i + 1)

        self.assertEqual(dv.elementSum(), 55)
        self.assertEqual(iv.elementSum(), 55)
Exemplo n.º 5
0
    def test_element_sum(self):
        dv = DoubleVector()
        iv = IntVector()
        for i in range(10):
            dv.append(i + 1)
            iv.append(i + 1)

        self.assertEqual(dv.elementSum(), 55)
        self.assertEqual(iv.elementSum(), 55)
Exemplo n.º 6
0
    def getDepthValues(self, report_step):
        """@rtype: DoubleVector"""
        block_obs = self.getBlockObservation(report_step)

        depth = DoubleVector()
        for index in block_obs:
            value = block_obs.getDepth(index)
            depth.append(value)

        return depth
Exemplo n.º 7
0
    def test_plot_block_vector(self):
        vector = DoubleVector()
        vector.append(1.5)
        vector.append(2.5)
        vector.append(3.5)
        plot_block_vector = PlotBlockVector(1, vector)

        self.assertEqual(plot_block_vector.getRealizationNumber(), 1)
        self.assertEqual(plot_block_vector[0], 1.5)
        self.assertEqual(plot_block_vector[2], 3.5)

        self.assertEqual(len(plot_block_vector), len(vector))
Exemplo n.º 8
0
    def test_stat_quantiles(self):
        rng = RandomNumberGenerator()
        rng.setState("0123456789ABCDEF")
        v = DoubleVector()
        for i in range(100000):
            v.append(rng.getDouble())

        self.assertAlmostEqual(quantile(v, 0.1), 0.1, 2)
        self.assertAlmostEqual(quantile_sorted(v, 0.2), 0.2, 2)
        self.assertAlmostEqual(quantile_sorted(v, 0.3), 0.3, 2)
        self.assertAlmostEqual(quantile_sorted(v, 0.4), 0.4, 2)
        self.assertAlmostEqual(quantile_sorted(v, 0.5), 0.5, 2)
Exemplo n.º 9
0
    def test_permutation_vector(self):
        vector = DoubleVector()

        for i in range(5, 0, -1):
            vector.append(i)

        permutation_vector = vector.permutationSort()

        for index, value in enumerate(range(5, 0, -1)):
            self.assertEqual(vector[index], value)

        vector.permute(permutation_vector)

        for index, value in enumerate(range(1, 6)):
            self.assertEqual(vector[index], value)
Exemplo n.º 10
0
    def test_permutation_vector(self):
        vector = DoubleVector()

        for i in range(5, 0, -1):
            vector.append(i)

        permutation_vector = vector.permutationSort()

        for index, value in enumerate(range(5, 0, -1)):
            self.assertEqual(vector[index], value)

        vector.permute(permutation_vector)

        for index, value in enumerate(range(1, 6)):
            self.assertEqual(vector[index], value)
Exemplo n.º 11
0
    def test_plot_block_data(self):
        depth = DoubleVector()
        depth.append(2.5)
        depth.append(3.5)

        data = PlotBlockData(depth)

        self.assertEqual(data.getDepth(), depth)

        vector = PlotBlockVector(1, DoubleVector())
        data.addPlotBlockVector(vector)
        data.addPlotBlockVector(PlotBlockVector(2, DoubleVector()))

        self.assertEqual(len(data), 2)

        self.assertEqual(vector, data[1])
Exemplo n.º 12
0
    def center(self):
        xlist = DoubleVector()
        ylist = DoubleVector()
        for segment in self:
            C1 = segment.getC1()
            C2 = segment.getC2()
            (J1, I1) = divmod(C1, self.__grid.getNX() + 1)
            (J2, I2) = divmod(C2, self.__grid.getNX() + 1)

            (x1, y1, z) = self.__grid.getNodePos(I1, J1, self.__k)
            (x2, y2, z) = self.__grid.getNodePos(I2, J2, self.__k)

            xlist.append(x1)
            xlist.append(x2)

            ylist.append(y1)
            ylist.append(y2)

        N = len(xlist)
        return (xlist.elementSum() / N, ylist.elementSum() / N)
Exemplo n.º 13
0
    def center(self):
        xlist = DoubleVector()
        ylist = DoubleVector()
        for segment in self:
            C1 = segment.getC1()
            C2 = segment.getC2()
            (J1, I1) = divmod(C1, self.__grid.getNX() + 1)
            (J2, I2) = divmod(C2, self.__grid.getNX() + 1)

            (x1,y1,z) = self.__grid.getNodePos(I1, J1, self.__k)
            (x2,y2,z) = self.__grid.getNodePos(I2, J2, self.__k)

            xlist.append(x1)
            xlist.append(x2)

            ylist.append(y1)
            ylist.append(y2)


        N = len(xlist)
        return (xlist.elementSum()/N, ylist.elementSum()/N)
Exemplo n.º 14
0
 def blocked_production(self, totalKey, timeRange):
     node = self.smspec_node(totalKey)
     if node.isTotal():
         total = DoubleVector()
         for t in timeRange:
             if t < CTime(self.start_time):
                 total.append(0)
             elif t >= CTime(self.end_time):
                 total.append(self.get_last_value(totalKey))
             else:
                 total.append(self.get_interp(totalKey, date=t))
         tmp = total << 1
         total.pop()
         return tmp - total
     else:
         raise TypeError(
             "The blockedProduction method must be called with one of the TOTAL keys like e.g. FOPT or GWIT"
         )
Exemplo n.º 15
0
    def test_polyfit(self):
        x_list = DoubleVector()
        y_list = DoubleVector()
        S = DoubleVector()

        A = 7.25
        B = -4
        C = 0.025

        x = 0
        dx = 0.1
        for i in range(100):
            y = A + B * x + C * x * x
            x_list.append(x)
            y_list.append(y)

            x += dx
            S.append(1.0)

        beta = polyfit(3, x_list, y_list, None)

        self.assertAlmostEqual(A, beta[0])
        self.assertAlmostEqual(B, beta[1])
        self.assertAlmostEqual(C, beta[2])