init package and add first subpackages

This commit is contained in:
Markus Clauß
2023-02-27 17:07:04 +01:00
commit 1b4ce18eca
16 changed files with 1658 additions and 0 deletions

192
src/paveit/labtest/citt.py Normal file
View File

@@ -0,0 +1,192 @@
import io
import os
from csv import reader
import numpy as np
import pandas as pd
from paveit.labtest import DataSineLoad
class CITTBase(DataSineLoad):
def _calc(self):
return (self.df.mean().mean(), self.df.max().max())
class CITT_KIT(DataSineLoad):
def _calc(self):
return (self.df.mean().mean(), self.df.max().max())
def _bytes_to_df(self):
logger.debug('convert bytes to pandas.DataFrame')
self.data.seek(0)
with io.TextIOWrapper(self.data, encoding='latin-1') as read_obj:
csv_reader = reader(read_obj, delimiter=';')
read = False
data = []
temp = []
for idx_row, row in enumerate(csv_reader):
if row == ['*****']:
if read == False:
read = True
else:
read = False
data.append(temp)
temp = []
continue
if read:
row = [r.replace(',', '.') for r in row]
temp.append(row)
#convert to pandas
res = []
freqs = [10.0, 5.0, 1.0, 0.1, 10.0]
for idx_data, d in enumerate(data):
t = pd.DataFrame(d[3:])
t.columns = d[1]
freq = freqs[idx_data]
t['f'] = freq
for col in t.columns:
t[col] = pd.to_numeric(t[col])
# add cycle number
dt = 1. / freq
Nmax = int(np.ceil(t['ZEIT'].max() / dt))
N = np.zeros_like(t['ZEIT'])
for i in range(Nmax):
if i == 0:
tmin = 0
tmax = dt
else:
tmax = (i + 1) * dt
tmin = (i) * dt
idx = t[(t['ZEIT'] >= tmin) & (t['ZEIT'] < tmax)].index
N[idx] = i
t['N'] = N
res.append(t)
#remove second 10 Hz
res = pd.concat(res[:-1])
res['T'] = self.temperature
#res = res.sort_values(['f', 'ZEIT'])
#define in class
self.df = res.reset_index()
class CITT_PTMDortmund(DataSineLoad):
def _calc(self):
return (self.df.mean().mean(), self.df.max().max())
def _bytes_to_df(self):
res = []
xl = pd.ExcelFile(self.data)
num_sheets = len(xl.sheet_names)
print(num_sheets)
diameter = []
height = []
for sheetid in range(num_sheets):
temp = pd.read_excel(self.data, sheetid, skiprows=97)
temp = temp.drop(index=0)
#convert data to numerical data
for col in temp.columns:
temp[col] = pd.to_numeric(temp[col])
#read metadata from file
meta = pd.read_excel(self.data, sheetid,
skiprows=1,
nrows=90)
meta = meta[meta.columns[[0, 2]]]
meta = meta.set_index(
meta.columns[0]).to_dict()[meta.columns[1]]
temp['sigma'] = float(meta['Max. Spannung'])
temp['T'] = float(meta['Versuchstemperatur'])
freq = float(meta['Frequenz'])
dt = 1 / freq
temp['f'] = freq
Nfrom = int(meta['Erster Aufzeichnungslastwechsel'])
Nto = int(meta['Letzer Aufzeichnungslastwechsel'])
#add cycle number to dataframe
time_idx = temp['Zeitfolgen'].values
N = np.zeros_like(time_idx)
self._logger.debug(len(N))
self._logger.info(f'cycles from {Nfrom} to {Nto}')
#BUG: Ist in Messdatei falsch definiert und wird von PTM angepasst. '''
#for cycle in range(Nfrom, Nto+1):
for cycle in range(10):
# time window
tmin = (cycle) * dt
tmax = (cycle + 1) * dt
#filter data
idx = temp[(time_idx >= tmin)
& (time_idx < tmax)].index
#FIX: siehe bug oben
if any(idx)>=500:
idx = idx[idx<500]
#set cycle number
N[idx] = cycle
temp['N'] = N
# add diameter and height to list
diameter.append(float(meta['Durchmesser (mm)']))
height.append(float(meta['Länge (mm)']))
#append data to final dataframe
res.append(temp)
#concat all parts to single dataframe
res = pd.concat(res)
# add data from speciment to metadata
if not 'diameter' in self.metadata:
self.metadata['diameter'] = np.mean(diameter)
if not 'height' in self.metadata:
self.metadata['height'] = np.mean(height)
#define in class
self.df = res.reset_index()
# log infos
logger.debug(self.metadata)
logger.debug(self.df.head())