Skip to content
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

Merged
merged 2 commits into from
Nov 17, 2021

Conversation

eivindjahren
Copy link
Contributor

@eivindjahren eivindjahren commented Oct 7, 2021

closes #646

@eivindjahren eivindjahren force-pushed the explicit_gridprop_init branch 4 times, most recently from 402804f to be443eb Compare October 29, 2021 11:31
@eivindjahren eivindjahren changed the title Explicit gridprop init Deprecate Implicit gridprop init Oct 29, 2021
@eivindjahren eivindjahren marked this pull request as ready for review October 29, 2021 11:40
@eivindjahren eivindjahren force-pushed the explicit_gridprop_init branch from be443eb to 774ea0b Compare October 29, 2021 11:56
Copy link
Collaborator

@jcrivenaes jcrivenaes left a 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?

src/xtgeo/grid3d/_ecl_output_file.py Outdated Show resolved Hide resolved
src/xtgeo/grid3d/_ecl_output_file.py Outdated Show resolved Hide resolved
src/xtgeo/grid3d/_ecl_output_file.py Outdated Show resolved Hide resolved
@eivindjahren eivindjahren force-pushed the explicit_gridprop_init branch 3 times, most recently from 6ea7b3a to fd14516 Compare November 10, 2021 06:09
@eivindjahren eivindjahren force-pushed the explicit_gridprop_init branch 3 times, most recently from ca1fa7b to 6b9aeee Compare November 12, 2021 08:21
@equinor equinor deleted a comment from ertomatic Nov 12, 2021
@eivindjahren eivindjahren force-pushed the explicit_gridprop_init branch 5 times, most recently from 3e20010 to aec1f55 Compare November 16, 2021 09:37
@dafeda dafeda self-requested a review November 16, 2021 10:13
return init_props[0]


def import_gridprop_from_restart(
Copy link

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?

Copy link
Contributor Author

@eivindjahren eivindjahren Nov 16, 2021

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added typehint.

Copy link
Contributor Author

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.

Copy link

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 :)

Copy link
Contributor Author

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):
Copy link

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?

Copy link
Contributor Author

@eivindjahren eivindjahren Nov 16, 2021

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.

Copy link
Contributor Author

@eivindjahren eivindjahren Nov 16, 2021

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):
Copy link

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.

Copy link
Contributor Author

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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not 42? :)

Copy link
Contributor Author

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(
Copy link

@dafeda dafeda Nov 16, 2021

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.

Copy link
Contributor Author

@eivindjahren eivindjahren Nov 16, 2021

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.

@eivindjahren eivindjahren force-pushed the explicit_gridprop_init branch 2 times, most recently from 93274cb to 8942580 Compare November 16, 2021 20:13
@@ -474,7 +471,7 @@ def section_generator(generator):
return


def import_gridprops_from_restart_file_sections(
def find_gridprops_from_restart_file_sections(
Copy link

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."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@eivindjahren eivindjahren force-pushed the explicit_gridprop_init branch from b13f581 to 24f9d98 Compare November 17, 2021 07:16


def sanitize_date(
date: Union[int, str, Literal["first", "last"]]
Copy link

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?

Copy link
Contributor Author

@eivindjahren eivindjahren Nov 17, 2021

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.

Copy link

@dafeda dafeda left a 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!

eivindjahren and others added 2 commits November 17, 2021 11:58
Deprecates initialization of GridProperty object from
file, and non-zero default values in initialization.
@eivindjahren eivindjahren force-pushed the explicit_gridprop_init branch from 372356a to c18a779 Compare November 17, 2021 10:58
@eivindjahren eivindjahren merged commit 37515d6 into equinor:master Nov 17, 2021
@eivindjahren eivindjahren deleted the explicit_gridprop_init branch November 17, 2021 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make GridProperty __init__ more explicit
3 participants