Skip to content

Commit

Permalink
Solar Resource Converter macro updates for new SolarAnywhere file for…
Browse files Browse the repository at this point in the history
…mats (#542)

* Fix #491 Solar Resource Converter macro for new SolarAnywhere format

* Replace SolarAnywhere format check for number of columns by check for "0" in first column of first row.

* Handle single-year files with less than one-year of data. For example, files for current year only have data up to current date.

* Clean up Solar Resource File Checker error mssage.

* Solar Resource UI, error message, explain to remove file from library when file with partial year data is added. I decided not to remove files with less than one year of data from library in preparation for SAM being able to run part year simulations in the future.

* Resolve Solar Resource Data.txt merge conflict with patch

* Solar Resource UI message when weather file reader fails

Show name of offending file with suggestion to remove it from weather file folders.
  • Loading branch information
cpaulgilman authored Feb 24, 2021
1 parent 9b59be9 commit ce8e156
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 31 deletions.
4 changes: 3 additions & 1 deletion deploy/runtime/macros/Solar Resource File Checker.lk
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ if ( result == 0 )
}
}
else
msgbox( 'Error:\n\n' + result );
{
msgbox( 'Weather File Check Error!\n' + result );
}

ssc_free( obj );
56 changes: 28 additions & 28 deletions deploy/runtime/macros/Solar Resource File Converter.lk
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,9 @@ function solar_anywhere_to_sam_csv( wf )
if ( line == 0 )
{
arr = split( str_line, ',');
if ( #arr != 8 )
if ( to_string(arr[0]) != "0" )
{
msgbox('Input file does not appear to be in a SolarAnywhere format: First row has ' + #arr + ' columns instead of 8. Exiting script.\n');
msgbox('Input file does not appear to be in a SolarAnywhere format.\n First column of first row does not contain a zero (0). Exiting script.\n');
exit;
}
}
Expand Down Expand Up @@ -358,25 +358,26 @@ function solar_anywhere_to_sam_csv( wf )
// write first and second header rows to output file
if ( line == 0 ) // first header row
{
headers = 'Source,Location ID,Latitude,Longitude,Time Zone,Elevation'; // SAM CSV header (minimum is Latitude,Longitude,Time Zone,Elevation)
//headers = 'Source,Location ID,Latitude,Longitude,Time Zone,Elevation'; // SAM CSV header (minimum is Latitude,Longitude,Time Zone,Elevation)
headers = 'Source,Latitude,Longitude,Time Zone,Elevation'; // SAM CSV header (minimum is Latitude,Longitude,Time Zone,Elevation)
ok = write_line( fout , to_string(headers) );
if ( ok == false )
{
outln('Failed to write column headers to file. Exiting script.\n');
exit;
}
arr = split( str_line, ',' ); // SA header
if ( #arr != 8 )
if ( to_string(arr[0]) != "0" )
{
outln('Input file does not appear to be in a SolarAnywhere format: First row has ' + #arr + ' columns instead of 8. Exiting script.\n');
outln('Input file does not appear to be in a SolarAnywhere format: First column of first row does not contain a zero (0). Exiting script.\n');
exit;
}
h1[0] = "SolarAnywhere"; // source
h1[1] = to_string(arr[0]) + to_string(arr[1]); // location id
h1[2] = arr[4]; // latitude
h1[3] = arr[5]; // longitude
h1[4] = arr[3]; // time zone
h1[5] = arr[6]; // elevation
//h1[1] = to_string(arr[0]) + to_string(arr[1]); // location id
h1[1] = arr[4]; // latitude
h1[2] = arr[5]; // longitude
h1[3] = arr[3]; // time zone
h1[4] = arr[6]; // elevation
ok = write_line( fout , arr_to_str(h1) );
if ( ok == false )
{
Expand Down Expand Up @@ -570,33 +571,32 @@ function solar_anywhere_to_sam_csv( wf )

// check to see if input file was for a set of complete years
// if not, rename the output file with a partial year
// (assumes that partial year was the last year in the multi-year file)
if ( mod(line-2,8760)!=0 )
{ // line should be the total number of lines in the input file
// (for multi-yaer, assumes that partial year was the last year)
if ( mod(line-2,8760)!=0 ) // line should be the total number of lines in the input file
{
outln('\n'+file_only(output_file) + ' does not contain a complete year of data.');
new_name = replace( output_file, '_samcsv_' + to_string(T.y), '_samcsv_' + to_string(T.y) + 'part' );
if ( fcount > 0 ) // last year from multi-year file with partial cata
{
new_name = replace( output_file, '_samcsv_' + to_string(T.y), '_samcsv_' + to_string(T.y) + 'part' );
}
else // single-year file with partial data
{
new_name = replace( output_file, '_samcsv', '_samcsv_part' );
}
ok = rename_file( output_file , new_name );
if (ok==true)
if (ok==true)
{
outln('File renamed to\n ' + file_only(new_name) );
outln('File renamed to\n ' + file_only(new_name) );
output_file = new_name;
}
else
{
outln('Unable to rename ' + file_only(output_file) );
outln('Unable to rename ' + file_only(output_file) );
}
}


outln('Weather file converted to:\n\t' + output_file );
browse( path_only(output_file) );
// if input file is for a single year, show converted data in data viewer
if (fcount == 0 )
{
outln('Weather file converted to:\n\t' + output_file );
/*if ( wf_check( output_file ) )
{
dview_solar( output_file );
browse( path_only( output_file ) );
}*/
}
}

// convert PVsyst CSV weather format to SAM CSV
Expand Down
6 changes: 4 additions & 2 deletions deploy/runtime/ui/Solar Resource Data.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2624,7 +2624,7 @@ equations{'ui_step_minutes'} = define() {
return(${step}/60);
};

32828
32933
on_load{'Solar Resource Data'} = define() {
//msgbox('on load');
//hide legacy data for 2020.2.29 Patch 3
Expand Down Expand Up @@ -2937,7 +2937,9 @@ function update_info( ctxt )
}
else
{
msgbox('Weather file reader failed!\n' + result);
msgbox('Weather file reader failed!\n'
+ result
+ '\n\nTo avoid this message, remove the following file from your weather file folders: \n' + wf);
value( 'annual_global', nan() );
value( 'annual_beam', nan() );
value( 'annual_diffuse', nan() );
Expand Down

0 comments on commit ce8e156

Please sign in to comment.