Пример #1
0
def test_active_index_list_empty():
    # Empty list
    active_list_obj = ActiveList()
    mode = active_list_obj.getMode()
    assert mode == ActiveMode.ALL_ACTIVE
    list1 = active_list_obj.get_active_index_list()
    assert len(list1) == 0
Пример #2
0
    def test_create(self):
        grid = EclGridGenerator.create_rectangular((10, 20, 5), (1, 1, 1))
        field_config = FieldConfig("PRESSURE", grid)
        block_obs = BlockObservation("P-CONFIG", field_config, grid)

        self.assertEqual(len(block_obs), 0)

        block_obs.addPoint(1, 2, 3, 100, 25)
        self.assertEqual(len(block_obs), 1)
        self.assertEqual(block_obs.getValue(0), 100)
        self.assertEqual(block_obs.getStd(0), 25)
        self.assertEqual(block_obs.getStdScaling(0), 1)

        block_obs.addPoint(1, 2, 4, 200, 50)
        self.assertEqual(len(block_obs), 2)
        self.assertEqual(block_obs.getValue(1), 200)
        self.assertEqual(block_obs.getStd(1), 50)
        self.assertEqual(block_obs.getStdScaling(1), 1)

        active_list = ActiveList()
        block_obs.updateStdScaling(0.50, active_list)
        self.assertEqual(block_obs.getStdScaling(0), 0.50)
        self.assertEqual(block_obs.getStdScaling(1), 0.50)

        active_list.addActiveIndex(1)
        block_obs.updateStdScaling(2.00, active_list)
        self.assertEqual(block_obs.getStdScaling(0), 0.50)
        self.assertEqual(block_obs.getStdScaling(1), 2.00)
Пример #3
0
def _active_list_from_index_list(index_list):
    """
    Creates an ActiveList from a list of indexes
    :param index_list: list of index
    :type index_list:  list
    :return: Active list, a c-object with mode (ALL-ACTIVE, PARTIALLY-ACTIVE, INACTIVE) and list of indices
    :rtype: active_list
    """
    active_list = ActiveList()
    [active_list.addActiveIndex(index) for index in index_list]
    return active_list
Пример #4
0
 def test_repr(self):
     al = ActiveList()
     rep = repr(al)
     self.assertFalse("PARTLY_ACTIVE" in rep)
     self.assertTrue("ALL_ACTIVE" in rep)
     pfx = "ActiveList("
     self.assertEqual(pfx, rep[:len(pfx)])
     for i in range(150):
         al.addActiveIndex(3 * i)
     rep = repr(al)
     self.assertTrue("150" in rep)
     self.assertTrue("PARTLY_ACTIVE" in rep)
     self.assertFalse("ALL_ACTIVE" in rep)
Пример #5
0
 def test_repr(self):
     al = ActiveList()
     rep = repr(al)
     self.assertFalse('PARTLY_ACTIVE' in rep)
     self.assertFalse('INACTIVE' in rep)
     self.assertTrue('ALL_ACTIVE' in rep)
     pfx = 'ActiveList('
     self.assertEqual(pfx, rep[:len(pfx)])
     for i in range(150):
         al.addActiveIndex(3 * i)
     rep = repr(al)
     self.assertTrue('150' in rep)
     self.assertTrue('PARTLY_ACTIVE' in rep)
     self.assertFalse('INACTIVE' in rep)
     self.assertFalse('ALL_ACTIVE' in rep)
Пример #6
0
    def test_std_scaling(self):
        sum_obs = SummaryObservation("WWCT:OP_X", "WWCT:OP_X", 0.25, 0.12)

        active_list = ActiveList()
        sum_obs.updateStdScaling(0.50, active_list)
        sum_obs.updateStdScaling(0.125, active_list)
        self.assertEqual(sum_obs.getStdScaling(), 0.125)
Пример #7
0
    def test_create(self):
        data_config = GenDataConfig("KEY")
        with self.assertRaises(ValueError):
            gen_obs = GenObservation("KEY", data_config)

        with TestAreaContext("gen_obs/create"):
            with open("obs1.txt", "w") as f:
                f.write("10  5  12 6\n")

            with self.assertRaises(ValueError):
                gen_obs = GenObservation("KEY",
                                         data_config,
                                         scalar_value=(1, 2),
                                         obs_file="obs1.txt")

            with self.assertRaises(TypeError):
                gen_obs = GenObservation("KEY", data_config, scalar_value=1)

            with self.assertRaises(IOError):
                gen_obs = GenObservation("KEY",
                                         data_config,
                                         obs_file="does/not/exist")

            gen_obs = GenObservation("KEY",
                                     data_config,
                                     obs_file="obs1.txt",
                                     data_index="10,20")
            self.assertEqual(len(gen_obs), 2)
            self.assertEqual(gen_obs[0], (10, 5))
            self.assertEqual(gen_obs[1], (12, 6))

            self.assertEqual(gen_obs.getValue(0), 10)
            self.assertEqual(gen_obs.getDataIndex(1), 20)
            self.assertEqual(gen_obs.getStdScaling(0), 1)
            self.assertEqual(gen_obs.getStdScaling(1), 1)

            active_list = ActiveList()
            gen_obs.updateStdScaling(0.25, active_list)
            self.assertEqual(gen_obs.getStdScaling(0), 0.25)
            self.assertEqual(gen_obs.getStdScaling(1), 0.25)

            active_list.addActiveIndex(1)
            gen_obs.updateStdScaling(2.00, active_list)
            self.assertEqual(gen_obs.getStdScaling(0), 0.25)
            self.assertEqual(gen_obs.getStdScaling(1), 2.00)
Пример #8
0
def test_active_index_list_add_more_active():
    active_list_obj = ActiveList()
    assign_list = [0, 1, 4, 12, 88, 77, 5]
    for index in assign_list:
        active_list_obj.addActiveIndex(index)
    # activate more (partly overlapping already activated )
    index = 1
    active_list_obj.addActiveIndex(index)

    list2 = active_list_obj.get_active_index_list()
    list2.sort()

    assign_list2 = [0, 1, 4, 5, 12, 77, 88]
    assert list2 == assign_list2
Пример #9
0
def test_active_index_list_add_active():
    # add elements, mode is changed to partly active
    active_list_obj = ActiveList()
    assign_list = [0, 1, 4, 12, 88, 77, 5]
    for index in assign_list:
        active_list_obj.addActiveIndex(index)
    mode = active_list_obj.getMode()
    assert mode == ActiveMode.PARTLY_ACTIVE
    list2 = active_list_obj.get_active_index_list()
    # Can not assume that the list is sorted or that it is
    # in the same order as the order the elements are added
    assign_list.sort()
    list2.sort()
    assert assign_list == list2
    default_value = 10
    size = active_list_obj.getActiveSize(default_value)
    assert size == len(list2)
Пример #10
0
    def test_scale_obs(self):
        with ErtTestContext("obs_test", self.config_file) as test_context:
            ert = test_context.getErt()
            obs = ert.getObservations()

            obs1 = obs["WWCT:OP_1"].getNode(50)
            obs2 = obs["WWCT:OP_1_50"].getNode(50)

            self.assertEqual(obs1.getStandardDeviation(),
                             obs2.getStandardDeviation())
            std0 = obs1.getStandardDeviation()

            local_obsdata = LocalObsdata("obs", obs)
            node1 = local_obsdata.addNode("WWCT:OP_1")
            node2 = local_obsdata.addNode("WWCT:OP_1_50")
            node1.addTimeStep(50)
            node2.addTimeStep(50)

            mask = BoolVector(default_value=True)
            mask[2] = True
            meas_data = MeasData(mask)
            obs_data = ObsData()
            fs = ert.getEnkfFsManager().getCurrentFileSystem()
            active_list = IntVector()
            active_list.initRange(0, 2, 1)
            obs.getObservationAndMeasureData(fs, local_obsdata, active_list,
                                             meas_data, obs_data)
            self.assertEqual(2, len(obs_data))

            v1 = obs_data[0]
            v2 = obs_data[1]

            self.assertEqual(v1[1], std0)
            self.assertEqual(v2[1], std0)

            meas_data = MeasData(mask)
            obs_data = ObsData(10)
            obs.getObservationAndMeasureData(fs, local_obsdata, active_list,
                                             meas_data, obs_data)
            self.assertEqual(2, len(obs_data))

            v1 = obs_data[0]
            v2 = obs_data[1]

            self.assertEqual(v1[1], std0 * 10)
            self.assertEqual(v2[1], std0 * 10)

            actl = ActiveList()
            obs1.updateStdScaling(10, actl)
            obs2.updateStdScaling(20, actl)
            meas_data = MeasData(mask)
            obs_data = ObsData()
            obs.getObservationAndMeasureData(fs, local_obsdata, active_list,
                                             meas_data, obs_data)
            self.assertEqual(2, len(obs_data))

            v1 = obs_data[0]
            v2 = obs_data[1]

            self.assertEqual(v1[1], std0 * 10)
            self.assertEqual(v2[1], std0 * 20)
Пример #11
0
 def test_create(self):
     active_list = ActiveList()
     self.assertEqual(active_list.getMode(), ActiveMode.ALL_ACTIVE)
     active_list.addActiveIndex(10)
     self.assertEqual(active_list.getMode(), ActiveMode.PARTLY_ACTIVE)
Пример #12
0
    def test_active_size(self):
        al = ActiveList()
        self.assertEqual(None, al.getActiveSize(None))
        self.assertEqual(7, al.getActiveSize(7))
        self.assertEqual(-1, al.getActiveSize(-1))

        al.addActiveIndex(10)
        self.assertEqual(1, al.getActiveSize(7))
        al.addActiveIndex(10)
        self.assertEqual(1, al.getActiveSize(7))
        al.addActiveIndex(100)
        self.assertEqual(2, al.getActiveSize(7))