Skip to content

Commit

Permalink
add hints for numpy and pandas
Browse files Browse the repository at this point in the history
  • Loading branch information
drunsinn committed Jan 2, 2023
1 parent 5f44f04 commit 8f4f5a6
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
4 changes: 4 additions & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ and also functions for calculations on heavy water. This includes:
* IAPWS R4
* IAPWS R14

Usage Examples
**************
Check out the examples given in :doc:`pyXSteamDemo` for a quick overview of how to use pyXSteam in different use cases.

Notes
*****
Density (rho)
Expand Down
43 changes: 38 additions & 5 deletions docs/source/pyXSteamDemo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Tutorial and Demos
##################

Usage
+++++
*****

Simple Example::

Expand All @@ -25,7 +25,7 @@ To enable logging, add the following lines to your code::
logger.addHandler(sh)

Calculate single values
+++++++++++++++++++++++
=======================
This is a simple example::

>>> from pyXSteam.XSteam import XSteam
Expand All @@ -35,8 +35,29 @@ This is a simple example::
>>> steam_table.tcV_p(1)
0.02475366759235046

Usage with numpy
================
By converting one to the functions to a NumPy universal function it is easy to use pyXSteam on NumPy arrays::

>>> npv_pt = np.frompyfunc(steam_table.v_pt, 2, 1)

* `NumPy documentation for frombyfunc <https://numpy.org/doc/stable/reference/generated/numpy.frompyfunc.html>`_
* `pyXSteamDemo.py <https://github.com/drunsinn/pyXSteam/blob/master/bin/pyXSteamDemo.py>`_

Usage with pandas
=================
Using pandas together with pyXSteam is very easy as well. Using
the `apply <https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.apply.html>`_ function and a
`lambda <https://docs.python.org/3/reference/expressions.html#lambda>`_ you can add a new column based on the
values of other columns::

>>> df['h'] = df.apply(lambda x: steamTable.h_pt(x.P, x.T), axis=1)

* `Pandas documentation on DataFrame.apply <https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.apply.html>`_
* `Python documentation on lambdas <https://docs.python.org/3/reference/expressions.html#lambda>`_

Generate Diagrams
+++++++++++++++++
=================
Diagrams based on the calculated values can easily be created using numpy and matplotlib.

Example: To draw a T(p) diagram showing the saturation curve::
Expand All @@ -54,17 +75,29 @@ Example: To draw a T(p) diagram showing the saturation curve::
pyplot.setp(line1, linewidth=1, color='b')
pyplot.show()

For more demos, see pyXSteamDemo.py
For more demos, see `pyXSteamDemo.py <https://github.com/drunsinn/pyXSteam/blob/master/bin/pyXSteamDemo.py>`_

Heavy Water functions
+++++++++++++++++++++
=====================
The functions to calculate values for heavy water are available through the
class XSteamHW

>>> from pyXSteam.XSteamHW import XSteamHW
>>> steam_table = XSteamHW(XSteam.UNIT_SYSTEM_MKS)
>>> steam_table.my_rhoT(1.2, 300.0)

Content of the demo files
*************************

Main demo file pyXSteamDemo.py
==============================
.. literalinclude:: ../../bin/pyXSteamDemo.py
:language: python

Example on how to calculate the values for a rankine cycle
==========================================================
Matlab example from converted example from Stu Blair converted to python
Original can be found at `his github page <https://github.com/stu314159/xsteam/blob/master/Examples/SimpleRankineCycle.m>`_

.. literalinclude:: ../../bin/pyXSteamRankineDemo.py
:language: python

0 comments on commit 8f4f5a6

Please sign in to comment.