Starting to write documentation for TOC code.
This commit is contained in:
1 parent
b2c36094cb
commit
912c0374de
8 files changed
+1035
-127
No files matched your search
@@ -0,0 +1,3 @@
|
||||
r"""
|
||||
An empty docstring
|
||||
"""
|
||||
+115
-5
@@ -8,7 +8,7 @@
|
||||
### ----------------------------------------------------------------------------------------------------------------------------------- ###
|
||||
### SUBMODULE DOCSTRING
|
||||
|
||||
"""The docstring for this submodule
|
||||
"""This submodule contains functionality to calibrate TOC measurement data and analyse them.
|
||||
"""
|
||||
|
||||
### ----------------------------------------------------------------------------------------------------------------------------------- ###
|
||||
@@ -27,10 +27,37 @@ from defs.Helper import compute_R2
|
||||
|
||||
class CalibrationCurve():
|
||||
|
||||
r"""An object representing a calibration curve for TOC, IC or NPOC Measurements.
|
||||
|
||||
Description
|
||||
-----------
|
||||
This object instanciates a class that relates the area $A$ measured in the TOC Analyser to the concentration $c$ used in the calibration solutions. The calibration curve is affine, $c=aA+b$ where $a$ and $b$ denote slope and intercept, respectively, of the affine map. This object can be used to represent linear calibration curves for TC (total carbon)-, IC (inorganic carbon)- and NPOC (non-purgeable organic carbon) measurements.
|
||||
|
||||
Attributes
|
||||
----------
|
||||
exists: Bool
|
||||
This value is set to `True` if a calibration curve is already available, else it is set to `False`.
|
||||
slope: float
|
||||
Value of the slope for the calibration of concentration (dependent variable) with measured area (independent variable).
|
||||
intercept: float
|
||||
Value of the intercep for the calibration of concentration (dependent variable) with measured area (independent variable).
|
||||
R2_value: float
|
||||
The coefficient of determination of the calibration curve. For a good calibration curve, this should be above 0.995.\
|
||||
excluded: list
|
||||
A list of integers denoting the samples in the calibrant data that are excluded.
|
||||
lower_bound: float
|
||||
The lower bound value for which this calibration curve can be used.
|
||||
upper_bound: float
|
||||
The upper bound value for which this calibration curve can be used.
|
||||
computed_on: pd.Timestamp
|
||||
A timestamp indicating the time at which the calibration curve was computed.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
|
||||
self.exists = False
|
||||
# initialises all member variables
|
||||
|
||||
self.exists = False
|
||||
self.slope = None
|
||||
self.intercept = None
|
||||
self.R2_value = None
|
||||
@@ -41,16 +68,76 @@ class CalibrationCurve():
|
||||
|
||||
def __linear_function(self, x_values, a, b):
|
||||
|
||||
r"""Computes the value of the calibration curve for the passed parameters.
|
||||
|
||||
Description
|
||||
-----------
|
||||
Computes the affine map, $c=aA+b$, given data $A$ and parameters $a$ (slope) and $b$ (intercept).
|
||||
|
||||
Parameters
|
||||
----------
|
||||
x_values: array-like
|
||||
An array-like (array or list) object of length $n$ containing the data for the independent variable that are to be mapped.
|
||||
a: float
|
||||
The slope of the calibration curve.
|
||||
b: float
|
||||
The intercept of the calibration curve.
|
||||
|
||||
Returns
|
||||
-------
|
||||
y_values: np.ndarray
|
||||
An array (of size $n$) containing the image under the affine map of `x_values`.
|
||||
"""
|
||||
|
||||
# check if the input data is an instance of a np.ndarray. If not, cast it to np.ndarray
|
||||
if not isinstance(x_values, np.ndarray):
|
||||
x_values = np.array(x_values)
|
||||
|
||||
# evaluate the image of the input under the affine map and return the results
|
||||
return a * x_values + b
|
||||
|
||||
def __optimise(self, x_data, y_data, p0):
|
||||
|
||||
r"""Finds the optimal parameters of the calibration curve
|
||||
|
||||
Description
|
||||
-----------
|
||||
Uses `scipy.optimize.curve_fit` to find optimal parameters for the calibrant data.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
x_data: array-like
|
||||
The data representing the independent variable.
|
||||
y_data: array-like
|
||||
The data representing the dependent variable.
|
||||
p0: list
|
||||
A list containing the initial guesses of the parameters.
|
||||
|
||||
Returns
|
||||
-------
|
||||
p: np.ndarray
|
||||
An array containing the optimal parameter values.
|
||||
pcov: The covariance matrix associated with the optimal parameters.
|
||||
"""
|
||||
|
||||
# evaluate the optimisation problem and return optimal parameters and their covariance matrix.
|
||||
return curve_fit(self.__linear_function, x_data, y_data, p0)
|
||||
|
||||
def __check_exist(self):
|
||||
|
||||
r"""Checks if attribute `exists` is set
|
||||
|
||||
Description
|
||||
-----------
|
||||
Checks of the attribute `exists` is set to `None` (its instanciation value) and returns `False` in this case, or returns `True` if attribute value is not `None` (i.e. if it has been set).
|
||||
|
||||
Returns
|
||||
-------
|
||||
t: Bool
|
||||
`True` if attribute has a value, else returns `None`.
|
||||
"""
|
||||
|
||||
# this line is equivalent to "if None is True" if attribute is not set, which evaluates to 'False'. Else evaluates to 'True'.
|
||||
if self.exists == True:
|
||||
return True
|
||||
else:
|
||||
@@ -58,6 +145,13 @@ class CalibrationCurve():
|
||||
|
||||
def __check(self):
|
||||
|
||||
r"""Gives a warning message when overwriting an existing calibration curve.
|
||||
|
||||
Description
|
||||
-----------
|
||||
Calls the private `check_exists` method to see if a calibration curve has already been computed. If yes, this will throw a warning message, but not an error.
|
||||
"""
|
||||
|
||||
if self.__check_exist():
|
||||
warnings.warn("Calibration alreadyt exists, will be overwritten...")
|
||||
else:
|
||||
@@ -65,6 +159,20 @@ class CalibrationCurve():
|
||||
|
||||
def calibrate(self, x_data, y_data):
|
||||
|
||||
"""Compute a calibration curve based on the available calibrant data.
|
||||
|
||||
Description
|
||||
-----------
|
||||
Bla Bla Bla
|
||||
|
||||
Parameters
|
||||
----------
|
||||
x_data: np.ndarray
|
||||
Bla bla bla
|
||||
y_data: np.ndarray
|
||||
Bla Bla Bla
|
||||
"""
|
||||
|
||||
self.__check()
|
||||
|
||||
parameters, _ = self.__optimise(x_data=x_data, y_data=y_data, p0=[10, 0.1])
|
||||
@@ -103,6 +211,8 @@ class Calibration():
|
||||
|
||||
self.__read_calibration_file()
|
||||
|
||||
self.mask = None
|
||||
|
||||
def __read_calibration_file(self):
|
||||
|
||||
conctr = []
|
||||
@@ -196,12 +306,12 @@ class Calibration():
|
||||
|
||||
if excluded_points:
|
||||
self.curve.excluded = excluded_points
|
||||
mask = [False if i + 1 in self.curve.excluded else True for i in range(len(self.calibrant_data))]
|
||||
self.mask = [False if i + 1 in self.curve.excluded else True for i in range(len(self.calibrant_data))]
|
||||
else:
|
||||
self.curve.excluded = None
|
||||
mask = [True for i in range(len(self.calibrant_data))]
|
||||
self.mask = [True for i in range(len(self.calibrant_data))]
|
||||
|
||||
self.curve.calibrate(x_data=self.calibrant_data['area_average'].values[mask], y_data=self.calibrant_data['concentration'].values[mask])
|
||||
self.curve.calibrate(x_data=self.calibrant_data['area_average'].values[self.mask], y_data=self.calibrant_data['concentration'].values[self.mask])
|
||||
|
||||
with open(self.cal_file, 'r', errors = 'ignore') as file:
|
||||
lines = file.readlines()
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1">
|
||||
<meta name="generator" content="pdoc3 0.11.1">
|
||||
<title>defs.visualising API documentation</title>
|
||||
<meta name="description" content="">
|
||||
<title>defs.BTOF API documentation</title>
|
||||
<meta name="description" content="An empty docstring">
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/13.0.0/sanitize.min.css" integrity="sha512-y1dtMcuvtTMJc1yPgEqF0ZjQbhnc/bFhyvIyVNb9Zk5mIGtqVaAB1Ttl28su8AvFMOY0EwRbAe+HCLqj6W7/KA==" crossorigin>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/13.0.0/typography.min.css" integrity="sha512-Y1DYSb995BAfxobCkKepB1BqJJTPrOp3zPL74AWFugHHmmdcvO+C48WLrUOlhGMc0QG7AE3f7gmvvcrmX2fDoA==" crossorigin>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/default.min.css" crossorigin>
|
||||
@@ -24,9 +24,10 @@ hljs.highlightAll();
|
||||
<main>
|
||||
<article id="content">
|
||||
<header>
|
||||
<h1 class="title">Module <code>defs.visualising</code></h1>
|
||||
<h1 class="title">Module <code>defs.BTOF</code></h1>
|
||||
</header>
|
||||
<section id="section-intro">
|
||||
<p>An empty docstring</p>
|
||||
</section>
|
||||
<section>
|
||||
</section>
|
||||
@@ -35,50 +36,6 @@ hljs.highlightAll();
|
||||
<section>
|
||||
</section>
|
||||
<section>
|
||||
<h2 class="section-title" id="header-classes">Classes</h2>
|
||||
<dl>
|
||||
<dt id="defs.visualising.HelloWorld"><code class="flex name class">
|
||||
<span>class <span class="ident">HelloWorld</span></span>
|
||||
<span>(</span><span>word='Hellow')</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<div class="desc"><p>The docstring for this class</p>
|
||||
<p>Description: Bla bla bla</p>
|
||||
<h2 id="attributes">Attributes</h2>
|
||||
<dl>
|
||||
<dt><strong><code>word</code></strong> : <code>str</code></dt>
|
||||
<dd>A word</dd>
|
||||
</dl>
|
||||
<h2 id="methods">Methods</h2>
|
||||
<p><strong>init</strong>: HelloWorld
|
||||
The class constructor</p></div>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">class HelloWorld():
|
||||
|
||||
"""The docstring for this class
|
||||
|
||||
Description: Bla bla bla
|
||||
|
||||
Attributes
|
||||
----------
|
||||
word: str
|
||||
A word
|
||||
|
||||
Methods
|
||||
-------
|
||||
__init__: HelloWorld
|
||||
The class constructor
|
||||
"""
|
||||
|
||||
def __init__(self, word = "Hellow"):
|
||||
|
||||
self.word = word</code></pre>
|
||||
</details>
|
||||
</dd>
|
||||
</dl>
|
||||
</section>
|
||||
</article>
|
||||
<nav id="sidebar">
|
||||
@@ -91,13 +48,6 @@ The class constructor</p></div>
|
||||
<li><code><a title="defs" href="index.html">defs</a></code></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><h3><a href="#header-classes">Classes</a></h3>
|
||||
<ul>
|
||||
<li>
|
||||
<h4><code><a title="defs.visualising.HelloWorld" href="#defs.visualising.HelloWorld">HelloWorld</a></code></h4>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</main>
|
||||
@@ -0,0 +1,168 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1">
|
||||
<meta name="generator" content="pdoc3 0.11.1">
|
||||
<title>defs.Helper API documentation</title>
|
||||
<meta name="description" content="The docstring for this submodule">
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/13.0.0/sanitize.min.css" integrity="sha512-y1dtMcuvtTMJc1yPgEqF0ZjQbhnc/bFhyvIyVNb9Zk5mIGtqVaAB1Ttl28su8AvFMOY0EwRbAe+HCLqj6W7/KA==" crossorigin>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/13.0.0/typography.min.css" integrity="sha512-Y1DYSb995BAfxobCkKepB1BqJJTPrOp3zPL74AWFugHHmmdcvO+C48WLrUOlhGMc0QG7AE3f7gmvvcrmX2fDoA==" crossorigin>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/default.min.css" crossorigin>
|
||||
<style>:root{--highlight-color:#fe9}.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:1.5em;overflow:hidden}#sidebar > *:last-child{margin-bottom:2cm}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:2em 0 .50em 0}h3{font-size:1.4em;margin:1.6em 0 .7em 0}h4{margin:0;font-size:105%}h1:target,h2:target,h3:target,h4:target,h5:target,h6:target{background:var(--highlight-color);padding:.2em 0}a{color:#058;text-decoration:none;transition:color .2s ease-in-out}a:visited{color:#503}a:hover{color:#b62}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900;font-weight:bold}pre code{font-size:.8em;line-height:1.4em;padding:1em;display:block}code{background:#f3f3f3;font-family:"DejaVu Sans Mono",monospace;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{margin-top:.6em;font-weight:bold}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}dt:target .name{background:var(--highlight-color)}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}td{padding:0 .5em}.admonition{padding:.1em 1em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style>
|
||||
<style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul ul{padding-left:1em}.toc > ul > li{margin-top:.5em}}</style>
|
||||
<style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style>
|
||||
<script type="text/x-mathjax-config">MathJax.Hub.Config({ tex2jax: { inlineMath: [ ['$','$'], ["\\(","\\)"] ], processEscapes: true } });</script>
|
||||
<script async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS_CHTML" integrity="sha256-kZafAc6mZvK3W3v1pHOcUix30OHQN6pU/NO2oFkqZVw=" crossorigin></script>
|
||||
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js" integrity="sha512-D9gUyxqja7hBtkWpPWGt9wfbfaMGVt9gnyCvYa+jojwwPHLCzUm5i8rpk7vD7wNee9bA35eYIjobYPaQuKS1MQ==" crossorigin></script>
|
||||
<script>window.addEventListener('DOMContentLoaded', () => {
|
||||
hljs.configure({languages: ['bash', 'css', 'diff', 'graphql', 'ini', 'javascript', 'json', 'plaintext', 'python', 'python-repl', 'rust', 'shell', 'sql', 'typescript', 'xml', 'yaml']});
|
||||
hljs.highlightAll();
|
||||
})</script>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<article id="content">
|
||||
<header>
|
||||
<h1 class="title">Module <code>defs.Helper</code></h1>
|
||||
</header>
|
||||
<section id="section-intro">
|
||||
<p>The docstring for this submodule</p>
|
||||
</section>
|
||||
<section>
|
||||
</section>
|
||||
<section>
|
||||
</section>
|
||||
<section>
|
||||
<h2 class="section-title" id="header-functions">Functions</h2>
|
||||
<dl>
|
||||
<dt id="defs.Helper.compute_R2"><code class="name flex">
|
||||
<span>def <span class="ident">compute_R2</span></span>(<span>y_true, y_est)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
</dl>
|
||||
</section>
|
||||
<section>
|
||||
<h2 class="section-title" id="header-classes">Classes</h2>
|
||||
<dl>
|
||||
<dt id="defs.Helper.DATFile"><code class="flex name class">
|
||||
<span>class <span class="ident">DATFile</span></span>
|
||||
<span>(</span><span>file, data_name='value')</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<div class="desc"><p>The docstring for this class</p>
|
||||
<p>Description: Bla bla bla</p>
|
||||
<h2 id="attributes">Attributes</h2>
|
||||
<dl>
|
||||
<dt><strong><code>word</code></strong> : <code>str</code></dt>
|
||||
<dd>A word</dd>
|
||||
</dl>
|
||||
<h2 id="methods">Methods</h2>
|
||||
<p><strong>init</strong>: HelloWorld
|
||||
The class constructor</p></div>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">class DATFile():
|
||||
|
||||
"""The docstring for this class
|
||||
|
||||
Description: Bla bla bla
|
||||
|
||||
Attributes
|
||||
----------
|
||||
word: str
|
||||
A word
|
||||
|
||||
Methods
|
||||
-------
|
||||
__init__: HelloWorld
|
||||
The class constructor
|
||||
"""
|
||||
|
||||
def __init__(self, file, data_name = 'value'):
|
||||
|
||||
self.file = file
|
||||
self.data_name = data_name
|
||||
self.data = None
|
||||
|
||||
def read(self):
|
||||
|
||||
dates = []
|
||||
times = []
|
||||
values = []
|
||||
|
||||
with open(self.file, 'r', errors='ignore') as f:
|
||||
for i, line in enumerate(f.readlines()):
|
||||
|
||||
if i >= 3:
|
||||
|
||||
items = line.split()
|
||||
dates.append(items[0])
|
||||
times.append(items[1])
|
||||
values.append(float(items[2]))
|
||||
|
||||
pre_datetimes = [date + ' ' + time for date, time in zip(dates, times)]
|
||||
datetimes = pd.to_datetime(pre_datetimes, format=r'%d.%m.%Y %H:%M:%S')
|
||||
self.data = pd.DataFrame({'timestamp': datetimes, self.data_name: values})
|
||||
|
||||
def exclude_outliers():
|
||||
|
||||
pass</code></pre>
|
||||
</details>
|
||||
<h3>Methods</h3>
|
||||
<dl>
|
||||
<dt id="defs.Helper.DATFile.exclude_outliers"><code class="name flex">
|
||||
<span>def <span class="ident">exclude_outliers</span></span>(<span>)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="defs.Helper.DATFile.read"><code class="name flex">
|
||||
<span>def <span class="ident">read</span></span>(<span>self)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
</dl>
|
||||
</dd>
|
||||
</dl>
|
||||
</section>
|
||||
</article>
|
||||
<nav id="sidebar">
|
||||
<div class="toc">
|
||||
<ul></ul>
|
||||
</div>
|
||||
<ul id="index">
|
||||
<li><h3>Super-module</h3>
|
||||
<ul>
|
||||
<li><code><a title="defs" href="index.html">defs</a></code></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><h3><a href="#header-functions">Functions</a></h3>
|
||||
<ul class="">
|
||||
<li><code><a title="defs.Helper.compute_R2" href="#defs.Helper.compute_R2">compute_R2</a></code></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><h3><a href="#header-classes">Classes</a></h3>
|
||||
<ul>
|
||||
<li>
|
||||
<h4><code><a title="defs.Helper.DATFile" href="#defs.Helper.DATFile">DATFile</a></code></h4>
|
||||
<ul class="">
|
||||
<li><code><a title="defs.Helper.DATFile.exclude_outliers" href="#defs.Helper.DATFile.exclude_outliers">exclude_outliers</a></code></li>
|
||||
<li><code><a title="defs.Helper.DATFile.read" href="#defs.Helper.DATFile.read">read</a></code></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</main>
|
||||
<footer id="footer">
|
||||
<p>Generated by <a href="https://pdoc3.github.io/pdoc" title="pdoc: Python API documentation generator"><cite>pdoc</cite> 0.11.1</a>.</p>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,180 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1">
|
||||
<meta name="generator" content="pdoc3 0.11.1">
|
||||
<title>defs.OzoneMonitor API documentation</title>
|
||||
<meta name="description" content="The docstring for this submodule">
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/13.0.0/sanitize.min.css" integrity="sha512-y1dtMcuvtTMJc1yPgEqF0ZjQbhnc/bFhyvIyVNb9Zk5mIGtqVaAB1Ttl28su8AvFMOY0EwRbAe+HCLqj6W7/KA==" crossorigin>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/13.0.0/typography.min.css" integrity="sha512-Y1DYSb995BAfxobCkKepB1BqJJTPrOp3zPL74AWFugHHmmdcvO+C48WLrUOlhGMc0QG7AE3f7gmvvcrmX2fDoA==" crossorigin>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/default.min.css" crossorigin>
|
||||
<style>:root{--highlight-color:#fe9}.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:1.5em;overflow:hidden}#sidebar > *:last-child{margin-bottom:2cm}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:2em 0 .50em 0}h3{font-size:1.4em;margin:1.6em 0 .7em 0}h4{margin:0;font-size:105%}h1:target,h2:target,h3:target,h4:target,h5:target,h6:target{background:var(--highlight-color);padding:.2em 0}a{color:#058;text-decoration:none;transition:color .2s ease-in-out}a:visited{color:#503}a:hover{color:#b62}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900;font-weight:bold}pre code{font-size:.8em;line-height:1.4em;padding:1em;display:block}code{background:#f3f3f3;font-family:"DejaVu Sans Mono",monospace;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{margin-top:.6em;font-weight:bold}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}dt:target .name{background:var(--highlight-color)}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}td{padding:0 .5em}.admonition{padding:.1em 1em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style>
|
||||
<style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul ul{padding-left:1em}.toc > ul > li{margin-top:.5em}}</style>
|
||||
<style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style>
|
||||
<script type="text/x-mathjax-config">MathJax.Hub.Config({ tex2jax: { inlineMath: [ ['$','$'], ["\\(","\\)"] ], processEscapes: true } });</script>
|
||||
<script async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS_CHTML" integrity="sha256-kZafAc6mZvK3W3v1pHOcUix30OHQN6pU/NO2oFkqZVw=" crossorigin></script>
|
||||
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js" integrity="sha512-D9gUyxqja7hBtkWpPWGt9wfbfaMGVt9gnyCvYa+jojwwPHLCzUm5i8rpk7vD7wNee9bA35eYIjobYPaQuKS1MQ==" crossorigin></script>
|
||||
<script>window.addEventListener('DOMContentLoaded', () => {
|
||||
hljs.configure({languages: ['bash', 'css', 'diff', 'graphql', 'ini', 'javascript', 'json', 'plaintext', 'python', 'python-repl', 'rust', 'shell', 'sql', 'typescript', 'xml', 'yaml']});
|
||||
hljs.highlightAll();
|
||||
})</script>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<article id="content">
|
||||
<header>
|
||||
<h1 class="title">Module <code>defs.OzoneMonitor</code></h1>
|
||||
</header>
|
||||
<section id="section-intro">
|
||||
<p>The docstring for this submodule</p>
|
||||
</section>
|
||||
<section>
|
||||
</section>
|
||||
<section>
|
||||
</section>
|
||||
<section>
|
||||
</section>
|
||||
<section>
|
||||
<h2 class="section-title" id="header-classes">Classes</h2>
|
||||
<dl>
|
||||
<dt id="defs.OzoneMonitor.OzoneAnalyser"><code class="flex name class">
|
||||
<span>class <span class="ident">OzoneAnalyser</span></span>
|
||||
<span>(</span><span>file: <a title="defs.Helper.DATFile" href="Helper.html#defs.Helper.DATFile">DATFile</a>, on_time_interval)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<div class="desc"><p>The docstring for this class</p>
|
||||
<p>Description: Bla bla bla</p>
|
||||
<h2 id="attributes">Attributes</h2>
|
||||
<dl>
|
||||
<dt><strong><code>word</code></strong> : <code>str</code></dt>
|
||||
<dd>A word</dd>
|
||||
</dl>
|
||||
<h2 id="methods">Methods</h2>
|
||||
<p><strong>init</strong>: HelloWorld
|
||||
The class constructor</p></div>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">class OzoneAnalyser():
|
||||
|
||||
"""The docstring for this class
|
||||
|
||||
Description: Bla bla bla
|
||||
|
||||
Attributes
|
||||
----------
|
||||
word: str
|
||||
A word
|
||||
|
||||
Methods
|
||||
-------
|
||||
__init__: HelloWorld
|
||||
The class constructor
|
||||
"""
|
||||
|
||||
def __init__(self, file: DATFile, on_time_interval):
|
||||
|
||||
self.file = file
|
||||
self.on_time_interval = on_time_interval
|
||||
self.averaged_data = None
|
||||
|
||||
def GetData(self):
|
||||
|
||||
self.file.read()
|
||||
|
||||
def AverageWithSMPS(self, smps_analyser: OFRAnalyser, cut_edges: int, subtract_baseline = ['yes', 5]):
|
||||
|
||||
avg_ozone = []
|
||||
mprr_data = []
|
||||
|
||||
local_smps_data = smps_analyser.data[(smps_analyser.data['Starting Time (-)'] >= smps_analyser.on_time_interval[0]) &
|
||||
(smps_analyser.data['Starting Time (-)'] <= smps_analyser.on_time_interval[1])].reset_index()
|
||||
|
||||
baseline = None
|
||||
|
||||
for index, data in local_smps_data.iterrows():
|
||||
|
||||
start = data['Starting Time (-)']
|
||||
|
||||
if index == 0:
|
||||
|
||||
if subtract_baseline[0] == 'yes':
|
||||
baseline_start = start - pd.Timedelta(minutes = int(subtract_baseline[1]))
|
||||
baseline_ozone_data = self.file.data[(self.file.data['timestamp'] >= baseline_start) &
|
||||
(self.file.data['timestamp'] <= start)]
|
||||
baseline = np.average(baseline_ozone_data['ozone'])
|
||||
|
||||
if index in list(range(cut_edges)):
|
||||
continue
|
||||
|
||||
stop = start + pd.Timedelta(seconds = data['Sampling Time (s)'])
|
||||
|
||||
mprr_data.append(data['Mass Production Rate (kg/s)'])
|
||||
|
||||
local_ozone_data = self.file.data[(self.file.data['timestamp'] >= start) &
|
||||
(self.file.data['timestamp'] <= stop)]
|
||||
avg_ozone.append(np.average(local_ozone_data['ozone']))
|
||||
|
||||
for sub_index in list(range(cut_edges)):
|
||||
del avg_ozone[-(sub_index + 1)]
|
||||
del mprr_data[-(sub_index + 1)]
|
||||
|
||||
out_mprr_data = np.array(mprr_data)
|
||||
|
||||
if subtract_baseline[0] == 'yes':
|
||||
out_avg_ozone = np.array([baseline - value for value in avg_ozone])
|
||||
elif subtract_baseline[0] != 'yes':
|
||||
out_avg_ozone = np.array([value for value in avg_ozone])
|
||||
|
||||
self.averaged_data = pd.DataFrame({'Ozone (ppb)': out_avg_ozone, 'Mass Production Rate (kg/s)': out_mprr_data})</code></pre>
|
||||
</details>
|
||||
<h3>Methods</h3>
|
||||
<dl>
|
||||
<dt id="defs.OzoneMonitor.OzoneAnalyser.AverageWithSMPS"><code class="name flex">
|
||||
<span>def <span class="ident">AverageWithSMPS</span></span>(<span>self, smps_analyser: <a title="defs.SMPS.OFRAnalyser" href="SMPS.html#defs.SMPS.OFRAnalyser">OFRAnalyser</a>, cut_edges: int, subtract_baseline=['yes', 5])</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="defs.OzoneMonitor.OzoneAnalyser.GetData"><code class="name flex">
|
||||
<span>def <span class="ident">GetData</span></span>(<span>self)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
</dl>
|
||||
</dd>
|
||||
</dl>
|
||||
</section>
|
||||
</article>
|
||||
<nav id="sidebar">
|
||||
<div class="toc">
|
||||
<ul></ul>
|
||||
</div>
|
||||
<ul id="index">
|
||||
<li><h3>Super-module</h3>
|
||||
<ul>
|
||||
<li><code><a title="defs" href="index.html">defs</a></code></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><h3><a href="#header-classes">Classes</a></h3>
|
||||
<ul>
|
||||
<li>
|
||||
<h4><code><a title="defs.OzoneMonitor.OzoneAnalyser" href="#defs.OzoneMonitor.OzoneAnalyser">OzoneAnalyser</a></code></h4>
|
||||
<ul class="">
|
||||
<li><code><a title="defs.OzoneMonitor.OzoneAnalyser.AverageWithSMPS" href="#defs.OzoneMonitor.OzoneAnalyser.AverageWithSMPS">AverageWithSMPS</a></code></li>
|
||||
<li><code><a title="defs.OzoneMonitor.OzoneAnalyser.GetData" href="#defs.OzoneMonitor.OzoneAnalyser.GetData">GetData</a></code></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</main>
|
||||
<footer id="footer">
|
||||
<p>Generated by <a href="https://pdoc3.github.io/pdoc" title="pdoc: Python API documentation generator"><cite>pdoc</cite> 0.11.1</a>.</p>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
@@ -4,7 +4,7 @@
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1">
|
||||
<meta name="generator" content="pdoc3 0.11.1">
|
||||
<title>defs.OFR API documentation</title>
|
||||
<title>defs.SMPS API documentation</title>
|
||||
<meta name="description" content="The docstring for this submodule">
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/13.0.0/sanitize.min.css" integrity="sha512-y1dtMcuvtTMJc1yPgEqF0ZjQbhnc/bFhyvIyVNb9Zk5mIGtqVaAB1Ttl28su8AvFMOY0EwRbAe+HCLqj6W7/KA==" crossorigin>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/13.0.0/typography.min.css" integrity="sha512-Y1DYSb995BAfxobCkKepB1BqJJTPrOp3zPL74AWFugHHmmdcvO+C48WLrUOlhGMc0QG7AE3f7gmvvcrmX2fDoA==" crossorigin>
|
||||
@@ -24,7 +24,7 @@ hljs.highlightAll();
|
||||
<main>
|
||||
<article id="content">
|
||||
<header>
|
||||
<h1 class="title">Module <code>defs.OFR</code></h1>
|
||||
<h1 class="title">Module <code>defs.SMPS</code></h1>
|
||||
</header>
|
||||
<section id="section-intro">
|
||||
<p>The docstring for this submodule</p>
|
||||
@@ -38,7 +38,7 @@ hljs.highlightAll();
|
||||
<section>
|
||||
<h2 class="section-title" id="header-classes">Classes</h2>
|
||||
<dl>
|
||||
<dt id="defs.OFR.Distribution"><code class="flex name class">
|
||||
<dt id="defs.SMPS.Distribution"><code class="flex name class">
|
||||
<span>class <span class="ident">Distribution</span></span>
|
||||
<span>(</span><span>variable_array, function_array, form='log10')</span>
|
||||
</code></dt>
|
||||
@@ -183,7 +183,7 @@ hljs.highlightAll();
|
||||
</details>
|
||||
<h3>Methods</h3>
|
||||
<dl>
|
||||
<dt id="defs.OFR.Distribution.integrate"><code class="name flex">
|
||||
<dt id="defs.SMPS.Distribution.integrate"><code class="name flex">
|
||||
<span>def <span class="ident">integrate</span></span>(<span>self) ‑> numpy.float64</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
@@ -191,25 +191,25 @@ hljs.highlightAll();
|
||||
<h2 id="description">Description</h2>
|
||||
<p>Bla Bla Bla</p></div>
|
||||
</dd>
|
||||
<dt id="defs.OFR.Distribution.mean"><code class="name flex">
|
||||
<dt id="defs.SMPS.Distribution.mean"><code class="name flex">
|
||||
<span>def <span class="ident">mean</span></span>(<span>)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="defs.OFR.Distribution.median"><code class="name flex">
|
||||
<dt id="defs.SMPS.Distribution.median"><code class="name flex">
|
||||
<span>def <span class="ident">median</span></span>(<span>)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="defs.OFR.Distribution.mode"><code class="name flex">
|
||||
<dt id="defs.SMPS.Distribution.mode"><code class="name flex">
|
||||
<span>def <span class="ident">mode</span></span>(<span>)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="defs.OFR.Distribution.transform"><code class="name flex">
|
||||
<dt id="defs.SMPS.Distribution.transform"><code class="name flex">
|
||||
<span>def <span class="ident">transform</span></span>(<span>self, to='linear')</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
@@ -222,7 +222,7 @@ hljs.highlightAll();
|
||||
<dd>Indicating into which representation the distribution should be transformed. Possible values are: <code>linear</code>, <code>ln</code> or <code>log10</code></dd>
|
||||
</dl></div>
|
||||
</dd>
|
||||
<dt id="defs.OFR.Distribution.update_units"><code class="name flex">
|
||||
<dt id="defs.SMPS.Distribution.update_units"><code class="name flex">
|
||||
<span>def <span class="ident">update_units</span></span>(<span>self, new_var_units, new_fct_units)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
@@ -237,7 +237,7 @@ hljs.highlightAll();
|
||||
<dd>The SI factor used to transform the dependent variable <code>self.fct</code></dd>
|
||||
</dl></div>
|
||||
</dd>
|
||||
<dt id="defs.OFR.Distribution.variance"><code class="name flex">
|
||||
<dt id="defs.SMPS.Distribution.variance"><code class="name flex">
|
||||
<span>def <span class="ident">variance</span></span>(<span>)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
@@ -245,9 +245,9 @@ hljs.highlightAll();
|
||||
</dd>
|
||||
</dl>
|
||||
</dd>
|
||||
<dt id="defs.OFR.OFRAnalyser"><code class="flex name class">
|
||||
<dt id="defs.SMPS.OFRAnalyser"><code class="flex name class">
|
||||
<span>class <span class="ident">OFRAnalyser</span></span>
|
||||
<span>(</span><span>data_source_file, flows_source_file, sample_number_list, data_separator=',')</span>
|
||||
<span>(</span><span>data_source_file, flow_source_file, smpl_number_list, on_time_interval, data_separator=',')</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<div class="desc"><p>An object representing an OFR experiment</p>
|
||||
@@ -257,10 +257,12 @@ hljs.highlightAll();
|
||||
<dl>
|
||||
<dt><strong><code>data_source_file</code></strong> : <code>str</code></dt>
|
||||
<dd>A string pointing to the data source file</dd>
|
||||
<dt><strong><code>flows_source_file</code></strong> : <code>str</code></dt>
|
||||
<dt><strong><code>flow_source_file</code></strong> : <code>str</code></dt>
|
||||
<dd>A string pointing to the flow data source file</dd>
|
||||
<dt><strong><code>sample_number_list</code></strong> : <code>[int]</code></dt>
|
||||
<dd>A list of integers indicating which samples to consider</dd>
|
||||
<dt><strong><code>on_time_interval</code></strong> : <code>[pd.Timestamp]</code></dt>
|
||||
<dd>A list with two elements containing the pd.Timestamp objects when the VOC flow was switched on and off, respectively.</dd>
|
||||
<dt><strong><code>max_samples</code></strong> : <code>int</code></dt>
|
||||
<dd>The highest sample available in the data</dd>
|
||||
<dt><strong><code>data</code></strong> : <code>pandas.DataFrame</code></dt>
|
||||
@@ -282,23 +284,27 @@ hljs.highlightAll();
|
||||
----------
|
||||
data_source_file: str
|
||||
A string pointing to the data source file
|
||||
flows_source_file: str
|
||||
flow_source_file: str
|
||||
A string pointing to the flow data source file
|
||||
sample_number_list: [int]
|
||||
A list of integers indicating which samples to consider
|
||||
on_time_interval: [pd.Timestamp]
|
||||
A list with two elements containing the pd.Timestamp objects when the VOC flow was switched on and off, respectively.
|
||||
max_samples: int
|
||||
The highest sample available in the data
|
||||
data: pandas.DataFrame
|
||||
A dataframe containing all the data
|
||||
"""
|
||||
|
||||
def __init__(self, data_source_file, flows_source_file, sample_number_list, data_separator = ',') -> None:
|
||||
def __init__(self, data_source_file, flow_source_file, smpl_number_list, on_time_interval, data_separator = ',') -> None:
|
||||
|
||||
self.data_source_file = data_source_file
|
||||
self.flows_source_file = flows_source_file
|
||||
self.sample_number_list = sample_number_list
|
||||
self.flow_source_file = flow_source_file
|
||||
self.smpl_number_list = smpl_number_list
|
||||
self.on_time_interval = on_time_interval
|
||||
self.__data_separator = data_separator
|
||||
|
||||
|
||||
with open(self.data_source_file, 'r', errors = 'ignore') as file:
|
||||
for i, line in enumerate(file.readlines()):
|
||||
if i == 17:
|
||||
@@ -310,11 +316,11 @@ hljs.highlightAll();
|
||||
self.max_samples = max_sample_number
|
||||
self.data = None
|
||||
|
||||
def __sample_number_list_check(self, sample_number_list) -> None:
|
||||
def __smpl_number_list_check(self, smpl_number_list) -> None:
|
||||
|
||||
# TODO: implement a similar check for the flow data file!
|
||||
|
||||
last_sample = sample_number_list[-1]
|
||||
last_sample = smpl_number_list[-1]
|
||||
|
||||
if last_sample > self.max_samples:
|
||||
raise IndexError("The last sample(s) are out of range of the number of recorded samples")
|
||||
@@ -331,32 +337,29 @@ hljs.highlightAll();
|
||||
# TODO make this work also for a specific sample!
|
||||
# TODO convert everything is SI units, making live a lot easier...
|
||||
|
||||
self.__sample_number_list_check(self.sample_number_list)
|
||||
self.__smpl_number_list_check(self.smpl_number_list)
|
||||
|
||||
# Quantities of interest:
|
||||
numbers_of_sample = [] # (-)
|
||||
starting_times = [] # (timestamp)
|
||||
sampling_times = [] # (s)
|
||||
number_concentrations = [] # (#/m^3)
|
||||
length_concentrations = [] # (m/m^3)
|
||||
surface_concentrations = [] # (m^2/m^3)
|
||||
volume_concentrations = [] # (m^3/m^3)
|
||||
aerosol_densities = [] # (kg/m^3)
|
||||
mass_concentrations = [] # (kg/m^3)
|
||||
starting_times = [] # (s)
|
||||
stopping_times = [] # (s)
|
||||
sampling_times = [] # (s)
|
||||
dry_air_flows = [] # (m^3/s)
|
||||
species_flows = [] # (m^3/s)
|
||||
ozone_flows = [] # (m^3/s)
|
||||
total_flows = None # (m^3/s)
|
||||
cpc_flows = [] # (m^3/s)
|
||||
filter_flows = [] # (m^3/s)
|
||||
mass_production_rate = None # (kg/s)
|
||||
mass_produced = None # (kg)
|
||||
cumulative_mass_produced = None # (kg)
|
||||
|
||||
|
||||
for sample_number in self.sample_number_list:
|
||||
for sample_number in self.smpl_number_list:
|
||||
sample = OFRSample(source_file=self.data_source_file, sample_number = sample_number, data_separator = self.__data_separator)
|
||||
|
||||
numbers_of_sample.append(sample_number)
|
||||
starting_times.append(sample.start_time)
|
||||
|
||||
number_concentrations.append(sample.Count.integrate())
|
||||
length_concentrations.append(sample.Length.integrate())
|
||||
surface_concentrations.append(sample.Surface.integrate())
|
||||
@@ -364,14 +367,11 @@ hljs.highlightAll();
|
||||
aerosol_densities.append(sample.SOA_density)
|
||||
mass_concentrations.append(sample.Mass.integrate())
|
||||
|
||||
starting_times.append((sample_number - 1) * sample.sampling_time)
|
||||
stopping_times.append(sample_number * sample.sampling_time)
|
||||
|
||||
sampling_times.append(sample.sampling_time)
|
||||
|
||||
out_flag = False
|
||||
|
||||
with open(self.flows_source_file, 'r', errors='ignore') as file:
|
||||
with open(self.flow_source_file, 'r', errors='ignore') as file:
|
||||
|
||||
j = 1
|
||||
|
||||
@@ -391,11 +391,8 @@ hljs.highlightAll();
|
||||
|
||||
while i < int(items[-1]):
|
||||
|
||||
if j in self.sample_number_list:
|
||||
dry_air_flows.append(float(items[0]) * 6E-4)
|
||||
species_flows.append(float(items[1]) * 6E-4)
|
||||
ozone_flows.append(float(items[2]) * 6E-4)
|
||||
cpc_flows.append(float(items[3]) * 6E-4)
|
||||
if j in self.smpl_number_list:
|
||||
filter_flows.append(float(items[0]) * (1E-3) / 60)
|
||||
|
||||
i += 1
|
||||
j += 1
|
||||
@@ -403,33 +400,27 @@ hljs.highlightAll();
|
||||
else:
|
||||
continue
|
||||
|
||||
total_flows = [(flow_1 + flow_2 + flow_3) for flow_1, flow_2, flow_3 in zip(dry_air_flows, species_flows, ozone_flows)]
|
||||
mass_production_rate = [(mass * flow) for mass, flow in zip(mass_concentrations, total_flows)]
|
||||
mass_production_rate = [(mass * flow) for mass, flow in zip(mass_concentrations, filter_flows)]
|
||||
mass_produced = [(mpr * duration) for mpr, duration in zip(mass_production_rate, sampling_times)]
|
||||
cumulative_mass_produced = np.cumsum(np.array(mass_produced)).tolist()
|
||||
|
||||
self.data = pd.DataFrame({'Sample (-)': numbers_of_sample,
|
||||
'Starting Time (-)': starting_times,
|
||||
'Sampling Time (s)': sampling_times,
|
||||
'Number (#/m^3)': number_concentrations,
|
||||
'Length (m/m^3)': length_concentrations,
|
||||
'Surface (m^2/m^3)': surface_concentrations,
|
||||
'Volume (m^3/m^3)': volume_concentrations,
|
||||
'Density (kg/m^3)': aerosol_densities,
|
||||
'Mass (kg/m^3)': mass_concentrations,
|
||||
'Start (s)': starting_times,
|
||||
'Stop (s)': stopping_times,
|
||||
'Duration (s)': sampling_times,
|
||||
'Dry Air Flow (m^3/s)': dry_air_flows,
|
||||
'Species Flow (m^3/s)': species_flows,
|
||||
'Ozone Flow (m^3/s)': ozone_flows,
|
||||
'Total Flow (m^3/s)': total_flows,
|
||||
'CPC Flow (m^3/s)': cpc_flows,
|
||||
'Filter Flow (m^3/s)': filter_flows,
|
||||
'Mass Production Rate (kg/s)': mass_production_rate,
|
||||
'Mass Produced (kg)': mass_produced,
|
||||
'Cumulative Mass Produced (kg)': cumulative_mass_produced})</code></pre>
|
||||
</details>
|
||||
<h3>Methods</h3>
|
||||
<dl>
|
||||
<dt id="defs.OFR.OFRAnalyser.GetData"><code class="name flex">
|
||||
<dt id="defs.SMPS.OFRAnalyser.GetData"><code class="name flex">
|
||||
<span>def <span class="ident">GetData</span></span>(<span>self) ‑> None</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
@@ -439,7 +430,7 @@ hljs.highlightAll();
|
||||
</dd>
|
||||
</dl>
|
||||
</dd>
|
||||
<dt id="defs.OFR.OFRSample"><code class="flex name class">
|
||||
<dt id="defs.SMPS.OFRSample"><code class="flex name class">
|
||||
<span>class <span class="ident">OFRSample</span></span>
|
||||
<span>(</span><span>source_file, sample_number, data_separator=',')</span>
|
||||
</code></dt>
|
||||
@@ -451,6 +442,8 @@ hljs.highlightAll();
|
||||
<dl>
|
||||
<dt><strong><code>number</code></strong> : <code>int</code></dt>
|
||||
<dd>The sample number</dd>
|
||||
<dt><strong><code>start_time</code></strong> : <code>pd.datetime</code></dt>
|
||||
<dd>The starting time of the sample recording</dd>
|
||||
<dt><strong><code>sourcefile</code></strong> : <code>str</code></dt>
|
||||
<dd>The path to the data file</dd>
|
||||
<dt><strong><code>headlines</code></strong> : <code>int</code></dt>
|
||||
@@ -485,6 +478,8 @@ hljs.highlightAll();
|
||||
|
||||
number: int
|
||||
The sample number
|
||||
start_time: pd.datetime
|
||||
The starting time of the sample recording
|
||||
sourcefile: str
|
||||
The path to the data file
|
||||
headlines: int
|
||||
@@ -513,8 +508,17 @@ hljs.highlightAll();
|
||||
midpoints = []
|
||||
counts = []
|
||||
|
||||
date_line = None
|
||||
time_line = None
|
||||
|
||||
with open(self.source_file, 'r', errors = 'ignore') as file:
|
||||
for i, line in enumerate(file.readlines()):
|
||||
if i == 18:
|
||||
date_line = line
|
||||
continue
|
||||
if i == 19:
|
||||
time_line = line
|
||||
continue
|
||||
if i == 20:
|
||||
data_flag = True
|
||||
continue
|
||||
@@ -548,6 +552,16 @@ hljs.highlightAll();
|
||||
self.sampling_time = self.scan_up_time + self.scan_down_time
|
||||
data_lines.pop(-1)
|
||||
|
||||
# obtaining the starting time
|
||||
raw_date_items = date_line.split(self.__data_separator)
|
||||
raw_time_items = time_line.split(self.__data_separator)
|
||||
del raw_date_items[0]
|
||||
del raw_time_items[0]
|
||||
|
||||
raw_date = raw_date_items[(self.sample_number - 1) * 2].splitlines()[0]
|
||||
raw_time = raw_time_items[(self.sample_number - 1) * 2].splitlines()[0]
|
||||
self.start_time = pd.to_datetime(raw_date + ' ' + raw_time, format=r'%m/%d/%y %H:%M:%S')
|
||||
|
||||
for line in data_lines:
|
||||
items = line.split(self.__data_separator)
|
||||
local_diameter_midpoint = float(items[0])
|
||||
@@ -563,7 +577,6 @@ hljs.highlightAll();
|
||||
self.lower_diameter_bound = self.lower_diameter_bound * 1E-9
|
||||
self.upper_diameter_bound = self.upper_diameter_bound * 1E-9
|
||||
|
||||
|
||||
# Input data from file is in (nm)
|
||||
return [np.array(midpoints), np.array(counts)]
|
||||
|
||||
@@ -575,6 +588,7 @@ hljs.highlightAll();
|
||||
# Sample information
|
||||
self.source_file = source_file # where the data is stored, i.e. "C:/Users/tschan_d/..."
|
||||
self.sample_number = sample_number # sample number, i.e. 33
|
||||
self.start_time = None
|
||||
self.__data_separator = data_separator
|
||||
|
||||
self.scan_up_time = None # Time to scan up the voltage range in DMA, in (s)
|
||||
@@ -621,25 +635,25 @@ hljs.highlightAll();
|
||||
<li><h3><a href="#header-classes">Classes</a></h3>
|
||||
<ul>
|
||||
<li>
|
||||
<h4><code><a title="defs.OFR.Distribution" href="#defs.OFR.Distribution">Distribution</a></code></h4>
|
||||
<h4><code><a title="defs.SMPS.Distribution" href="#defs.SMPS.Distribution">Distribution</a></code></h4>
|
||||
<ul class="two-column">
|
||||
<li><code><a title="defs.OFR.Distribution.integrate" href="#defs.OFR.Distribution.integrate">integrate</a></code></li>
|
||||
<li><code><a title="defs.OFR.Distribution.mean" href="#defs.OFR.Distribution.mean">mean</a></code></li>
|
||||
<li><code><a title="defs.OFR.Distribution.median" href="#defs.OFR.Distribution.median">median</a></code></li>
|
||||
<li><code><a title="defs.OFR.Distribution.mode" href="#defs.OFR.Distribution.mode">mode</a></code></li>
|
||||
<li><code><a title="defs.OFR.Distribution.transform" href="#defs.OFR.Distribution.transform">transform</a></code></li>
|
||||
<li><code><a title="defs.OFR.Distribution.update_units" href="#defs.OFR.Distribution.update_units">update_units</a></code></li>
|
||||
<li><code><a title="defs.OFR.Distribution.variance" href="#defs.OFR.Distribution.variance">variance</a></code></li>
|
||||
<li><code><a title="defs.SMPS.Distribution.integrate" href="#defs.SMPS.Distribution.integrate">integrate</a></code></li>
|
||||
<li><code><a title="defs.SMPS.Distribution.mean" href="#defs.SMPS.Distribution.mean">mean</a></code></li>
|
||||
<li><code><a title="defs.SMPS.Distribution.median" href="#defs.SMPS.Distribution.median">median</a></code></li>
|
||||
<li><code><a title="defs.SMPS.Distribution.mode" href="#defs.SMPS.Distribution.mode">mode</a></code></li>
|
||||
<li><code><a title="defs.SMPS.Distribution.transform" href="#defs.SMPS.Distribution.transform">transform</a></code></li>
|
||||
<li><code><a title="defs.SMPS.Distribution.update_units" href="#defs.SMPS.Distribution.update_units">update_units</a></code></li>
|
||||
<li><code><a title="defs.SMPS.Distribution.variance" href="#defs.SMPS.Distribution.variance">variance</a></code></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<h4><code><a title="defs.OFR.OFRAnalyser" href="#defs.OFR.OFRAnalyser">OFRAnalyser</a></code></h4>
|
||||
<h4><code><a title="defs.SMPS.OFRAnalyser" href="#defs.SMPS.OFRAnalyser">OFRAnalyser</a></code></h4>
|
||||
<ul class="">
|
||||
<li><code><a title="defs.OFR.OFRAnalyser.GetData" href="#defs.OFR.OFRAnalyser.GetData">GetData</a></code></li>
|
||||
<li><code><a title="defs.SMPS.OFRAnalyser.GetData" href="#defs.SMPS.OFRAnalyser.GetData">GetData</a></code></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<h4><code><a title="defs.OFR.OFRSample" href="#defs.OFR.OFRSample">OFRSample</a></code></h4>
|
||||
<h4><code><a title="defs.SMPS.OFRSample" href="#defs.SMPS.OFRSample">OFRSample</a></code></h4>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
@@ -0,0 +1,468 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1">
|
||||
<meta name="generator" content="pdoc3 0.11.1">
|
||||
<title>defs.TOC API documentation</title>
|
||||
<meta name="description" content="This submodule contains functionality to calibrate TOC measurement data and analyse them.">
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/13.0.0/sanitize.min.css" integrity="sha512-y1dtMcuvtTMJc1yPgEqF0ZjQbhnc/bFhyvIyVNb9Zk5mIGtqVaAB1Ttl28su8AvFMOY0EwRbAe+HCLqj6W7/KA==" crossorigin>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/13.0.0/typography.min.css" integrity="sha512-Y1DYSb995BAfxobCkKepB1BqJJTPrOp3zPL74AWFugHHmmdcvO+C48WLrUOlhGMc0QG7AE3f7gmvvcrmX2fDoA==" crossorigin>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/default.min.css" crossorigin>
|
||||
<style>:root{--highlight-color:#fe9}.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:1.5em;overflow:hidden}#sidebar > *:last-child{margin-bottom:2cm}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:2em 0 .50em 0}h3{font-size:1.4em;margin:1.6em 0 .7em 0}h4{margin:0;font-size:105%}h1:target,h2:target,h3:target,h4:target,h5:target,h6:target{background:var(--highlight-color);padding:.2em 0}a{color:#058;text-decoration:none;transition:color .2s ease-in-out}a:visited{color:#503}a:hover{color:#b62}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900;font-weight:bold}pre code{font-size:.8em;line-height:1.4em;padding:1em;display:block}code{background:#f3f3f3;font-family:"DejaVu Sans Mono",monospace;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{margin-top:.6em;font-weight:bold}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}dt:target .name{background:var(--highlight-color)}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}td{padding:0 .5em}.admonition{padding:.1em 1em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style>
|
||||
<style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul ul{padding-left:1em}.toc > ul > li{margin-top:.5em}}</style>
|
||||
<style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style>
|
||||
<script type="text/x-mathjax-config">MathJax.Hub.Config({ tex2jax: { inlineMath: [ ['$','$'], ["\\(","\\)"] ], processEscapes: true } });</script>
|
||||
<script async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS_CHTML" integrity="sha256-kZafAc6mZvK3W3v1pHOcUix30OHQN6pU/NO2oFkqZVw=" crossorigin></script>
|
||||
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js" integrity="sha512-D9gUyxqja7hBtkWpPWGt9wfbfaMGVt9gnyCvYa+jojwwPHLCzUm5i8rpk7vD7wNee9bA35eYIjobYPaQuKS1MQ==" crossorigin></script>
|
||||
<script>window.addEventListener('DOMContentLoaded', () => {
|
||||
hljs.configure({languages: ['bash', 'css', 'diff', 'graphql', 'ini', 'javascript', 'json', 'plaintext', 'python', 'python-repl', 'rust', 'shell', 'sql', 'typescript', 'xml', 'yaml']});
|
||||
hljs.highlightAll();
|
||||
})</script>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<article id="content">
|
||||
<header>
|
||||
<h1 class="title">Module <code>defs.TOC</code></h1>
|
||||
</header>
|
||||
<section id="section-intro">
|
||||
<p>This submodule contains functionality to calibrate TOC measurement data and analyse them.</p>
|
||||
</section>
|
||||
<section>
|
||||
</section>
|
||||
<section>
|
||||
</section>
|
||||
<section>
|
||||
</section>
|
||||
<section>
|
||||
<h2 class="section-title" id="header-classes">Classes</h2>
|
||||
<dl>
|
||||
<dt id="defs.TOC.Calibration"><code class="flex name class">
|
||||
<span>class <span class="ident">Calibration</span></span>
|
||||
<span>(</span><span>cal_file: pathlib.Path)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<div class="desc"></div>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">class Calibration():
|
||||
|
||||
def __init__(self, cal_file: Path):
|
||||
|
||||
self.metadata = CalibrationMetadata()
|
||||
self.curve = CalibrationCurve()
|
||||
self.cal_file = cal_file
|
||||
self.calibrant_data = None
|
||||
self.__results_index = None
|
||||
self.excluded_points = None
|
||||
|
||||
self.__read_calibration_file()
|
||||
|
||||
self.mask = None
|
||||
|
||||
def __read_calibration_file(self):
|
||||
|
||||
conctr = []
|
||||
diltns = []
|
||||
area_1 = []
|
||||
area_2 = []
|
||||
area_3 = []
|
||||
|
||||
results_flag = False
|
||||
|
||||
with open(self.cal_file, 'r', errors = 'ignore') as file:
|
||||
|
||||
results_index = None
|
||||
|
||||
for index, line in enumerate(file.readlines()):
|
||||
|
||||
# Reading in the metadata
|
||||
if index == 2:
|
||||
self.metadata.standard = float(line.split()[1])
|
||||
if index == 3:
|
||||
self.metadata.unit = line.split()[1]
|
||||
if index == 4:
|
||||
self.metadata.prepared = line.split()[1]
|
||||
if index == 5:
|
||||
self.metadata.measured = line.split()[1]
|
||||
|
||||
# Reading in the calibration data
|
||||
if index >= 10 and results_flag == False:
|
||||
|
||||
if line.startswith('CALIBRATION RESULTS'):
|
||||
|
||||
results_flag = True
|
||||
continue
|
||||
|
||||
elif not results_flag:
|
||||
|
||||
if line == '\n':
|
||||
continue
|
||||
|
||||
items = line.split()
|
||||
|
||||
conctr.append(float(items[0]))
|
||||
diltns.append(float(items[1]))
|
||||
area_1.append(float(items[2]))
|
||||
area_2.append(float(items[3]))
|
||||
area_3.append(float(items[4]))
|
||||
|
||||
if results_flag == True:
|
||||
|
||||
if line.startswith('-'):
|
||||
|
||||
if results_index is None:
|
||||
self.__results_index = index + 1
|
||||
continue
|
||||
else:
|
||||
continue
|
||||
|
||||
items = line.split()
|
||||
|
||||
if index == self.__results_index:
|
||||
self.curve.exists = True
|
||||
self.curve.slope = float(items[1])
|
||||
elif index == self.__results_index + 1:
|
||||
self.curve.intercept = float(items[1])
|
||||
elif index == self.__results_index + 2:
|
||||
self.curve.R2_value = float(items[1])
|
||||
elif index == self.__results_index + 3:
|
||||
if items[1] == 'None':
|
||||
continue
|
||||
else:
|
||||
del items[0]
|
||||
self.curve.excluded = [int(items[i].replace(',', '')) for i in range(len(items))]
|
||||
elif index == self.__results_index + 4:
|
||||
self.curve.lower_bound = float(items[1])
|
||||
elif index == self.__results_index + 5:
|
||||
self.curve.upper_bound = float(items[1])
|
||||
elif index == self.__results_index + 6:
|
||||
self.curve.computed_on = pd.to_datetime(items[1] + ' ' + items[2])
|
||||
|
||||
self.calibrant_data = pd.DataFrame({'concentration': conctr,
|
||||
'dilution': diltns,
|
||||
'area_1': area_1,
|
||||
'area_2': area_2,
|
||||
'area_3': area_3,
|
||||
'area_average': [(a1 + a2 + a3) / 3 for a1, a2, a3 in zip(area_1, area_2, area_3)]})
|
||||
def produce_statistics():
|
||||
# TODO
|
||||
pass
|
||||
|
||||
def calibrate(self, excluded_points = [], write_to_new_file = False):
|
||||
|
||||
if excluded_points:
|
||||
self.curve.excluded = excluded_points
|
||||
self.mask = [False if i + 1 in self.curve.excluded else True for i in range(len(self.calibrant_data))]
|
||||
else:
|
||||
self.curve.excluded = None
|
||||
self.mask = [True for i in range(len(self.calibrant_data))]
|
||||
|
||||
self.curve.calibrate(x_data=self.calibrant_data['area_average'].values[self.mask], y_data=self.calibrant_data['concentration'].values[self.mask])
|
||||
|
||||
with open(self.cal_file, 'r', errors = 'ignore') as file:
|
||||
lines = file.readlines()
|
||||
|
||||
if self.__results_index is None:
|
||||
|
||||
lines.append('\nCALIBRATION RESULTS\n')
|
||||
lines.append('----------------------------------------------------------------------\n')
|
||||
lines.append('Slope\t\t' + f"{self.curve.slope:2.4f}\n")
|
||||
lines.append('Intercept\t' + f"{self.curve.intercept:2.4f}\n")
|
||||
lines.append('R2\t\t' + f"{self.curve.R2_value:1.4f}\n")
|
||||
if self.curve.excluded is None:
|
||||
lines.append('EXCLUDED\t' + f"None\n")
|
||||
else:
|
||||
lines.append('EXCLUDED\t' + ', '.join([str(n) for n in self.curve.excluded]) + '\n')
|
||||
lines.append('FROM\t\t' + f"{self.curve.lower_bound:2.4f}\n")
|
||||
lines.append('TO\t\t' + f"{self.curve.upper_bound:2.4f}\n")
|
||||
lines.append('COMPUTED\t' + f"{self.curve.computed_on:%d.%m.%Y %H:%M:%S}")
|
||||
|
||||
else:
|
||||
lines[self.__results_index] = 'Slope\t\t' + f"{self.curve.slope:2.4f}\n"
|
||||
lines[self.__results_index + 1] ='Intercept\t' + f"{self.curve.intercept:2.4f}\n"
|
||||
lines[self.__results_index + 2] ='R2\t\t' + f"{self.curve.R2_value:1.4f}\n"
|
||||
if self.curve.excluded is None:
|
||||
lines[self.__results_index + 3] = 'EXCLUDED\t' + f"None\n"
|
||||
else:
|
||||
lines[self.__results_index + 3] = 'EXCLUDED\t' + ', '.join([str(n) for n in self.curve.excluded]) + '\n'
|
||||
lines[self.__results_index + 4] ='FROM\t\t' + f"{self.curve.lower_bound:2.4f}\n"
|
||||
lines[self.__results_index + 5] ='TO\t\t' + f"{self.curve.upper_bound:2.4f}\n"
|
||||
lines[self.__results_index + 6] ='COMPUTED\t' + f"{self.curve.computed_on:%d.%m.%Y %H:%M:%S}"
|
||||
|
||||
if write_to_new_file == False:
|
||||
|
||||
with open(self.cal_file, 'w', errors = 'ignore') as file:
|
||||
file.writelines(lines)
|
||||
|
||||
elif write_to_new_file == True:
|
||||
|
||||
directory_path = self.cal_file.parents[0]
|
||||
new_file = self.cal_file.stem + '_' + self.curve.computed_on.strftime('%d_%m_%Y_%H_%M_%S') + '.cal'
|
||||
new_path = PurePath(directory_path, new_file)
|
||||
|
||||
with open(new_path, 'w', errors = 'ignore') as file:
|
||||
file.writelines(lines)
|
||||
|
||||
def compute(self, sample_areas):
|
||||
return self.curve.compute(sample_areas=sample_areas)</code></pre>
|
||||
</details>
|
||||
<h3>Methods</h3>
|
||||
<dl>
|
||||
<dt id="defs.TOC.Calibration.calibrate"><code class="name flex">
|
||||
<span>def <span class="ident">calibrate</span></span>(<span>self, excluded_points=[], write_to_new_file=False)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="defs.TOC.Calibration.compute"><code class="name flex">
|
||||
<span>def <span class="ident">compute</span></span>(<span>self, sample_areas)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="defs.TOC.Calibration.produce_statistics"><code class="name flex">
|
||||
<span>def <span class="ident">produce_statistics</span></span>(<span>)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
</dl>
|
||||
</dd>
|
||||
<dt id="defs.TOC.CalibrationCurve"><code class="flex name class">
|
||||
<span>class <span class="ident">CalibrationCurve</span></span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<div class="desc"><p>An object representing a calibration curve for TOC, IC or NPOC Measurements.</p>
|
||||
<h2 id="description">Description</h2>
|
||||
<p>This object instanciates a class that relates the area $A$ measured in the TOC Analyser to the concentration $c$ used in the calibration solutions. The calibration curve is affine, $c=aA+b$ where $a$ and $b$ denote slope and intercept, respectively, of the affine map. This object can be used to represent linear calibration curves for TC (total carbon)-, IC (inorganic carbon)- and NPOC (non-purgeable organic carbon) measurements. </p>
|
||||
<h2 id="attributes">Attributes</h2>
|
||||
<dl>
|
||||
<dt><strong><code>exists</code></strong> : <code>Bool</code></dt>
|
||||
<dd>This value is set to <code>True</code> if a calibration curve is already available, else it is set to <code>False</code>.</dd>
|
||||
<dt><strong><code>slope</code></strong> : <code>float</code></dt>
|
||||
<dd>Value of the slope for the calibration of concentration (dependent variable) with measured area (independent variable).</dd>
|
||||
<dt><strong><code>intercep</code></strong> : <code>float</code></dt>
|
||||
<dd>Value of the intercep for the calibration of concentration (dependent variable) with measured area (independent variable).</dd>
|
||||
<dt><strong><code>R2_value</code></strong> : <code>float</code></dt>
|
||||
<dd>The coefficient of determination of the calibration curve. For a good calibration curve, this should be above 0.995.\</dd>
|
||||
<dt><strong><code>excluded</code></strong> : <code>list</code></dt>
|
||||
<dd>A list of integers denoting the samples in the calibrant data that are excluded.</dd>
|
||||
<dt><strong><code>lower_bound</code></strong> : <code>float</code></dt>
|
||||
<dd>The lower bound value for which this calibration curve can be used.</dd>
|
||||
<dt><strong><code>upper_bound</code></strong> : <code>float</code></dt>
|
||||
<dd>The upper bound value for which this calibration curve can be used.</dd>
|
||||
<dt><strong><code>computed_on</code></strong> : <code>pd.Timestamp</code></dt>
|
||||
<dd>A timestamp indicating the time at which the calibration curve was computed.</dd>
|
||||
</dl></div>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">class CalibrationCurve():
|
||||
|
||||
r"""An object representing a calibration curve for TOC, IC or NPOC Measurements.
|
||||
|
||||
Description
|
||||
-----------
|
||||
This object instanciates a class that relates the area $A$ measured in the TOC Analyser to the concentration $c$ used in the calibration solutions. The calibration curve is affine, $c=aA+b$ where $a$ and $b$ denote slope and intercept, respectively, of the affine map. This object can be used to represent linear calibration curves for TC (total carbon)-, IC (inorganic carbon)- and NPOC (non-purgeable organic carbon) measurements.
|
||||
|
||||
Attributes
|
||||
----------
|
||||
exists: Bool
|
||||
This value is set to `True` if a calibration curve is already available, else it is set to `False`.
|
||||
slope: float
|
||||
Value of the slope for the calibration of concentration (dependent variable) with measured area (independent variable).
|
||||
intercep: float
|
||||
Value of the intercep for the calibration of concentration (dependent variable) with measured area (independent variable).
|
||||
R2_value: float
|
||||
The coefficient of determination of the calibration curve. For a good calibration curve, this should be above 0.995.\
|
||||
excluded: list
|
||||
A list of integers denoting the samples in the calibrant data that are excluded.
|
||||
lower_bound: float
|
||||
The lower bound value for which this calibration curve can be used.
|
||||
upper_bound: float
|
||||
The upper bound value for which this calibration curve can be used.
|
||||
computed_on: pd.Timestamp
|
||||
A timestamp indicating the time at which the calibration curve was computed.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
|
||||
# initialises all member variables
|
||||
|
||||
self.exists = False
|
||||
self.slope = None
|
||||
self.intercept = None
|
||||
self.R2_value = None
|
||||
self.excluded = None
|
||||
self.lower_bound = None
|
||||
self.upper_bound = None
|
||||
self.computed_on = None
|
||||
|
||||
def __linear_function(self, x_values, a, b):
|
||||
|
||||
r"""Computes the value of the calibration curve for the passed parameters.
|
||||
|
||||
Description
|
||||
-----------
|
||||
Computes the affine map, $c=aA+b$, given data $A$ and parameters $a$ (slope) and $b$ (intercept).
|
||||
|
||||
Parameters
|
||||
----------
|
||||
x_values: array-like
|
||||
An array-like (array or list) object of length $n$ containing the data for the independent variable that are to be mapped.
|
||||
a: float
|
||||
The slope of the calibration curve.
|
||||
b: float
|
||||
The intercept of the calibration curve.
|
||||
|
||||
Returns
|
||||
-------
|
||||
y_values: np.ndarray
|
||||
An array (of size $n$) containing the image under the affine map of `x_values`.
|
||||
"""
|
||||
|
||||
if not isinstance(x_values, np.ndarray):
|
||||
x_values = np.array(x_values)
|
||||
|
||||
return a * x_values + b
|
||||
|
||||
def __optimise(self, x_data, y_data, p0):
|
||||
return curve_fit(self.__linear_function, x_data, y_data, p0)
|
||||
|
||||
def __check_exist(self):
|
||||
|
||||
if self.exists == True:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def __check(self):
|
||||
|
||||
if self.__check_exist():
|
||||
warnings.warn("Calibration alreadyt exists, will be overwritten...")
|
||||
else:
|
||||
return
|
||||
|
||||
def calibrate(self, x_data, y_data):
|
||||
|
||||
"""The docstring for this method
|
||||
|
||||
Description
|
||||
-----------
|
||||
Bla Bla Bla
|
||||
|
||||
Parameters
|
||||
----------
|
||||
x_data: np.ndarray
|
||||
Bla bla bla
|
||||
y_data: np.ndarray
|
||||
Bla Bla Bla
|
||||
"""
|
||||
|
||||
self.__check()
|
||||
|
||||
parameters, _ = self.__optimise(x_data=x_data, y_data=y_data, p0=[10, 0.1])
|
||||
|
||||
self.exists = True
|
||||
self.slope = parameters[0]
|
||||
self.intercept = parameters[1]
|
||||
self.R2_value = compute_R2(y_true = y_data, y_est = self.__linear_function(x_values=x_data, a = parameters[0], b=parameters[1]))
|
||||
self.lower_bound = np.min(y_data)
|
||||
self.upper_bound = np.max(y_data)
|
||||
self.computed_on = pd.to_datetime(datetime.datetime.now())
|
||||
|
||||
def compute(self, sample_areas):
|
||||
return self.__linear_function(x_values=sample_areas, a = self.slope, b = self.intercept)</code></pre>
|
||||
</details>
|
||||
<h3>Methods</h3>
|
||||
<dl>
|
||||
<dt id="defs.TOC.CalibrationCurve.calibrate"><code class="name flex">
|
||||
<span>def <span class="ident">calibrate</span></span>(<span>self, x_data, y_data)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<div class="desc"><p>The docstring for this method</p>
|
||||
<h2 id="description">Description</h2>
|
||||
<p>Bla Bla Bla</p>
|
||||
<h2 id="parameters">Parameters</h2>
|
||||
<dl>
|
||||
<dt><strong><code>x_data</code></strong> : <code>np.ndarray</code></dt>
|
||||
<dd>Bla bla bla</dd>
|
||||
<dt><strong><code>y_data</code></strong> : <code>np.ndarray</code></dt>
|
||||
<dd>Bla Bla Bla</dd>
|
||||
</dl></div>
|
||||
</dd>
|
||||
<dt id="defs.TOC.CalibrationCurve.compute"><code class="name flex">
|
||||
<span>def <span class="ident">compute</span></span>(<span>self, sample_areas)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
</dl>
|
||||
</dd>
|
||||
<dt id="defs.TOC.CalibrationMetadata"><code class="flex name class">
|
||||
<span>class <span class="ident">CalibrationMetadata</span></span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<div class="desc"></div>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">class CalibrationMetadata():
|
||||
|
||||
def __init__(self):
|
||||
|
||||
self.standard = None
|
||||
self.unit = None
|
||||
self.prepared = None
|
||||
self.measured = None</code></pre>
|
||||
</details>
|
||||
</dd>
|
||||
</dl>
|
||||
</section>
|
||||
</article>
|
||||
<nav id="sidebar">
|
||||
<div class="toc">
|
||||
<ul></ul>
|
||||
</div>
|
||||
<ul id="index">
|
||||
<li><h3>Super-module</h3>
|
||||
<ul>
|
||||
<li><code><a title="defs" href="index.html">defs</a></code></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><h3><a href="#header-classes">Classes</a></h3>
|
||||
<ul>
|
||||
<li>
|
||||
<h4><code><a title="defs.TOC.Calibration" href="#defs.TOC.Calibration">Calibration</a></code></h4>
|
||||
<ul class="">
|
||||
<li><code><a title="defs.TOC.Calibration.calibrate" href="#defs.TOC.Calibration.calibrate">calibrate</a></code></li>
|
||||
<li><code><a title="defs.TOC.Calibration.compute" href="#defs.TOC.Calibration.compute">compute</a></code></li>
|
||||
<li><code><a title="defs.TOC.Calibration.produce_statistics" href="#defs.TOC.Calibration.produce_statistics">produce_statistics</a></code></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<h4><code><a title="defs.TOC.CalibrationCurve" href="#defs.TOC.CalibrationCurve">CalibrationCurve</a></code></h4>
|
||||
<ul class="">
|
||||
<li><code><a title="defs.TOC.CalibrationCurve.calibrate" href="#defs.TOC.CalibrationCurve.calibrate">calibrate</a></code></li>
|
||||
<li><code><a title="defs.TOC.CalibrationCurve.compute" href="#defs.TOC.CalibrationCurve.compute">compute</a></code></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<h4><code><a title="defs.TOC.CalibrationMetadata" href="#defs.TOC.CalibrationMetadata">CalibrationMetadata</a></code></h4>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</main>
|
||||
<footer id="footer">
|
||||
<p>Generated by <a href="https://pdoc3.github.io/pdoc" title="pdoc: Python API documentation generator"><cite>pdoc</cite> 0.11.1</a>.</p>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
+20
-5
@@ -33,13 +33,25 @@ hljs.highlightAll();
|
||||
<section>
|
||||
<h2 class="section-title" id="header-submodules">Sub-modules</h2>
|
||||
<dl>
|
||||
<dt><code class="name"><a title="defs.OFR" href="OFR.html">defs.OFR</a></code></dt>
|
||||
<dt><code class="name"><a title="defs.BTOF" href="BTOF.html">defs.BTOF</a></code></dt>
|
||||
<dd>
|
||||
<div class="desc"><p>An empty docstring</p></div>
|
||||
</dd>
|
||||
<dt><code class="name"><a title="defs.Helper" href="Helper.html">defs.Helper</a></code></dt>
|
||||
<dd>
|
||||
<div class="desc"><p>The docstring for this submodule</p></div>
|
||||
</dd>
|
||||
<dt><code class="name"><a title="defs.visualising" href="visualising.html">defs.visualising</a></code></dt>
|
||||
<dt><code class="name"><a title="defs.OzoneMonitor" href="OzoneMonitor.html">defs.OzoneMonitor</a></code></dt>
|
||||
<dd>
|
||||
<div class="desc"></div>
|
||||
<div class="desc"><p>The docstring for this submodule</p></div>
|
||||
</dd>
|
||||
<dt><code class="name"><a title="defs.SMPS" href="SMPS.html">defs.SMPS</a></code></dt>
|
||||
<dd>
|
||||
<div class="desc"><p>The docstring for this submodule</p></div>
|
||||
</dd>
|
||||
<dt><code class="name"><a title="defs.TOC" href="TOC.html">defs.TOC</a></code></dt>
|
||||
<dd>
|
||||
<div class="desc"><p>This submodule contains functionality to calibrate TOC measurement data and analyse them.</p></div>
|
||||
</dd>
|
||||
</dl>
|
||||
</section>
|
||||
@@ -57,8 +69,11 @@ hljs.highlightAll();
|
||||
<ul id="index">
|
||||
<li><h3><a href="#header-submodules">Sub-modules</a></h3>
|
||||
<ul>
|
||||
<li><code><a title="defs.OFR" href="OFR.html">defs.OFR</a></code></li>
|
||||
<li><code><a title="defs.visualising" href="visualising.html">defs.visualising</a></code></li>
|
||||
<li><code><a title="defs.BTOF" href="BTOF.html">defs.BTOF</a></code></li>
|
||||
<li><code><a title="defs.Helper" href="Helper.html">defs.Helper</a></code></li>
|
||||
<li><code><a title="defs.OzoneMonitor" href="OzoneMonitor.html">defs.OzoneMonitor</a></code></li>
|
||||
<li><code><a title="defs.SMPS" href="SMPS.html">defs.SMPS</a></code></li>
|
||||
<li><code><a title="defs.TOC" href="TOC.html">defs.TOC</a></code></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
Reference in new issue
Block a user