|
| 1 | +/*@ |
| 2 | + |
| 3 | +<p>This macro reads data from an OND or PAN file and populates inputs on SAM's |
| 4 | + Module or Inverter input page.</p> |
| 5 | + |
| 6 | +<p>The macro was tested with OND and PAN text files from PVsyst Version 6.6 and |
| 7 | +SAM 2018.11.11. It will not convert binary OND or PAN files from older versions |
| 8 | +of PVsyst.</p> |
| 9 | + |
| 10 | +<p><strong>Notes:</strong></p> |
| 11 | +<ul> |
| 12 | +<li>For inverters, the script reads the number of MPPT inputs from the OND file |
| 13 | +and sets the value in SAM accordingly. For inverters with more than one MPPT input, |
| 14 | +you may need to assign a subarray to each MPPT input on the System Design page.</li> |
| 15 | +<li>For bifacial modules, the script does not read the bifaciality factor from |
| 16 | +the PAN file. You will need to set the bifacial inputs by hand on SAM's Module |
| 17 | +input page.</li> |
| 18 | +</ul> |
| 19 | +@*/ |
| 20 | + |
| 21 | +function read_pvsyst_file ( file , T ) |
| 22 | +{ |
| 23 | + text_line = ''; |
| 24 | + first_line = ''; |
| 25 | + arr = []; |
| 26 | + skipped_data = []; |
| 27 | + n = 0; |
| 28 | + T{'error'} = ''; |
| 29 | + fin = open( file, 'r' ); |
| 30 | + read_line( fin, first_line ); |
| 31 | + if ( strpos( lower(first_line), 'pvobject_' ) < 0 ) |
| 32 | + { |
| 33 | + T{'error'} = 'File does not appear to be a PVsyst PAN or OND text file.'; |
| 34 | + } |
| 35 | + else |
| 36 | + { |
| 37 | + while( read_line( fin, text_line ) ) |
| 38 | + { |
| 39 | + if ( text_line != '' ) // skip blank lines (assume blank lines have no spaces) |
| 40 | + { |
| 41 | + // assume lines with valid data contain an equal sign that separates a |
| 42 | + // pvsyst variable name from its value |
| 43 | + arr = split( text_line, '=' ); |
| 44 | + arr[0] = replace( arr[0], ' ' , '' ); // remove leading spaces |
| 45 | + } |
| 46 | + if ( lower(arr[0]) == 'pvobject_' ) |
| 47 | + { |
| 48 | + T{'componenttype'} = arr[1]; // not used by sam |
| 49 | + } |
| 50 | + if ( #arr == 1 ) // skip lines with no equal sign |
| 51 | + { |
| 52 | + continue; |
| 53 | + } |
| 54 | + elseif ( T ?@ lower( arr[0] ) ) |
| 55 | + { |
| 56 | + T{lower(arr[0])} = arr[1]; |
| 57 | + } |
| 58 | + else |
| 59 | + { |
| 60 | + skipped_data[n] = arr; |
| 61 | + n++; |
| 62 | + } |
| 63 | + } |
| 64 | + } |
| 65 | + close( fin ); |
| 66 | + T{'skippeddata'} = skipped_data; |
| 67 | + return( T ); |
| 68 | +} |
| 69 | + |
| 70 | +// opens a pan file and returns a table of pan variables and their values |
| 71 | +// only returns variables that have equivalents in sam. |
| 72 | +function read_pan_file ( f ) |
| 73 | +{ |
| 74 | + |
| 75 | + Tvars = {}; |
| 76 | + |
| 77 | + // initialize table of pvsyst variables that sam uses |
| 78 | + Tvars{'muisc'} = ''; |
| 79 | + Tvars{'width'} = ''; |
| 80 | + Tvars{'height'} = ''; |
| 81 | + Tvars{'muvocspec'} = ''; |
| 82 | + Tvars{'tecnol'} = ''; |
| 83 | + Tvars{'mupmpreq'} = ''; |
| 84 | + Tvars{'imp'} = ''; |
| 85 | + Tvars{'isc'} = ''; |
| 86 | + Tvars{'manufacturer'} = ''; |
| 87 | + Tvars{'model'} = ''; |
| 88 | + Tvars{'ncels'} = ''; |
| 89 | + Tvars{'vmp'} = ''; |
| 90 | + Tvars{'voc'} = ''; |
| 91 | + |
| 92 | + return( read_pvsyst_file( f, Tvars ) ); |
| 93 | + |
| 94 | +} |
| 95 | + |
| 96 | +function read_ond_file ( f ) |
| 97 | +{ |
| 98 | + |
| 99 | + var = {}; |
| 100 | + |
| 101 | + // initialize table of pvsyst variables that sam uses |
| 102 | + Tvars{'pmaxout'} = ''; |
| 103 | + Tvars{'vmppmin'} = ''; |
| 104 | + Tvars{'vmppmax'} = ''; |
| 105 | + Tvars{'vmppnom'} = ''; |
| 106 | + Tvars{'vabsmax'} = ''; |
| 107 | + Tvars{'pseuil'} = ''; |
| 108 | + Tvars{'modeaffenum'} = ''; |
| 109 | + Tvars{'efficmax'} = ''; |
| 110 | + Tvars{'nbmppt'} = ''; |
| 111 | + Tvars{'night_loss'} = ''; |
| 112 | + |
| 113 | + return( read_pvsyst_file( f, Tvars ) ); |
| 114 | + |
| 115 | +} |
| 116 | + |
| 117 | +// converts a table of pvsyst pan file variables to a table of input variables |
| 118 | +// for sam's module model with user-entered specifications |
| 119 | +function pan_to_sam_vars( T ) |
| 120 | +{ |
| 121 | + |
| 122 | + sam_var = {}; |
| 123 | + |
| 124 | + // some pvsyst variables need conversion before using in sam |
| 125 | + aisc = to_real(T.muisc) / 1000; // mA/degC to A/degC |
| 126 | + bvoc = to_real(T.muvocspec) / 1000; // mV/degC to V/degC |
| 127 | + aiscunits = 0; // A/degC in SAM |
| 128 | + bvocunits = 0; // V/degC in SAM |
| 129 | + area = to_real(T.width) * to_real(T.height); |
| 130 | + modulename = T.manufacturer + ' ' + T.model; |
| 131 | + mounting = 0; |
| 132 | + standoff = 6; |
| 133 | + tnoct = 46; |
| 134 | + celltech={}; |
| 135 | + celltech.sam = ['monoSi','multiSi','CdTe','CIS','CIGS','Amorphous']; |
| 136 | + celltech.pvsyst = ['mtSiMono','undefined!','undefined!','undefined!','undefined!','undefined!']; |
| 137 | + |
| 138 | + // assign SAM variable values |
| 139 | + sam_var{'6par_aisc_display'} = aisc; // muisc /1000 // muisc is mA/degC |
| 140 | + sam_var{'6par_aisc_units'} = aiscunits; // not in pvsys, set to 0 for A/degC |
| 141 | + sam_var{'6par_area'} = area; // width * height, pvsyst cell area is not used |
| 142 | + sam_var{'6par_bvoc_display'} = bvoc; // mV/degC |
| 143 | + sam_var{'6par_bvoc_units'} = bvocunits; // not in pvsyst, set to 0 for V/degC |
| 144 | + sam_var{'6par_celltech'} = celltech.sam[lower(celltech.pvsyst) ?@ T.tecnol]; |
| 145 | + sam_var{'6par_gpmp'} = to_real(T.mupmpreq); // %/degC no conversion required |
| 146 | + sam_var{'6par_imp'} = to_real(T.imp); // A |
| 147 | + sam_var{'6par_isc'} = to_real(T.isc); // A |
| 148 | + sam_var{'6par_module_name'} = modulename; // manufacturer + model (strings) |
| 149 | + sam_var{'6par_mounting'} = mounting; // use default, see field thermal loss factor inputs in pvsyst |
| 150 | + sam_var{'6par_nser'} = to_real(T.ncels); |
| 151 | + sam_var{'6par_standoff'} = standoff; // use default, see field thermal loss factor inputs in pvsyst |
| 152 | + sam_var{'6par_tnoct'} = tnoct; // not used in pvsyst, set to 46 ?? |
| 153 | + sam_var{'6par_vmp'} = to_real(T.vmp); // |
| 154 | + sam_var{'6par_voc'} = to_real(T.voc); // V |
| 155 | + |
| 156 | + return sam_var; |
| 157 | +} |
| 158 | + |
| 159 | +// converts a table of pvsyst ond file variables to a table of input variables |
| 160 | +// for sam's inverter datasheet model |
| 161 | +function ond_to_sam_vars( T ) |
| 162 | +{ |
| 163 | + sam_var = {}; |
| 164 | + |
| 165 | + // set inv_ds_eff_type to 1 for manufacturer |
| 166 | + sam_var{'inv_ds_eff_type'} = 1; |
| 167 | + |
| 168 | + // assign SAM variable values |
| 169 | + sam_var{'inv_ds_paco'} = to_real(T{'pmaxout'}) * 1000; // kW to W |
| 170 | + sam_var{'inv_ds_eff_peak_or_nom'} = to_real(T{'efficmax'}); |
| 171 | + sam_var{'inv_ds_pnt'} = to_real(T{'night_loss'}); // should be very small |
| 172 | + sam_var{'inv_ds_pso'} = to_real(T{'pseuil'}); // power threshold in UI is minimum power to operate and inverter self consumption, should be about 1% of nominal power |
| 173 | + sam_var{'inv_ds_vdco'} = to_real(T{'vmppnom'}); |
| 174 | + sam_var{'inv_ds_vdcmax'} = to_real(T{'vabsmax'}); |
| 175 | + sam_var{'inv_ds_mppt_low'} = to_real(T{'vmppmin'}); |
| 176 | + sam_var{'inv_ds_mppt_hi'} = to_real(T{'vmppmax'}); |
| 177 | + sam_var{'inv_ds_num_mppt'} = to_real(T{'nbmppt'}); |
| 178 | + |
| 179 | + return sam_var; |
| 180 | +} |
| 181 | + |
| 182 | +// read values from a table of sam variables and set value of inputs |
| 183 | +// set model = 1 for ond/inverter, model = 2 for pan/module |
| 184 | +function set_sam_inputs( var , model ) |
| 185 | +{ |
| 186 | + vars = @var; |
| 187 | + if ( model == 1 ) { set( 'inverter_model' , model ); } |
| 188 | + elseif ( model == 2 ) { set( 'module_model', model ); } |
| 189 | + else { outln('invalid model'); } |
| 190 | + for( i=0; i<#vars; i++ ) |
| 191 | + { set( vars[i], var{vars[i]} ); } |
| 192 | +} |
| 193 | + |
| 194 | +//////////////////////////////////////////////////////////////////////////////// |
| 195 | +// Main |
| 196 | +//////////////////////////////////////////////////////////////////////////////// |
| 197 | + |
| 198 | +fname = choose_file( homedir(), 'Choose PAN or OND file', 'PVsyst files (*.ond;*.pan)|*.ond;*.pan' ); |
| 199 | +outln( 'Converting ' + fname + '...' ); |
| 200 | +if ( strpos( lower(fname), 'pan' ) > -1 ) |
| 201 | +{ |
| 202 | + |
| 203 | + pan_vars = read_pan_file( fname ); |
| 204 | + if ( pan_vars{'error'} == '' ) |
| 205 | + { |
| 206 | + sam_vars = pan_to_sam_vars( pan_vars ); |
| 207 | + set_sam_inputs( sam_vars , 2 ); |
| 208 | + show_page( 'Module' ); |
| 209 | + } |
| 210 | + else |
| 211 | + { |
| 212 | + msgbox( 'Failed to convert PAN file!\n' + pan_vars{'error'} + '\n\nThis macro cannot convert binary files from PVsyst versions ealier than Version 6.6.'); |
| 213 | + } |
| 214 | + |
| 215 | +} |
| 216 | +elseif ( strpos( lower(fname), 'ond' ) > -1 ) |
| 217 | +{ |
| 218 | + ond_vars = read_ond_file( fname ); |
| 219 | + if ( ond_vars{'error'} == '' ) |
| 220 | + { |
| 221 | + sam_vars = ond_to_sam_vars( ond_vars ); |
| 222 | + set_sam_inputs( sam_vars , 1 ); |
| 223 | + show_page( 'Inverter' ); |
| 224 | + } |
| 225 | + else |
| 226 | + { |
| 227 | + msgbox( 'Failed to convert OND file!\n' + pan_vars{'error'} + '\n\nThis macro cannot convert binary files from PVsyst versions ealier than Version 6.6.'); |
| 228 | + } |
| 229 | +} |
| 230 | +else |
| 231 | + outln( 'File must have extension pan or ond.' ); |
| 232 | +outln('Done.'); |
0 commit comments