コード例 #1
0
ファイル: test_design_matrix.py プロジェクト: mycarta/libres
    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")
コード例 #2
0
ファイル: test_export_join.py プロジェクト: ManInFez/ert
    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], 457.491003)
            self.assertFloatEqual(result["MISFIT:FOPR"][24][last_date], 1630.774198)

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

            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)
コード例 #3
0
ファイル: csv_export.py プロジェクト: pgdr/ert
    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)

            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)

            case_data["Iteration"] = iteration_number
            case_data["Case"] = case
            case_data.set_index(["Case", "Iteration"], append=True, inplace=True)

            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
コード例 #4
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)