Ejemplo n.º 1
0
    def test_read_design_matrix(self):
        with TestAreaContext("python/enkf/export/design_matrix"):
            dumpDesignMatrix1("DesignMatrix.txt")
            dm = DesignMatrixReader.loadDesignMatrix("DesignMatrix.txt")

            self.assertEqual(dm["CORR_SEIS_HEIMDAL"][0], 0.8)
            self.assertEqual(dm["VOL_FRAC_HEIMDAL"][0], 0.08)
            self.assertEqual(dm["AZIM_IND_HEIMDAL"][0], 125)
            self.assertEqual(dm["VARIO_PARAL_HEIMDAL"][0], 1000)
            self.assertEqual(dm["VARIO_NORM_HEIMDAL"][0], 500)
            self.assertEqual(dm["VARIO_VERT_HEIMDAL"][0], 25)
            self.assertEqual(dm["SEIS_COND_HEIMDAL"][0], "ON")

            self.assertEqual(dm["CORR_SEIS_HEIMDAL"][1], 0.8)
            self.assertEqual(dm["VOL_FRAC_HEIMDAL"][1], 0.15)
            self.assertEqual(dm["AZIM_IND_HEIMDAL"][1], 125)
            self.assertEqual(dm["VARIO_PARAL_HEIMDAL"][1], 2000)
            self.assertEqual(dm["VARIO_NORM_HEIMDAL"][1], 1000)
            self.assertEqual(dm["VARIO_VERT_HEIMDAL"][1], 25)
            self.assertEqual(dm["SEIS_COND_HEIMDAL"][1], "ON")

            self.assertEqual(dm["CORR_SEIS_HEIMDAL"][2], 0.8)
            self.assertEqual(dm["VOL_FRAC_HEIMDAL"][2], 0.20)
            self.assertEqual(dm["AZIM_IND_HEIMDAL"][2], 125)
            self.assertEqual(dm["VARIO_PARAL_HEIMDAL"][2], 4000)
            self.assertEqual(dm["VARIO_NORM_HEIMDAL"][2], 2000)
            self.assertEqual(dm["VARIO_VERT_HEIMDAL"][2], 25)
            self.assertEqual(dm["SEIS_COND_HEIMDAL"][2], "ON")
Ejemplo n.º 2
0
    def test_read_design_matrix(self):
        with TestAreaContext("python/enkf/export/design_matrix"):
            dumpDesignMatrix1("DesignMatrix.txt")
            dm = DesignMatrixReader.loadDesignMatrix("DesignMatrix.txt")

            self.assertEqual(dm["CORR_SEIS_HEIMDAL"][0], 0.8)
            self.assertEqual(dm["VOL_FRAC_HEIMDAL"][0], 0.08)
            self.assertEqual(dm["AZIM_IND_HEIMDAL"][0], 125)
            self.assertEqual(dm["VARIO_PARAL_HEIMDAL"][0], 1000)
            self.assertEqual(dm["VARIO_NORM_HEIMDAL"][0], 500)
            self.assertEqual(dm["VARIO_VERT_HEIMDAL"][0], 25)
            self.assertEqual(dm["SEIS_COND_HEIMDAL"][0], "ON")

            self.assertEqual(dm["CORR_SEIS_HEIMDAL"][1], 0.8)
            self.assertEqual(dm["VOL_FRAC_HEIMDAL"][1], 0.15)
            self.assertEqual(dm["AZIM_IND_HEIMDAL"][1], 125)
            self.assertEqual(dm["VARIO_PARAL_HEIMDAL"][1], 2000)
            self.assertEqual(dm["VARIO_NORM_HEIMDAL"][1], 1000)
            self.assertEqual(dm["VARIO_VERT_HEIMDAL"][1], 25)
            self.assertEqual(dm["SEIS_COND_HEIMDAL"][1], "ON")

            self.assertEqual(dm["CORR_SEIS_HEIMDAL"][2], 0.8)
            self.assertEqual(dm["VOL_FRAC_HEIMDAL"][2], 0.20)
            self.assertEqual(dm["AZIM_IND_HEIMDAL"][2], 125)
            self.assertEqual(dm["VARIO_PARAL_HEIMDAL"][2], 4000)
            self.assertEqual(dm["VARIO_NORM_HEIMDAL"][2], 2000)
            self.assertEqual(dm["VARIO_VERT_HEIMDAL"][2], 25)
            self.assertEqual(dm["SEIS_COND_HEIMDAL"][2], "ON")
Ejemplo n.º 3
0
    def test_join(self):

        with ErtTestContext("python/enkf/export/export_join",
                            self.config) as context:
            dumpDesignMatrix("DesignMatrix.txt")
            ert = context.getErt()

            summary_data = SummaryCollector.loadAllSummaryData(ert, "default")
            gen_kw_data = GenKwCollector.loadAllGenKwData(ert, "default")
            misfit = MisfitCollector.loadAllMisfitData(ert, "default")
            dm = DesignMatrixReader.loadDesignMatrix("DesignMatrix.txt")

            result = summary_data.join(gen_kw_data, how='inner')
            result = result.join(misfit, how='inner')
            result = result.join(dm, how='inner')

            self.assertFloatEqual(result["FLUID_PARAMS:SGCR"][0]["2000-02-01"],
                                  0.018466)
            self.assertFloatEqual(
                result["FLUID_PARAMS:SGCR"][24]["2000-02-01"], 0.221049)
            self.assertFloatEqual(
                result["FLUID_PARAMS:SGCR"][24]["2004-12-01"], 0.221049)

            self.assertFloatEqual(
                result["EXTRA_FLOAT_COLUMN"][0]["2000-02-01"], 0.08)
            self.assertEqual(result["EXTRA_INT_COLUMN"][0]["2000-02-01"], 125)
            self.assertEqual(result["EXTRA_STRING_COLUMN"][0]["2000-02-01"],
                             "ON")

            self.assertFloatEqual(
                result["EXTRA_FLOAT_COLUMN"][0]["2004-12-01"], 0.08)
            self.assertEqual(result["EXTRA_INT_COLUMN"][0]["2004-12-01"], 125)
            self.assertEqual(result["EXTRA_STRING_COLUMN"][0]["2004-12-01"],
                             "ON")

            self.assertFloatEqual(
                result["EXTRA_FLOAT_COLUMN"][1]["2004-12-01"], 0.07)
            self.assertEqual(result["EXTRA_INT_COLUMN"][1]["2004-12-01"], 225)
            self.assertEqual(result["EXTRA_STRING_COLUMN"][1]["2004-12-01"],
                             "OFF")

            self.assertFloatEqual(result["MISFIT:WWCT:OP_2"][0]["2004-12-01"],
                                  0.617793)
            self.assertFloatEqual(result["MISFIT:WWCT:OP_2"][24]["2004-12-01"],
                                  0.256436)

            self.assertFloatEqual(result["MISFIT:TOTAL"][0]["2000-02-01"],
                                  7236.322836)
            self.assertFloatEqual(result["MISFIT:TOTAL"][0]["2004-12-01"],
                                  7236.322836)
            self.assertFloatEqual(result["MISFIT:TOTAL"][24]["2004-12-01"],
                                  2261.726621)

            with self.assertRaises(KeyError):
                realization_13 = result.loc[60]

            column_count = len(result.columns)
            self.assertEqual(result.dtypes[0], numpy.float64)
            self.assertEqual(result.dtypes[column_count - 1], numpy.object)
            self.assertEqual(result.dtypes[column_count - 2], numpy.int64)
Ejemplo n.º 4
0
    def run(self, output_file, case_list=None, design_matrix_path=None, infer_iteration=True):
        cases = []

        if case_list is not None:
            if case_list.strip() == "*":
                cases = self.getAllCaseList()
            else:
                cases = case_list.split(",")

        if case_list is None or len(cases) == 0:
            cases = [self.ert().getEnkfFsManager().getCurrentFileSystem().getCaseName()]

        if design_matrix_path is not None:
            if not os.path.exists(design_matrix_path):
                raise UserWarning("The design matrix file does not exists!")

            if not os.path.isfile(design_matrix_path):
                raise UserWarning("The design matrix is not a file!")

        data = pandas.DataFrame()

        for index, case in enumerate(cases):
            case = case.strip()

            if not self.ert().getEnkfFsManager().caseExists(case):
                raise UserWarning("The case '%s' does not exist!" % case)

            if not self.ert().getEnkfFsManager().caseHasData(case):
                raise UserWarning("The case '%s' does not have any data!" % case)

            if infer_iteration:
                iteration_number = self.inferIterationNumber(case)
            else:
                iteration_number = index

            case_data = GenKwCollector.loadAllGenKwData(self.ert(), case)

            if design_matrix_path is not None:
               design_matrix_data = DesignMatrixReader.loadDesignMatrix(design_matrix_path)
               case_data = case_data.join(design_matrix_data, how='inner')

            misfit_data = MisfitCollector.loadAllMisfitData(self.ert(), case)

            case_data = case_data.join(misfit_data, how='inner')

            summary_data = SummaryCollector.loadAllSummaryData(self.ert(), case)
            summary_data["Iteration"] = iteration_number
            summary_data["Case"] = case
            summary_data.set_index(["Case", "Iteration"], append=True, inplace=True)

            case_data = case_data.join(summary_data, how='inner')

            data = pandas.concat([data, case_data])

        data = data.reorder_levels(["Realization", "Iteration", "Date", "Case"])
        data.to_csv(output_file)

        export_info = "Exported %d rows and %d columns to %s." % (len(data.index), len(data.columns), output_file)
        return export_info
Ejemplo n.º 5
0
    def test_join(self):

        with ErtTestContext("python/enkf/export/export_join", self.config) as context:
            dumpDesignMatrix("DesignMatrix.txt")
            ert = context.getErt()

            summary_data = SummaryCollector.loadAllSummaryData(ert, "default_1")
            gen_kw_data = GenKwCollector.loadAllGenKwData(ert, "default_1")
            misfit = MisfitCollector.loadAllMisfitData(ert, "default_1")
            dm = DesignMatrixReader.loadDesignMatrix("DesignMatrix.txt")

            result = summary_data.join(gen_kw_data, how='inner')
            result = result.join(misfit, how='inner')
            result = result.join(dm, how='inner')

            first_date = "2010-01-10"
            last_date = "2015-06-23"

            self.assertFloatEqual(result["SNAKE_OIL_PARAM:OP1_OCTAVES"][0][first_date], 3.947766)
            self.assertFloatEqual(result["SNAKE_OIL_PARAM:OP1_OCTAVES"][24][first_date], 4.206698)
            self.assertFloatEqual(result["SNAKE_OIL_PARAM:OP1_OCTAVES"][24][last_date], 4.206698)

            self.assertFloatEqual(result["EXTRA_FLOAT_COLUMN"][0][first_date], 0.08)
            self.assertEqual(result["EXTRA_INT_COLUMN"][0][first_date], 125)
            self.assertEqual(result["EXTRA_STRING_COLUMN"][0][first_date], "ON")

            self.assertFloatEqual(result["EXTRA_FLOAT_COLUMN"][0][last_date], 0.08)
            self.assertEqual(result["EXTRA_INT_COLUMN"][0][last_date], 125)
            self.assertEqual(result["EXTRA_STRING_COLUMN"][0][last_date], "ON")

            self.assertFloatEqual(result["EXTRA_FLOAT_COLUMN"][1][last_date], 0.07)
            self.assertEqual(result["EXTRA_INT_COLUMN"][1][last_date], 225)
            self.assertEqual(result["EXTRA_STRING_COLUMN"][1][last_date], "OFF")

            self.assertFloatEqual(result["MISFIT:FOPR"][0][last_date], 489.191069)
            self.assertFloatEqual(result["MISFIT:FOPR"][24][last_date], 1841.906872)

            self.assertFloatEqual(result["MISFIT:TOTAL"][0][first_date], 500.170035)
            self.assertFloatEqual(result["MISFIT:TOTAL"][0][last_date], 500.170035)
            self.assertFloatEqual(result["MISFIT:TOTAL"][24][last_date], 1925.793865)


            with self.assertRaises(KeyError):
                realization_13 = result.loc[60]

            column_count = len(result.columns)
            self.assertEqual(result.dtypes[0], numpy.float64)
            self.assertEqual(result.dtypes[column_count - 1], numpy.object)
            self.assertEqual(result.dtypes[column_count - 2], numpy.int64)
Ejemplo n.º 6
0
    def test_join(self):

        with ErtTestContext("python/enkf/export/export_join", self.config) as context:
            dumpDesignMatrix("DesignMatrix.txt")
            ert = context.getErt()

            summary_data = SummaryCollector.loadAllSummaryData(ert, "default")
            gen_kw_data = GenKwCollector.loadAllGenKwData(ert, "default")
            misfit = MisfitCollector.loadAllMisfitData(ert, "default")
            dm = DesignMatrixReader.loadDesignMatrix("DesignMatrix.txt")

            result = summary_data.join(gen_kw_data, how='inner')
            result = result.join(misfit, how='inner')
            result = result.join(dm, how='inner')

            self.assertFloatEqual(result["FLUID_PARAMS:SGCR"][0]["2000-02-01"], 0.295136)
            self.assertFloatEqual(result["FLUID_PARAMS:SGCR"][24]["2000-02-01"], 0.177833)
            self.assertFloatEqual(result["FLUID_PARAMS:SGCR"][24]["2004-12-01"], 0.177833)

            self.assertFloatEqual(result["EXTRA_FLOAT_COLUMN"][0]["2000-02-01"], 0.08)
            self.assertEqual(result["EXTRA_INT_COLUMN"][0]["2000-02-01"], 125)
            self.assertEqual(result["EXTRA_STRING_COLUMN"][0]["2000-02-01"], "ON")

            self.assertFloatEqual(result["EXTRA_FLOAT_COLUMN"][0]["2004-12-01"], 0.08)
            self.assertEqual(result["EXTRA_INT_COLUMN"][0]["2004-12-01"], 125)
            self.assertEqual(result["EXTRA_STRING_COLUMN"][0]["2004-12-01"], "ON")

            self.assertFloatEqual(result["EXTRA_FLOAT_COLUMN"][1]["2004-12-01"], 0.07)
            self.assertEqual(result["EXTRA_INT_COLUMN"][1]["2004-12-01"], 225)
            self.assertEqual(result["EXTRA_STRING_COLUMN"][1]["2004-12-01"], "OFF")

            self.assertFloatEqual(result["MISFIT:WWCT:OP_2"][0]["2004-12-01"], 3.552157351038322)
            self.assertFloatEqual(result["MISFIT:WWCT:OP_2"][24]["2004-12-01"], 25.318572860839158)

            self.assertFloatEqual(result["MISFIT:TOTAL"][0]["2000-02-01"], 1621.755076130249)
            self.assertFloatEqual(result["MISFIT:TOTAL"][0]["2004-12-01"], 1621.755076130249)
            self.assertFloatEqual(result["MISFIT:TOTAL"][24]["2004-12-01"], 2783.7582107191383)


            with self.assertRaises(KeyError):
                realization_13 = result.loc[13]

            column_count = len(result.columns)
            self.assertEqual(result.dtypes[0], numpy.float64)
            self.assertEqual(result.dtypes[column_count - 1], numpy.object)
            self.assertEqual(result.dtypes[column_count - 2], numpy.int64)
Ejemplo n.º 7
0
                                  case)

            if infer_iteration:
                iteration_number = self.inferIterationNumber(case)
            else:
                iteration_number = index

            case_data = GenKwCollector.loadAllGenKwData(self.ert(), case)

            custom_kw_data = CustomKWCollector.loadAllCustomKWData(
                self.ert(), case)
            if not custom_kw_data.empty:
                case_data = case_data.join(custom_kw_data, how='outer')

            if design_matrix_path is not None:
                design_matrix_data = DesignMatrixReader.loadDesignMatrix(
                    design_matrix_path)
                if not design_matrix_data.empty:
                    case_data = case_data.join(design_matrix_data, how='outer')

            misfit_data = MisfitCollector.loadAllMisfitData(self.ert(), case)
            if not misfit_data.empty:
                case_data = case_data.join(misfit_data, how='outer')

            summary_data = SummaryCollector.loadAllSummaryData(
                self.ert(), case)
            if not summary_data.empty:
                case_data = case_data.join(summary_data, how='outer')
            else:
                case_data["Date"] = None
                case_data.set_index(["Date"], append=True, inplace=True)
Ejemplo n.º 8
0
    def test_join(self):

        with ErtTestContext("python/enkf/export/export_join",
                            self.config) as context:
            dumpDesignMatrix("DesignMatrix.txt")
            ert = context.getErt()

            summary_data = SummaryCollector.loadAllSummaryData(
                ert, "default_1")
            gen_kw_data = GenKwCollector.loadAllGenKwData(ert, "default_1")
            misfit = MisfitCollector.loadAllMisfitData(ert, "default_1")
            dm = DesignMatrixReader.loadDesignMatrix("DesignMatrix.txt")

            result = summary_data.join(gen_kw_data, how='inner')
            result = result.join(misfit, how='inner')
            result = result.join(dm, how='inner')

            first_date = "2010-01-10"
            last_date = "2015-06-23"

            self.assertFloatEqual(
                result["SNAKE_OIL_PARAM:OP1_OCTAVES"][0][first_date], 3.947766)
            self.assertFloatEqual(
                result["SNAKE_OIL_PARAM:OP1_OCTAVES"][24][first_date],
                4.206698)
            self.assertFloatEqual(
                result["SNAKE_OIL_PARAM:OP1_OCTAVES"][24][last_date], 4.206698)

            self.assertFloatEqual(result["EXTRA_FLOAT_COLUMN"][0][first_date],
                                  0.08)
            self.assertEqual(result["EXTRA_INT_COLUMN"][0][first_date], 125)
            self.assertEqual(result["EXTRA_STRING_COLUMN"][0][first_date],
                             "ON")

            self.assertFloatEqual(result["EXTRA_FLOAT_COLUMN"][0][last_date],
                                  0.08)
            self.assertEqual(result["EXTRA_INT_COLUMN"][0][last_date], 125)
            self.assertEqual(result["EXTRA_STRING_COLUMN"][0][last_date], "ON")

            self.assertFloatEqual(result["EXTRA_FLOAT_COLUMN"][1][last_date],
                                  0.07)
            self.assertEqual(result["EXTRA_INT_COLUMN"][1][last_date], 225)
            self.assertEqual(result["EXTRA_STRING_COLUMN"][1][last_date],
                             "OFF")

            self.assertFloatEqual(result["MISFIT:FOPR"][0][last_date],
                                  489.191069)
            self.assertFloatEqual(result["MISFIT:FOPR"][24][last_date],
                                  1841.906872)

            self.assertFloatEqual(result["MISFIT:TOTAL"][0][first_date],
                                  500.170035)
            self.assertFloatEqual(result["MISFIT:TOTAL"][0][last_date],
                                  500.170035)
            self.assertFloatEqual(result["MISFIT:TOTAL"][24][last_date],
                                  1925.793865)

            with self.assertRaises(KeyError):
                realization_13 = result.loc[60]

            column_count = len(result.columns)
            self.assertEqual(result.dtypes[0], numpy.float64)
            self.assertEqual(result.dtypes[column_count - 1], numpy.object)
            self.assertEqual(result.dtypes[column_count - 2], numpy.int64)