
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "auto_examples/oil_and_gas/plot_gas_density_calcs.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_auto_examples_oil_and_gas_plot_gas_density_calcs.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_auto_examples_oil_and_gas_plot_gas_density_calcs.py:


===============================
Calculation of gas density
===============================

Gas density is calculated using real gas equations from input pressure, temperature and specific gravity of gas.
The compressibility factor is calculated explicitly (Beggs and Brill - 1973) for the pressure and temperature combinations.
The plot shows the variation of the gas density for methane gas (SG = 0.55) with varying temperature and pressure.

.. GENERATED FROM PYTHON SOURCE LINES 11-56



.. image-sg:: /auto_examples/oil_and_gas/images/sphx_glr_plot_gas_density_calcs_001.png
   :alt: plot gas density calcs
   :srcset: /auto_examples/oil_and_gas/images/sphx_glr_plot_gas_density_calcs_001.png
   :class: sphx-glr-single-img





.. code-block:: Python


    import os

    import matplotlib.pyplot as plt
    import pandas as pd

    from indsl.oil_and_gas.gas_density_calcs import calculate_gas_density as cd


    # pressure and temperature series define
    base_path = "" if __name__ == "__main__" else os.path.dirname(__file__)
    data = pd.read_csv(os.path.join(base_path, "../../datasets/data/density_pr_tmp.csv"), index_col=0)
    sg = pd.Series([0.5534])
    fig, ax = plt.subplots(1, 2, figsize=[10, 5])

    ax[0].plot(
        data["T_var (F)"],
        cd(data["P_con (psi)"], data["T_var (F)"], sg),
        color="blue",
        linestyle="dashed",
        linewidth=1,
        markersize=10,
        marker=".",
        label="Gas density at " + str(data["P_con (psi)"][0]) + " psi",
    )

    ax[0].set_xlabel("Temperature (deg F)")
    ax[0].set_ylabel("Gas Density (pcf)")
    ax[0].legend()


    ax[1].plot(
        data["P_var (psi)"],
        cd(data["P_var (psi)"], data["T_con (F)"], sg),
        color="blue",
        linestyle="dashed",
        linewidth=1,
        markersize=10,
        marker=".",
        label="Gas density at " + str(data["T_con (F)"][0]) + " deg F",
    )
    ax[1].set_xlabel("Pressure (psi)")
    ax[1].legend()

    plt.show()


.. rst-class:: sphx-glr-timing

   **Total running time of the script:** (0 minutes 0.178 seconds)


.. _sphx_glr_download_auto_examples_oil_and_gas_plot_gas_density_calcs.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: plot_gas_density_calcs.ipynb <plot_gas_density_calcs.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: plot_gas_density_calcs.py <plot_gas_density_calcs.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: plot_gas_density_calcs.zip <plot_gas_density_calcs.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
