gascompressibility.calc_z#

calc_z(sg=None, P=None, T=None, H2S=None, CO2=None, N2=None, Pr=None, Tr=None, pmodel='piper', zmodel='DAK', guess=None, newton_kwargs=None, smart_guess=None, ps_props=False, ignore_conflict=False, **kwargs)[source]#

Calculates the gas compressibility factor, \(Z\).

Basic (most common) usage:

>>> import gascompressibility as gc
>>>
>>> gc.calc_z(sg=0.7, T=75, P=2010)
0.7366562810878984

In presence of significant non-hydrocarbon impurities:

>>> gc.calc_z(sg=0.7, T=75, P=2010, CO2=0.1, H2S=0.07, N2=0.05)
0.7765149771306533

When pseudo-critical properties are known (not common):

>>> gc.calc_z(Pr=1.5, Tr=1.5)
0.859314380561347

Picking correlation models of your choice

>>> gc.calc_z(sg=0.7, T=75, P=2010, zmodel='kareem', pmodel='sutton')
0.7150183342641309

Returning all associated pseudo-critical properties computed

>>> gc.calc_z(sg=0.7, T=75, P=2010, ps_props=True)
{'z': 0.7366562810878984, 'Tpc': 371.4335560823552, 'Ppc': 660.6569792741872, 'J': 0.56221847, 'K': 14.450840999999999, 'Tr': 1.4394768357478496, 'Pr': 3.0646766226921294}
Parameters:
  • sg (float) – specific gravity of gas (dimensionless)

  • P (float) – pressure of gas (psig)

  • T (float) – temperature of gas (°F)

  • H2S (float) – mole fraction of H2S (dimensionless)

  • CO2 (float) – mole fraction of CO2 (dimensionless)

  • N2 (float) – mole fraction of N2 (dimensionless). Available only when pmodel='piper' (default)

  • Pr (float) – pseudo-reduced pressure, Pr (dimensionless)

  • Tr (float) – pseudo-reduced temperature, Tr (dimensionless)

  • pmodel (str) –

    choice of a pseudo-critical model. Check Theories 1: Pseudo-Critical Property Models for more information. Accepted inputs: 'sutton' | 'piper'

    See also

    Sutton, Piper

  • zmodel (str) – choice of a z-correlation model. Check Theories 2: Z-Factor Correlation Models for more information. Accepted inputs: 'DAK' | 'hall_yarborough' | 'londono' |'kareem'

  • guess (float) – initial guess of z-value for z-correlation models using iterative convergence ('DAK' | 'hall_yarborough' | 'londono'). NOT RECOMMENDED to manually set this parameter unless the computed \(P_r\) exceeds 15. If so a default guess=2 is applied, which is a good estimate for high-pressure scenarios. Otherwise for \(P_r < 15\), the built-in smart_guess takes over to automatically provide a good initial guess that’s fast and accurate.

  • newton_kwargs (dict) –

    dictonary of keyword-arguments used by scipy.optimize.newton method for z-correlation models that use iterative convergence ('DAK' | 'hall_yarborough' | 'londono').

    >>> gc.calc_z(sg=0.7, P=2010, T=75, newton_kwargs={'maxiter': 10000})
    0.7366562810878984
    

  • smart_guess (bool) – True by default. Prevents rare corner cases where scipy.optimize.newton fails to converge to a true solution, and improves speed. It provides “smart” initial guess with explicit z-models (like zmodel='kareem') for \(P_r < 15\). For \(P_r > 15\), smart guess is turned off and uses a fixed value of guess=2, which is shown to work well. Check Theories 2.6: Caveats for more information.

  • ps_props (bool) – set this to True to return a dictionary of all associated pseudo-critical properties computed during calculation of the z-factor.

  • ignore_conflict (bool) – set this to True to override calculated variables with input keyword arguments.

  • kwargs

    optional kwargs used by pseudo-critical models (Sutton | Piper) that allow direct calculation of z-factor from pseudo-critical properties instead of specific gravity correlation. Consider the below code example that uses pmodel='sutton':

    >>> gc.calc_z(Ppc=663, e_correction=21, Tpc=377.59, P=2010, T=75, pmodel='sutton', ignore_conflict=True)
    0.7720015496503527
    

    Ppc, e_correction, Tpc aren’t default parameters defined in this function, but they can be optionally passed into Sutton’s Sutton.calc_Pr and Sutton.calc_Tr methods if you already know these values (not common) and would like to compute the z-factor from these instead of using specific gravity correlation.

Returns:

gas compressibility factor, \(Z\) (dimensionless)

Return type:

float