Skip to content

Commit fd496ae

Browse files
committed
Sample LK script to create PV losses bar plot
1 parent 6493441 commit fd496ae

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
This script creates a horizontal bar graph of PV loss values for the Detailed
3+
PV model.
4+
5+
Tested in SAM 2025.4.16
6+
*/
7+
8+
if (varinfo('annual_poa_shading_loss_percent')== null) {
9+
outln('This script must be run from a Detailed PV case.');
10+
return;
11+
}
12+
elseif (get('annual_energy') == null) {
13+
outln('No results to plot. Run a simulation before running this script.');
14+
return;
15+
}
16+
17+
// list of loss variables
18+
outputs = ['annual_poa_shading_loss_percent',
19+
'annual_poa_soiling_loss_percent',
20+
'annual_poa_cover_loss_percent',
21+
'annual_dc_module_loss_percent',
22+
'annual_dc_mppt_clip_loss_percent',
23+
'annual_dc_mismatch_loss_percent',
24+
'annual_dc_diodes_loss_percent',
25+
'annual_dc_wiring_loss_percent',
26+
'annual_dc_tracking_loss_percent',
27+
'annual_dc_nameplate_loss_percent',
28+
'annual_dc_optimizer_loss_percent',
29+
'annual_dc_perf_adj_loss_percent',
30+
'annual_ac_inv_clip_loss_percent',
31+
'annual_ac_inv_pso_loss_percent',
32+
'annual_ac_inv_pnt_loss_percent',
33+
'annual_ac_inv_eff_loss_percent',
34+
'annual_xfmr_loss_percent',
35+
'annual_ac_perf_adj_loss_percent'];
36+
37+
// set data for plot
38+
y = [];
39+
x = [];
40+
xlabels = [];
41+
for(i=0; i<#outputs; i++ ){
42+
y[i] = get(outputs[i]);
43+
xlabels[i] = [i+1,varinfo(outputs[i]){'label'}];
44+
x[i]=i+1;
45+
}
46+
47+
// show data for debugging
48+
outln(y);
49+
outln(xlabels);
50+
outln(x);
51+
52+
// create plot
53+
newplot();
54+
plot(y, x, {'type'='hbar', 'yap'='left', 'thick'=10, 'color'='grey'});
55+
plotopt( {'title'='', 'fine' = true, 'coarse' = true, 'scale'=1 } );
56+
axis( 'y1', {'type'='label', 'labels'=xlabels, 'min'=0,'max'=max(x)+1, 'ticksizes'=[0,0]});
57+
axis( 'x1', { 'label'='%', 'max'=max(y)+max(y)/10 } );
58+
59+
// save plot as image file
60+
if ( yesno( 'Save graph as PNG?' ) )
61+
{
62+
f_path=choose_dir(homedir(),'Save Plot');
63+
f_name = f_path + '/plot.png';
64+
outln(f_name);
65+
ok = plotout( f_name , 'png'); // png, pdf, bmp, or jpg. Defaults to png if file type not given.
66+
if ( ok == false) {
67+
outln('Could not save the plot to ' + f_name);
68+
}
69+
else {
70+
outln('Saved plot to ' + f_name);
71+
browse(f_name);
72+
}
73+
}

0 commit comments

Comments
 (0)