{ "cells": [ { "cell_type": "markdown", "id": "c5554800", "metadata": {}, "source": [ "# Example 07: Uncertainty in gas properties calculated from measured speed of sound\n", "\n", "This notebook demonstrates uncertainty calculations for gas properties (density and molar mass) derived from measured speed of sound.\n", "The calculation uses the GERG-2008 equation of state to calculate the isentropic exponent (kappa) and compressibility factor (Z),\n", "which are then used together with the measured speed of sound to calculate density and molar mass.\n", "\n", "Uncertainty evaluations are performed using standard uncertainty calculations based on sensitivity coefficients and input uncertainties." ] }, { "cell_type": "code", "execution_count": 1, "id": "6c4e97f6", "metadata": {}, "outputs": [], "source": [ "# Import Required Libraries\n", "import pvtlib\n", "from uncertaintylib import uncertainty_functions, plot_functions\n", "import pandas as pd\n", "import os" ] }, { "cell_type": "markdown", "id": "02e0ae5d", "metadata": {}, "source": [ "### Read inputs from CSV file\n", "\n", "The inputs to the uncertainty calculation are provided in a CSV file.\n", "\n", "The input contains:\n", "- Pressure (P) - bara\n", "- Temperature (T) - °C\n", "- Measured speed of sound (measured_sos)\n", "- Gas composition (N2, CO2, C1, C2, C3, iC4, nC4)\n", "- GERG model uncertainty factors for kappa and Z\n", "\n", "Key features:\n", "- Uncertainty can be provided either as an absolute value (standard_uncertainty) or as a percentage (standard_uncertainty_percent)\n", "- If both are given, the code will use the larger of the two\n", "- Distribution, min and max are used by Monte Carlo simulations\n", "- Unit is for information only\n", "- The GERG uncertainty factors (mean value = 1.0, uncertainty = 0.05%) account for model uncertainty in the equation of state" ] }, { "cell_type": "code", "execution_count": 2, "id": "289334f4", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | input_name | \n", "unit | \n", "mean | \n", "standard_uncertainty | \n", "standard_uncertainty_percent | \n", "distribution | \n", "min | \n", "max | \n", "
|---|---|---|---|---|---|---|---|---|
| 0 | \n", "P | \n", "bara | \n", "100.00 | \n", "0.1500 | \n", "NaN | \n", "normal | \n", "NaN | \n", "NaN | \n", "
| 1 | \n", "T | \n", "C | \n", "50.00 | \n", "0.1500 | \n", "NaN | \n", "normal | \n", "NaN | \n", "NaN | \n", "
| 2 | \n", "measured_sos | \n", "m/s | \n", "433.00 | \n", "NaN | \n", "0.10 | \n", "normal | \n", "NaN | \n", "NaN | \n", "
| 3 | \n", "N2 | \n", "mol% | \n", "1.00 | \n", "0.0344 | \n", "NaN | \n", "normal | \n", "0.0 | \n", "100.0 | \n", "
| 4 | \n", "CO2 | \n", "mol% | \n", "2.00 | \n", "0.0191 | \n", "NaN | \n", "normal | \n", "0.0 | \n", "100.0 | \n", "
| 5 | \n", "C1 | \n", "mol% | \n", "90.00 | \n", "0.0000 | \n", "NaN | \n", "normal | \n", "0.0 | \n", "100.0 | \n", "
| 6 | \n", "C2 | \n", "mol% | \n", "6.40 | \n", "0.0329 | \n", "NaN | \n", "normal | \n", "0.0 | \n", "100.0 | \n", "
| 7 | \n", "C3 | \n", "mol% | \n", "0.50 | \n", "0.0126 | \n", "NaN | \n", "normal | \n", "0.0 | \n", "100.0 | \n", "
| 8 | \n", "iC4 | \n", "mol% | \n", "0.05 | \n", "0.0026 | \n", "NaN | \n", "normal | \n", "0.0 | \n", "100.0 | \n", "
| 9 | \n", "nC4 | \n", "mol% | \n", "0.05 | \n", "0.0025 | \n", "NaN | \n", "normal | \n", "0.0 | \n", "100.0 | \n", "
| 10 | \n", "GERG_kappa_uncertainty_factor | \n", "- | \n", "1.00 | \n", "NaN | \n", "0.05 | \n", "normal | \n", "NaN | \n", "NaN | \n", "
| 11 | \n", "GERG_Z_uncertainty_factor | \n", "- | \n", "1.00 | \n", "NaN | \n", "0.05 | \n", "normal | \n", "NaN | \n", "NaN | \n", "