fonsim.data package
Submodules
fonsim.data.curve module
Class Curve
2020, September 1
- class fonsim.data.curve.Curve(data, 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
- Parameters
data – filepath to CSV file or DataSeries-like object
fonsim.data.dataseries module
Class DataSeries
2020, September 1
- class fonsim.data.dataseries.DataSeries(filename, 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
- Parameters
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.
- Parameters
filename – path to file to read or, if bytestring given, filetype
bytestring – bytestring with file data
- Returns
None
fonsim.data.interpolate module
Function interpolate_fdf
2020, September 4
- fonsim.data.interpolate.interpolate_fdf(x, 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
- TODO
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
andextrapolate_derivative
?
- Parameters
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’
- Returns
f and df/dx, both evaluated at x
Note
Given that this function is used very often, it is written with the eye on fast execution rather than modularity and good looks.
fonsim.data.pvcurve module
Class PVCurve
2020, September 4
- class fonsim.data.pvcurve.PVCurve(data, 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.
Example:
import fonsim # Create PVCurve object curve = fonsim.data.pvcurve.PVCurve('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.
- Parameters
data – filepath to CSV file or DataSeries-like object
pressure_reference – “relative” or “absolute”
autocorrect – see description
interpolation_opts – kwargs for interpolation function
- fdf_volume(volume)[source]
Readout the pressure for a given volume
- Parameters
volume – volume in [m3]
- Returns
f, df
fonsim.data.writeout module
Function writeout_simulation
2020, September 9
- class fonsim.data.writeout.Bank[source]
Bases:
object
- fonsim.data.writeout.writeout_simulation(filename, simulation)[source]
Write out simulation data in components to a file. Supported formats: JSON. Format follows from filename extension.
- Parameters
filename – string with filepath
simulation – Simulation-like object
- Returns
None
===
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