Exemplo n.º 1
0
    def test_create(self):
        ensemble_config = EnsembleConfig()
        obs = EnkfObs(ensemble_config)
        self.assertEqual(len(obs), 0)

        self.assertFalse(obs.valid)
        with self.assertRaises(ValueError):
            obs.load(self.obs_config)
        self.assertEqual(len(obs), 0)

        time_map = TimeMap()
        obs = EnkfObs(ensemble_config, external_time_map=time_map)
        self.assertEqual(len(obs), 0)

        grid = EclGrid(self.grid)
        refcase = EclSum(self.refcase)

        history = History(refcase, False)
        obs = EnkfObs(ensemble_config, grid=grid, history=history)
        self.assertTrue(obs.valid)
        with self.assertRaises(IOError):
            obs.load("/does/not/exist")

        obs.load(self.obs_config)
        self.assertTrue(obs.valid)
        self.assertEqual(len(obs), 33)
        obs.clear()
        self.assertEqual(len(obs), 0)

        obs.load(self.obs_config)
        self.assertEqual(len(obs), 33)
        self.assertNotIn("RFT2", obs)
        obs.load(self.obs_config2)
        self.assertEqual(len(obs), 35)
        self.assertIn("RFT2", obs)
Exemplo n.º 2
0
    def test_create(self):
        conf = EnsembleConfig( )
        self.assertEqual( len(conf) , 0 )
        self.assertFalse( "XYZ" in conf )

        with self.assertRaises(KeyError):
            node = conf["KEY"]
Exemplo n.º 3
0
    def _alloc_from_dict(self, config_dict, throw_on_error=True):
        # treat the default config dir
        config_dir = os.getcwd()
        if ConfigKeys.CONFIG_DIRECTORY in config_dict:
            config_dir = config_dict[ConfigKeys.CONFIG_DIRECTORY]
        config_dict[ConfigKeys.CONFIG_DIRECTORY] = config_dir

        subst_config = SubstConfig(config_dict=config_dict)
        site_config = SiteConfig(config_dict=config_dict)
        rng_config = RNGConfig(config_dict=config_dict)
        analysis_config = AnalysisConfig(config_dict=config_dict)
        ecl_config = EclConfig(config_dict=config_dict)
        log_config = LogConfig(config_dict=config_dict)
        queue_config = QueueConfig(config_dict=config_dict)

        ert_workflow_list = ErtWorkflowList(
            subst_list=subst_config.subst_list, config_dict=config_dict
        )

        hook_manager = HookManager(
            workflow_list=ert_workflow_list, config_dict=config_dict
        )

        ert_templates = ErtTemplates(
            parent_subst=subst_config.subst_list, config_dict=config_dict
        )

        ensemble_config = EnsembleConfig(
            grid=ecl_config.getGrid(),
            refcase=ecl_config.getRefcase(),
            config_dict=config_dict,
        )

        model_config = ModelConfig(
            data_root=config_dir,
            joblist=site_config.get_installed_jobs(),
            last_history_restart=ecl_config.getLastHistoryRestart(),
            refcase=ecl_config.getRefcase(),
            config_dict=config_dict,
        )

        return [
            subst_config,
            site_config,
            rng_config,
            analysis_config,
            ert_workflow_list,
            hook_manager,
            ert_templates,
            ecl_config,
            ensemble_config,
            model_config,
            log_config,
            queue_config,
        ], config_dir
Exemplo n.º 4
0
    def _alloc_from_content(self,
                            user_config_file=None,
                            config=None,
                            throw_on_error=True):
        if user_config_file is not None:
            # initialize configcontent if user_file provided
            parser = ConfigParser()
            config_content = self._alloc_config_content(
                user_config_file, parser)
            config_dir = config_content.getValue(ConfigKeys.CONFIG_DIRECTORY)
        else:
            config_dir = os.getcwd()
            config_content = self._build_config_content(config)

        if self.errors and throw_on_error:
            raise ValueError("Error loading configuration: " +
                             str(self._errors))

        subst_config = SubstConfig(config_content=config_content)
        site_config = SiteConfig(config_content=config_content)
        rng_config = RNGConfig(config_content=config_content)
        analysis_config = AnalysisConfig(config_content=config_content)
        ecl_config = EclConfig(config_content=config_content)
        log_config = LogConfig(config_content=config_content)
        queue_config = QueueConfig(config_content=config_content)

        ert_workflow_list = ErtWorkflowList(subst_list=subst_config.subst_list,
                                            config_content=config_content)

        hook_manager = HookManager(workflow_list=ert_workflow_list,
                                   config_content=config_content)

        ert_templates = ErtTemplates(parent_subst=subst_config.subst_list,
                                     config_content=config_content)

        ensemble_config = EnsembleConfig(config_content=config_content,
                                         grid=ecl_config.getGrid(),
                                         refcase=ecl_config.getRefcase())

        model_config = ModelConfig(
            data_root=config_dir,
            joblist=site_config.get_installed_jobs(),
            last_history_restart=ecl_config.getLastHistoryRestart(),
            refcase=ecl_config.getRefcase(),
            config_content=config_content)

        return [
            subst_config, site_config, rng_config, analysis_config,
            ert_workflow_list, hook_manager, ert_templates, ecl_config,
            ensemble_config, model_config, log_config, queue_config
        ], config_dir
Exemplo n.º 5
0
    def test_ensemble_config_constructor(self):
        config_dict = {
            ConfigKeys.GEN_KW_TAG_FORMAT:
            "<%s>",
            ConfigKeys.GEN_PARAM: [
                {
                    ConfigKeys.NAME: "GP",
                    ConfigKeys.FORWARD_INIT: False,
                    ConfigKeys.INPUT_FORMAT: GenDataFileType.ASCII,
                    ConfigKeys.OUTPUT_FORMAT: GenDataFileType.ASCII,
                    ConfigKeys.INIT_FILES: "GP/GP.txt",
                    ConfigKeys.ECL_FILE: "GP.txt",
                    ConfigKeys.MIN_STD: None,
                    ConfigKeys.TEMPLATE: None,
                    ConfigKeys.KEY_KEY: None,
                },
            ],
            ConfigKeys.GEN_DATA: [
                {
                    ConfigKeys.NAME: "SNAKE_OIL_OPR_DIFF",
                    ConfigKeys.INPUT_FORMAT: GenDataFileType.ASCII,
                    ConfigKeys.RESULT_FILE: "snake_oil_opr_diff_%d.txt",
                    ConfigKeys.REPORT_STEPS: [199],
                    ConfigKeys.INIT_FILES: None,
                    ConfigKeys.ECL_FILE: None,
                    ConfigKeys.TEMPLATE: None,
                    ConfigKeys.KEY_KEY: None,
                },
                {
                    ConfigKeys.NAME: "SNAKE_OIL_GPR_DIFF",
                    ConfigKeys.INPUT_FORMAT: GenDataFileType.ASCII,
                    ConfigKeys.RESULT_FILE: "snake_oil_gpr_diff_%d.txt",
                    ConfigKeys.REPORT_STEPS: [199],
                    ConfigKeys.INIT_FILES: None,
                    ConfigKeys.ECL_FILE: None,
                    ConfigKeys.TEMPLATE: None,
                    ConfigKeys.KEY_KEY: None,
                },
            ],
            ConfigKeys.GEN_KW: [{
                ConfigKeys.NAME: "MULTFLT",
                ConfigKeys.TEMPLATE: "configuration_tests/FAULT_TEMPLATE",
                ConfigKeys.OUT_FILE: "MULTFLT.INC",
                ConfigKeys.PARAMETER_FILE: "configuration_tests/MULTFLT.TXT",
                ConfigKeys.INIT_FILES: None,
                ConfigKeys.MIN_STD: None,
                ConfigKeys.FORWARD_INIT: False,
            }],
            ConfigKeys.SURFACE_KEY: [{
                ConfigKeys.NAME: "TOP",
                ConfigKeys.INIT_FILES:
                "configuration_tests/surface/small.irap",
                ConfigKeys.OUT_FILE:
                "configuration_tests/surface/small_out.irap",
                ConfigKeys.BASE_SURFACE_KEY:
                "configuration_tests/surface/small.irap",
                ConfigKeys.MIN_STD: None,
                ConfigKeys.FORWARD_INIT: False,
            }],
            ConfigKeys.SUMMARY: ["WOPR:OP_1"],
            ConfigKeys.FIELD_KEY: [{
                ConfigKeys.NAME: "PERMX",
                ConfigKeys.VAR_TYPE: "PARAMETER",
                ConfigKeys.INIT_FILES: "fields/permx%d.grdecl",
                ConfigKeys.OUT_FILE: "permx.grdcel",
                ConfigKeys.ENKF_INFILE: None,
                ConfigKeys.INIT_TRANSFORM: None,
                ConfigKeys.OUTPUT_TRANSFORM: None,
                ConfigKeys.INPUT_TRANSFORM: None,
                ConfigKeys.MIN_KEY: None,
                ConfigKeys.MAX_KEY: None,
                ConfigKeys.MIN_STD: None,
                ConfigKeys.FORWARD_INIT: False,
            }],
            ConfigKeys.SCHEDULE_PREDICTION_FILE: [{
                ConfigKeys.TEMPLATE:
                "configuration_tests/input/schedule.sch",
                ConfigKeys.INIT_FILES:
                None,
                ConfigKeys.MIN_STD:
                None,
                ConfigKeys.PARAMETER_KEY:
                None,
            }],
            ConfigKeys.CONTAINER_KEY: [{
                ConfigKeys.NAME: "CXX",
                ConfigKeys.ARGLIST: ["PERMX", "MULTFLT"]
            }],
        }

        self.case_directory = self.createTestPath("local/configuration_tests/")
        with TestAreaContext("ensemble_config_test") as work_area:
            work_area.copy_directory(self.case_directory)
            res_config = ResConfig("configuration_tests/ensemble_config.ert")
            ensemble_config_file = res_config.ensemble_config
            ensemble_config_dict = EnsembleConfig(
                config_dict=config_dict, grid=res_config.ecl_config.getGrid())
            self.assertEqual(ensemble_config_dict, ensemble_config_file)
Exemplo n.º 6
0
    def __init__(self,
                 user_config_file=None,
                 config=None,
                 throw_on_error=True):

        self._errors, self._failed_keys = None, None
        self._assert_input(user_config_file, config, throw_on_error)

        if config is not None:
            config_content = self._build_config_content(config)
        elif user_config_file is not None:

            parser = ConfigParser()

            config_content = self._alloc_config_content(
                user_config_file, parser)
        else:
            raise ValueError("No config provided")

        if self.errors and throw_on_error:
            raise ValueError("Error loading configuration: " +
                             str(self._errors))

        config_dir = config_content.getValue(ConfigKeys.CONFIG_DIRECTORY)

        subst_config = SubstConfig(config_content=config_content)
        site_config = SiteConfig(config_content=config_content)
        rng_config = RNGConfig(config_content=config_content)
        analysis_config = AnalysisConfig(config_content=config_content)
        ecl_config = EclConfig(config_content=config_content)
        log_config = LogConfig(config_content=config_content)
        queue_config = QueueConfig(config_content=config_content)

        ert_workflow_list = ErtWorkflowList(
            ert_workflow_list=subst_config.subst_list,
            config_content=config_content)

        hook_manager = HookManager(workflow_list=ert_workflow_list,
                                   config_content=config_content)

        ert_templates = ErtTemplates(parent_subst=subst_config.subst_list,
                                     config_content=config_content)

        ensemble_config = EnsembleConfig(config_content=config_content,
                                         grid=ecl_config.getGrid(),
                                         refcase=ecl_config.getRefcase())

        model_config = ModelConfig(
            config_content=config_content,
            data_root=config_dir,
            joblist=site_config.get_installed_jobs(),
            last_history_restart=ecl_config.getLastHistoryRestart(),
            sched_file=ecl_config._get_sched_file(),
            refcase=ecl_config.getRefcase())

        configs = [
            subst_config, site_config, rng_config, analysis_config,
            ert_workflow_list, hook_manager, ert_templates, ecl_config,
            ensemble_config, model_config, log_config, queue_config
        ]

        c_ptr = None

        for conf in configs:
            conf.convertToCReference(None)
        c_ptr = self._alloc_full(config_dir, user_config_file, *configs)

        if c_ptr:
            super(ResConfig, self).__init__(c_ptr)
        else:
            raise ValueError(
                'Failed to construct ResConfig instance from %r.' %
                (user_config_file if user_config_file else config))
Exemplo n.º 7
0
    def test_ensemble_config_constructor(self):
        config_dict = {
            ConfigKeys.GEN_KW_TAG_FORMAT:
            '<%s>',
            ConfigKeys.GEN_PARAM: [
                {
                    ConfigKeys.NAME: 'GP',
                    ConfigKeys.FORWARD_INIT: False,
                    ConfigKeys.INPUT_FORMAT: GenDataFileType.ASCII,
                    ConfigKeys.OUTPUT_FORMAT: GenDataFileType.ASCII,
                    ConfigKeys.INIT_FILES: 'GP/GP.txt',
                    ConfigKeys.ECL_FILE: 'GP.txt',
                    ConfigKeys.MIN_STD: None,
                    ConfigKeys.TEMPLATE: None,
                    ConfigKeys.KEY_KEY: None
                },
            ],
            ConfigKeys.GEN_DATA: [{
                ConfigKeys.NAME: 'SNAKE_OIL_OPR_DIFF',
                ConfigKeys.INPUT_FORMAT: GenDataFileType.ASCII,
                ConfigKeys.RESULT_FILE: 'snake_oil_opr_diff_%d.txt',
                ConfigKeys.REPORT_STEPS: [199],
                ConfigKeys.INIT_FILES: None,
                ConfigKeys.ECL_FILE: None,
                ConfigKeys.TEMPLATE: None,
                ConfigKeys.KEY_KEY: None
            }, {
                ConfigKeys.NAME: 'SNAKE_OIL_GPR_DIFF',
                ConfigKeys.INPUT_FORMAT: GenDataFileType.ASCII,
                ConfigKeys.RESULT_FILE: 'snake_oil_gpr_diff_%d.txt',
                ConfigKeys.REPORT_STEPS: [199],
                ConfigKeys.INIT_FILES: None,
                ConfigKeys.ECL_FILE: None,
                ConfigKeys.TEMPLATE: None,
                ConfigKeys.KEY_KEY: None
            }],
            ConfigKeys.CUSTOM_KW: [{
                ConfigKeys.NAME: 'SNAKE_OIL_NPV',
                ConfigKeys.RESULT_FILE: 'snake_oil_npv.txt',
                ConfigKeys.OUT_FILE: None
            }],
            ConfigKeys.GEN_KW: [{
                ConfigKeys.NAME: 'MULTFLT',
                ConfigKeys.TEMPLATE: 'configuration_tests/FAULT_TEMPLATE',
                ConfigKeys.OUT_FILE: 'MULTFLT.INC',
                ConfigKeys.PARAMETER_FILE: 'configuration_tests/MULTFLT.TXT',
                ConfigKeys.INIT_FILES: None,
                ConfigKeys.MIN_STD: None,
                ConfigKeys.FORWARD_INIT: False,
            }],
            ConfigKeys.SURFACE_KEY: [{
                ConfigKeys.NAME: 'TOP',
                ConfigKeys.INIT_FILES:
                'configuration_tests/surface/small.irap',
                ConfigKeys.OUT_FILE:
                'configuration_tests/surface/small_out.irap',
                ConfigKeys.BASE_SURFACE_KEY:
                'configuration_tests/surface/small.irap',
                ConfigKeys.MIN_STD: None,
                ConfigKeys.FORWARD_INIT: False
            }],
            ConfigKeys.SUMMARY: [{
                ConfigKeys.NAME: 'WOPR:OP_1'
            }],
            ConfigKeys.FIELD_KEY: [{
                ConfigKeys.NAME: 'PERMX',
                ConfigKeys.VAR_TYPE: 'PARAMETER',
                ConfigKeys.INIT_FILES: 'fields/permx%d.grdecl',
                ConfigKeys.OUT_FILE: 'permx.grdcel',
                ConfigKeys.ENKF_INFILE: None,
                ConfigKeys.INIT_TRANSFORM: None,
                ConfigKeys.OUTPUT_TRANSFORM: None,
                ConfigKeys.INPUT_TRANSFORM: None,
                ConfigKeys.MIN_KEY: None,
                ConfigKeys.MAX_KEY: None,
                ConfigKeys.MIN_STD: None,
                ConfigKeys.FORWARD_INIT: False
            }],
            ConfigKeys.SCHEDULE_PREDICTION_FILE: [{
                ConfigKeys.TEMPLATE:
                'configuration_tests/input/schedule.sch',
                ConfigKeys.INIT_FILES:
                None,
                ConfigKeys.MIN_STD:
                None,
                ConfigKeys.PARAMETER_KEY:
                None
            }],
            ConfigKeys.CONTAINER_KEY: [{
                ConfigKeys.NAME: 'CXX',
                ConfigKeys.ARGLIST: ['PERMX', 'MULTFLT']
            }]
        }

        self.case_directory = self.createTestPath("local/configuration_tests/")
        with TestAreaContext("ensemble_config_test") as work_area:
            work_area.copy_directory(self.case_directory)
            res_config = ResConfig('configuration_tests/ensemble_config.ert')
            ensemble_config_file = res_config.ensemble_config
            ensemble_config_dict = EnsembleConfig(
                config_dict=config_dict, grid=res_config.ecl_config.getGrid())
            self.assertEqual(ensemble_config_dict, ensemble_config_file)