Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
Learning Python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Steinmann, Victor
Learning Python
Commits
26641bcc
Commit
26641bcc
authored
7 months ago
by
Steinmann
Browse files
Options
Downloads
Patches
Plain Diff
nicer
parent
d8be71fd
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Kennlinien_und_Fitting.ipynb
+19
-13
19 additions, 13 deletions
Kennlinien_und_Fitting.ipynb
with
19 additions
and
13 deletions
Kennlinien_und_Fitting.ipynb
+
19
−
13
View file @
26641bcc
...
...
@@ -189,27 +189,33 @@
},
{
"cell_type": "code",
"execution_count": 10
9
,
"execution_count": 1
1
0,
"metadata": {},
"outputs": [
{
"ename": "TypeError",
"evalue": "array() missing required argument 'object' (pos 0)",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[1;32mIn[109], line 2\u001b[0m\n\u001b[0;32m 1\u001b[0m df \u001b[38;5;241m=\u001b[39m pd\u001b[38;5;241m.\u001b[39mDataFrame(combine_csvs(),columns\u001b[38;5;241m=\u001b[39m[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mQ\u001b[39m\u001b[38;5;124m'\u001b[39m,\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mn\u001b[39m\u001b[38;5;124m'\u001b[39m,\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mH\u001b[39m\u001b[38;5;124m'\u001b[39m,\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mP\u001b[39m\u001b[38;5;124m'\u001b[39m])\n\u001b[1;32m----> 2\u001b[0m X\u001b[38;5;241m=\u001b[39m \u001b[43mnp\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43marray\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 3\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m i \u001b[38;5;129;01min\u001b[39;00m df\u001b[38;5;241m.\u001b[39mindex:\n\u001b[0;32m 4\u001b[0m X\u001b[38;5;241m=\u001b[39mnp\u001b[38;5;241m.\u001b[39marray(df[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mQ\u001b[39m\u001b[38;5;124m'\u001b[39m]\u001b[38;5;241m.\u001b[39mget(i)\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m2\u001b[39m)\n",
"\u001b[1;31mTypeError\u001b[0m: array() missing required argument 'object' (pos 0)"
"name": "stdout",
"output_type": "stream",
"text": [
" Q n H P\n",
"0 -0.0 0.208333 0.380667 0.003501\n",
"1 0.5 0.208333 0.386749 0.004184\n",
"2 1.0 0.208333 0.373531 0.004867\n",
"3 1.5 0.208333 0.341249 0.005549\n",
"4 2.0 0.208333 0.287062 0.006061\n",
".. ... ... ... ...\n",
"97 2.5 0.902778 7.107076 0.112583\n",
"98 3.0 0.902778 7.034061 0.123044\n",
"99 3.5 0.902778 6.906989 0.132358\n",
"100 -0.0 1.0 8.403823 0.078036\n",
"101 0.5 1.0 8.494628 0.088328\n",
"\n",
"[102 rows x 4 columns]\n"
]
}
],
"source": [
"df = pd.DataFrame(combine_csvs(),columns=['Q','n','H','P'])\n",
"for i in df.index:\n",
" X=np.array(df['Q'].get(i)**2)\n",
"\n",
"print(X)"
"print(df)"
]
},
{
...
...
%% Cell type:markdown id: tags:
Pumpenkennlinien importieren und auf Pumpengleichung Fitten
aus Webplotdigitizer .csv datei eines Plots extrahieren
mit pandas read_csv importieren
-> rechenspaß
->Profit!!!
Q^2 -> Q_sq quit
Multiple Linear Regression with Intercept
Q^3, Q^2
pandas -> read_csv
%% Cell type:code id: tags:
```
python
%
pip
install
pandas
%
pip
install
numpy
%
pip
install
matplotlib
%
pip
install
scikit
-
learn
```
%% Cell type:markdown id: tags:
Zusammenhänge der Pumpe:
$
\D
elta p=
\a
lpha_1
\c
dot Q^2+
\a
lpha_2
\c
dot Q
\c
dot n_{est}+
\a
lpha_3
\c
dot n_{est}^2$
$l_{est}=
\f
rac{
\D
elta p}{Q^2}$
Leistungsgleichung:
$P_{est}=
\b
eta_1
\c
dot Q^3+
\b
eta_2 Q^2
\c
dot n_{est}+
\b
eta_3
\c
dot Qn_{est}^2+
\b
eta_4n^3+
\b
eta_5$
%% Cell type:code id: tags:
```
python
#Implementierung des .csv zu DataFrame converters
import
pandas
as
pd
def
csv_einlesen
(
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
```
%% Cell type:code id: tags:
```
python
#def combine_csvs():
#with open ('learning-python'):
#for i in os.listdir(.csv):
#pd.read_csv(i)
```
%% Cell type:code id: tags:
```
python
def
combine_csvs
():
import
numpy
as
np
dz
=
[
750
,
1150
,
1500
,
1850
,
2200
,
2550
,
2900
,
3250
,
3600
]
array
=
np
.
array
(
float
)
for
z
in
dz
:
df
=
csv_einlesen
(
'
h
'
,
z
)
df_P
=
csv_einlesen
(
'
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
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
```
%% Cell type:markdown id: tags:
Fitting aus den Kurven mit sklearn
%% Cell type:code id: tags:
```
python
import
pandas
as
pd
import
numpy
as
np
from
matplotlib
import
pyplot
as
plt
from
sklearn.linear_model
import
LinearRegression
results
=
pd
.
DataFrame
()
results
[
'
n
'
]
=
[
750
,
1150
,
1500
,
1850
,
2200
,
2550
,
2900
,
3250
,
3600
]
fig
,
(
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
)
for
x
,
x2
in
zip
(
ax1
.
get_xgridlines
()
,
ax2
.
get_xgridlines
()):
x
.
set_visible
(
True
)
x2
.
set_visible
(
True
)
for
y
,
y2
in
zip
(
ax1
.
get_ygridlines
(),
ax2
.
get_ygridlines
()):
y
.
set_visible
(
True
)
y2
.
set_visible
(
True
)
ax1
.
set_title
(
'
Förderhöhe Kennlinie
'
,
loc
=
'
center
'
)
ax1
.
set_ylabel
(
'
$H$ in m
'
)
ax2
.
set_title
(
'
Leistungskennlinien
'
,
loc
=
'
center
'
,
y
=-
0.25
)
ax2
.
set_ylabel
(
'
$P$ in kW
'
)
for
n
in
results
.
index
:
df
=
csv_einlesen
(
'
H
'
,
results
[
'
n
'
].
get
(
n
))
X
=
df
.
loc
[:,[
'
Q^2
'
,
'
Qn
'
,
'
n^2
'
]].
to_numpy
(
float
)
y
=
df
[
'
H
'
].
to_numpy
(
float
)
results
[
'
Q-h_fit
'
]
=
LinearRegression
(
fit_intercept
=
False
).
fit
(
X
,
y
)
#plotten der Punkte und des Graphen
ax1
.
plot
(
df
[
'
Q
'
].
to_numpy
(),
results
[
'
Q-h_fit
'
].
get
(
n
).
predict
(
X
))
ax1
.
errorbar
(
df
[
'
Q
'
].
to_numpy
(),
results
[
'
Q-h_fit
'
].
get
(
n
).
predict
(
X
),
fmt
=
'
b+
'
)
#regression aus den Werten für Q und P
df2
=
csv_einlesen
(
'
P
'
,
results
[
'
n
'
].
get
(
n
))
X2
=
df2
.
loc
[:,[
'
Q^3
'
,
'
Q^2n
'
,
'
Qn^2
'
,
'
n^3
'
]].
to_numpy
(
float
)
y2
=
df2
[
'
H
'
].
to_numpy
(
float
)
results
[
'
Q-P_fit
'
]
=
LinearRegression
().
fit
(
X2
,
y2
)
#plotten der Punkte und der gefundnen Funktion mit
ax2
.
errorbar
(
df2
[
'
Q
'
].
to_numpy
(),
results
[
'
Q-P_fit
'
].
get
(
n
).
predict
(
X2
),
fmt
=
'
b+
'
)
ax2
.
plot
(
df2
[
'
Q
'
].
to_numpy
(),
results
[
'
Q-P_fit
'
].
get
(
n
).
predict
(
X2
))
print
(
results
[
'
Q-h_fit
'
].
get
(
n
).
coef_
)
print
(
f
'
R^2:
{
results
[
'
Q-h_fit
'
].
get
(
n
).
score
(
X
,
y
)
}
'
)
#print(results['Q-P_fit'].get(n).coef_)
```
%% Cell type:code id: tags:
```
python
df
=
pd
.
DataFrame
(
combine_csvs
(),
columns
=
[
'
Q
'
,
'
n
'
,
'
H
'
,
'
P
'
])
for
i
in
df
.
index
:
X
=
np
.
array
(
df
[
'
Q
'
].
get
(
i
)
**
2
)
print
(
X
)
print
(
df
)
```
%% Output
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[109], line 2
1 df = pd.DataFrame(combine_csvs(),columns=['Q','n','H','P'])
----> 2 X= np.array()
3 for i in df.index:
4 X=np.array(df['Q'].get(i)
**
2)
TypeError: array() missing required argument 'object' (pos 0)
Q n H P
0 -0.0 0.208333 0.380667 0.003501
1 0.5 0.208333 0.386749 0.004184
2 1.0 0.208333 0.373531 0.004867
3 1.5 0.208333 0.341249 0.005549
4 2.0 0.208333 0.287062 0.006061
.. ... ... ... ...
97 2.5 0.902778 7.107076 0.112583
98 3.0 0.902778 7.034061 0.123044
99 3.5 0.902778 6.906989 0.132358
100 -0.0 1.0 8.403823 0.078036
101 0.5 1.0 8.494628 0.088328
[102 rows x 4 columns]
%% Cell type:markdown id: tags:
df =
Q | n | P | H
-------- | -------- | -------- | --
0 | 0.35 | 10 | 2
0.
5 | 0.35 | 15 | 1.8
1 | 0.35 |20| 1.5
0 | 0.5 | 15 | 2
0.
5 | 0.5 | 20 | 1.8
1 | 0.5 | 25 | 1.5
```
python
X
=
numpy
.
array
([
df
.
loc
[:,
'
Q
'
]
**
3
,
df
.
loc
[:,
'
Q
'
]
**
2
*
df
.
loc
[:,
'
n
'
]...)
```
anmelden Thesis
Ziel einen Fit mit n als zweite Variable
multiple linear REgression
Ziel2 den FST custom stil zum plotten des Kennfelds einbinden
Ziel3 eine Präsi erstellen anhand des Leitfadens im studierende Starterpaket
schritt 4 Profit
%% Cell type:code id: tags:
```
python
results
[
'
Q-h_fit
'
]
```
%% Output
0 LinearRegression(fit_intercept=False)
1 LinearRegression(fit_intercept=False)
2 LinearRegression(fit_intercept=False)
3 LinearRegression(fit_intercept=False)
4 LinearRegression(fit_intercept=False)
5 LinearRegression(fit_intercept=False)
6 LinearRegression(fit_intercept=False)
7 LinearRegression(fit_intercept=False)
8 LinearRegression(fit_intercept=False)
Name: Q-h_fit, dtype: object
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment