-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft: Partial deck parsing #487
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,7 +83,7 @@ def get_path(self) -> Path: | |
"""Return the full path to the directory with the .DATA file""" | ||
return Path(self._eclbase).absolute().parent | ||
|
||
def get_deck(self) -> "opm.libopmcommon_python.Deck": | ||
def get_deck(self, sections: list = []) -> "opm.libopmcommon_python.Deck": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://docs.python-guide.org/writing/gotchas/ use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. considered to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is a bug, you need to change it :) There will be situations where you think you have an empty list, but then it isn't. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if I understand you correctly. So basically my question is: is what described above the "bug" or is it something else? I have no big issue with switching the default to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pylint should also give you There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It bit me hard once: equinor/fmu-ensemble@f109b6e |
||
"""Return a opm.io :term:`deck` of the .DATA file""" | ||
if not self._deck: | ||
if Path(self._eclbase + ".DATA").is_file(): | ||
|
@@ -92,8 +92,16 @@ def get_deck(self) -> "opm.libopmcommon_python.Deck": | |
deckfile = self._eclbase # Will be any filename | ||
logger.info("Parsing deck file %s...", deckfile) | ||
parsecontext = opm.io.ParseContext(OPMIOPARSER_RECOVERY) | ||
deck = opm.io.Parser().parse(deckfile, parsecontext) | ||
self._deck = deck | ||
if len(sections) > 0: | ||
try: | ||
deck = opm.io.Parser().parse(deckfile, parsecontext, sections) | ||
# Return without caching as only a part of the deck is parsed | ||
return deck | ||
except RuntimeError: | ||
# Occurs if not able to parse individual sections | ||
# pass to parse and cache full deck | ||
pass | ||
self._deck = opm.io.Parser().parse(deckfile, parsecontext) | ||
return self._deck | ||
|
||
@staticmethod | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,6 +75,15 @@ def test_filedescriptors(): | |
assert len(list(fd_dir.glob("*"))) == pre_fd_count | ||
assert resdatafiles._rftfile is None | ||
|
||
deck = resdatafiles.get_deck(sections=[opm.io.eclSectionType.PROPS]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These new lines should probably be in a new test function, it is not related to testing of file descriptors. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will fix that |
||
assert "WELSPECS" not in deck # verify section parsing | ||
deck = resdatafiles.get_deck(sections=[opm.io.eclSectionType.SCHEDULE]) | ||
assert "WELSPECS" in deck # verify that last result was not cached | ||
deck = resdatafiles.get_deck() # full deck will be cached | ||
assert "SWOF" in deck | ||
assert "WELSPECS" in deck | ||
deck = resdatafiles.get_deck(sections=[opm.io.eclSectionType.PROPS]) | ||
assert "WELSPECS" in deck # verify that the full deck was cached and used | ||
resdatafiles.get_deck() | ||
# This should not leave any file descriptor open | ||
assert len(list(fd_dir.glob("*"))) == pre_fd_count |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may want to move this
except
to insideget_deck()
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will take a look at it, probably a good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like an issue in this case will be that we cannot run it with opm < 2024.04 (which doesn't exist yet), as
opm.io.eclSectionType.RUNSPEC
isn't valid (without complicating the code outside get_deck).An option is to instead have a list of strings as the
get_deck()
input and then map them toopm.io.eclSectionType
insideget_deck()
. Might also make it easier for most users.E.g. a syntax like this
get_deck(sections=["RUNSPEC", "PROPS"]
)