-
Notifications
You must be signed in to change notification settings - Fork 59
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
Deprecate Implicit gridprop init #662
Deprecate Implicit gridprop init #662
Conversation
402804f
to
be443eb
Compare
be443eb
to
774ea0b
Compare
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.
Most looks good. It is a big PR so it could be good if one other can review, if available?
6ea7b3a
to
fd14516
Compare
ca1fa7b
to
6b9aeee
Compare
3e20010
to
aec1f55
Compare
return init_props[0] | ||
|
||
|
||
def import_gridprop_from_restart( |
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.
I think this function could benefit from type-hints, docstring and perhaps a test.
Do I read this right that date
can be of some kind of format like "2012-26-07", and "20122607" and one of "all", "first", "last"?
If so, why?
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.
Yes, date can be any one of those, and the reason is to avoid breaking changes. I'll add the same typehints from the other functions.
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.
Added typehint.
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.
Also, "all" is not a valid option, so removed that.
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.
"all" still seems to be an option for both find_gridprops_from_restart_file
and find_gridprops_from_restart_file_sections
since typehints Literal["all"]
are used.
Are you thinking about something else?
By the way, Literal[]
is new to me and it's cool so thanks :)
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.
Yes, "all" is still an option for "find". I think the confusion is that the "find" functions are reused to also find more than one gridproperty.
@@ -568,3 +565,35 @@ def import_gridprops_from_restart_file( | |||
if close: | |||
filehandle.close() | |||
return read_properties | |||
|
|||
|
|||
def import_gridprop_from_init(pfile, name, grid, fracture=False): |
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.
I find it a bit hard to parse that import_gridprop_from_init
calls import_gridprop_from_init_file
.
Do we need both?
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.
This is indeed some bad naming, we need both as we will need to have an entry point which does the collecting both when we are getting just one grid property and when we are getting a collection of properties matching a search criteria. I guess some wording involving search
or collect
might help.
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.
I tried a rename to find in case that helps.
@@ -14,7 +14,7 @@ | |||
logger = xtg.functionlogger(__name__) | |||
|
|||
|
|||
def import_xtgcpprop(self, mfile, ijrange=None, zerobased=False): | |||
def import_xtgcpprop(mfile, ijrange=None, zerobased=False): |
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.
Docstring outdated - self
can be removed.
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.
Fixed
@@ -25,7 +25,6 @@ def import_xtgcpprop(self, mfile, ijrange=None, zerobased=False): | |||
zerobased (bool): If ijrange basis is zero or one. | |||
|
|||
""" | |||
# | |||
offset = 36 |
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.
Why not 42? :)
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.
That is indeed the question
result["values"].reshape(-1).compressed(), roxprop.code_names | ||
) | ||
logger.info("Fixed codes: %s", result["codes"]) | ||
return result | ||
|
||
|
||
def export_prop_roxapi( |
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.
Remove self-parameter.
Same goes for the function _store_in_roxar
in the same file.
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.
This is the export functions so they do indeed take an object instance. Whether it should be named self is another thing. I think that renaming is out of scope for this PR, but could be made a separate issue.
93274cb
to
8942580
Compare
8942580
to
0ccf427
Compare
0ccf427
to
e7d00aa
Compare
@@ -474,7 +471,7 @@ def section_generator(generator): | |||
return | |||
|
|||
|
|||
def import_gridprops_from_restart_file_sections( | |||
def find_gridprops_from_restart_file_sections( |
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.
Pedantic alert (!)
"Imports list of parameters from an sections generator."
"Finds list of parameters from a sections generator."
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.
Fixed
b13f581
to
24f9d98
Compare
|
||
|
||
def sanitize_date( | ||
date: Union[int, str, Literal["first", "last"]] |
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.
The way I read this type is that we allow any int and any string and that mypy would not complain if we passed say "norway" as the date parameter.
What if we specified Union[int, Literal["first", "last"]]
and have the caller be responsible for converting a string representation of a date to int?
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.
That is unfortunately not possible now as what we are doing here is sanitizing input from the public API where str
has been allowed. So dropping it would be a breaking change. We can make sure the "find" part of the code does not need to worry about str
though. I can create an issue for that as it means bigger changes.
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.
I think this is a nice improvement.
In general, the functions could use a bit more testing, typing and docstrings, but hey can't fix it all one PR!
Deprecates initialization of GridProperty object from file, and non-zero default values in initialization.
372356a
to
c18a779
Compare
closes #646