Skip to content

Commit

Permalink
Update code corresponsding to warnings in new pylint version (#437)
Browse files Browse the repository at this point in the history
Co-authored-by: Ubuntu <opl@flownet-vm-opl.430u41ciwbmupm0cbb0cjpnibd.fx.internal.cloudapp.net>
  • Loading branch information
olelod and Ubuntu authored Sep 30, 2021
1 parent 4edca20 commit be805f5
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 21 deletions.
22 changes: 7 additions & 15 deletions src/flownet/config_parser/_config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2103,9 +2103,7 @@ def parse_config(
"place candidates within the reservoir volume."
)

if (config.flownet.mitchells_algorithm != "normal") and (
config.flownet.mitchells_algorithm != "fast"
):
if config.flownet.mitchells_algorithm not in ("normal", "fast"):
raise ValueError(
f"'{config.flownet.mitchells_algorithm}' is not a valid mitchells_algorithm."
)
Expand Down Expand Up @@ -2239,10 +2237,7 @@ def parse_config(
"'scheme', 'fraction', and 'delta_depth'."
"Currently one or more parameters are missing."
)
if (
config.model_parameters.aquifer.scheme != "global"
and config.model_parameters.aquifer.scheme != "individual"
):
if config.model_parameters.aquifer.scheme not in ("global", "individual"):
raise ValueError(
f"The aquifer scheme "
f"'{config.model_parameters.aquifer.scheme}' is not valid.\n"
Expand Down Expand Up @@ -2511,10 +2506,7 @@ def _check_distribution(path_in_config_dict: dict, parameter: str):
_check_for_negative_values(path_in_config_dict, parameter)
_check_order_of_values(path_in_config_dict, parameter)
# uniform can be defined by either min/max, min/mean or mean/max
if (
getattr(path_in_config_dict, parameter).distribution == "uniform"
or getattr(path_in_config_dict, parameter).distribution == "logunif"
):
if getattr(path_in_config_dict, parameter).distribution in ("uniform", "logunif"):
if {"min", "max", "mean"}.issubset(defined_parameters):
raise ValueError(
f"The {parameter} has values defined for 'min', 'mean' and 'max'. Only two of them should be defined"
Expand Down Expand Up @@ -2555,10 +2547,10 @@ def _check_distribution(path_in_config_dict: dict, parameter: str):
)

# check that mean and stddev is defined for the distributions that need it
if (
getattr(path_in_config_dict, parameter).distribution == "normal"
or getattr(path_in_config_dict, parameter).distribution == "lognormal"
or getattr(path_in_config_dict, parameter).distribution == "truncated_normal"
if getattr(path_in_config_dict, parameter).distribution in (
"normal",
"lognormal",
"truncated_normal",
):
if not {"mean", "stddev"}.issubset(
_check_defined(path_in_config_dict, parameter)
Expand Down
2 changes: 1 addition & 1 deletion src/flownet/ert/_run_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def _handler(*args): # pylint: disable=unused-argument
process.terminate()
error_files = glob.glob(str(cwd / runpath.replace("%d", "*") / "ERROR"))
raise subprocess.SubprocessError(
pathlib.Path(error_files[0]).read_text()
pathlib.Path(error_files[0]).read_text(encoding="utf8")
)

if process.returncode != 0:
Expand Down
2 changes: 1 addition & 1 deletion src/flownet/ert/forward_models/_flow_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ def run_flow():

subprocess.run([flow_path, args.data_file], check=True)

Path("FLOW_SIMULATION.OK").write_text("")
Path("FLOW_SIMULATION.OK").write_text("", encoding="utf8")
4 changes: 3 additions & 1 deletion src/flownet/ert/forward_models/_save_iteration_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ def _load_parameters(runpath: str) -> Tuple[int, Dict]:
"""
realization = int(re.findall(r"[0-9]+", runpath)[-2])
parameters = json.loads((pathlib.Path(runpath) / "parameters.json").read_text())
parameters = json.loads(
(pathlib.Path(runpath) / "parameters.json").read_text(encoding="utf8")
)

return realization, parameters["FLOWNET_PARAMETERS"]

Expand Down
4 changes: 2 additions & 2 deletions src/flownet/parameters/_relative_permeability.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def swof_from_parameters(parameters: Dict) -> str:
pc = np.zeros(len(sw))

swof = np.transpose(np.stack((sw, krw, krow, pc)))
swof_string = np.array2string(swof, formatter={"float_kind": lambda x: "%.7f" % x})
swof_string = np.array2string(swof, formatter={"float_kind": lambda x: f"{x:.7f}"})
swof_string = swof_string.replace(" [", "").replace("[", "").replace("]", "")

return swof_string
Expand Down Expand Up @@ -93,7 +93,7 @@ def sgof_from_parameters(parameters: Dict) -> str:
pc = np.zeros(len(sg))

sgof = np.transpose(np.stack((sg, krg, krog, pc)))
sgof_string = np.array2string(sgof, formatter={"float_kind": lambda x: "%.7f" % x})
sgof_string = np.array2string(sgof, formatter={"float_kind": lambda x: f"{x:.7f}"})
sgof_string = sgof_string.replace(" [", "").replace("[", "").replace("]", "")

return sgof_string
Expand Down
2 changes: 1 addition & 1 deletion src/flownet/utils/write_grdecl_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def write_grdecl_file(

if filename is None:
outputfile = pathlib.Path(outputfilename)
content = outputfile.read_text()
content = outputfile.read_text(encoding="utf8")
outputfile.unlink()
return content
return None

0 comments on commit be805f5

Please sign in to comment.