Submodules module

Class Curve

2020, September 1

class, key_x, key_f, convert_to_base_si=False, autocorrect=False, **interpolation_opts)[source]

Bases: object

Class to ease working with pv- and pn-curves and similar curves


data – filepath to CSV file or DataSeries-like object


TODO implement autocorrect here I made this a separate function such that child classes can modify the data as they want before they use the autocorrect functionality.

Return None


Readout f(x)


x – x


f, df module

Class DataSeries

2020, September 1

class, bytestring=None)[source]

Bases: object

Class to load and hold tabular data from CSV file. Numerical data is stored in numpy arrays as floats. Labels and units are stored in Python lists

  • filename – path to file to read or, if bytestring given, filetype

  • bytestring – bytestring with file data

load_data(filename, bytestring=None)[source]

Load in data. Provide a filename or byte string. If providing a byte string, provide the filetype extension (e.g. .csv) to the filename argument such that the formatting of the bytestring can be determined.

  • filename – path to file to read or, if bytestring given, filetype

  • bytestring – bytestring with file data


None module

Function interpolate_fdf

2020, September 4, xs, ys, extrapolate=False, extrapolate_derivative=False, method='linear')[source]

Quickly interpolate a dataseries and return both interpolated value and its derivative.

Arrays xs, ys can be Numpy arrays, yet any object that allows indexing can be used, such as Python lists.

Method: linear or quadratic Search: bisection

  • Document pchip method.

  • Document extrapolation options. The current naming is not great, as choosing ‘False’ for extrapolation results in a zero-order extrapolation. Better to use numbers, e.g. ‘-1’ for no extrapolation (throw error), ‘0’ for zero-order extrapolation and ‘1’ for linear extrapolation?

  • Shorten parameters extrapolate and extrapolate_derivative?

  • x – x value to interpolate at

  • xs – x dataseries

  • ys – y dataseries

  • extrapolate – True or False

  • extrapolate_derivative – True or False

  • method – ‘linear’ or ‘quadratic’


f and df/dx, both evaluated at x


Given that this function is used very often, it is written with the eye on fast execution rather than modularity and good looks. module

Class PVCurve

2020, September 4

class, pressure_reference='relative', autocorrect=False, **interpolation_opts)[source]

Bases: Curve

Class to ease working with pv-curves

Warning: original data in DataSeries object may be modified by this function. Take a deepcopy if modification undesirable.

The autocorrect functionality provides a little tool to correct measurement data. Parameter autocorrect should be a tuple of length two (respectively volume and pressure) or a scalar. The elements of this tuple, or the scalar, can be:

  • False: No correction applied.

  • True: Default correction applied. For volume, the volume at index 0 will equal zero. For pressure, the pressure at index 0 will equal standard atmospheric pressure.

  • A scalar value: Default correction is applied whereafter an offset with the given value is applied. Units are m^3 for volume and Pa for pressure.

  • A function: The function is applied to the value series. The function should take the value series as argument and should return the new value series.

Note: the pressure_reference parameter looses its effect when autocorrect is applied to pressure.

Note: The volume data sequence should be increasing or decreasing, otherwise the interpolation function will not work.


import fonsim

# Create PVCurve object
curve ='mypvcurvefile.csv',
                pressure_reference='relative', autocorrect=True)

# Readout the absolute pressure and its derivative to volume
# at volume 3.8e-6 m^3 (= 3.8 ml)
p, dp_dv = PVCurve.fdf_volume(3.8e-6)

TODO Discuss format of CSV file.

  • data – filepath to CSV file or DataSeries-like object

  • pressure_reference – “relative” or “absolute”

  • autocorrect – see description

  • interpolation_opts – kwargs for interpolation function


Readout the pressure for a given volume


volume – volume in [m3]


f, df


Get the volume of the first datapoint on the curve that approaches the provided pressure value the closest

TODO what is this function used for?


p0 – pressure at which to find the first matching volume


first closest matching volume

property p[source]
property v[source] module

Function writeout_simulation

2020, September 9


Bases: object


Add an object. Object does not have to be hashable. :param obj: object :return: index of object, integer


Return all indices pointing to objects. :return: all indices, Python range, simulation)[source]

Write out simulation data in components to a file. Supported formats: JSON. Format follows from filename extension.

  • filename – string with filepath

  • simulation – Simulation-like object




JSON specification:

  "scheme": <string>,
  "general": {
    "date": <timestamp>,
    "hostname": <computer name",
    "version": <version>
  "simulation": {
    "system": {
      "label": <string>,
      "nb components": <integer>
    "solver": {
      "name": <string>,
    "time": <key in "data"
  "components": {
    <component_label>: {
      "terminals": {
        <terminal_label>: {
          "over": {
            <over_label>: <key in "data">
          through": {
            <through_label>: <key in "data">
      "states": {
        <state_label>: <key in "data">,
      "time": <key in "data">
  "data": {
    <key>: <list with numbers>,

Module contents

2020, September 18