Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
WindEnergyToolbox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
wtlib
WindEnergyToolbox
Commits
3adda7db
Commit
3adda7db
authored
7 years ago
by
David Verelst
Browse files
Options
Downloads
Patches
Plain Diff
prepost.dlcplots: prune unused method, do not set legend alpha if no leg
parent
af4aeb2a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
wetb/prepost/dlcplots.py
+3
-233
3 additions, 233 deletions
wetb/prepost/dlcplots.py
with
3 additions
and
233 deletions
wetb/prepost/dlcplots.py
+
3
−
233
View file @
3adda7db
...
...
@@ -150,242 +150,10 @@ def merge_sim_ids(sim_ids, post_dirs, post_dir_save=False):
return
run_dirs
,
df_stats
# =============================================================================
### STAT PLOTS
# =============================================================================
def
plot_stats
(
sim_ids
,
post_dirs
,
fig_dir_base
=
None
):
"""
For each wind speed, take the max of the max.
Only one or two sim_ids are supported. When they are from different
models/projects, specify for each sim_id a different post_dir
Parameters
----------
sim_ids : list
list of sim_id
'
s, 1 or 2
post_dirs
list of post_dir
'
s, 1 or 2. If 2, should correspond to sim_ids
fig_dir_base : str, default=None
"""
# if sim_id is a list, combine the two dataframes into one
df_stats
=
pd
.
DataFrame
()
if
type
(
sim_ids
).
__name__
==
'
list
'
:
for
ii
,
sim_id
in
enumerate
(
sim_ids
):
if
isinstance
(
post_dirs
,
list
):
post_dir
=
post_dirs
[
ii
]
else
:
post_dir
=
post_dirs
cc
=
sim
.
Cases
(
post_dir
,
sim_id
,
rem_failed
=
True
)
if
ii
==
0
:
df_stats
,
_
,
_
=
cc
.
load_stats
()
else
:
# because there is no unique index, we will ignore it
df_stats
,
_
,
_
=
pd
.
concat
([
df_stats
,
cc
.
load_stats
()],
ignore_index
=
True
)
else
:
sim_id
=
sim_ids
sim_ids
=
False
post_dir
=
post_dirs
cc
=
sim
.
Cases
(
post_dir
,
sim_id
,
rem_failed
=
True
)
df_stats
,
_
,
_
=
cc
.
load_stats
()
# if force_dir:
# cc.change_results_dir(resdir=force_dir)
# for case in cc.cases:
# sim_id = cc.cases[case]['[post_dir]']
# cc.cases[case]['[post_dir]'] = post_dir
# # add DLC category
# f = lambda x: x.split('_')[0]
# df_stats['DLC'] = df_stats['[Case id.]'].map(f)
# fig, axes = plt.subplots(nrows=1, ncols=1, figsize=(12,8), num=1)
# define the number of positions you want to have the color for
N
=
22
# select a color map
cmap
=
mpl
.
cm
.
get_cmap
(
'
jet
'
,
N
)
# convert to array
cmap_arr
=
cmap
(
np
.
arange
(
N
))
# color=cmap_arr[icol][0:3]
# make a stastics plot for each channel
gb_ch
=
df_stats
.
groupby
(
df_stats
.
channel
)
# channel selection
plot_chans
=
{}
plot_chans
[
'
DLL-2-inpvec-2
'
]
=
'
P_e
'
plot_chans
[
'
bearing-shaft_rot-angle_speed-rpm
'
]
=
'
RPM
'
plot_chans
[
'
tower-tower-node-001-momentvec-x
'
]
=
'
M_x T_B
'
plot_chans
[
'
tower-tower-node-001-momentvec-y
'
]
=
'
M_y T_B
'
plot_chans
[
'
tower-tower-node-001-momentvec-z
'
]
=
'
M_z T_B
'
plot_chans
[
'
tower-tower-node-008-momentvec-z
'
]
=
'
M_x T_T
'
plot_chans
[
'
tower-tower-node-008-momentvec-z
'
]
=
'
M_y T_T
'
plot_chans
[
'
tower-tower-node-008-momentvec-z
'
]
=
'
M_z T_T
'
plot_chans
[
'
shaft-shaft-node-004-momentvec-x
'
]
=
'
M_x Shaft_{MB}
'
plot_chans
[
'
shaft-shaft-node-004-momentvec-y
'
]
=
'
M_y Shaft_{MB}
'
plot_chans
[
'
shaft-shaft-node-004-momentvec-z
'
]
=
'
M_z Shaft_{MB}
'
plot_chans
[
'
blade1-blade1-node-003-momentvec-x
'
]
=
'
M_x B1_{root}
'
plot_chans
[
'
blade1-blade1-node-003-momentvec-y
'
]
=
'
M_y B1_{root}
'
plot_chans
[
'
blade1-blade1-node-003-momentvec-z
'
]
=
'
M_z B1_{root}
'
plot_chans
[
'
blade2-blade2-node-003-momentvec-x
'
]
=
'
M_x B2_{root}
'
plot_chans
[
'
blade2-blade2-node-003-momentvec-y
'
]
=
'
M_y B2_{root}
'
plot_chans
[
'
blade2-blade2-node-003-momentvec-z
'
]
=
'
M_z B2_{root}
'
plot_chans
[
'
blade3-blade3-node-003-momentvec-x
'
]
=
'
M_x B3_{root}
'
plot_chans
[
'
blade3-blade3-node-003-momentvec-y
'
]
=
'
M_y B3_{root}
'
plot_chans
[
'
blade3-blade3-node-003-momentvec-z
'
]
=
'
M_z B3_{root}
'
plot_chans
[
'
DLL-5-inpvec-1
'
]
=
'
Min tower clearance
'
plot_chans
[
'
bearing-pitch1-angle-deg
'
]
=
'
B1_{pitch}
'
plot_chans
[
'
bearing-pitch2-angle-deg
'
]
=
'
B2_{pitch}
'
plot_chans
[
'
bearing-pitch3-angle-deg
'
]
=
'
B3_{pitch}
'
plot_chans
[
'
setbeta-bladenr-1-flapnr-1
'
]
=
'
B1_{flap}
'
plot_chans
[
'
setbeta-bladenr-2-flapnr-1
'
]
=
'
B2_{flap}
'
plot_chans
[
'
setbeta-bladenr-3-flapnr-1
'
]
=
'
B3_{flap}
'
mfcs1
=
[
'
k
'
,
'
w
'
]
mfcs2
=
[
'
b
'
,
'
w
'
]
mfcs3
=
[
'
r
'
,
'
w
'
]
stds
=
[
'
r
'
,
'
b
'
]
for
nr
,
(
ch_name
,
gr_ch
)
in
enumerate
(
gb_ch
):
if
ch_name
not
in
plot_chans
:
continue
for
dlc_name
,
gr_ch_dlc
in
gr_ch
.
groupby
(
df_stats
[
'
[DLC]
'
]):
print
(
'
start plotting: %s %s
'
%
(
str
(
dlc_name
).
ljust
(
7
),
ch_name
))
fig
,
axes
=
mplutils
.
make_fig
(
nrows
=
1
,
ncols
=
1
,
figsize
=
(
7
,
5
))
ax
=
axes
[
0
,
0
]
# seperate figure for the standard deviations
fig2
,
axes2
=
mplutils
.
make_fig
(
nrows
=
1
,
ncols
=
1
,
figsize
=
(
7
,
5
))
ax2
=
axes2
[
0
,
0
]
if
fig_dir_base
is
None
and
not
sim_ids
:
res_dir
=
gr_ch_dlc
[
'
[res_dir]
'
][:
1
].
values
[
0
]
run_dir
=
gr_ch_dlc
[
'
[run_dir]
'
][:
1
].
values
[
0
]
fig_dir
=
os
.
path
.
join
(
fig_dir_base
,
res_dir
)
elif
fig_dir_base
is
None
and
isinstance
(
sim_ids
,
list
):
fig_dir
=
os
.
path
.
join
(
fig_dir_base
,
'
-
'
.
join
(
sim_ids
))
elif
fig_dir_base
and
not
sim_ids
:
res_dir
=
gr_ch_dlc
[
'
[res_dir]
'
][:
1
].
values
[
0
]
fig_dir
=
os
.
path
.
join
(
fig_dir_base
,
res_dir
)
elif
sim_ids
and
fig_dir_base
is
not
None
:
# create the compare directory if not defined
fig_dir
=
fig_dir_base
# if we have a list of different cases, we also need to group those
# because the sim_id wasn't saved before in the data frame,
# we need to derive that from the run dir
# if there is only one run dir nothing changes
ii
=
0
sid_names
=
[]
for
run_dir
,
gr_ch_dlc_sid
in
gr_ch_dlc
.
groupby
(
df_stats
[
'
[run_dir]
'
]):
sid_name
=
run_dir
.
split
(
'
/
'
)[
-
2
]
sid_names
.
append
(
sid_name
)
print
(
sid_name
)
wind
=
gr_ch_dlc_sid
[
'
[Windspeed]
'
].
values
dmin
=
gr_ch_dlc_sid
[
'
min
'
].
values
dmean
=
gr_ch_dlc_sid
[
'
mean
'
].
values
dmax
=
gr_ch_dlc_sid
[
'
max
'
].
values
dstd
=
gr_ch_dlc_sid
[
'
std
'
].
values
if
not
sim_ids
:
lab1
=
'
mean
'
lab2
=
'
min
'
lab3
=
'
max
'
lab4
=
'
std
'
else
:
lab1
=
'
mean %s
'
%
sid_name
lab2
=
'
min %s
'
%
sid_name
lab3
=
'
max %s
'
%
sid_name
lab4
=
'
std %s
'
%
sid_name
mfc1
=
mfcs1
[
ii
]
mfc2
=
mfcs2
[
ii
]
mfc3
=
mfcs3
[
ii
]
ax
.
plot
(
wind
,
dmean
,
mec
=
'
k
'
,
marker
=
'
o
'
,
mfc
=
mfc1
,
ls
=
''
,
label
=
lab1
,
alpha
=
0.7
)
ax
.
plot
(
wind
,
dmin
,
mec
=
'
b
'
,
marker
=
'
^
'
,
mfc
=
mfc2
,
ls
=
''
,
label
=
lab2
,
alpha
=
0.7
)
ax
.
plot
(
wind
,
dmax
,
mec
=
'
r
'
,
marker
=
'
v
'
,
mfc
=
mfc3
,
ls
=
''
,
label
=
lab3
,
alpha
=
0.7
)
ax2
.
plot
(
wind
,
dstd
,
mec
=
stds
[
ii
],
marker
=
'
s
'
,
mfc
=
stds
[
ii
],
ls
=
''
,
label
=
lab4
,
alpha
=
0.7
)
ii
+=
1
# for wind, gr_wind in gr_ch_dlc.groupby(df_stats['[Windspeed]']):
# wind = gr_wind['[Windspeed]'].values
# dmin = gr_wind['min'].values#.mean()
# dmean = gr_wind['mean'].values#.mean()
# dmax = gr_wind['max'].values#.mean()
## dstd = gr_wind['std'].mean()
# ax.plot(wind, dmean, 'ko', label='mean', alpha=0.7)
# ax.plot(wind, dmin, 'b^', label='min', alpha=0.7)
# ax.plot(wind, dmax, 'rv', label='max', alpha=0.7)
## ax.errorbar(wind, dmean, c='k', ls='', marker='s', mfc='w',
## label='mean and std', yerr=dstd)
ax
.
grid
()
ax
.
set_xlim
([
3
,
27
])
leg
=
ax
.
legend
(
loc
=
'
best
'
,
ncol
=
2
)
leg
.
get_frame
().
set_alpha
(
0.7
)
ax
.
set_title
(
r
'
{DLC%s} $%s$
'
%
(
dlc_name
,
plot_chans
[
ch_name
]))
ax
.
set_xlabel
(
'
Wind speed [m/s]
'
)
fig
.
tight_layout
()
fig
.
subplots_adjust
(
top
=
0.92
)
if
not
sim_ids
:
fig_path
=
os
.
path
.
join
(
fig_dir
,
ch_name
.
replace
(
'
'
,
'
_
'
)
+
'
.png
'
)
else
:
sids
=
'
_
'
.
join
(
sid_names
)
# fig_dir = run_dir.split('/')[:-1] + 'figures/'
fname
=
'
%s_%s.png
'
%
(
ch_name
.
replace
(
'
'
,
'
_
'
),
sids
)
fig_path
=
os
.
path
.
join
(
fig_dir
,
'
dlc%s/
'
%
dlc_name
)
if
not
os
.
path
.
exists
(
fig_path
):
os
.
makedirs
(
fig_path
)
fig_path
=
fig_path
+
fname
fig
.
savefig
(
fig_path
)
#.encode('latin-1')
# canvas.close()
fig
.
clear
()
print
(
'
saved: %s
'
%
fig_path
)
ax2
.
grid
()
ax2
.
set_xlim
([
3
,
27
])
leg
=
ax2
.
legend
(
loc
=
'
best
'
,
ncol
=
2
)
leg
.
get_frame
().
set_alpha
(
0.7
)
ax2
.
set_title
(
r
'
{DLC%s} $%s$
'
%
(
dlc_name
,
plot_chans
[
ch_name
]))
ax2
.
set_xlabel
(
'
Wind speed [m/s]
'
)
fig2
.
tight_layout
()
fig2
.
subplots_adjust
(
top
=
0.92
)
if
not
sim_ids
:
fig_path
=
os
.
path
.
join
(
fig_dir
,
ch_name
.
replace
(
'
'
,
'
_
'
)
+
'
_std.png
'
)
else
:
sids
=
'
_
'
.
join
(
sid_names
)
fname
=
'
%s_std_%s.png
'
%
(
ch_name
.
replace
(
'
'
,
'
_
'
),
sids
)
fig_path
=
os
.
path
.
join
(
fig_dir
,
'
dlc%s/
'
%
dlc_name
)
if
not
os
.
path
.
exists
(
fig_path
):
os
.
makedirs
(
fig_path
)
fig_path
=
fig_path
+
fname
fig2
.
savefig
(
fig_path
)
#.encode('latin-1')
# canvas.close()
fig2
.
clear
()
print
(
'
saved: %s
'
%
fig_path
)
def
plot_stats2
(
sim_ids
,
post_dirs
,
plot_chans
,
fig_dir_base
=
None
,
labels
=
None
,
post_dir_save
=
False
,
dlc_ignore
=
[
'
00
'
],
figsize
=
(
8
,
6
)):
"""
...
...
@@ -619,7 +387,9 @@ def plot_dlc_stats(df_stats, plot_chans, fig_dir_base, labels=None,
ax
.
grid
()
ax
.
set_xlim
(
xlims
)
leg
=
ax
.
legend
(
loc
=
'
best
'
,
ncol
=
3
)
leg
.
get_frame
().
set_alpha
(
0.7
)
# if no data at all was found
if
leg
is
not
None
:
leg
.
get_frame
().
set_alpha
(
0.7
)
ax
.
set_title
(
r
'
{DLC%s} %s
'
%
(
dlc_name
,
ch_dscr
))
ax
.
set_xlabel
(
xlabel
)
fig
.
tight_layout
()
...
...
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