Skip to content

Commit

Permalink
Merge pull request #4450 from lisajulia/documentation/python
Browse files Browse the repository at this point in the history
Add documentation to opm.io.ecl.ERst class
  • Loading branch information
blattms authored Jan 28, 2025
2 parents a3a1af9 + e3afef0 commit af59001
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 16 deletions.
33 changes: 17 additions & 16 deletions python/cxx/eclipse_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,35 +461,36 @@ void python::common::export_IO(py::module& m) {
.def("__get_data", &get_vector_name, py::arg("name"), EclFile_get_data_name_docstring)
.def("__get_data", &get_vector_occurrence, py::arg("name"), py::arg("occurrence"), EclFile_get_data_occurrence_docstring);

py::class_<Opm::EclIO::ERst>(m, "ERst")
.def(py::init<const std::string &>())
.def("__has_report_step", &Opm::EclIO::ERst::hasReportStepNumber)
.def("load_report_step", &Opm::EclIO::ERst::loadReportStepNumber)
.def_property_readonly("report_steps", &Opm::EclIO::ERst::listOfReportStepNumbers)
.def("__len__", &Opm::EclIO::ERst::numberOfReportSteps)
.def("count", &Opm::EclIO::ERst::occurrence_count)
.def("__contains", &erst_contains)
py::class_<Opm::EclIO::ERst>(m, "ERst", ERst_docstring)
.def(py::init<const std::string &>(), py::arg("filename"), ERst_init_docstring)
.def("__has_report_step", &Opm::EclIO::ERst::hasReportStepNumber, py::arg("report_step"), ERst_has_report_step_docstring)
.def("load_report_step", &Opm::EclIO::ERst::loadReportStepNumber, py::arg("report_step"), ERst_load_report_step_docstring)
.def_property_readonly("report_steps", &Opm::EclIO::ERst::listOfReportStepNumbers, ERst_report_steps_docstring)
.def("__len__", &Opm::EclIO::ERst::numberOfReportSteps, ERst_len_docstring)
.def("count", &Opm::EclIO::ERst::occurrence_count, py::arg("name"), py::arg("report_step"), ERst_count_docstring)
.def("__contains", &erst_contains, py::arg("tuple"), ERst_contains_docstring)
.def("arrays", (std::vector< std::tuple<std::string, Opm::EclIO::eclArrType, int64_t> >
(Opm::EclIO::ERst::*)(int) ) &Opm::EclIO::ERst::listOfRstArrays)
(Opm::EclIO::ERst::*)(int) ) &Opm::EclIO::ERst::listOfRstArrays, py::arg("report_step"), ERst_arrays_docstring)
.def("arrays", (std::vector< std::tuple<std::string, Opm::EclIO::eclArrType, int64_t> >
(Opm::EclIO::ERst::*)(int, const std::string&) ) &Opm::EclIO::ERst::listOfRstArrays)
.def("__get_data", &get_erst_by_index)
.def("__get_data", &get_erst_vector);
(Opm::EclIO::ERst::*)(int, const std::string&) ) &Opm::EclIO::ERst::listOfRstArrays, py::arg("report_step"), py::arg("lgr_name"), ERst_arrays_with_string_docstring)
.def("__get_data", &get_erst_by_index, py::arg("index"), py::arg("report_step"), ERst_get_data_by_index_docstring)
.def("__get_data", &get_erst_vector, py::arg("name"), py::arg("report_step"), py::arg("occurrence"), ERst_get_data_vector_docstring);


py::class_<ESmryBind>(m, "ESmry")
.def(py::init<const std::string &, const bool>(), py::arg("filename"), py::arg("load_base_run") = false)
.def("__contains__", &ESmryBind::hasKey)
.def("__contains__", &ESmryBind::hasKey, py::arg("key"))
.def("make_esmry_file", &ESmryBind::make_esmry_file)
.def("__len__", &ESmryBind::numberOfTimeSteps)
.def("__get_all", &ESmryBind::get_smry_vector)
.def("__get_at_rstep", &ESmryBind::get_smry_vector_at_rsteps)
.def("__get_all", &ESmryBind::get_smry_vector, py::arg("key"))
.def("__get_at_rstep", &ESmryBind::get_smry_vector_at_rsteps, py::arg("key"))
.def_property_readonly("start_date", &ESmryBind::smry_start_date)
.def("keys", (const std::vector<std::string>& (ESmryBind::*) (void) const)
&ESmryBind::keywordList)
.def("keys", (std::vector<std::string> (ESmryBind::*) (const std::string&) const)
&ESmryBind::keywordList)
.def("dates", &ESmryBind::dates)
.def("units", &ESmryBind::units);
.def("units", &ESmryBind::units, py::arg("field"));

py::class_<Opm::EclIO::EGrid>(m, "EGrid")
.def(py::init<const std::string &, const std::string &>(), py::arg("filename"),
Expand Down
49 changes: 49 additions & 0 deletions python/docstrings_common.json
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,55 @@
"EclFile_get_data_occurrence": {
"signature": "opm.io.ecl.EclFile.__get_data(name: str, occurrence: int) -> tuple(numpy.ndarray, Opm::EclIO::eclArrType)",
"doc": "Retrieves the given occurence of the array with the given name from the EclFile.\n\n:param name: The name.\n:type name: str\n:param occurrence: The occurrence.\n:type occurrence: int\n:return: A tupe of the array and its type.\n:tuple(numpy.ndarray, Opm::EclIO::eclArrType)"
},
"ERst": {
"type": "class",
"signature": "opm.io.ecl.ERst",
"doc": "Represents an Eclipse Restart file. This class inherits from the class EclFile."
},
"ERst_init": {
"signature": "opm.io.ecl.ERst.__init__(filename: str)",
"doc": "Initializes the ERst object by loading the Restart file (and the underlying EclFile) from the specified path.\n\n:param filename: The path to the Restart file.\n:type filename: str"
},
"ERst_has_report_step": {
"signature": "opm.io.ecl.ERst.__has_report_step(report_step: int) -> bool",
"doc": "Checks if the specified report step exists in the file.\n\n:param report_step: The report step number to check.\n:type report_step: int\n:return: True if the report step exists, otherwise False.\n:type: bool"
},
"ERst_load_report_step": {
"signature": "opm.io.ecl.ERst.load_report_step(report_step: int) -> None",
"doc": "Loads the specified report step from the file into memory.\n\n:param report_step: The report step number to load.\n:type report_step: int\n:return: None"
},
"ERst_report_steps": {
"signature": "opm.io.ecl.ERst.report_steps -> list[int]",
"doc": "Returns a list of all available report step numbers in the file.\n\n:return: A list of integers representing the available report steps.\n:type: list[int]"
},
"ERst_len": {
"signature": "opm.io.ecl.ERst.__len__() -> int",
"doc": "Returns the number of available report steps in the file.\n\n:return: The number of report steps.\n:type: int"
},
"ERst_count": {
"signature": "opm.io.ecl.ERst.count(name: str, report_step: int) -> int",
"doc": "Counts the occurrences of vectors with the specified name for the given report step.\n\n:param name: The name of the array to count.\n:type name: str\n:param report_step: The report step number to load.\n:type report_step: int\n:return: The number of occurrences of the array for the given report step.\n:type: int"
},
"ERst_contains": {
"signature": "opm.io.ecl.ERst.__contains__(tuple: [name: str, report_step: int]) -> bool",
"doc": "Checks if the Restart file contains a vector with the given name at the given report step.\n\n:param name: The name to check.\n:type name: str\n:param report_step: The report step to check.\n:type report_step: int\n:return: True if such a vector exists, otherwise False.\n:type: bool"
},
"ERst_arrays": {
"signature": "opm.io.ecl.ERst.arrays(report_step: int) -> list[tuple[str, eclArrType, int]]",
"doc": "Returns the list of arrays at the given report step.\n\n:param report_step: The report step number.\n:type report_step: int\n:return: A list of tuples containing the name, type, and size of each array.\n:type: list[tuple[str, eclArrType, int]]"
},
"ERst_arrays_with_string": {
"signature": "opm.io.ecl.ERst.arrays(report_step: int, lgr_name: str) -> list[tuple[str, eclArrType, int]]",
"doc": "Returns a list of arrays matching the given LGR at the given report_step.\n\n:param report_step: The report step number.\n:type report_step: int\n:param lgr_name: The name of the LGR.\n:type lgr_name: str\n:return: A list of tuples containing the name, type, and size of each array.\n:type: list[tuple[str, eclArrType, int]]"
},
"ERst_get_data_by_index": {
"signature": "opm.io.ecl.ERst.__get_data(index: int, report_step: int) -> tuple[numpy.ndarray, eclArrType]",
"doc": "Retrieves the given index of the data at the given report step.\n\n:param index: The index.\n:type index: int\n:return: A tuple containing the data array and its associated type.\n:rtype: tuple[numpy.ndarray, eclArrType]"
},
"ERst_get_data_vector": {
"signature": "opm.io.ecl.ERst.get_erst_vector(name: str, report_step: int, occurrence: int) -> tuple[numpy.ndarray, eclArrType]",
"doc": "Retrieves the data array of the given name a the given occurrence at the given report step.\n\n:param name: The name of the arrays.\n:type name: str\n:param report_step: The report step.\n:type report_step: int\n:param occurrence: The occurrence to retrieve.\n:type occurrence: int\n:return: A tuple containing the data array and its associated type.\n:rtype: tuple[numpy.ndarray, eclArrType]"
}

}

0 comments on commit af59001

Please sign in to comment.