Skip to main content

pyiapws: IAPWS for python.

Project description

Introduction

Python wrapper around the Fortran iapws library. The Fortran library does not need to be installed, the python wrapper embeds all needed dependencies for Windows and MacOS. On linux, you might have to install libgfortran if it is not distributed with your linux distribution.

All functions that operate on arrays, more precisely on objects with the buffer protocol, return memory views in order to avoid compilation dependencies on 3rd party packages.

Installation

In a terminal, enter:

pip install pyiapws

Usage

import array
import numpy as np
import matplotlib.pyplot as plt
import pyiapws

print("########################## IAPWS VERSION ##########################")
print(pyiapws.__version__)

print("########################## IAPWS R2-83 ##########################")
print("Tc in H2O", pyiapws.r283.tc_H2O, "K")
print("pc in H2O", pyiapws.r283.pc_H2O, "MPa")
print("rhoc in H2O", pyiapws.r283.rhoc_H2O, "kg/m3")

print("Tc in D2O", pyiapws.r283.tc_D2O, "K")
print("pc in D2O", pyiapws.r283.pc_D2O, "MPa")
print("rhoc in D2O", pyiapws.r283.rhoc_D2O, "kg/m3")

print("")

print("########################## IAPWS G7-04 ##########################")
gas  = "O2"
T = array.array("d", (25.0,))

# Compute kh and kd in H2O
heavywater = False
m = pyiapws.g704.kh(T, "O2", heavywater)
k = array.array("d", m)
print(f"Gas={gas}\tT={T[0]}C\tkh={k[0]:+10.4f}\n")

m = pyiapws.g704.kd(T, "O2", heavywater)
k = array.array("d", m)
print(f"Gas={gas}\tT={T[0]}C\tkh={k[0]:+10.4f}\n")

# Get and print the available gases
heavywater = False
gases_list = pyiapws.g704.gases(heavywater)
gases_str = pyiapws.g704.gases2(heavywater)
ngas = pyiapws.g704.ngases(heavywater)
print(f"Gases in H2O: {ngas:}")
print(gases_str)
for gas in gases_list:
    print(gas)

heavywater = True
gases_list = pyiapws.g704.gases(heavywater)
gases_str = pyiapws.g704.gases2(heavywater)
ngas = pyiapws.g704.ngases(heavywater)
print(f"Gases in D2O: {ngas:}")
print(gases_str)
for gas in gases_list:
    print(gas)

style = {"marker":".", "ls":"", "ms":2}
T_KELVIN = 273.15
T = np.linspace(0.0, 360.0, 1000)

solvent = {True: "D2O", False: "H2O"}

print("Generating plot for kh")
kname = "kh"
for HEAVYWATER in (False, True):
    print(solvent[HEAVYWATER])
    fig = plt.figure()
    ax = fig.add_subplot()
    ax.grid(visible=True, ls=':')
    ax.set_xlabel("T /°C")
    ax.set_ylabel("ln (kh/1GPa)")
    gases = pyiapws.g704.gases(HEAVYWATER)
    for gas in gases:
        k_m = pyiapws.g704.kh(T, gas, HEAVYWATER)
        k = np.asarray(k_m) / 1000.0
        ln_k = np.log(k)
        ax.plot(T, ln_k, label=gas, **style)
    ax.legend(ncol=3)

print("Generating plot for kd")
kname = "kd"
for HEAVYWATER in (False, True):
    print(solvent[HEAVYWATER])
    fig = plt.figure()
    ax = fig.add_subplot()
    ax.grid(visible=True, ls=':')
    ax.set_xlabel("T /°C")
    ax.set_ylabel("ln kd")
    gases = pyiapws.g704.gases(HEAVYWATER)
    for gas in gases:
        k_m = pyiapws.g704.kd(T, gas, HEAVYWATER)
        k = np.asarray(k_m)
        ln_k = np.log(k)
        ax.plot(T, ln_k, label=gas, **style)
    ax.legend(ncol=3)

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyiapws-0.3.0.tar.gz (1.7 MB view hashes)

Uploaded Source

Built Distributions

pyiapws-0.3.0-cp312-cp312-win_amd64.whl (1.5 MB view hashes)

Uploaded CPython 3.12 Windows x86-64

pyiapws-0.3.0-cp312-cp312-manylinux_2_31_x86_64.whl (1.3 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.31+ x86-64

pyiapws-0.3.0-cp312-cp312-macosx_12_0_x86_64.whl (1.5 MB view hashes)

Uploaded CPython 3.12 macOS 12.0+ x86-64

pyiapws-0.3.0-cp311-cp311-win_amd64.whl (1.5 MB view hashes)

Uploaded CPython 3.11 Windows x86-64

pyiapws-0.3.0-cp311-cp311-manylinux_2_31_x86_64.whl (1.3 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.31+ x86-64

pyiapws-0.3.0-cp311-cp311-macosx_12_0_x86_64.whl (1.5 MB view hashes)

Uploaded CPython 3.11 macOS 12.0+ x86-64

pyiapws-0.3.0-cp310-cp310-win_amd64.whl (1.5 MB view hashes)

Uploaded CPython 3.10 Windows x86-64

pyiapws-0.3.0-cp310-cp310-manylinux_2_31_x86_64.whl (1.3 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.31+ x86-64

pyiapws-0.3.0-cp310-cp310-macosx_12_0_x86_64.whl (1.5 MB view hashes)

Uploaded CPython 3.10 macOS 12.0+ x86-64

pyiapws-0.3.0-cp39-cp39-win_amd64.whl (1.5 MB view hashes)

Uploaded CPython 3.9 Windows x86-64

pyiapws-0.3.0-cp39-cp39-manylinux_2_31_x86_64.whl (1.3 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.31+ x86-64

pyiapws-0.3.0-cp39-cp39-macosx_12_0_x86_64.whl (1.5 MB view hashes)

Uploaded CPython 3.9 macOS 12.0+ x86-64

pyiapws-0.3.0-cp38-cp38-win_amd64.whl (1.5 MB view hashes)

Uploaded CPython 3.8 Windows x86-64

pyiapws-0.3.0-cp38-cp38-manylinux_2_31_x86_64.whl (1.3 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.31+ x86-64

pyiapws-0.3.0-cp38-cp38-macosx_12_0_x86_64.whl (1.5 MB view hashes)

Uploaded CPython 3.8 macOS 12.0+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page