Skip to content

Commit d8352b8

Browse files
authored
Increase test coverage (#251)
Solve minor inconsistencies uncovered by added tests
1 parent 1edeb8f commit d8352b8

10 files changed

Lines changed: 375 additions & 123 deletions

pyscal/factory.py

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,6 @@ def create_water_oil(params=None, fast=False):
226226
"Added LET water to WaterOil object from parameters %s",
227227
str(params_let_water.keys()),
228228
)
229-
else:
230-
logger.warning(
231-
"Missing or ambiguous parameters for water curve in WaterOil object"
232-
)
233229

234230
# Oil curve:
235231
params_corey_oil = slicedict(params, WO_COREY_OIL + WO_OIL_ENDPOINTS)
@@ -269,10 +265,6 @@ def create_water_oil(params=None, fast=False):
269265
"Added LET water to WaterOil object from parameters %s",
270266
str(params_let_oil.keys()),
271267
)
272-
else:
273-
logger.warning(
274-
"Missing or ambiguous parameters for oil curve in WaterOil object"
275-
)
276268

277269
# Capillary pressure:
278270
params_simple_j = slicedict(params, WO_SIMPLE_J + ["g"])
@@ -457,7 +449,7 @@ def create_water_oil_gas(params=None, fast=False):
457449
wateroilgas.gasoil = gasoil # This might be None
458450
if not wateroilgas.selfcheck():
459451
raise ValueError(
460-
("Incomplete WaterOilGas object, some parameters missing to factory")
452+
f"Inconsistent WaterOilGas object. Bug? Input was {params}"
461453
)
462454
return wateroilgas
463455

@@ -616,7 +608,7 @@ def load_relperm_df(inputfile, sheet_name=None):
616608
Ensures case-insensitiveness SATNUM, CASE, TAG and COMMENT
617609
618610
Merges COMMENT into TAG column, as only TAG is picked up downstream.
619-
Adds a prexix "SATNUM <number>" to all tags.
611+
Adds a prefix "SATNUM <number>" to all tags.
620612
621613
All strings in CASE column are converted to lowercase. Applies
622614
aliasing in the CASE column so that "pessimistic" and "pess" map to
@@ -642,7 +634,7 @@ def load_relperm_df(inputfile, sheet_name=None):
642634
"Sheet name only relevant for XLSX files, ignoring %s", sheet_name
643635
)
644636
excel_engines = {"xls": "xlrd", "xlsx": "openpyxl"}
645-
if sheet_name:
637+
if tabular_file_format != "csv" and sheet_name:
646638
try:
647639
input_df = pd.read_excel(
648640
inputfile,
@@ -655,10 +647,10 @@ def load_relperm_df(inputfile, sheet_name=None):
655647
inputfile,
656648
sheet_name,
657649
)
658-
except KeyError as error:
659-
logger.error("Non-existing sheet-name %s provided?", sheet_name)
660-
logger.error(str(error))
661-
return pd.DataFrame()
650+
except (KeyError, ValueError) as error:
651+
raise ValueError(
652+
f"Non-existing sheet-name {sheet_name} provided."
653+
) from error
662654
elif tabular_file_format.startswith("xls"):
663655
input_df = pd.read_excel(
664656
inputfile, engine=excel_engines[tabular_file_format]
@@ -738,10 +730,9 @@ def load_relperm_df(inputfile, sheet_name=None):
738730
raise ValueError("SATNUM must start at 1")
739731

740732
if max(input_df["SATNUM"]) != len(input_df["SATNUM"].unique()):
741-
logger.error(
733+
raise ValueError(
742734
"Missing SATNUMs? Max SATNUM is not equal to number of unique SATNUMS"
743735
)
744-
raise ValueError
745736
if "CASE" not in input_df and len(input_df["SATNUM"].unique()) != len(input_df):
746737
raise ValueError("Non-unique SATNUMs?")
747738
# If we are in a SCAL recommendation setting
@@ -775,12 +766,9 @@ def load_relperm_df(inputfile, sheet_name=None):
775766
# Check that we are able to make something out of the first row:
776767
firstrow = input_df.iloc[0, :]
777768
error = False
778-
try:
779-
wo_ok = sufficient_water_oil_params(firstrow)
780-
go_ok = sufficient_gas_oil_params(firstrow)
781-
gw_ok = sufficient_gas_water_params(firstrow)
782-
except ValueError:
783-
error = True
769+
wo_ok = sufficient_water_oil_params(firstrow)
770+
go_ok = sufficient_gas_oil_params(firstrow)
771+
gw_ok = sufficient_gas_water_params(firstrow)
784772
if error or not wo_ok and not go_ok and not gw_ok:
785773
raise ValueError(
786774
"Can't make neither WaterOil, GasOil or GasWater from "

pyscal/gasoil.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""Representing a GasOil object"""
22

33
import logging
4-
import warnings
54

65
import numpy as np
76
import pandas as pd
@@ -74,12 +73,7 @@ def __init__(
7473
assert -epsilon < sgcr < 1, "0 <= sgcr < 1 is required"
7574
assert -epsilon < swl < 1, "0 <= swl < 1 is required"
7675
assert -epsilon < sorg < 1, "0 <= sorg < 1 is required"
77-
if not isinstance(tag, str):
78-
warnings.warn(
79-
"tag must be a string, this will be a hard failure later",
80-
DeprecationWarning,
81-
)
82-
tag = ""
76+
8377
if krgendanchor is None:
8478
krgendanchor = ""
8579

@@ -638,13 +632,17 @@ def selfcheck(self, mode="SGOF"):
638632
if "krg" in self.table and not np.isclose(min(self.table["krg"]), 0.0):
639633
logger.error("krg must start at zero")
640634
error = True
641-
if "pc" in self.table and self.table["pc"][0] > 0:
635+
if "pc" in self.table and self.table["pc"][0] > -epsilon:
642636
if not (self.table["pc"].diff().dropna() < epsilon).all():
643-
logger.error("pc data for gas-oil not strictly deceasing")
637+
logger.error("pc data for gas-oil not strictly decreasing")
644638
error = True
645639
if "pc" in self.table and np.isinf(self.table["pc"].max()):
646640
logger.error("pc goes to infinity for gas-oil. ")
647641
error = True
642+
if "pc" in self.table.columns and np.isnan(self.table["pc"]).any():
643+
logger.error("pc data contains NaN")
644+
error = True
645+
648646
for col in list(set(["sg", "krg", "krog"]) & set(self.table.columns)):
649647
if not (
650648
(min(self.table[col]) >= -epsilon)
@@ -837,6 +835,9 @@ def SGFN(
837835
string, overrides what this object can provide. Used by GasWater.
838836
If None, it will be computed, use empty string to avoid.
839837
"""
838+
if not self.selfcheck(mode="SGFN"):
839+
# Selfcheck will issue error messages.
840+
return ""
840841
string = ""
841842
if "pc" not in self.table.columns:
842843
self.table["pc"] = 0.0

pyscal/wateroil.py

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@ def __init__(
9595
if _sgcr is not None:
9696
self.sgcr = _sgcr
9797

98-
if not isinstance(tag, str):
99-
tag = ""
10098
self.swirr = swirr
10199
self.swl = max(swl, swirr) # Cannot allow swl < swirr. Warn?
102100
if not np.isclose(sorw, 0) and sorw < 1 / SWINTEGERS:
@@ -622,10 +620,9 @@ def add_simple_J(self, a=5, b=-1.5, poro_ref=0.25, perm_ref=100, drho=300, g=9.8
622620
assert perm_ref > 0.0
623621

624622
if self.swl < epsilon:
625-
logger.error(
626-
"swl must larger than zero to avoid infinite capillary pressure"
623+
raise ValueError(
624+
"swl must be larger than zero to avoid infinite capillary pressure"
627625
)
628-
raise ValueError
629626

630627
if b > 0:
631628
logger.warning(
@@ -688,13 +685,12 @@ def add_simple_J_petro(self, a, b, poro_ref=0.25, perm_ref=100, drho=300, g=9.81
688685
assert perm_ref > 0.0
689686

690687
if self.swl < epsilon:
691-
logger.error(
692-
"swl must larger than zero to avoid infinite capillary pressure"
688+
raise ValueError(
689+
"swl must be larger than zero to avoid infinite capillary pressure"
693690
)
694-
raise ValueError
695691

696692
if b > 0:
697-
logger.warning(
693+
raise ValueError(
698694
"positive b will give increasing capillary pressure with saturation"
699695
)
700696

@@ -743,8 +739,7 @@ def add_normalized_J(self, a, b, poro, perm, sigma_costau):
743739
assert isinstance(sigma_costau, (int, float))
744740

745741
if b < 0 and np.isclose(self.swirr, self.swl):
746-
logger.error("swl must be set larger than swirr to avoid infinite p_c")
747-
raise ValueError("swl must be larger than swirr")
742+
raise ValueError("swl must be larger than swirr to avoid infinite p_c")
748743

749744
if abs(b) < 0.01:
750745
logger.warning(
@@ -794,36 +789,27 @@ def add_skjaeveland_pc(self, cw, co, aw, ao, swr=None, sor=None):
794789
Returns false if error occured.
795790
796791
""" # noqa
797-
inputerror = False # Flag to be able to catch all errors
798792
if cw < 0:
799-
logger.error("cw must be larger or equal to zero")
800-
inputerror = True
793+
raise ValueError("cw must be larger or equal to zero")
801794
if co > 0:
802-
logger.error("co must be less than zero")
803-
inputerror = True
795+
raise ValueError("co must be less than zero")
804796
if aw <= 0:
805-
logger.error("aw must be larger than zero")
806-
inputerror = True
797+
raise ValueError("aw must be larger than zero")
807798
if ao <= 0:
808-
logger.error("ao must be larger than zero")
809-
inputerror = True
799+
raise ValueError("ao must be larger than zero")
810800

811801
if swr is None:
812802
swr = self.swirr
813803
if sor is None:
814804
sor = self.sorw
815805

816806
if swr >= 1 - sor:
817-
logger.error("swr (swirr) must be less than 1 - sor")
818-
inputerror = True
807+
raise ValueError("swr (swirr) must be less than 1 - sor")
819808
if swr < 0 or swr > 1:
820-
logger.error("swr must be contained in [0,1]")
821-
inputerror = True
809+
raise ValueError("swr must be contained in [0,1]")
822810
if sor < 0 or sor > 1:
823-
logger.error("sor must be contained in [0,1]")
824-
inputerror = True
825-
if inputerror:
826-
return
811+
raise ValueError("sor must be contained in [0,1]")
812+
827813
self.pccomment = (
828814
"-- Skjæveland correlation for Pc;\n"
829815
+ "-- cw=%g, co=%g, aw=%g, ao=%g, swr=%g, sor=%g\n"
@@ -846,13 +832,9 @@ def add_skjaeveland_pc(self, cw, co, aw, ao, swr=None, sor=None):
846832
self.table["swnpc"] ** aw
847833
) + co / (self.table["sonpc"] ** ao)
848834

849-
# From 1-sor, the pc is not defined. We want to extrapolate constantly,
850-
# but with a twist as Eclipse does not non-monotone capillary pressure:
851-
self.table["pc"].fillna(value=self.table["pc"].min(), inplace=True)
852-
nanrows = self.table["sw"] > 1 - sor - epsilon
853-
self.table.loc[nanrows, "pc"] = (
854-
self.table.loc[nanrows, "pc"] - self.table.loc[nanrows, "sw"]
855-
) # Just deduct sw to make it monotone..
835+
# From 1-sor, the pc is not defined. Extrapolate constantly, and let
836+
# the non-monotonocity be fixed in the output generators.
837+
self.table["pc"].fillna(method="ffill", inplace=True)
856838

857839
def add_LET_pc_pd(self, Lp, Ep, Tp, Lt, Et, Tt, Pcmax, Pct):
858840
# pylint: disable=line-too-long
@@ -1046,6 +1028,9 @@ def selfcheck(self, mode="SWOF"):
10461028
if not (self.table["pc"].diff().dropna().round(10) < epsilon).all():
10471029
logger.error("pc data not strictly decreasing")
10481030
error = True
1031+
if "pc" in self.table.columns and np.isnan(self.table["pc"]).any():
1032+
logger.error("pc data contains NaN")
1033+
error = True
10491034
if "pc" in self.table.columns and np.isinf(self.table["pc"].max()):
10501035
logger.error("pc goes to infinity. Maybe swirr=swl?")
10511036
error = True

pyscal/wateroilgas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def SOF3(self, header=True, dataincommentrow=True):
194194
width = 10
195195
string += (
196196
"-- "
197-
+ "SW".ljust(width - 3)
197+
+ "SO".ljust(width - 3)
198198
+ "KROW".ljust(width)
199199
+ "KROG".ljust(width)
200200
+ "\n"

0 commit comments

Comments
 (0)