From fd496ae7e36046ef043a4efc0881f3418ba59073 Mon Sep 17 00:00:00 2001 From: Paul Gilman Date: Fri, 12 Dec 2025 15:43:32 -0800 Subject: [PATCH] Sample LK script to create PV losses bar plot --- .../plot-detailed-pv-losses.lk | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 samples/LK Scripts for SAM/plot-detailed-pv-losses.lk diff --git a/samples/LK Scripts for SAM/plot-detailed-pv-losses.lk b/samples/LK Scripts for SAM/plot-detailed-pv-losses.lk new file mode 100644 index 0000000000..d2324648c8 --- /dev/null +++ b/samples/LK Scripts for SAM/plot-detailed-pv-losses.lk @@ -0,0 +1,73 @@ +/* +This script creates a horizontal bar graph of PV loss values for the Detailed +PV model. + +Tested in SAM 2025.4.16 +*/ + +if (varinfo('annual_poa_shading_loss_percent')== null) { + outln('This script must be run from a Detailed PV case.'); + return; +} +elseif (get('annual_energy') == null) { + outln('No results to plot. Run a simulation before running this script.'); + return; +} + +// list of loss variables +outputs = ['annual_poa_shading_loss_percent', +'annual_poa_soiling_loss_percent', +'annual_poa_cover_loss_percent', +'annual_dc_module_loss_percent', +'annual_dc_mppt_clip_loss_percent', +'annual_dc_mismatch_loss_percent', +'annual_dc_diodes_loss_percent', +'annual_dc_wiring_loss_percent', +'annual_dc_tracking_loss_percent', +'annual_dc_nameplate_loss_percent', +'annual_dc_optimizer_loss_percent', +'annual_dc_perf_adj_loss_percent', +'annual_ac_inv_clip_loss_percent', +'annual_ac_inv_pso_loss_percent', +'annual_ac_inv_pnt_loss_percent', +'annual_ac_inv_eff_loss_percent', +'annual_xfmr_loss_percent', +'annual_ac_perf_adj_loss_percent']; + +// set data for plot +y = []; +x = []; +xlabels = []; +for(i=0; i<#outputs; i++ ){ + y[i] = get(outputs[i]); + xlabels[i] = [i+1,varinfo(outputs[i]){'label'}]; + x[i]=i+1; +} + +// show data for debugging +outln(y); +outln(xlabels); +outln(x); + +// create plot +newplot(); +plot(y, x, {'type'='hbar', 'yap'='left', 'thick'=10, 'color'='grey'}); +plotopt( {'title'='', 'fine' = true, 'coarse' = true, 'scale'=1 } ); +axis( 'y1', {'type'='label', 'labels'=xlabels, 'min'=0,'max'=max(x)+1, 'ticksizes'=[0,0]}); +axis( 'x1', { 'label'='%', 'max'=max(y)+max(y)/10 } ); + +// save plot as image file +if ( yesno( 'Save graph as PNG?' ) ) +{ + f_path=choose_dir(homedir(),'Save Plot'); + f_name = f_path + '/plot.png'; + outln(f_name); + ok = plotout( f_name , 'png'); // png, pdf, bmp, or jpg. Defaults to png if file type not given. + if ( ok == false) { + outln('Could not save the plot to ' + f_name); + } + else { + outln('Saved plot to ' + f_name); + browse(f_name); + } +}