Beispiel #1
0
    def _initializeRealization(self, target_fs, geo_id, iens, keywords):
        ens_config = self.ert.ensembleConfig()

        for kw in ens_config.getKeylistFromVarType(EnkfVarType.PARAMETER):
            if not kw in keywords:
                config_node = ens_config[kw]
                data_node = EnkfNode(config_node)
                init_id = NodeId(0, geo_id)
                run_id = NodeId(0, iens)
                data_node.load(self._getInitializationCase(), init_id)
                data_node.save(target_fs, run_id)

        for key, values in keywords.items():
            config_node = ens_config[key]
            data_node = EnkfNode(config_node)

            gen_kw = data_node.asGenKw()
            gen_kw.setValues(values)

            run_id = NodeId(0, iens)
            data_node.save(target_fs, run_id)

        target_fs.fsync()
        state_map = target_fs.getStateMap()
        state_map[iens] = RealizationStateEnum.STATE_INITIALIZED
Beispiel #2
0
    def handleADD_SIMULATION(self, args):
        geo_id = args[0]
        pert_id = args[1]
        iens = args[2]
        kw_list = args[3]
        state = self.ert_handle.getRealisation(iens)
        state.addSubstKeyword("GEO_ID", "%s" % geo_id)

        elco_kw = [l[0] for l in kw_list]
        ens_config = self.ert_handle.ensembleConfig()

        for kw in ens_config.getKeylistFromVarType(EnkfVarType.PARAMETER):
            if not kw in elco_kw:
                node = state[kw]
                init_id = NodeId(0, geo_id, EnkfStateType.ANALYZED)
                run_id = NodeId(0, iens, EnkfStateType.ANALYZED)
                node.load(self.init_fs, init_id)
                node.save(self.run_fs, run_id)

        for kw_arg in kw_list:
            kw = str(kw_arg[0])
            data = kw_arg[1:]

            node = state[kw]
            gen_kw = node.asGenKw()
            gen_kw.setValues(data)

            run_id = NodeId(0, iens, EnkfStateType.ANALYZED)
            node.save(self.run_fs, run_id)

        state_map = self.run_fs.getStateMap()
        state_map[iens] = RealizationStateEnum.STATE_INITIALIZED

        self.run_context.startSimulation(iens)
        return self.handleSTATUS([])
Beispiel #3
0
    def load_active_masks(self, case1, case2):
        with ErtTestContext("gen_data_config_test",
                            self.config_file) as test_context:
            ert = test_context.getErt()

            fs1 = ert.getEnkfFsManager().getFileSystem(case1)
            config_node = ert.ensembleConfig().getNode("TIMESHIFT")
            data_node = EnkfNode(config_node)
            data_node.tryLoad(fs1, NodeId(60, 0))

            active_mask = self._get_active_mask(
                config_node.getDataModelConfig())
            first_active_mask_length = len(active_mask)
            self.assertEqual(first_active_mask_length, 2560)

            fs2 = ert.getEnkfFsManager().getFileSystem(case2)
            data_node = EnkfNode(config_node)
            data_node.tryLoad(fs2, NodeId(60, 0))

            active_mask = self._get_active_mask(
                config_node.getDataModelConfig())
            second_active_mask_len = len(active_mask)
            self.assertEqual(second_active_mask_len, 2560)
            self.assertEqual(first_active_mask_length, second_active_mask_len)

            # Setting one element to False, load different case, check, reload, and check.
            self.assertTrue(active_mask[10])
            active_mask_modified = active_mask.copy()
            active_mask_modified[10] = False

            self.updateMask(config_node.getDataModelConfig(), 60, fs2,
                            active_mask_modified)
            active_mask = self._get_active_mask(
                config_node.getDataModelConfig())
            self.assertFalse(active_mask[10])

            #Load first - check element is true
            data_node = EnkfNode(config_node)
            data_node.tryLoad(fs1, NodeId(60, 0))
            active_mask = self._get_active_mask(
                config_node.getDataModelConfig())
            self.assertTrue(active_mask[10])

            # Reload second again, should now be false at 10, due to the update further up
            data_node = EnkfNode(config_node)
            data_node.tryLoad(fs2, NodeId(60, 0))
            active_mask = self._get_active_mask(
                config_node.getDataModelConfig())
            self.assertFalse(active_mask[10])
Beispiel #4
0
    def exportGenData(self, keyword, path, iactive, file_type, report_step,
                      selected_case):
        """
        @type keyword: str
        @type path: str
        @type iactive: BoolVector
        @type file_type: EnkfFieldFileFormatEnum
        @type report_step: int
        @type selected_case: str
        """
        fs = ERT.ert.getEnkfFsManager().getFileSystem(selected_case)
        config_node = ERT.ert.ensembleConfig().getNode(keyword)
        gen_data_config_node = config_node.getDataModelConfig()

        export_type = gen_data_config_node.getOutputFormat()
        if export_type == GenDataFileType.GEN_DATA_UNDEFINED:
            export_type = gen_data_config_node.getInputFormat()

        node = EnkfNode(config_node)

        for index, active in enumerate(iactive):
            if active:
                node_id = NodeId(int(report_step), index)

                if node.tryLoad(fs, node_id):
                    gen_data = node.asGenData()

                    filename = str(path + "/" + keyword +
                                   "_{0}").format(index) + ".txt"
                    gen_data.export(filename, export_type, None)
Beispiel #5
0
    def exportGenKw(self, keyword, path, iactive, file_type, report_step,
                    selected_case):
        """
        @type keyword: str
        @type path: str
        @type iactive: BoolVector
        @type file_type: EnkfFieldFileFormatEnum
        @type report_step: int
        @type selected_case: str
        """
        enkf_config_node = ERT.ert.ensembleConfig().getNode(keyword)
        assert isinstance(enkf_config_node, EnkfConfigNode)
        node = EnkfNode(enkf_config_node)
        fs = ERT.ert.getEnkfFsManager().getFileSystem(selected_case)

        for index, value in enumerate(iactive):
            if value:
                if node.tryLoad(fs, NodeId(report_step, index)):
                    gen_kw = GenKw.createCReference(node.valuePointer())
                    filename = str(path + "/" + keyword + "_{0}").format(index)
                    if file_type == "Parameter list":
                        filename += ".txt"
                        gen_kw.exportParameters(filename)
                    else:
                        filename += ".inc"
                        gen_kw.exportTemplate(filename)
Beispiel #6
0
    def handleGET_RESULT(self, args):
        iens = args[0]
        kw = str(args[2])

        try:
            year, month, day = args[1]
            time_map = self.run_fs.getTimeMap()
            report_step = time_map.lookupTime(
                datetime.date(year, month, day),
                tolerance_seconds_before=24 * 3600,
                tolerance_seconds_after=24 * 3600)
        except TypeError:
            report_step = args[1]

        ensembleConfig = self.ert_handle.ensembleConfig()
        if kw in ensembleConfig:
            state = self.ert_handle.getRealisation(iens)
            node = state[kw]
            gen_data = node.asGenData()

            fs = self.ert_handle.getEnkfFsManager().getCurrentFileSystem()
            node_id = NodeId(report_step, iens, EnkfStateType.FORECAST)
            if node.tryLoad(fs, node_id):
                data = gen_data.getData()
                return self.SUCCESS(["OK"] + data.asList())
            else:
                raise Exception("Loading iens:%d  report:%d   kw:%s   failed" %
                                (iens, report_step, kw))
        else:
            raise KeyError("The keyword:%s is not recognized" % kw)
Beispiel #7
0
    def getCustomKWResult(self, target_case_name, iens, keyword):
        ensemble_config = self.ert.ensembleConfig()

        if not self.isRealizationFinished(iens):
            raise createFault(
                UserWarning,
                "The simulation with id: %d is still running." % iens)

        if keyword in ensemble_config:
            enkf_config_node = self.ert.ensembleConfig().getNode(keyword)
            node = EnkfNode(enkf_config_node)

            if not node.getImplType() == ErtImplType.CUSTOM_KW:
                raise createFault(UserWarning,
                                  "The keyword is not a CustomKW keyword.")

            custom_kw = node.asCustomKW()

            fs = self.ert.getEnkfFsManager().getFileSystem(target_case_name)
            node_id = NodeId(0, iens)
            if node.tryLoad(fs, node_id):
                config = custom_kw.getConfig()
                result = {}
                for key in config.getKeys():
                    result[key] = custom_kw[key]
                return result
            else:
                raise createFault(
                    UserWarning,
                    "Unable to load data for iens: %d kw: %s for case: %s" %
                    (iens, keyword, target_case_name))
        else:
            raise createFault(KeyError,
                              "The keyword: %s is not recognized" % keyword)
Beispiel #8
0
    def getGenDataResult(self, target_case_name, iens, report_step, keyword):
        ensemble_config = self.ert.ensembleConfig()

        if not self.isRealizationFinished(iens):
            raise createFault(
                UserWarning,
                "The simulation with id: %d is still running." % iens)

        if keyword in ensemble_config:
            enkf_config_node = self.ert.ensembleConfig().getNode(keyword)
            node = EnkfNode(enkf_config_node)

            if not node.getImplType() == ErtImplType.GEN_DATA:
                raise createFault(UserWarning,
                                  "The keyword is not a GenData keyword.")

            gen_data = node.asGenData()

            fs = self.ert.getEnkfFsManager().getFileSystem(target_case_name)
            node_id = NodeId(report_step, iens)
            if node.tryLoad(fs, node_id):
                data = gen_data.getData()
                return data.asList()
            else:
                raise createFault(
                    UserWarning,
                    "Unable to load data for iens: %d report_step: %d kw: %s for case: %s"
                    % (iens, report_step, keyword, target_case_name))
        else:
            raise createFault(KeyError,
                              "The keyword: %s is not recognized" % keyword)
Beispiel #9
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)
Beispiel #10
0
    def _storeData(self, enkf_node, fs, group_name, keyword, value, realization_number):
        node_id = NodeId(0, realization_number)
        enkf_node.tryLoad(fs, node_id)  # Fetch any data from previous store calls
        custom_kw = enkf_node.asCustomKW()
        custom_kw[keyword] = value

        if not enkf_node.save(fs, node_id):
            raise createFault(UserWarning, "Unable to store data for group: '%s' and key: '%s' into realization: '%d'" % (group_name, keyword, realization_number))
Beispiel #11
0
 def exportMany(cls , config_node , file_format , fs , iens_list  , state = EnkfStateType.ANALYZED , report_step = 0 , file_type = None , arg = None):
     node = EnkfNode( config_node )
     for iens in iens_list:
         filename = file_format % iens
         node_id = NodeId( report_step , iens , state )
         if node.tryLoad(fs , node_id):
             if node.export( filename , file_type = file_type , arg = arg):
                 print("%s[%03d] -> %s" % (config_node.getKey() , iens , filename))
         else:
             sys.stderr.write("** ERROR: Could not load realisation:%d - export failed" % iens)
Beispiel #12
0
    def test_field_export(self):
        with ErtTestContext("export_test", self.config_file) as test_context:
            ert = test_context.getErt()
            fs_manager = ert.getEnkfFsManager()
            ens_config = ert.ensembleConfig()
            config_node = ens_config["PERMX"]
            data_node = EnkfNode(config_node)
            node_id = NodeId(0, 0)
            fs = fs_manager.getCurrentFileSystem()
            data_node.tryLoad(fs, node_id)

            data_node.export("export/with/path/PERMX.grdecl")
            self.assertTrue(os.path.isfile("export/with/path/PERMX.grdecl"))
Beispiel #13
0
    def _initializeRealization(self, target_fs, geo_id, iens, keywords):
        state = self.ert.getRealisation(iens)
        ens_config = self.ert.ensembleConfig()

        for kw in ens_config.getKeylistFromVarType(EnkfVarType.PARAMETER):
            if not kw in keywords:
                node = state[kw]
                init_id = NodeId(0, geo_id, EnkfStateType.ANALYZED)
                run_id = NodeId(0, iens, EnkfStateType.ANALYZED)
                node.load(self._getInitializationCase(), init_id)
                node.save(target_fs, run_id)

        for key, value in keywords.iteritems():
            node = state[key]
            gen_kw = node.asGenKw()
            gen_kw.setValues(value)

            run_id = NodeId(0, iens, EnkfStateType.ANALYZED)
            node.save(target_fs, run_id)

        target_fs.fsync()
        state_map = target_fs.getStateMap()
        state_map[iens] = RealizationStateEnum.STATE_INITIALIZED
Beispiel #14
0
    def handleGET_RESULT(self, args):
        iens = args[0]
        report_step = args[1]
        kw = str(args[2])

        ensembleConfig = self.ert_handle.ensembleConfig()
        if ensembleConfig.hasKey(kw):
            state = self.ert_handle.getRealisation(iens)
            node = state[kw]
            gen_data = node.asGenData()

            fs = self.ert_handle.getEnkfFsManager().getCurrentFileSystem()
            node_id = NodeId(report_step, iens, EnkfStateType.FORECAST)
            if node.tryLoad(fs, node_id):
                data = gen_data.getData()
                return self.SUCCESS(["OK"] + data.asList())
            else:
                raise Exception("Loading iens:%d  report:%d   kw:%s   failed" %
                                (iens, report_step, kw))
        else:
            raise KeyError("The keyword:%s is not recognized" % kw)
Beispiel #15
0
    def loadAllCustomKWData(ert, case_name, keys=None):
        """
        @type ert: EnKFMain
        @type case_name: str
        @type keys: list of str
        @rtype: DataFrame
        """
        fs = ert.getEnkfFsManager().getFileSystem(case_name)

        realizations = fs.realizationList(RealizationStateEnum.STATE_HAS_DATA)

        custom_kw_keys = CustomKWCollector.getAllCustomKWKeys(ert)

        if keys is not None:
            custom_kw_keys = [key for key in keys if key in custom_kw_keys
                              ]  # ignore keys that doesn't exist

        custom_kw_data = DataFrame(index=realizations, columns=custom_kw_keys)
        custom_kw_data.index.name = "Realization"

        custom_kw_keys = CustomKWCollector.groupKeys(custom_kw_keys)

        for name in custom_kw_keys:
            ensemble_config_node = ert.ensembleConfig().getNode(name)
            enkf_node = EnkfNode(ensemble_config_node)

            keys = custom_kw_keys[name]

            for realization_number in realizations:
                node_id = NodeId(0, realization_number, EnkfStateType.FORECAST)
                if enkf_node.tryLoad(fs, node_id):
                    custom_kw = enkf_node.asCustomKW()

                    for key in keys:
                        value = custom_kw[key]
                        custom_kw_data["%s:%s" %
                                       (name, key)][realization_number] = value

        return custom_kw_data
Beispiel #16
0
    ert.submitSimulation(arg)

while True:
    print("Waiting:%d  Running:%d  Complete:%d/%d" %
          (queue_manager.getNumWaiting(), queue_manager.getNumRunning(),
           queue_manager.getNumSuccess(), queue_manager.getNumFailed()))
    if not queue_manager.isRunning():
        break

    time.sleep(5)

ens_config = ert.ensembleConfig()
data_config = ens_config["SNAKE_OIL_OPR_DIFF"]
param_config = ens_config["SNAKE_OIL_PARAM"]
for iens in range(ert.getEnsembleSize()):
    data_id = NodeId(realization_number=iens, report_step=199)
    enkf_node1 = EnkfNode(data_config)
    enkf_node1.load(fs, data_id)
    gen_data = enkf_node1.asGenData()
    data = gen_data.getData()

    param_id = NodeId(realization_number=iens, report_step=0)

    enkf_node2 = EnkfNode(param_config)
    enkf_node2.load(fs, param_id)
    gen_kw = enkf_node2.asGenKw()

    print sum(data)
    for v in gen_kw:
        print v