uncertaintylib.uncertainty_models.gas_composition

MIT License

Copyright (c) 2025 Equinor

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Functions

component_uncertainty_from_ASTM_D1945(...)

Estimate gas composition uncertainty according to ASTM D1945 standard.

component_uncertainty_from_haagenvik2024(...)

Estimate component uncertainties from the Hagenvik et al. (2024) model.

component_uncertainty_from_norsok_I106(...)

Estimate gas composition uncertainty according to NORSOK I-106:2014 standard.

uncertaintylib.uncertainty_models.gas_composition.component_uncertainty_from_ASTM_D1945(composition_mole_percent)[source]

Estimate gas composition uncertainty according to ASTM D1945 standard.

This function calculates component uncertainty according to ASTM D1945 “Reproducibility” (chapter 10.1.2). The uncertainty values are based on 95% confidence level (k=2) and given in absolute terms (mol%). The interpretation follows the NFOGM Fiscal Gas Metering Station Uncertainty (GasMet) tool (https://gasmetapp.web.norce.cloud/).

Parameters:

composition_mole_percent (dict) – Gas composition as a dictionary with component names as keys and mole percentages as values. The composition does not need to be normalized to 100%. Supported components: N2, CO2, C1, C2, C3, iC4, nC4, iC5, nC5, nC6, nC7, nC8, nC9, nC10. Example: {‘C1’: 85.0, ‘C2’: 10.0, ‘N2’: 5.0}

Returns:

dict – A dictionary in standard uncertaintylib format with the following keys:

  • ’mean’dict

    Normalized mole percentages for each component.

  • ’standard_uncertainty’dict

    Standard uncertainty (k=1) for each component in absolute terms (mol%).

  • ’distribution’dict

    Distribution type for each component (all set to ‘normal’).

  • ’min’dict

    Minimum allowable values for each component (0.0 mol%).

  • ’max’dict

    Maximum allowable values for each component (100.0 mol%).

Return type:

dict

Notes

The reproducibility values from ASTM D1945 are applied as follows:

  • < 0.1 mol%: U = 0.02 mol% (k=2)

  • 0.1 to 1.0 mol%: U = 0.07 mol% (k=2)

  • 1.0 to 5.0 mol%: U = 0.10 mol% (k=2)

  • 5.0 to 10.0 mol%: U = 0.12 mol% (k=2)

  • > 10.0 mol%: U = 0.15 mol% (k=2)

The standard uncertainty is calculated by dividing the expanded uncertainty (k=2) by 2 to obtain the single standard deviation (k=1).

Examples

>>> composition = {'C1': 85.0, 'C2': 10.0, 'N2': 5.0}
>>> uncertainty_data = component_uncertainty_from_ASTM_D1945(composition)
>>> print(uncertainty_data['standard_uncertainty']['C1'])
0.075
uncertaintylib.uncertainty_models.gas_composition.component_uncertainty_from_norsok_I106(composition_mole_percent)[source]

Estimate gas composition uncertainty according to NORSOK I-106:2014 standard.

This function calculates the expanded uncertainty (k=2) for gas composition components based on the NORSOK I-106:2014 standard. The uncertainty depends on the mole fraction of each component and the ratio of average molar mass to component molar mass. Molar masses are automatically retrieved from GERG-2008 reference values. NORSOK I-106 only provides component uncertainty down to 0.5 mol%. This function uses the same uncertainty value below 0.5 mol% to handle low concentration components.

Note: This method do not take into account increased uncertainty for heavier components, and therefore tend to underestimate compositional uncertainties for rich natural gases. The higher the molar mass of a component, the lower the uncertainty according to this method, while in reality the opposite is often the case.

Parameters:

composition_mole_percent (dict) – Gas composition as a dictionary with component names as keys and mole percentages as values. The composition does not need to be normalized to 100%. Supports all GERG-2008 components: C1, N2, CO2, C2, C3, iC4, nC4, iC5, nC5, nC6, nC7, nC8, nC9, nC10, H2, O2, CO, H2O, H2S, He, Ar. Example: {‘C1’: 85.0, ‘C2’: 10.0, ‘N2’: 5.0}

Returns:

dict – A dictionary in standard uncertaintylib format with the following keys:

  • ’mean’dict

    Normalized mole percentages for each component.

  • ’standard_uncertainty’dict

    Standard uncertainty (k=1) for each component in absolute terms (mol%).

  • ’distribution’dict

    Distribution type for each component (all set to ‘normal’).

  • ’min’dict

    Minimum allowable values for each component (0.0 mol%).

  • ’max’dict

    Maximum allowable values for each component (100.0 mol%).

Return type:

dict

Notes

The NORSOK I-106 method calculates uncertainty using the formula:

\[U_{x_i} = \text{factor} \times \frac{M_{\text{avg}}}{M_i}\]

where:

  • U_{x_i} is the expanded uncertainty (k=2) for component i (mol%)

  • M_{avg} is the average molar mass of the gas mixture (g/mol)

  • M_i is the molar mass of component i (g/mol)

  • factor depends on the component’s mass percent (not mole percent):

    • < 20 mass%: factor = 0.15

    • 20 to 50 mass%: factor = 0.30

    • > 50 mass%: factor = 0.60

The input composition is provided in mole percent, which is then converted to mass percent to determine the appropriate factor. The calculated uncertainty is returned in mole percent. The standard uncertainty is calculated by dividing the expanded uncertainty (k=2) by 2 to obtain the single standard deviation (k=1).

Molar masses are taken from GERG-2008 reference data.

Examples

>>> composition = {'C1': 85.0, 'C2': 10.0, 'N2': 5.0}
>>> uncertainty_data = component_uncertainty_from_norsok_I106(composition)
>>> print(uncertainty_data['standard_uncertainty']['C1'])
0.3

References

NORSOK standard I-106:2014: “Fiscal metering systems for hydrocarbon liquid and gas”

uncertaintylib.uncertainty_models.gas_composition.component_uncertainty_from_haagenvik2024(composition_mole_percent, lower_uncertainty_limit=None)[source]

Estimate component uncertainties from the Hagenvik et al. (2024) model.

The method applies empirical power-law regressions to each reported component and returns the result in the standard uncertaintylib format. Input compositions are internally normalized to 100 mol% before uncertainties are calculated.

This model should only be used for gas compositions with substantial methane content (minimum 60 mol%).

Parameters:
  • composition_mole_percent (dict) – Gas composition as a dictionary with component names as keys and mole percentages as values. The input does not need to sum to 100; it is normalized internally before use. Supported components: N2, CO2, C1, C2, C3, iC4, nC4, iC5, nC5, nC6, nC7, nC8, nC9, nC10. Example: {‘C1’: 85.0, ‘C2’: 10.0, ‘N2’: 5.0}

  • lower_uncertainty_limit (float, optional) – Optional lower limit for standard uncertainty estimates (mol%). When provided, it is applied only to non-zero, non-C1 components after the power-law uncertainty has been calculated. It is not applied to methane (C1), whose uncertainty is always set to 0.0, or to zero-concentration components, which also remain at 0.0. Default is None.

Returns:

dict – A dictionary in standard uncertaintylib format with the following keys:

  • ’mean’dict

    Normalized mole percentages for each component.

  • ’standard_uncertainty’dict

    Standard uncertainty (k=1) for each component in absolute terms (mol%).

  • ’distribution’dict

    Distribution type for each component (all set to ‘normal’).

  • ’min’dict

    Minimum allowable values for each component (0.0 mol%).

  • ’max’dict

    Maximum allowable values for each component (100.0 mol%).

Return type:

dict

Notes

For non-zero components other than methane, the standard uncertainty is estimated from a component-specific power law:

\[u_i = a \times x_i^b\]

where \(u_i\) is the standard uncertainty, \(x_i\) is the normalized mole percentage of component \(i\), and \(a\) and \(b\) are fitted parameters from K-lab parallel test data.

Methane (C1) is intentionally assigned a standard uncertainty of 0.0. After the composition is normalized to 100 mol%, the methane value is constrained by the other reported components, so its uncertainty contribution is treated as being represented through the normalization effect rather than a separate methane regression.

Components reported as 0.0 mol% keep a standard uncertainty of 0.0, even when lower_uncertainty_limit is provided.

For heavy components (C6+), the same power law coefficients as C6 are used.

Power law coefficients (from K-lab parallel test data):

  • N2: a=0.034, b=1.005

  • CO2: a=0.013, b=0.514

  • C2: a=0.041, b=-0.118

  • C3: a=0.025, b=0.970

  • iC4: a=0.018, b=0.635

  • nC4: a=0.027, b=0.793

  • iC5: a=0.016, b=0.383

  • nC5: a=0.023, b=0.470

  • C6+: a=0.103, b=0.683

Examples

>>> composition = {'C1': 85.0, 'C2': 8.0, 'C3': 4.0, 'N2': 3.0}
>>> uncertainty_data = component_uncertainty_from_haagenvik2024(composition)
>>> uncertainty_data['standard_uncertainty']['C1']
0.0

References

Hagenvik, C., et al. (2024). “Exploring the Relationship between Speed of Sound, Density and Isentropic Exponent.” Presented at NFOGM 2024. https://nfogm.no/wp-content/uploads/2025/08/1-Single-Phase-1-Exploring-the-Relationship-between-Speed-of-Sound-Density-and-Isentropic-Exponent-Christian-Hagenvik_Equinor.pdf