-
Notifications
You must be signed in to change notification settings - Fork 0
/
generator.py
368 lines (321 loc) · 13.2 KB
/
generator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
# -*- coding: utf-8 -*-
"""
Created on Mon Jun 13 09:38:18 2016
@author: dave
"""
from __future__ import print_function
from __future__ import division
from __future__ import unicode_literals
from __future__ import absolute_import
import numpy as np
import scipy.interpolate as interpolate
import matplotlib as mpl
from matplotlib import pyplot as plt
import pandas as pd
import plotting
plt.rc('font', family='serif')
plt.rc('xtick', labelsize=10)
plt.rc('ytick', labelsize=10)
plt.rc('axes', labelsize=12)
plt.rc('text', usetex=True)
plt.rc('legend', fontsize=11)
plt.rc('legend', numpoints=1)
plt.rc('legend', borderaxespad=0)
mpl.rcParams['text.latex.unicode'] = True
#plt.rc('text', usetex=True)
def torque_power_at_ohm(Rset):
qlist, rpmlist, plist, efflist = [], [], [], []
fname = 'data/model/generator-windbluepower-st-540.csv'
df = pd.read_csv(fname, sep=',')
for k in [49, 117, 209, 275, 365, 490, 650, 870]:
sel = df[df['W [rpm]']==k]
qs = sel['tau_input [N-m]'].values
rs = sel['Rsetting [ohm]'].values
ps = sel['P_output [W]'].values
effs = sel['Eff [-]'].values
q = float(interpolate.griddata(rs, qs, Rset))
p = float(interpolate.griddata(rs, ps, Rset))
eff = float(interpolate.griddata(rs, effs, Rset))
rpmlist.append(k)
qlist.append(q)
plist.append(p)
efflist.append(eff)
return np.array(qlist), np.array(plist), np.array(rpmlist), np.array(efflist)
def rpm2torque(rpms, ohms):
"""Given the RPM and resistance setting, return the torque and electrical
power output. Based on windbluepower.com provided data. Re-used with their
permission.
Return
------
q : shaft torque
p : output electrical power
e : effeciency
"""
qlist, plist, efflist = [], [], []
for rpm, ohm in zip(rpms, ohms):
qs, ps, rpms, effs = torque_power_at_ohm(ohm)
qlist.append(interpolate.griddata(rpms, qs, rpm))
plist.append(interpolate.griddata(rpms, ps, rpm))
efflist.append(interpolate.griddata(rpms, effs, rpm))
return np.array(qlist), np.array(plist), np.array(efflist)
def plot_windbluepower_st_540():
"""Plot the data and add some other constant resistance values to it.
"""
q_rmax, p_rmax, rpm_rmax, emax = torque_power_at_ohm(28)
q_rmin, p_rmin, rpm_rmin, emin = torque_power_at_ohm(11)
# headers:
# Run #,W [rpm],Rsetting [ohm],Voltage [V],Current [A],tau_input [N-m]
# P_output [W],Eff [-]
fname = 'data/model/generator-windbluepower-st-540.csv'
df = pd.read_csv(fname, sep=',')
rad = df['W [rpm]'].values*np.pi/30.0
rpm = df['W [rpm]'].values
Qc = df['tau_input [N-m]']
R = df['Rsetting [ohm]']
eff = df['Eff [-]']*100.0
# the torque-rpm grid
xi = np.linspace(rpm.min(), rpm.max(), 200)
yi = np.linspace(Qc.min(), Qc.max(), 200)
cmap = mpl.cm.get_cmap('jet', 8)
# -------------------------------------------------------------------------
# iso-lines: dump load resistance value in Ohm
# grid the data
zi = mpl.mlab.griddata(rpm, Qc, R, xi, yi, interp='linear')
# consider switching to: matplotlib.tri.Triangulation or
# matplotlib.tri.TriInterpolator, see: matplotlib.org/api/tri_api.html
fig, axes = plotting.subplots(nrows=1, ncols=1, figsize=(4,2), dpi=120)
ax = axes.flatten()[0]
cnt = ax.contour(xi, yi, zi,8, colors=None, cmap=cmap) #, vmax=35, vmin=0)
ax.clabel(cnt, inline=1, fontsize=10, fmt='%1.0f')
ax.set_xlabel('rotor speed [rpm]')
ax.set_ylabel('input torque [Nm]')
ax.grid()
# clb = fig.colorbar(cnt)
# clb.set_label('color bar label')
# leg = ax.legend(loc='best', labelspacing=0, columnspacing=0)
# leg.get_frame().set_alpha(0.6)
fig.tight_layout()
fig.savefig('figures/generator-st-540-contour.png')
fig.savefig('figures/generator-st-540-contour.eps')
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
# iso-lines: efficiency
# grid the data
zi = mpl.mlab.griddata(rpm, Qc, eff, xi, yi, interp='linear')
# consider switching to: matplotlib.tri.Triangulation or
# matplotlib.tri.TriInterpolator, see: matplotlib.org/api/tri_api.html
fig, axes = plotting.subplots(nrows=1, ncols=1, figsize=(4,2), dpi=120)
ax = axes.flatten()[0]
cnt = ax.contour(xi, yi, zi,8, colors=None, cmap=cmap) #, vmax=35, vmin=0)
ax.clabel(cnt, inline=1, fontsize=10, fmt='%1.0f')
ax.set_xlabel('rotor speed [rpm]')
ax.set_ylabel('input torque [Nm]')
ax.grid()
fig.tight_layout()
fig.savefig('figures/generator-st-540-contour-eff.png')
fig.savefig('figures/generator-st-540-contour-eff.eps')
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
fig, axes = plotting.subplots(nrows=1, ncols=1, figsize=(5,3), dpi=120)
ax = axes.flatten()[0]
# plt.figure()
# plt.contour(xi, yi, zi,6, colors='k') #, vmax=35, vmin=0)
N = len(range(5, 30, 1))
# select a color map
cmap = mpl.cm.get_cmap('jet', N) # hot
# convert to array
cmap_arr = cmap(np.arange(N))
# and now you have each color as an RGB tuple as
# for i in cmap_arr:
# coltuple = tuple(i[0:3])
for r, color in zip(range(5, 30, 1), cmap_arr):
c = tuple(color[0:3])
q_, p_, rpm_, eff_ = torque_power_at_ohm(r)
ax.plot(rpm_, q_, ls='-', alpha=0.6, color=c, marker='+')
# plt.plot(rpm_rmax, q_rmax, 'r-', label='R=28 (dc0)')
# plt.plot(rpm_rmin, q_rmin, 'b-', label='R=11 (dc1)')
# plt.legend(loc='best')
ax.set_xlabel('rotor speed [rpm]')
ax.set_xlabel('input torque [Nm]')
ax.grid()
# leg = ax.legend(loc='best', labelspacing=0, columnspacing=0)
# leg.get_frame().set_alpha(0.6)
fig.tight_layout()
fig.savefig('figures/generator-st-540.png')
fig.savefig('figures/generator-st-540.eps')
# -------------------------------------------------------------------------
# slope, intercept, r_value, p_value, std_err
# regress : ndarray(len(x)-samples, 5)
# 2nd dimension holds: slope, intercept, r_value, p_value, std_err
# regress[i,:] = sp.stats.linregress(x[i:i1], y=y[i:i1])
def plot_windblue():
"""
Make some Torque, efficiency plots from the wind blue power data
"""
# data originally obtained from:
# http://www.windbluepower.com/
# Permanent_Magnet_Alternator_Wind_Blue_Low_Wind_p/dc-540.htm
# TODO: can I trace back the original download link?
fname = 'data/model/generator-windbluepower-st-540.csv'
# headers:
# Run #,W [rpm],Rsetting [ohm],Voltage [V],Current [A],tau_input [N-m]
# P_output [W],Eff [-]
iff = 5
iP = 4
iQ = 3
iR = 0
data = np.genfromtxt(fname, delimiter=',', dtype=np.float64,
skip_header=1, usecols=range(2,8))
rpm = np.genfromtxt(fname, delimiter=',', dtype=np.int16,
skip_header=1, usecols=[1])
rad = rpm*np.pi/30.0
Qc = data[:,iQ]/rad
# selection based on R setting? No, the whole range isn't tested at all
# rotor speeds
# plot RPM vs torque constant
# plt.figure()
# plt.plot(rpm, Qc, 'r+')
# reds = plt.get_cmap("Reds")
# plt.scatter(rpm, Qc, c=data[:,iR], s=20.0*data[:,iR], cmap=reds,
# vmin=0, vmax=35)
# plt.xlabel('RPM')
# plt.ylabel('Torque Constant')
# plt.grid()
#
# plt.figure()
# plt.plot(rpm, data[:,iQ], 'bo')
# plt.xlabel('RPM')
# plt.ylabel('Torque')
# plt.grid()
#
# plt.figure()
# plt.plot(data[:,iR], data[:,iQ], 'ks')
# plt.xlabel('Resistance')
# plt.ylabel('Torque')
# plt.grid()
# ------------------------------------------------------------------------
# torque vs RPM at constant resistance setting
# ------------------------------------------------------------------------
# because not always the same resistance settings are used, interpolate
# the data to a uniform grid. Higher RPMs are only tested for higher
# resistance settings. So take the lowest at 490 RPM and interpolate
# to that value for the other lower RPMs
rpmlist, Qlist, rpmlist21, Qlist21 = windblue_measurements()
xi = np.linspace(rpm.min(), rpm.max(), 200)
yi = np.linspace(data[:,iQ].min(), data[:,iQ].max(), 200)
# grid the data
zi = mpl.mlab.griddata(rpm,data[:,iQ],data[:,iR],xi,yi,interp='nn')
figpath = '/home/dave/PhD/Projects/OJF/SmallTurbine/'
figname = 'sta-540-torque-rpm'
figsize_x = plotting.TexTemplate.pagewidth*0.49
figsize_y = plotting.TexTemplate.pagewidth*0.55
scale = 1.8
pa4 = plotting.A4Tuned(scale=scale)
pa4.setup(figpath + figname, nr_plots=1, hspace_cm=2.,
grandtitle=False, wsleft_cm=1.3, wsright_cm=0.5,
wstop_cm=1.5, wsbottom_cm=1.0,
figsize_x=figsize_x, figsize_y=figsize_y)
ax1 = pa4.fig.add_subplot(pa4.nr_rows, pa4.nr_cols, 1)
# the manually interpollated torque curve at constant R setting
ax1.plot(rpmlist, Qlist, 'r--', label=r'$R=10.5 \Omega$')
ax1.plot(rpmlist21, Qlist21, 'b--', label=r'$R=21.0 \Omega$')
ax1.legend(loc='lower right')
# the actual measurements
# ax1.plot(rpm, data[:,iQ], 'r+')
# reds = plotting.mpl.cm.get_cmap("Reds")
# ax1.scatter(rpm, data[:,iQ], c=data[:,iR], s=10.0*data[:,iR])#, cmap=reds)
# contour the gridded data, plotting dots at the nonuniform data points
# draw the contour lines
CT = ax1.contour(xi,yi,zi,6, colors='k') #, vmax=35, vmin=0)
ax1.clabel(CT, fontsize=7*scale, inline=1, fmt='%1.0f')
title = 'Generator torque for different\nload settings (contours in Ohm)'
title += '\nWindbluepower measurements'
ax1.set_title(title)
ax1.set_ylabel('torque [Nm]')
ax1.set_xlabel('rotor speed [rpm]')
ax1.set_xlim([0, 1000])
ax1.grid(True)
pa4.save_fig()
# ------------------------------------------------------------------------
# torque constant plot
# ------------------------------------------------------------------------
figpath = '/home/dave/PhD/Projects/OJF/SmallTurbine/'
figname = 'sta-540-torque-constant'
figsize_x = plotting.TexTemplate.pagewidth*0.49
figsize_y = plotting.TexTemplate.pagewidth*0.6
scale = 1.8
pa4 = plotting.A4Tuned(scale=scale)
pa4.setup(figpath + figname, nr_plots=1, hspace_cm=2.,
grandtitle=False, wsleft_cm=1.7, wsright_cm=1.0,
wstop_cm=1.0, wsbottom_cm=1.0,
figsize_x=figsize_x, figsize_y=figsize_y)
ax1 = pa4.fig.add_subplot(pa4.nr_rows, pa4.nr_cols, 1)
# the interpolated result didn't look right: the offgrid points had a range
# that by far exceeded the R settings
# xi = np.linspace(rpm.min(), rpm.max(), 20)
# yi = np.linspace(Qc.min(), Qc.max(), 20)
# # grid the data
# zi = plotting.mpl.mlab.griddata(rpm,Qc,data[:,iR],xi,yi,interp='nn')
# # contour the gridded data, plotting dots at the nonuniform data points
# # draw the contour lines
# ct = ax1.contourf(xi,yi,zi,10, cmap=plotting.mpl.cm.rainbow)#,
# #vmax=35, vmin=0)
# pa4.fig.colorbar(plotting.mpl.cm.rainbow) # draw colorbar
# plot data points
# ax1.scatter(rpm, Qc, s=data[:,iR], marker='o')
reds = plotting.mpl.cm.get_cmap("Reds")
ax1.scatter(rpm, Qc, c=data[:,iR], s=10.0*data[:,iR], cmap=reds)
ax1.grid()
ax1.set_xlim([0, 1200])
ax1.set_xlabel('RPM')
ax1.set_ylabel(r'torque constant $\frac{Nm}{rad/s}$')
title = 'Torque constants for different\ngenerator loads '
title += '(circle radius)'
ax1.set_title(title)
pa4.save_fig()
# ax1.plot(rpm, data[:,iQ]/rad, 'r+')
def windblue_measurements():
"""
just return the torque/rpms for R=10.5 and R=21 of the windbluepower.com
measurements
"""
fname = 'data/model/generator-windbluepower-st-540.csv'
# headers:
# Run #,W [rpm],Rsetting [ohm],Voltage [V],Current [A],tau_input [N-m]
# P_output [W],Eff [-]
iff = 5
iP = 4
iQ = 3
iR = 0
data = np.genfromtxt(fname, delimiter=',', dtype=np.float64,
skip_header=1, usecols=range(2,8))
rpm = np.genfromtxt(fname, delimiter=',', dtype=np.int16,
skip_header=1, usecols=[1])
rad = rpm*np.pi/30.0
Qc = data[:,iQ]/rad
iRmin = data[rpm.__eq__(490), iR].argmin()
Rset = data[rpm.__eq__(490), iR][iRmin]
Qlist = []
rpmlist = []
# and for all other RPMs, find the (interpolated) performance for that R
# setting
for k in [49, 117, 209, 275, 365]:
qs = data[rpm.__eq__(k), iQ]
rs = data[rpm.__eq__(k), iR]
qnew = float(interpolate.griddata(rs, qs, Rset))
Qlist.append(qnew)
rpmlist.append(k)
Qlist.append(data[rpm.__eq__(490), iQ][iRmin])
rpmlist.append(490)
Qlist21, rpmlist21 = [], []
# make another list at 21 ohm
Rset = 21.0
for k in [49, 117, 209, 275, 365, 490, 650, 870]:
qs = data[rpm.__eq__(k), iQ]
rs = data[rpm.__eq__(k), iR]
qnew = float(interpolate.griddata(rs, qs, Rset))
Qlist21.append(qnew)
rpmlist21.append(k)
return rpmlist, Qlist, rpmlist21, Qlist21
if __name__ == '__main__':
dummy = None