Пример #1
0
    def test_custom_kw_config_define_and_read(self):
        data_1 = {"VALUE_1": 123453.3, "VALUE_2": 0.234234}

        data_2 = {"VALUE_1": 965689, "VALUE_3": 1.1222}

        with TestAreaContext("python/enkf/data/custom_kw_config") as test_area:

            self.createResultFile("result_file_1", data_1)
            self.createResultFile("result_file_2", data_2)

            custom_kw_config = CustomKWConfig("CUSTOM_KW", "result_file")

            result_1 = StringList()
            success = custom_kw_config.parseResultFile("result_file_1",
                                                       result_1)
            self.assertTrue(success)

            result_2 = StringList()
            success = custom_kw_config.parseResultFile("result_file_2",
                                                       result_2)
            self.assertFalse(success)

            for key in custom_kw_config:
                self.assertTrue(key in data_1)

            self.assertFalse("VALUE_3" in custom_kw_config)
Пример #2
0
def initializeCurrentCaseFromScratch(parameters, members):
    selected_parameters = StringList(parameters)
    for member in members:
        member = int(member.strip())
        ERT.ert.getEnkfFsManager().initializeFromScratch(selected_parameters, member, member)

    ERT.emitErtChange()
Пример #3
0
    def test_append_ptr(self):
        arg = ArgPack(StringList())
        self.assertEqual(len(arg), 1)

        func = getattr(TEST_LIB, "test_argpack_is_stringlist")
        func.restype = None
        func.argtypes = [ArgPack]

        func(arg)
Пример #4
0
    def test_custom_kw_config_parse_fail(self):
            data = {"KEY_1": "Value Key_2"}

            with TestAreaContext("python/enkf/data/custom_kw_config_fail") as test_area:

                self.createResultFile("result_file", data)

                custom_kw_config = CustomKWConfig("CUSTOM_KW_FAIL", "result_file")
                self.assertIsNone(custom_kw_config.getOutputFile())

                self.assertFalse(custom_kw_config.parseResultFile("result_file", StringList()))
Пример #5
0
def initializeCurrentCaseFromExisting(source_case, target_case, source_report_step, parameters, members):
    if caseExists(source_case) and caseIsInitialized(source_case) and caseExists(target_case):
        total_member_count = getRealizationCount()

        member_mask = BoolVector.createFromList(total_member_count, members)
        selected_parameters = StringList(parameters)

        ERT.ert.getEnkfFsManager().customInitializeCurrentFromExistingCase(source_case, source_report_step, member_mask,
                                                                           selected_parameters)

        ERT.emitErtChange()
Пример #6
0
    def load(cls,
             smspec_file,
             unsmry_file,
             key_join_string=":",
             include_restart=True):
        if not os.path.isfile(smspec_file):
            raise IOError("No such file: %s" % smspec_file)

        if not os.path.isfile(unsmry_file):
            raise IOError("No such file: %s" % unsmry_file)

        data_files = StringList()
        data_files.append(unsmry_file)
        c_ptr = cls._fread_alloc(smspec_file, data_files, key_join_string,
                                 include_restart)
        if c_ptr is None:
            raise IOError("Failed to create summary instance")

        ecl_sum = cls.createPythonObject(c_ptr)
        ecl_sum._load_case = smspec_file
        return ecl_sum
Пример #7
0
    def test_create(self):
        arg = ArgPack()
        self.assertEqual(len(arg), 0)

        arg.append(StringList())
        self.assertEqual(len(arg), 1)

        arg.append(3.14)
        self.assertEqual(len(arg), 2)

        o = object()
        with self.assertRaises(TypeError):
            arg.append(o)
Пример #8
0
    def keys(self, pattern=None):
        """
        Return a StringList of summary keys matching @pattern.

        The matching algorithm is ultimately based on the fnmatch()
        function, i.e. normal shell-character syntax is used. With
        @pattern == "WWCT:*" you will get a list of watercut keys for
        all wells.

        If pattern is None you will get all the keys of summary
        object.
        """
        s = StringList()
        self._select_matching_keys(pattern, s)
        return s
Пример #9
0
    def test_custom_kw_config_multiple_identical_keys(self):
            data = {"VALUE_1": 2345.234,
                    "VALUE_2": 0.001234,
                    "VALUE_3": "string_1",
                    "VALUE_4": "string_2 VALUE_4 repeat_of_value_4"}

            with TestAreaContext("python/enkf/data/custom_kw_config_multiple_identical_keys") as test_area:

                self.createResultFile("result_file", data)

                custom_kw_config = CustomKWConfig("CUSTOM_KW", "result_file")

                result = StringList()
                success = custom_kw_config.parseResultFile("result_file", result)
                self.assertTrue(success)

                index_of_value_4 = custom_kw_config.indexOfKey("VALUE_4")
                self.assertEqual(result[index_of_value_4], "repeat_of_value_4")
Пример #10
0
    def test_custom_kw_config_creation(self):
        data = {
            "VALUE_1": 2345.234,
            "VALUE_2": 0.001234,
            "VALUE_3": "string_1",
            "VALUE_4": "string_2"
        }

        with TestAreaContext("python/enkf/data/custom_kw_config") as test_area:

            self.createResultFile("result_file", data)

            custom_kw_config = CustomKWConfig("CUSTOM_KW", "result_file",
                                              "output_file")

            self.assertEqual(custom_kw_config.getName(), "CUSTOM_KW")
            self.assertEqual(custom_kw_config.getResultFile(), "result_file")
            self.assertEqual(custom_kw_config.getOutputFile(), "output_file")

            self.assertEqual(len(custom_kw_config), 0)

            result = StringList()
            success = custom_kw_config.parseResultFile("result_file", result)
            self.assertTrue(success)

            self.assertEqual(len(custom_kw_config), 4)

            for index, key in enumerate(data):
                self.assertTrue(key in custom_kw_config)

                key_is_string = isinstance(data[key], str)
                self.assertTrue(
                    custom_kw_config.keyIsDouble(key) != key_is_string)
                self.assertEqual(index, custom_kw_config.indexOfKey(key))

                self.assertEqual(result[index], str(data[key]))

            self.assertTrue(len(custom_kw_config.getKeys()) == 4)

            for key in custom_kw_config:
                self.assertTrue(key in data)
Пример #11
0
    def export_csv(self, filename, keys=None, date_format="%Y-%m-%d", sep=";"):
        """Will create a CSV file with summary data.

        By default all the vectors in the summary case will be
        exported, but by using the optional keys parameter you can
        limit the keys which are exported:

          ecl_sum = EclSum("CASE")
          ecl_sum.exportCSV("case.csv", keys=["W*:OP1", "W*:OP2", "F*T"])

        Will export all well related variables for wells 'OP1' and
        'OP2' and all total field vectors.
        """

        if keys is None:
            var_list = self.keys()
        else:
            var_list = StringList()
            for key in keys:
                var_list |= self.keys(pattern=key)
        self._export_csv(filename, var_list, date_format, sep)
Пример #12
0
    def _build_config_content(self, config):
        self._failed_keys = {}
        defines, config_dir, config_list = self._extract_config(config)

        config_parser  = ConfigParser()
        ResConfig.init_config_parser(config_parser)
        config_content = ConfigContent(None)
        config_content.setParser(config_parser)

        # Insert defines
        for key in defines:
            config_content.add_define(key, defines[key])

        # Insert key values
        if not os.path.exists( config_dir ):
            raise IOError("The configuration direcetory: %s does not exist" % config_dir)
        
        path_elm = config_content.create_path_elm(config_dir)
        add_key_value = lambda key, value : config_parser.add_key_value(
                                                            config_content,
                                                            key,
                                                            StringList([key] + value),
                                                            path_elm=path_elm)

        for key, value in config_list:
            if isinstance(value, str):
                value = [value]
            if not isinstance(value, list):
                raise ValueError("Expected value to be str or list, was %r" % (type(value)))

            ok = add_key_value(key, value)
            if not ok:
                self._failed_keys[key] = value

        config_parser.validate(config_content)
        self._errors = list(config_content.getErrors())

        return config_content
Пример #13
0
    def _build_config_content(self, config):
        self._failed_keys = {}
        defines, config_dir, config_list = self._extract_config(config)

        config_parser = ConfigParser()
        ResConfig.init_config_parser(config_parser)
        config_content = ConfigContent(None)
        config_content.setParser(config_parser)

        if config_dir is None:
            raise ValueError("Expected config to specify %s" %
                             ConfigKeys.CONFIG_DIRECTORY)

        # Insert defines
        for key in defines:
            config_content.add_define(key, defines[key])

        # Insert key values
        path_elm = config_content.create_path_elm(config_dir)
        add_key_value = lambda key, value: config_parser.add_key_value(
            config_content, key, StringList([key] + value), path_elm=path_elm)

        for key, value in config_list:
            if isinstance(value, str):
                value = [value]
            if not isinstance(value, list):
                raise ValueError("Expected value to be str or list, was %r" %
                                 (type(value)))

            ok = add_key_value(key, value)
            if not ok:
                self._failed_keys[key] = value

        config_parser.validate(config_content)
        self._errors = list(config_content.getErrors())

        return config_content
Пример #14
0
 def create_ext_param(cls, key, key_list, output_file=None):
     keys = StringList(initial=key_list)
     return cls._alloc_ext_param_node(key, keys, output_file)
Пример #15
0
 def __init__(self, key, input_keys):
     keys = StringList(initial=input_keys)
     c_ptr = self._alloc(key, keys)
     super(ExtParamConfig, self).__init__(c_ptr)