114 lines
4.2 KiB
Python
114 lines
4.2 KiB
Python
# Author: David Tschan
|
|
# Institute: Paul-Scherrer Institute, Laboratory for Atmospheric Chemistry, Multiphase Chemistry Group,
|
|
# Forschungsstrasse 111, 5232 Villigen PSI, Switzerland
|
|
# Role: Master Student
|
|
# License: n/a
|
|
# Date: 2026
|
|
|
|
### ----------------------------------------------------------------------------------------------------------------------------------- ###
|
|
### SUBMODULE DOCSTRING
|
|
|
|
"""The docstring for this submodule
|
|
"""
|
|
|
|
### ----------------------------------------------------------------------------------------------------------------------------------- ###
|
|
### IMPORTS AND CONFIGURATIONS
|
|
|
|
import pandas as pd
|
|
import numpy as np
|
|
import matplotlib
|
|
import matplotlib.pyplot as plt
|
|
|
|
### ----------------------------------------------------------------------------------------------------------------------------------- ###
|
|
### Helper.py
|
|
|
|
def quick_plot_setup(fontsize = 8):
|
|
|
|
plt.style.use(r'C:\Users\tschan_d\Documents\code\.plotstyle\quick.mplstyle')
|
|
matplotlib.rcParams.update({'font.size': fontsize})
|
|
|
|
return ".pdf"
|
|
|
|
def final_plot_setup(fontsize = 8):
|
|
|
|
matplotlib.use('pgf')
|
|
plt.style.use(r'C:\Users\tschan_d\Documents\code\.plotstyle\final.mplstyle')
|
|
|
|
matplotlib.rcParams.update({'text.usetex': True,
|
|
'pgf.rcfonts': False,
|
|
'font.family': 'serif',
|
|
'font.size': fontsize,
|
|
'legend.fontsize': fontsize,
|
|
'xtick.labelsize': fontsize,
|
|
'ytick.labelsize': fontsize,
|
|
'pgf.texsystem': r'lualatex',
|
|
'pgf.preamble': r'\usepackage[fontsize = ' + str(fontsize) + r']{fontsize}' +
|
|
r'\usepackage{unicode-math}' +
|
|
r'\usepackage{accents}' +
|
|
r'\usepackage{fontspec}' +
|
|
r'\usepackage[T1]{fontenc}' +
|
|
r'\usepackage{unicode-math}' +
|
|
r'\setmainfont{STIX Two Text}' +
|
|
r'\setmathfont{STIX Two Math}' +
|
|
r'\usepackage{siunitx}' +
|
|
r'\usepackage{mhchem}' +
|
|
r'\newcommand{\der}[1]{\ensuremath{\textnormal{d}\,{#1}}}' +
|
|
r'\DeclareSIUnit\ppb{ppb}' +
|
|
r'\DeclareSIUnit\ppm{ppm}'})
|
|
|
|
# Exporting via the pgf backend produces some font issues, therefore outputting via pdf is most consistent...
|
|
return ".pdf"
|
|
|
|
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
|
|
|
|
def compute_R2(y_true, y_est):
|
|
|
|
residuals = y_est - y_true
|
|
distances = y_true - np.mean(y_true)
|
|
|
|
return 1 - np.sum(np.power(residuals, 2)) / np.sum(np.power(distances, 2)) |