From 5c88da1a41ee1995647d982ccd88a4c23d6c9a3f Mon Sep 17 00:00:00 2001 From: Frank Male Date: Mon, 23 Sep 2024 23:14:42 -0400 Subject: [PATCH] :recycle: ruff formatting --- .pre-commit-config.yaml | 6 +- noxfile.py | 8 +- src/bluebonnet/flow/flowproperties.py | 85 ++++++-------------- src/bluebonnet/flow/reservoir.py | 8 +- src/bluebonnet/fluids/fluid.py | 18 ++--- src/bluebonnet/fluids/gas.py | 49 +++++------ src/bluebonnet/fluids/oil.py | 32 +++----- src/bluebonnet/fluids/water.py | 4 +- src/bluebonnet/forecast/forecast.py | 2 +- src/bluebonnet/forecast/forecast_pressure.py | 32 +++----- src/bluebonnet/plotting.py | 4 +- tests/flow/test_properties.py | 8 +- tests/flow/test_reservoir.py | 4 +- tests/fluids/test_gas.py | 4 +- tests/fluids/test_water.py | 5 +- tests/forecast/test_forecast.py | 4 +- tests/test_plots.py | 6 +- 17 files changed, 90 insertions(+), 189 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 426d46f..f125d95 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,9 +1,4 @@ repos: - - repo: https://github.com/psf/black-pre-commit-mirror - rev: 24.8.0 - hooks: - - id: black-jupyter - - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.6.0 hooks: @@ -51,6 +46,7 @@ repos: hooks: - id: ruff args: ["--fix", "--show-fixes"] + - id: ruff-format # - repo: https://github.com/pre-commit/mirrors-mypy # rev: v0.950 diff --git a/noxfile.py b/noxfile.py index 590332e..4977449 100644 --- a/noxfile.py +++ b/noxfile.py @@ -36,9 +36,7 @@ def docs(session: nox.Session) -> None: """Build the docs. Pass "--serve" to serve. Pass "-b linkcheck" to check links.""" parser = argparse.ArgumentParser() parser.add_argument("--serve", action="store_true", help="Serve after building") - parser.add_argument( - "-b", dest="builder", default="html", help="Build target (default: html)" - ) + parser.add_argument("-b", dest="builder", default="html", help="Build target (default: html)") args, posargs = parser.parse_known_args(session.posargs) if args.builder != "html" and args.serve: @@ -50,9 +48,7 @@ def docs(session: nox.Session) -> None: session.chdir("docs") if args.builder == "linkcheck": - session.run( - "sphinx-build", "-b", "linkcheck", ".", "_build/linkcheck", *posargs - ) + session.run("sphinx-build", "-b", "linkcheck", ".", "_build/linkcheck", *posargs) return shared_args = ( diff --git a/src/bluebonnet/flow/flowproperties.py b/src/bluebonnet/flow/flowproperties.py index a728d93..40ade93 100644 --- a/src/bluebonnet/flow/flowproperties.py +++ b/src/bluebonnet/flow/flowproperties.py @@ -54,7 +54,7 @@ def __init__(self, pvt_props: Mapping[str, ndarray], p_i: float): compressibility and viscosity. Parameters - ----------- + ---------- pvt_props : Mapping has accessors for pseudopressure, alpha (optional), compressibility, viscosity, z-factor @@ -77,9 +77,7 @@ def __init__(self, pvt_props: Mapping[str, ndarray], p_i: float): ): raise ValueError("Need pvt_props to have: " + ", ".join(need_cols_short)) if "alpha" in pvt_props: - m_scale_func = interp1d( - pvt_props["pressure"], 1 / pvt_props["pseudopressure"] - ) + m_scale_func = interp1d(pvt_props["pressure"], 1 / pvt_props["pseudopressure"]) warnings.warn( "warning: scaling pseudopressure, using user's hydraulic diffusivity", RuntimeWarning, @@ -131,7 +129,7 @@ def __init__(self, pvt_props: Mapping[str, ndarray], p_i: float): compressibility and viscosity. Parameters - ----------- + ---------- pvt_props : Mapping has accessors for pressure, compressibility, viscosity @@ -234,23 +232,14 @@ def from_table( msg = f"df_kr needs all of {need_cols_kr}" raise ValueError(msg) pvt = { - prop: interp1d( - pvt_props["pressure"], pvt_props[prop], fill_value="extrapolate" - ) + prop: interp1d(pvt_props["pressure"], pvt_props[prop], fill_value="extrapolate") for prop in need_cols_pvt } pvt.update(reference_densities) # pvt.update({"rho_o0": rho_o0, "rho_g0": rho_g0, "rho_w0": rho_w0}) - kr = { - fluid: interp1d(kr_props["So"], kr_props[fluid]) - for fluid in ("kro", "krg", "krw") - } - alpha_calc = alpha_multiphase( - pvt_props["pressure"], pvt_props["So"], phi, Sw, pvt, kr - ) - pseudopressure = pseudopressure_threephase( - pvt_props["pressure"], pvt_props["So"], pvt, kr - ) + kr = {fluid: interp1d(kr_props["So"], kr_props[fluid]) for fluid in ("kro", "krg", "krw")} + alpha_calc = alpha_multiphase(pvt_props["pressure"], pvt_props["So"], phi, Sw, pvt, kr) + pseudopressure = pseudopressure_threephase(pvt_props["pressure"], pvt_props["So"], pvt, kr) with warnings.catch_warnings(): warnings.simplefilter("ignore") object = cls( @@ -287,9 +276,9 @@ def rescale_pseudopressure( """ df_pvt = df_pvt.copy() if hasattr(df_pvt, "copy") else copy.deepcopy(df_pvt) pseudopressure = interp1d(df_pvt.pressure, df_pvt.pseudopressure) - df_pvt["pseudopressure"] = ( - pseudopressure(df_pvt["pressure"]) - pseudopressure(p_frac) - ) / (pseudopressure(p_i) - pseudopressure(p_frac)) + df_pvt["pseudopressure"] = (pseudopressure(df_pvt["pressure"]) - pseudopressure(p_frac)) / ( + pseudopressure(p_i) - pseudopressure(p_frac) + ) return df_pvt @@ -331,9 +320,7 @@ def alpha_multiphase( return lambda_combined / compressibility_combined -def lambda_combined_func( - pressure: ndarray, So: ndarray, pvt: dict, kr: dict -) -> ndarray: +def lambda_combined_func(pressure: ndarray, So: ndarray, pvt: dict, kr: dict) -> ndarray: """Calculate mobility for three phase system. Args @@ -362,15 +349,11 @@ def lambda_combined_func( mobility for the cells """ lambda_oil = pvt["rho_o0"] * ( - pvt["Rv"](pressure) - * kr["krg"](So) - / (pvt["mu_g"](pressure) * pvt["Bg"](pressure)) + pvt["Rv"](pressure) * kr["krg"](So) / (pvt["mu_g"](pressure) * pvt["Bg"](pressure)) + kr["kro"](So) / (pvt["mu_o"](pressure) * pvt["Bo"](pressure)) ) lambda_gas = pvt["rho_g0"] * ( - pvt["Rs"](pressure) - * kr["kro"](So) - / (pvt["mu_o"](pressure) * pvt["Bo"](pressure)) + pvt["Rs"](pressure) * kr["kro"](So) / (pvt["mu_o"](pressure) * pvt["Bo"](pressure)) + kr["krg"](So) / (pvt["mu_g"](pressure) * pvt["Bg"](pressure)) ) lambda_water = pvt["rho_w0"] * ( @@ -431,16 +414,12 @@ def compressibility_combined_func( ) ) water_cp = ( - phi - * pvt["rho_w0"] - * (Sw / pvt["Bw"](pressure + 0.5) - Sw / pvt["Bw"](pressure - 0.5)) + phi * pvt["rho_w0"] * (Sw / pvt["Bw"](pressure + 0.5) - Sw / pvt["Bw"](pressure - 0.5)) ) return oil_cp + gas_cp + water_cp -def pseudopressure_threephase( - pressure: ndarray, So: ndarray, pvt: dict, kr: dict -) -> ndarray: +def pseudopressure_threephase(pressure: ndarray, So: ndarray, pvt: dict, kr: dict) -> ndarray: """Calculate pseudopressure over pressure for three-phase fluid. Args @@ -468,20 +447,14 @@ def pseudopressure_threephase( pseudopressure : ndarray """ lambda_oil = pvt["rho_o0"] * ( - pvt["Rv"](pressure) - * kr["krg"](So) - / (pvt["mu_g"](pressure) * pvt["Bg"](pressure)) + pvt["Rv"](pressure) * kr["krg"](So) / (pvt["mu_g"](pressure) * pvt["Bg"](pressure)) + kr["kro"](So) / (pvt["mu_o"](pressure) * pvt["Bo"](pressure)) ) lambda_gas = pvt["rho_g0"] * ( - pvt["Rs"](pressure) - * kr["kro"](So) - / (pvt["mu_o"](pressure) * pvt["Bo"](pressure)) + pvt["Rs"](pressure) * kr["kro"](So) / (pvt["mu_o"](pressure) * pvt["Bo"](pressure)) + kr["krg"](So) / (pvt["mu_g"](pressure) * pvt["Bg"](pressure)) ) - lambda_water = pvt["rho_w0"] * ( - kr["krw"](So) / (pvt["mu_w"](pressure) * pvt["Bw"](pressure)) - ) + lambda_water = pvt["rho_w0"] * (kr["krw"](So) / (pvt["mu_w"](pressure) * pvt["Bw"](pressure))) integrand = lambda_oil + lambda_gas + lambda_water pseudopressure = cumulative_trapezoid(pressure, integrand, initial=0) return pseudopressure @@ -515,7 +488,8 @@ def __init__(self, df: Mapping[str, ndarray]): Args: df (Mapping[str, ndarray]): table, including pseudopressure, So, Sg, Sw - Raises: + Raises + ------ ValueError: Table columns are missing """ need_cols = {"pseudopressure", "alpha", "So", "Sg", "Sw"} @@ -611,18 +585,9 @@ def relative_permeabilities( raise ValueError(msg) denominator = 1 - params.S_or - params.S_wc - params.S_gc - kro = ( - params.k_ro_max - * ((saturations["So"] - params.S_or) / denominator) ** params.n_o - ) - krw = ( - params.k_rw_max - * ((saturations["Sw"] - params.S_wc) / denominator) ** params.n_w - ) - krg = ( - params.k_rg_max - * ((saturations["Sg"] - params.S_gc) / denominator) ** params.n_g - ) + kro = params.k_ro_max * ((saturations["So"] - params.S_or) / denominator) ** params.n_o + krw = params.k_rw_max * ((saturations["Sw"] - params.S_wc) / denominator) ** params.n_w + krg = params.k_rg_max * ((saturations["Sg"] - params.S_gc) / denominator) ** params.n_g k_rel = np.array( list(zip(kro, krw, krg)), dtype=[(i, np.float64) for i in ("kro", "krw", "krg")], @@ -632,9 +597,7 @@ def relative_permeabilities( return k_rel -def relative_permeabilities_twophase( - params: RelPermParams, Sw: float = 0.1 -) -> pd.DataFrame: +def relative_permeabilities_twophase(params: RelPermParams, Sw: float = 0.1) -> pd.DataFrame: """Make two-phase relative permeability curves from Brooks-Corey. Parameters diff --git a/src/bluebonnet/flow/reservoir.py b/src/bluebonnet/flow/reservoir.py index 1f95dfa..8aa81f6 100644 --- a/src/bluebonnet/flow/reservoir.py +++ b/src/bluebonnet/flow/reservoir.py @@ -166,9 +166,7 @@ def fvf_scale(self) -> float: """ return 1 - def simulate( - self, time: ndarray[float], pressure_fracface: ndarray[float] | None = None - ): + def simulate(self, time: ndarray[float], pressure_fracface: ndarray[float] | None = None): """Calculate simulation pressure over time. Args @@ -300,9 +298,7 @@ def simulate(self, time: ndarray): alpha_scaled = self.alpha_scaled(b, sat) kt_h2 = mesh_ratio * alpha_scaled a_matrix = _build_matrix(kt_h2) - pseudopressure[i + 1], info = sparse.linalg.bicgstab( - a_matrix, b, atol=_ATOL - ) + pseudopressure[i + 1], info = sparse.linalg.bicgstab(a_matrix, b, atol=_ATOL) saturations[i + 1] = self._step_saturation(sat, b, pseudopressure[i + 1]) self.time = time self.pseudopressure = pseudopressure diff --git a/src/bluebonnet/fluids/fluid.py b/src/bluebonnet/fluids/fluid.py index 6ef8dc4..47e0eef 100644 --- a/src/bluebonnet/fluids/fluid.py +++ b/src/bluebonnet/fluids/fluid.py @@ -39,7 +39,7 @@ def build_pvt_gas( """Build a table of PVT properties for use in the flow module. Parameters - ----------- + ---------- gas_values : dictionary keys include 'N2','H2S','CO2', 'Gas Specific Gravity', 'Reservoir Temperature (deg F)' @@ -91,10 +91,7 @@ def build_pvt_gas( ] ) compressibility = np.array( - [ - compressibility_DAK(temperature, p, temperature_pc, pressure_pc) - for p in pressure - ] + [compressibility_DAK(temperature, p, temperature_pc, pressure_pc) for p in pressure] ) pvt_gas = pd.DataFrame( data={ @@ -148,17 +145,16 @@ class Fluid: water_saturation_initial: float = 0.0 """Initial water saturation""" - def water_FVF( - self, pressure: NDArray[np.float] | float - ) -> NDArray[np.float] | float: + def water_FVF(self, pressure: NDArray[float] | float) -> NDArray[float] | float: """Water formation volume factor (B-factor) from McCain. Parameters ---------- pressure: np.ndarray water pressure in psia + Returns - ---------- + ------- b_w: ndarray b-factor in reservoir bbl / standard bbl """ @@ -238,7 +234,7 @@ def gas_viscosity( viscosity_gas (centipoise) Examples - ------- + -------- >>> Fluid(400, 35, 0.65, 0).viscosity_gas(100, -102, 649) 0.01652719692109309 """ @@ -307,7 +303,7 @@ def pressure_bubblepoint( Bubble point pressure in psia. Examples - ------- + -------- >>> Fluid(200, 35, 0.8, 650).pressure_bubblepoint() 2627.2017021875276 """ diff --git a/src/bluebonnet/fluids/gas.py b/src/bluebonnet/fluids/gas.py index c83e45b..5c3ecc5 100644 --- a/src/bluebonnet/fluids/gas.py +++ b/src/bluebonnet/fluids/gas.py @@ -30,7 +30,7 @@ def make_nonhydrocarbon_properties( for other non-hydrocarbon molecules Returns - -------- + ------- non_hydrocrabon_properties : NDArray structured array of non-hydrocarbon fluid properties @@ -81,7 +81,7 @@ def z_factor_DAK( z_factor (dimensionless) Examples - ------ + -------- >>> z_factor_DAK(400, 100, -102, 649) 0.9969013621293381 """ @@ -139,9 +139,7 @@ def calculate_error_fraction(rho: NDArray[np.float64]): return math.fabs(F_rho / DF_rho) rho_guess = 0.27 * pressure_reduced / temp_reduced - bounds = ( - (rho_guess / 5, rho_guess * 20), - ) # bounds go from a z-factor of 0.05 to 5 + bounds = ((rho_guess / 5, rho_guess * 20),) # bounds go from a z-factor of 0.05 to 5 result = minimize(calculate_error_fraction, rho_guess, bounds=bounds) rho = result.x[0] Z_factor = 0.27 * pressure_reduced / (rho * temp_reduced) @@ -180,9 +178,7 @@ def z_factor_hallyarbrough(pressure: float, temperature: float) -> float: dfdy = ( (1 + 4 * y + 4 * y**2 - 4 * y**3 + y**4) / (1 - y) ** 4 - (29.52 * t - 19.52 * t**2 + 9.16 * t**3) * y - + (2.18 + 2.82 * t) - * (90.7 * t - 242.2 * t**2 + 42.4 * t**3) - * y ** (1.18 + 2.82 * t) + + (2.18 + 2.82 * t) * (90.7 * t - 242.2 * t**2 + 42.4 * t**3) * y ** (1.18 + 2.82 * t) ) y = y - fdum / dfdy zfact = 0.06125 * pressure * t * np.exp(-1.2 * (1 - t) ** 2) / y @@ -216,7 +212,7 @@ def b_factor_DAK( b-factor (reservoir barrels / scf) Examples - ------- + -------- >>> b_factor_DAK(400, 100, -102, 649, 60, 14.7) 0.04317415921420302 """ @@ -260,7 +256,7 @@ def density_DAK( density_gas (lb / cubic ft) Examples - ------- + -------- >>> density_DAK(400, 100, -102, 649, 0.65) # returns 0.2143 """ MOLECULAR_WEIGHT_AIR = 28.964 @@ -298,7 +294,7 @@ def compressibility_DAK( compressibility (1 / psi) Examples - ------ + -------- >>> compressibility_DAK(400, 104.7, -102, 649) 0.009576560643021937 """ @@ -337,9 +333,9 @@ def compressibility_DAK( + 2 * A[9] * A[10] * rho**3 / (temp_reduced**3) - 2 * A[9] * A[10] ** 2 * rho**5 / (temp_reduced**3) ) * math.exp(-A[10] * rho**2) - compressibility_reduced = 1.0 / pressure_reduced - 0.27 / ( - z_factor**2 * temp_reduced - ) * (dz_drho / (1 + rho * dz_drho / z_factor)) + compressibility_reduced = 1.0 / pressure_reduced - 0.27 / (z_factor**2 * temp_reduced) * ( + dz_drho / (1 + rho * dz_drho / z_factor) + ) compressibility = compressibility_reduced / pressure_pseudocritical return compressibility @@ -372,7 +368,7 @@ def viscosity_Sutton( viscosity_gas (centipoise) Examples - ------- + -------- >>> viscosity_Sutton(400, 100, -102, 649, 0.65) 0.01652719692109309 """ @@ -388,8 +384,7 @@ def viscosity_Sutton( ) rho *= 16.018463 / 1e3 # convert to grams / cc xi = 0.949 * ( - (temperature_pseudocritical + 459.67) - / (molecular_weight**3 * pressure_pseudocritical**4) + (temperature_pseudocritical + 459.67) / (molecular_weight**3 * pressure_pseudocritical**4) ) ** (1.0 / 6.0) viscosity_lowpressure = ( 1e-5 @@ -432,7 +427,7 @@ def pseudocritical_point_Sutton( pressure_pseudocritical (psia) Examples - ------ + -------- >>> non_hydrocarbon_properties = make_nonhydrocarbon_properties(0.03, 0.012, 0.018) >>> points_pseudocritical_Sutton(0.65, non_hydrocarbon_properties, "dry gas") (-102.21827232417752, 648.510797253794) @@ -454,25 +449,17 @@ def pseudocritical_point_Sutton( ) / fraction_hydrocarbon if fluid == "dry gas": temp_critical_hydrocarbon = ( - 120.1 - + 429 * specific_gravity_hydrocarbon - - 62.9 * specific_gravity_hydrocarbon**2 + 120.1 + 429 * specific_gravity_hydrocarbon - 62.9 * specific_gravity_hydrocarbon**2 ) pressure_critical_hydrocarbon = ( - 671.1 - - 14 * specific_gravity_hydrocarbon - - 34.3 * specific_gravity_hydrocarbon**2 + 671.1 - 14 * specific_gravity_hydrocarbon - 34.3 * specific_gravity_hydrocarbon**2 ) else: temp_critical_hydrocarbon = ( - 164.3 - + 357.7 * specific_gravity_hydrocarbon - - 67.7 * specific_gravity_hydrocarbon**2 + 164.3 + 357.7 * specific_gravity_hydrocarbon - 67.7 * specific_gravity_hydrocarbon**2 ) pressure_critical_hydrocarbon = ( - 744 - - 125.4 * specific_gravity_hydrocarbon - + 5.9 * specific_gravity_hydrocarbon**2 + 744 - 125.4 * specific_gravity_hydrocarbon + 5.9 * specific_gravity_hydrocarbon**2 ) temperature_star = fraction_hydrocarbon * temp_critical_hydrocarbon + sum( fraction * temp_critical_nonhc @@ -524,7 +511,7 @@ def pseudopressure_Hussainy( pseudopressure (psi^2 / centipoise) Examples - ------- + -------- >>> pseudopressure_Hussainy(400, 100, -102, 649, 0.65) 593363.7626437937 """ diff --git a/src/bluebonnet/fluids/oil.py b/src/bluebonnet/fluids/oil.py index f6d7e2c..a2ae2a7 100644 --- a/src/bluebonnet/fluids/oil.py +++ b/src/bluebonnet/fluids/oil.py @@ -38,7 +38,7 @@ def b_o_Standing( Bo, the formation volume factor (V/V) Examples - ------- + -------- >>> b_o_Standing(200, 3_000, 35, 0.8, 650) >>> b_o_Standing(200, 2_000, 35, 0.8, 650) @@ -116,7 +116,7 @@ def pressure_bubblepoint_Standing( Bubble point pressure in psia. Examples - ------- + -------- >>> pressure_bubblepoint_Standing(200, 35, 0.8, 650) 2627.2017021875276 """ @@ -237,7 +237,7 @@ def solution_gor_Standing( Solution GOR in scf/stb Examples - ------- + -------- >>> solution_gor_Standing(200, 3_000, 35, 0.8, 650) 650 >>> solution_gor_Standing(200, 2_000, 35, 0.8, 650) @@ -249,8 +249,7 @@ def solution_gor_Standing( def gor_belowbubble(pressure: NDArray | float) -> NDArray | float: gor = gas_specific_gravity * ( - (pressure / 18.2 + 1.4) - * 10 ** (0.0125 * api_gravity - 0.00091 * temperature) + (pressure / 18.2 + 1.4) * 10 ** (0.0125 * api_gravity - 0.00091 * temperature) ) ** (1 / 0.83) return gor @@ -356,8 +355,7 @@ def oil_compressibility_undersat_Standing( temperature, api_gravity, gas_specific_gravity, solution_gor_initial ) density_bubblepoint = ( - 62.37 * oil_specific_gravity - + 0.0136 * gas_specific_gravity * solution_gor_initial + 62.37 * oil_specific_gravity + 0.0136 * gas_specific_gravity * solution_gor_initial ) / b_o_bubblepoint oil_compressibility = 1e-6 * math.exp( (density_bubblepoint + 0.004347 * (pressure - pressure_bubblepoint) - 79.1) @@ -493,7 +491,7 @@ def oil_compressibility_Standing( oil compressibility in 1/psi Examples - ------ + -------- >>> oil_compressibility_Standing(200, 3000, 35, 0.8, 650, -72.2, 653) >>> oil_compressibility_Standing(200, 2000, 35, 0.8, 650, -72.2, 653) @@ -536,9 +534,7 @@ def oil_compressibility_Standing( b_o_bubblepoint = b_o_bubblepoint_Standing( temperature, api_gravity, gas_specific_gravity, solution_gor_initial ) - dBo_dGOR = db_o_dgor_Standing( - temperature, api_gravity, gas_specific_gravity, solution_gor - ) + dBo_dGOR = db_o_dgor_Standing(temperature, api_gravity, gas_specific_gravity, solution_gor) compressibility = (b_g - dBo_dGOR) * dGOR_dpressure / b_o_bubblepoint return compressibility @@ -571,7 +567,7 @@ def density_Standing( oil density (lb/ft^3) Examples - ------ + -------- >>> density_Standing(200, 2000, 35, 0.8, 650) 44.989365953905136 """ @@ -582,9 +578,7 @@ def density_Standing( b_o = b_o_Standing( temperature, pressure, api_gravity, gas_specific_gravity, solution_gor_initial ) - density = ( - 62.37 * oil_specific_gravity + 0.0136 * gas_specific_gravity * solution_gor - ) / b_o + density = (62.37 * oil_specific_gravity + 0.0136 * gas_specific_gravity * solution_gor) / b_o return density @@ -622,17 +616,13 @@ def viscosity_beggs_robinson( temperature, pressure, api_gravity, gas_specific_gravity, solution_gor_initial ) if pressure >= pressure_bubblepoint: - mu_o_dead = ( - 10 ** (10 ** (3.0324 - 0.02023 * api_gravity) * temperature**-1.163) - 1 - ) + mu_o_dead = 10 ** (10 ** (3.0324 - 0.02023 * api_gravity) * temperature**-1.163) - 1 mu_o_live = _mu_dead_to_live_br(mu_o_dead, solution_gor_initial) mu_o = mu_o_live * (pressure / pressure_bubblepoint) ** ( 2.6 * pressure**1.187 * np.exp(-11.513 - 8.98e-5 * pressure) ) else: - mu_o_dead = ( - 10 ** (10 ** (3.0324 - 0.02023 * api_gravity) * temperature**-1.163) - 1 - ) + mu_o_dead = 10 ** (10 ** (3.0324 - 0.02023 * api_gravity) * temperature**-1.163) - 1 mu_o = _mu_dead_to_live_br(mu_o_dead, solution_gor) return mu_o diff --git a/src/bluebonnet/fluids/water.py b/src/bluebonnet/fluids/water.py index dab4ee0..dd1e5de 100644 --- a/src/bluebonnet/fluids/water.py +++ b/src/bluebonnet/fluids/water.py @@ -159,7 +159,5 @@ def viscosity_water_McCain( + 5.47119e-5 * salinity**3 - 1.55586e-6 * salinity**4 ) - mu_water = ( - A * temperature**-B * (0.9994 + 4.0295e-5 * pressure + 3.1062e-9 * pressure**2) - ) + mu_water = A * temperature**-B * (0.9994 + 4.0295e-5 * pressure + 3.1062e-9 * pressure**2) return mu_water diff --git a/src/bluebonnet/forecast/forecast.py b/src/bluebonnet/forecast/forecast.py index 2ffe40a..8551137 100644 --- a/src/bluebonnet/forecast/forecast.py +++ b/src/bluebonnet/forecast/forecast.py @@ -48,7 +48,7 @@ def fit_bounds(self): return ((self.M[0], self.tau[0]), (self.M[1], self.tau[1])) def regularize_initial_guess(self, guess: list[float]) -> list[float]: - """Ensure that initial guess is within bounds""" + """Ensure that initial guess is within bounds.""" if self.M[0] > guess[0]: guess[0] = self.M[0] elif guess[0] > self.M[1]: diff --git a/src/bluebonnet/forecast/forecast_pressure.py b/src/bluebonnet/forecast/forecast_pressure.py index 1e84837..4395a56 100644 --- a/src/bluebonnet/forecast/forecast_pressure.py +++ b/src/bluebonnet/forecast/forecast_pressure.py @@ -52,9 +52,7 @@ def _obj_function( # ) t = days / tau flow_propertiesM = FlowProperties(pvt_table, pressure_initial) - res_realgasM = SinglePhaseReservoir( - 80, pressure_initial, pressure_initial, flow_propertiesM - ) + res_realgasM = SinglePhaseReservoir(80, pressure_initial, pressure_initial, flow_propertiesM) res_realgasM.simulate(t, pressure_fracface=pressure_fracface) recovery_factor = res_realgasM.recovery_factor() return resource_in_place * recovery_factor - production @@ -101,9 +99,9 @@ def fit_production_pressure( Best fits for tau, M, and p_initial """ if filter_zero_prod_days: - prod_data = prod_data[ - (prod_data["Gas"] > 0) & (pd.notna(prod_data["Pressure"])) - ][["Days", "Gas", "Pressure"]] + prod_data = prod_data[(prod_data["Gas"] > 0) & (pd.notna(prod_data["Pressure"]))][ + ["Days", "Gas", "Pressure"] + ] else: prod_data = prod_data[["Days", "Gas", "Pressure"]] @@ -112,16 +110,12 @@ def fit_production_pressure( # with noisy data, sometimes a boxcar filter is beneficial if filter_window_size is not None: - pressure_fracface = sp.ndimage.uniform_filter1d( - pressure_fracface, size=filter_window_size - ) + pressure_fracface = sp.ndimage.uniform_filter1d(pressure_fracface, size=filter_window_size) cumulative_prod = np.cumsum(np.array(prod_data["Gas"])) if params is None: params = Parameters() - params.add( - "tau", value=1000.0, min=30.0, max=time[len(time) - 1] * 2 - ) # units: days + params.add("tau", value=1000.0, min=30.0, max=time[len(time) - 1] * 2) # units: days params.add( "M", value=cumulative_prod[-1], @@ -179,9 +173,9 @@ def plot_production_comparison( pressure over time (scaled by tau) """ if filter_zero_prod_days: - prod_data = prod_data[ - (prod_data["Gas"] > 0) & (pd.notna(prod_data["Pressure"])) - ][["Days", "Gas", "Pressure"]] + prod_data = prod_data[(prod_data["Gas"] > 0) & (pd.notna(prod_data["Pressure"]))][ + ["Days", "Gas", "Pressure"] + ] time = np.arange(len(prod_data["Days"])) else: prod_data = prod_data[["Days", "Gas", "Pressure"]] @@ -190,9 +184,7 @@ def plot_production_comparison( pressure_fracface = np.array(prod_data["Pressure"]) # if filter_window_size is not None: - pressure_fracface = sp.ndimage.uniform_filter1d( - pressure_fracface, size=filter_window_size - ) + pressure_fracface = sp.ndimage.uniform_filter1d(pressure_fracface, size=filter_window_size) # cumulative_prod = np.cumsum(np.array(prod_data["Gas"])) @@ -202,9 +194,7 @@ def plot_production_comparison( # pressure_fracface = pressure_initial flow_propertiesM = FlowProperties(pvt_table, pressure_initial) - res_realgasM = SinglePhaseReservoir( - 80, pressure_fracface, pressure_initial, flow_propertiesM - ) + res_realgasM = SinglePhaseReservoir(80, pressure_fracface, pressure_initial, flow_propertiesM) res_realgasM.simulate(time / tau, pressure_fracface=pressure_fracface) rf2M = res_realgasM.recovery_factor() diff --git a/src/bluebonnet/plotting.py b/src/bluebonnet/plotting.py index fb1d91e..75ac806 100644 --- a/src/bluebonnet/plotting.py +++ b/src/bluebonnet/plotting.py @@ -17,9 +17,7 @@ TwoPhaseReservoir, ) -Reservoir = Union[ - IdealReservoir, SinglePhaseReservoir, TwoPhaseReservoir, MultiPhaseReservoir -] +Reservoir = Union[IdealReservoir, SinglePhaseReservoir, TwoPhaseReservoir, MultiPhaseReservoir] class SquareRootScale(mscale.ScaleBase): diff --git a/tests/flow/test_properties.py b/tests/flow/test_properties.py index fefe08f..f9c6554 100644 --- a/tests/flow/test_properties.py +++ b/tests/flow/test_properties.py @@ -92,7 +92,7 @@ def df_pvt(): def pvt_multiphase_oil(): - """Generate pvt_multiphase_oil.csv""" + """Generate pvt_multiphase_oil.csv.""" Sw = 0.1 p_frac = 1000 p_res = 6_000 @@ -124,9 +124,9 @@ def pvt_multiphase_oil(): # scale pseudopressure pseudopressure = interp1d(df_pvt.pressure, df_pvt.pseudopressure) - df_pvt["pseudopressure"] = ( - pseudopressure(df_pvt["pressure"]) - pseudopressure(p_frac) - ) / (pseudopressure(p_res) - pseudopressure(p_frac)) + df_pvt["pseudopressure"] = (pseudopressure(df_pvt["pressure"]) - pseudopressure(p_frac)) / ( + pseudopressure(p_res) - pseudopressure(p_frac) + ) df_pvt.to_csv("../data/pvt_multiphase_oil.csv") diff --git a/tests/flow/test_reservoir.py b/tests/flow/test_reservoir.py index 5a33b3a..9a66ee8 100644 --- a/tests/flow/test_reservoir.py +++ b/tests/flow/test_reservoir.py @@ -96,9 +96,7 @@ def curve(time, intercept, slope): for density in (True, False): rf = reservoir.recovery_factor(density=density) slope = logslope(time, rf, (time > 0.1) & (time < 0.3)) - assert ( - np.abs(slope - 0.5) < 0.05 - ), "Early recovery factor goes as the square root" + assert np.abs(slope - 0.5) < 0.05, "Early recovery factor goes as the square root" def test_rf_late_asymptotes(self, nx, pf, pi, fluid, Reservoir, nt): if Reservoir == MultiPhaseReservoir: diff --git a/tests/fluids/test_gas.py b/tests/fluids/test_gas.py index 2f7b01e..f24b33e 100644 --- a/tests/fluids/test_gas.py +++ b/tests/fluids/test_gas.py @@ -143,9 +143,7 @@ def test_compressibility_DAK(gas_properties): real_compressibility = pytest.approx(0.01002548578259275, rel=1e-3) else: real_compressibility = pytest.approx(1.4644387216173005e-4, rel=1e-3) - compressibility = gas.compressibility_DAK( - temperature, pressure, temperature_pc, pressure_pc - ) + compressibility = gas.compressibility_DAK(temperature, pressure, temperature_pc, pressure_pc) assert compressibility == real_compressibility diff --git a/tests/fluids/test_water.py b/tests/fluids/test_water.py index 2aed5b0..aabb510 100644 --- a/tests/fluids/test_water.py +++ b/tests/fluids/test_water.py @@ -28,10 +28,7 @@ def test_compressibility_McCain(water_properties): pressure = water_properties.pressure salinity = water_properties.salinity co_water_true = pytest.approx(3.0860375940019587e-06) - assert ( - water.compressibility_water_McCain(temperature, pressure, salinity) - == co_water_true - ) + assert water.compressibility_water_McCain(temperature, pressure, salinity) == co_water_true def test_density_McCain(water_properties): diff --git a/tests/forecast/test_forecast.py b/tests/forecast/test_forecast.py index 306420d..54933c4 100644 --- a/tests/forecast/test_forecast.py +++ b/tests/forecast/test_forecast.py @@ -43,9 +43,7 @@ def pressure_varying_prod(): reservoir = SinglePhaseReservoir(nx, pf, pi, flow_props) reservoir.simulate(time_scaled, pressure_v_time) rf = reservoir.recovery_factor() - prod = pd.DataFrame( - {"Days": time_scaled * tau_in, "Gas": rf, "Pressure": pressure_v_time} - ) + prod = pd.DataFrame({"Days": time_scaled * tau_in, "Gas": rf, "Pressure": pressure_v_time}) return prod, pvt_table diff --git a/tests/test_plots.py b/tests/test_plots.py index 83254fe..507396e 100644 --- a/tests/test_plots.py +++ b/tests/test_plots.py @@ -1,3 +1,5 @@ +"""Test plotting functionality.""" + from __future__ import annotations import matplotlib.pyplot as plt @@ -29,9 +31,7 @@ @pytest.fixture() def reservoir(): - reservoir = SinglePhaseReservoir( - nx, pressure_fracface=pf, pressure_initial=pi, fluid=fluid - ) + reservoir = SinglePhaseReservoir(nx, pressure_fracface=pf, pressure_initial=pi, fluid=fluid) t_end = 11 time_scaled = np.linspace(0, np.sqrt(t_end), nt) ** 2 reservoir.simulate(time_scaled)