pyscal.factory

Factory functions for creating the pyscal objects

class pyscal.factory.PyscalFactory[source]

Class for implementing the factory pattern for Pyscal objects

The factory functions herein can take multiple parameter sets, determine what kind of parametrization to be used, and set up the full objects based on these parameters, instead of explicitly having to call the API for each task.

Example:

wo = WaterOil(sorw=0.05)
wo.add_corey_water(nw=3)
wo.add_corey_oil(now=2)
# is equivalent to:
wo = factory.create_water_oil(dict(sorw=0.05, nw=3, now=2))

Parameter names to factory functions are case insensitive, while the add_*() parameters are not. This is because the add_*() parameters are meant as a Python API, while the factory class is there to aid users when input is written in a different context, like an Excel spreadsheet.

static alias_sgrw(params)[source]

Allow sgrw as an alias for sorw by remapping a sgrw value to a sorw value in an incoming dict.

Will error hard of sorw already exists and is not nan.

This aliasing is relevant when GasWater is modelled as three-phase to allow for condensate forming, and mirrors GasWater.__init__() which performs the same aliasing.

Parameters:

params (Dict[str, Any]) – Keys must be lower case.

Return type:

Dict[str, Any]

static create_gas_oil(params=None, fast=False)[source]

Create a GasOil object from a dictionary of parameters.

Parameterization (Corey/LET) is inferred from presence of certain parameters in the dictionary.

Don’t rely on behaviour of you supply both Corey and LET at the same time.

NB: the add_LET_* methods have the names ‘l’, ‘e’ and ‘t’ in their signatures, which is not precise enough in this context, so we require e.g. ‘Lg’ and ‘Log’ (which both will be translated to ‘l’).

Recognized parameters:

swirr, sgcr, sorg, swl, krgendanchor, h, tag, ng, krgend, krgmax, nog, kroend, kromax lg, eg, tg, log, eog, tog

Parameters:
  • params (Optional[Dict[str, float]]) – Dictionary with parameters describing the GasOil object.

  • fast (bool) – If fast-mode should be set for constructed object.

Return type:

GasOil

static create_gas_water(params=None, fast=False)[source]

Create a GasWater object.

Parameterization (Corey/LET) is inferred from presence of certain parameters in the dictionary.

Parameters:
  • params (Optional[Dict[str, float]]) – Dictionary with parameters for GasWater.

  • fast (bool) – If fast-mode should be set for constructed object.

Return type:

GasWater

static create_gasoil_list(relperm_params_df, h=None, fast=False)[source]

Create a PyscalList with GasOil objects from a dataframe

Parameters:
  • relperm_params_df (DataFrame) – A valid dataframe with GasOil parameters, processed through load_relperm_df()

  • h (Optional[float]) – Saturation steplength

  • fast (bool) – If fast-mode should be set for constructed object

Return type:

PyscalList

Returns:

PyscalList, consisting of GasOil objects

static create_gaswater_list(relperm_params_df, h=None, fast=False)[source]

Create a PyscalList with WaterOilGas objects from a dataframe, to be used for GasWater

Parameters:
  • relperm_params_df (DataFrame) – A valid dataframe with GasWater parameters, processed through load_relperm_df()

  • h (Optional[float]) – Saturation steplength

  • fast (bool) – If fast-mode should be set for constructed object

Return type:

PyscalList

Returns:

PyscalList, consisting of GasWater objects

static create_pyscal_list(relperm_params_df, h=None, fast=False)[source]

Create WaterOilGas, WaterOil, GasOil or GasWater list based on what is available

Parameters:
  • relperm_params_df (DataFrame) – Input data, should have been processed through load_relperm_df().

  • h (Optional[float]) – Saturation step-value

  • fast (bool) – If fast-mode should be set for constructed object

Returns:

PyscalList, consisting of either WaterOil, GasOil or WaterOilGas objects

static create_scal_recommendation(params, tag='', h=None, fast=False)[source]

Set up a SCAL recommendation curve set from input as a dictionary of dictionary.

The keys in in the dictionary must be “low”, “base” and “high”.

The value for “low” must be a new dictionary with saturation endpoints and LET/Corey parameters, as you would feed it to the create_water_oil_gas() factory function, and then similarly for base and high.

For oil-water only, you may omit the parameters for gas-oil. A WaterOilGas object for each case is created, but only the WaterOil part of it will be used.

For gas-water, a GasWater object is created for each pess, base and high.

Parameters:
  • params (Dict[str, Dict[str, float]]) – keys low, base and high. The value for “low” must be a new dictionary with saturation endpoints and LET/Corey parameters, as you would feed it to the create_water_oil_gas() factory function, and then similarly for base and high.

  • tag (str) – String to be used as the tag, will end up in comments.

  • h (Optional[float]) – Saturation step length

  • fast (bool) – If fast-mode should be set for constructed object.

Return type:

SCALrecommendation

static create_scal_recommendation_list(input_df, h=None, fast=False)[source]

Requires SATNUM and CASE to be defined in the input data

Parameters:
  • input_df (DataFrame) – Input data, should have been processed through load_relperm_df().

  • h (Optional[float]) – Saturation step-value

  • fast (bool) – If fast-mode should be set for constructed object

Return type:

PyscalList

Returns:

PyscalList, consisting of SCALrecommendation objects

static create_water_oil(params=None, fast=False)[source]

Create a WaterOil object from a dictionary of parameters.

Parameterization (Corey/LET) is inferred from presence of certain parameters in the dictionary.

Don’t rely on behaviour of you supply both Corey and LET at the same time.

Parameter names in the dictionary are case insensitive. You can use Swirr, swirr, sWirR, swiRR etc.

NB: the add_LET_* methods have the names ‘l’, ‘e’ and ‘t’ in their signatures, which is not precise enough in this context, so we require e.g. ‘Lw’ and ‘Low’ (which both will be translated to ‘l’)

Recognized parameters:

swirr, swl, swcr, sorw, socr, sgrw, h, tag, nw, now, krwmax, krwend, lw, ew, tw, low, eow, tow, lo, eo, to, kroend, a, a_petro, b, b_petro, poro_ref, perm_ref, drho, a, b, poro, perm, sigma_costau

Parameters:
  • params (Optional[Dict[str, float]]) – Dictionary with parameters describing the WaterOil object.

  • fast (bool) – If fast-mode should be set for constructed object.

Return type:

WaterOil

static create_water_oil_gas(params=None, fast=False)[source]

Create a WaterOilGas object from a dictionary of parameters

Parameterization (Corey/LET) is inferred from presence of certain parameters in the dictionary.

Check create_water_oil() and create_gas_oil() for lists of supported parameters (case insensitive)

Return type:

WaterOilGas

Params:

params: Dictionary with parameters describing the WaterOilGas object. fast: If fast-mode should be set for constructed object.

static create_wateroil_list(relperm_params_df, h=None, fast=False)[source]

Create a PyscalList with WaterOil objects from a dataframe

Parameters:
  • relperm_params_df (DataFrame) – A valid dataframe with WaterOil parameters, processed through load_relperm_df()

  • h (Optional[float]) – Saturation steplength

  • fast (bool) – If fast-mode should be set for constructed object

Return type:

PyscalList

Returns:

PyscalList, consisting of WaterOil objects

static create_wateroilgas_list(relperm_params_df, h=None, fast=False)[source]

Create a PyscalList with WaterOilGas objects from a dataframe

Parameters:
  • relperm_params_df (DataFrame) – Input data, should have been processed through load_relperm_df().

  • h (Optional[float]) – Saturation step-value

  • fast (bool) – If fast-mode should be set for constructed object

Return type:

PyscalList

Returns:

PyscalList, consisting of WaterOilGas objects

static load_relperm_df(inputfile, sheet_name=None)[source]

Read CSV or XLSX from file and return scal/relperm data a dataframe.

Checks validity in SATNUM and CASE columns. Ensures case-insensitiveness SATNUM, CASE, TAG and COMMENT

Merges COMMENT into TAG column, as only TAG is picked up downstream. Adds a prefix “SATNUM <number>” to all tags.

All strings in CASE column are converted to lowercase. Applies aliasing in the CASE column so that “pessimistic” and “pess” map to “low”, and “optimistic” and “opt” map to “high”.

Parameters:
  • inputfile (Union[str, DataFrame]) – Filename for XLSX or CSV file, or a pandas DataFrame.

  • sheet_name (Optional[str]) – Sheet-name, only used when loading xlsx files.

Return type:

DataFrame

Returns:

To be handed over to pyscal list factory methods. Empty dataframe in case of errors (messages will be logged).

static remap_validate_cases(casevalues)[source]

Remap values in the CASE column so that we can use aliases.

All values are first made lower case, then “pessimistic” and “pess” are mapped to “low” and “optimistic” and “opt” are mapped to “high”.

Will raise ValueError if some values are not understood, and if we don’t have exactly three unique values.

Parameters:

casevalues (List[str]) – values to remap.

Return type:

List[str]

pyscal.factory.check_deprecated(params)[source]

Check for deprecated parameter names

Parameters:

params (Dict[str, Any]) – Dictionary of parameters for which only the keys are used here.

Return type:

None

pyscal.factory.filter_nan_from_dict(params)[source]

Clean out keys with NaN values in a dict.

Key with string values are passed through (empty strings are allowed)

Parameters:

params (dict) – Any dictionary

Return type:

dict

Returns

dict, with as many or fewer keys.

pyscal.factory.infer_tabular_file_format(filename)[source]

Determine the file format of a file containing tabular data, distinguishes between csv, xls and xlsx

Parameters:

filename (Union[str, Path]) – Path to file

Return type:

str

Returns:

One of “csv”, “xlsx” or “xls”. Empty string if nothing found out.

pyscal.factory.slicedict(dct, keys)[source]

Slice a dictionary for a set of keys. Keys not existing will be ignored.

pyscal.factory.sufficient_gas_oil_params(params, failhard=False)[source]

Determine if the supplied parameters are sufficient for attempting at creating a GasOil object.

In the factory context, relying on the defaults in the API is not allowed, as that would leave the tasks for the factory undefined (Corey or LET, and which pc?)

Parameters:
  • params (dict) – Dictionary of parameters to a GasOil object.

  • failhard (bool) – If True, will raise ValueError when parameters are insufficient. If defaulted, no exception is raised.

Return type:

bool

Returns:

True if a GasOil object should be attempted constructed (but no guarantee for validity of numerical values)

pyscal.factory.sufficient_gas_water_params(params, failhard=False)[source]

Determine if the supplied parameters are sufficient for attempting creating a WaterOilGas object to be used for gas water.

In the factory context, relying on the defaults in the API (wateroilgas.py) is not allowed, as that would leave the tasks for the factory undefined (Corey or LET, and which pc?)

Parameters:
  • params (dict) – Dictionary of parameters to a GasWater object.

  • failhard (bool) – If True, will raise ValueError when parameters are insufficient. If defaulted, no exception is raised.

Return type:

bool

Returns:

True if a GasWater object should be attempted constructed

(but no guarantee for validity of numerical values)

pyscal.factory.sufficient_water_oil_params(params, failhard=False)[source]

Determine if the supplied parameters are sufficient for attempting creating a WaterOil object.

In the factory context, relying on the defaults in the API is not allowed, as that would leave the tasks for the factory undefined (Corey or LET, and which pc?)

Parameters:
  • params (dict) – Dictionary of parameters to a WaterOil object.

  • failhard (bool) – If True, will raise ValueError when parameters are insufficient. If defaulted, no exception is raised.

Return type:

bool

Returns:

True if a WaterOil object should be attempted constructed (but no guarantee for validity of numerical values)