From ce8e15686b694be0b9aad3e68c5700e4f04dd350 Mon Sep 17 00:00:00 2001 From: Paul Gilman Date: Tue, 23 Feb 2021 17:05:30 -0800 Subject: [PATCH] Solar Resource Converter macro updates for new SolarAnywhere file formats (#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. --- .../macros/Solar Resource File Checker.lk | 4 +- .../macros/Solar Resource File Converter.lk | 56 +++++++++---------- deploy/runtime/ui/Solar Resource Data.txt | 6 +- 3 files changed, 35 insertions(+), 31 deletions(-) diff --git a/deploy/runtime/macros/Solar Resource File Checker.lk b/deploy/runtime/macros/Solar Resource File Checker.lk index ab9d2bdbed..21dff8ab08 100644 --- a/deploy/runtime/macros/Solar Resource File Checker.lk +++ b/deploy/runtime/macros/Solar Resource File Checker.lk @@ -58,6 +58,8 @@ if ( result == 0 ) } } else - msgbox( 'Error:\n\n' + result ); +{ + msgbox( 'Weather File Check Error!\n' + result ); +} ssc_free( obj ); \ No newline at end of file diff --git a/deploy/runtime/macros/Solar Resource File Converter.lk b/deploy/runtime/macros/Solar Resource File Converter.lk index 55733cf81d..c750b8994d 100644 --- a/deploy/runtime/macros/Solar Resource File Converter.lk +++ b/deploy/runtime/macros/Solar Resource File Converter.lk @@ -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; } } @@ -358,7 +358,8 @@ 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 ) { @@ -366,17 +367,17 @@ function solar_anywhere_to_sam_csv( wf ) 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 ) { @@ -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 diff --git a/deploy/runtime/ui/Solar Resource Data.txt b/deploy/runtime/ui/Solar Resource Data.txt index 25b9f68d30..cbe4d34dc9 100644 --- a/deploy/runtime/ui/Solar Resource Data.txt +++ b/deploy/runtime/ui/Solar Resource Data.txt @@ -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 @@ -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() );