Skip to content
Snippets Groups Projects
Commit f643550d authored by Steinmann's avatar Steinmann
Browse files

moved methods from .ipynb to .py files

parent 50452ba7
Branches
No related tags found
No related merge requests found
Source diff could not be displayed: it is too large. Options to address this: view the blob.
def combine_csvs():
import numpy as np
import pandas as pd
import df_from_csv
dz= [750,1150,1500,1850,2200,2550,2900,3250,3600]
array = np.array(float)
for z in dz:
df=df_from_csv('h',z)
df_P=df_from_csv('P',z)
if dz.index(z)==0:
array = df.loc[:,['Q','n_rel','H']].to_numpy(float)
array = np.append(array,df_P.loc[:,['P']].to_numpy(float),axis=1)
continue
#abschneiden der datanpaare, die keine korrespondierenden werte für H oder P haben
#vielleicht dumm
if len(df.index)<len(df_P.index):
for i in range(len(df_P.index)-len(df.index)):
df_P.drop(len(df.index)+i,inplace=True)
elif len(df.index)>len(df_P.index):
for i in range(len(df.index)-len(df_P.index)):
df.drop(len(df_P.index)+i,inplace=True)
array = np.append(array, np.append(df.loc[:,['Q','n_rel','H']].to_numpy(),df_P.loc[:,['P']].to_numpy(),axis=1), axis=0)
return array
#Implementierung des .csv zu DataFrame converters
import pandas as pd
def df_from_csv(y_Achse,drehzahl):
with open('{0}-Q_kennlinie_n_{1}.csv'.format(y_Achse,drehzahl)) as kennlinie:
dataframe = pd.read_csv(kennlinie, delimiter=';')
dataframe.loc[-1] = dataframe.columns
dataframe.index = dataframe.index +1
dataframe= dataframe.sort_index()
if y_Achse=='h':
sorted_set = dataframe.set_axis(['Q','H'],axis='columns')
elif y_Achse=='P':
sorted_set =dataframe.set_axis(['Q','P'],axis='columns')
#im Datensatz alle ',' durch '.' ersetzen und die String werte als Float Werte casten
for x in sorted_set.index:
for y in sorted_set.columns:
sorted_set.loc[x,[y]] = sorted_set.loc[x,[y]].str.replace(',','.')
sorted_set.loc[x,[y]] = sorted_set.loc[x,[y]].astype(float)
#berechnen der Spalte Q^2, Q^3 n_relativ, n^2, n^3, Q*n, Q^2*n,Q*n^2
sorted_set['Q^2'] = sorted_set['Q'] **2
sorted_set['Q^3'] = sorted_set['Q'] **3
sorted_set['n_rel'] = drehzahl/3600
sorted_set['n^2'] = sorted_set['n_rel']**2
sorted_set['n^3'] = sorted_set['n_rel']**3
sorted_set['Qn'] = sorted_set['n_rel']*sorted_set['Q']
sorted_set['Q^2n'] = sorted_set['Q^2']*sorted_set['n_rel']
sorted_set['Qn^2'] = sorted_set['Q']*sorted_set['n^2']
return sorted_set
\ No newline at end of file
#multiple lineare Regression um Kennfeld zu bestimmen
def regress_pump():
from matplotlib import pyplot as plt
import pandas as pd
import numpy as np
import combine_csvs
from sklearn.linear_model import LinearRegression
from IPython.display import display,Latex
df = pd.DataFrame(combine_csvs(),columns=['Q','n','H','P'])
#erstellen eines np arrays für die werte von Q^3 Q^2 Q^2n Qn^2 n^3
X = np.empty((0,3),float)
X2 = np.empty((0,4),float)
for i in df.index:
Q_temp= df['Q'].get(i)
n_temp= df['n'].get(i)
X = np.append(X,[[(Q_temp**2), (Q_temp*n_temp), (n_temp**2)]],axis=0)
X2 = np.append(X2,[[(Q_temp**3),(Q_temp**2) *n_temp, Q_temp*(n_temp**2), (n_temp**3)]],axis=0)
LR_H = LinearRegression(fit_intercept=False).fit(X , df['H'].to_numpy(float))
LR_P = LinearRegression().fit(X2,(df['P'].to_numpy(float)*1000))
plt.style.use('FST.mplstyle')
fig1, (ax1,ax2) = plt.subplots(2,1,sharex=True,gridspec_kw={'hspace':0})
ax1.set_xticks(np.linspace(0,10,11))
ax1.set_xticks(np.linspace(0,10,21),minor=True)
ax1.set_ylabel('Förderhöhe $\\it{H}$ in m',labelpad=13)
ax2.set_xlabel('Durchfluss $\\it{Q}$ in $m^3$')
ax2.set_ylabel('Leistung $\\it{P}$ in W')
ax1.plot(df['Q'],df['H'],'k.',ms=3)
ax2.plot(df['Q'],df['P']*1000,'k.',ms=3)
#muss für jeden bereich von n einzeln geplottet werden
n=set()
for x in df.index:
n.add(df['n'].get(x))
for i in range(9):
n_plt=n.pop()
z_pts=df[df['n']==n_plt].shape[0]
Q=np.linspace(0,(z_pts-1)*0.5,z_pts).reshape(-1,1)
X_plt=np.append(np.append(Q*Q, Q*n_plt,axis=1),np.ones((z_pts,1))*n_plt**2,axis=1)
X2_plt=np.append(np.append(np.append(Q*Q*Q, Q*Q*n_plt,axis=1),Q*(n_plt**2),axis=1),np.ones((z_pts,1))*(n_plt**3),axis=1)
ax1.plot(Q,LR_H.predict(X_plt),'k-')
ax2.plot(Q,LR_P.predict(X2_plt),'k-')
ax1.set_xlim([0,10])
ax2.set_ylim([0,200])
ax1.set_ylim([0,10])
plt.tight_layout()
print(f'R^2{LR_H.score(X,df['H'])}')
print(f'R^2{LR_P.score(X2,df['P'])}')
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment