Exemple #1
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)
Exemple #2
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()
    for index in index_list:
        active_list.addActiveIndex(index)
    return active_list
Exemple #3
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)
Exemple #4
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
Exemple #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)
Exemple #6
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)
Exemple #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)
Exemple #8
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))
Exemple #9
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)