- Posts: 5423
SAM Access to Metadata from Weather Files on Disk
- pgilman
- Topic Author
Less
More
19 Dec 2014 11:08 #2861
by pgilman
SAM Access to Metadata from Weather Files on Disk was created by pgilman
I'm working on an LK script that runs a PV model across a large number of weather files (from disk), and I want to set the tilt on the PV array to latitude rounded to the nearest 5 deg. Unfortunately, it appears that when I load a weather file from disk, the location information in SAM (lat/lon/etc.) does not automatically populate from the weather file? Is there a way to force SAM to reload the location metadata from the weather file?
Related to this: can I be confident that even though the GUI is not displaying updated location, that SAM behind the scenes is using the updated latitude, longitude, etc. from the loaded weather file in addition to the irradiance data? Or do I need to change those explicitly using my script?
The location metadata, including latitude and longitude values, that SAM displays in the user interface are from a temporary file (SolarResourceData.csv, in C:\Users\[windows-user-name]l\AppData\Local\SAM\sam-2014.11.24) that SAM creates on installation and again anytime you click Refresh Library on the Location and Resource page. The temporary file only lists metadata from files in the solar resource library. The file makes it possible for SAM to quickly display those values when you move your cursor through the list of locations in the library list -- its only purpose is for displaying values in the UI.
If you choose the User a specific weather file on disk option on the Location and Resource page, SAM does not display location data from that file on the input page. We included that option for LK scripters because the LK script does not interact with the library.
When you run a simulation, SAM takes the latitude, longitude, and elevation values from the weather file, not the temporary file.
In your LK script, to read the latitude value from the weather file, you'll have to read it directly from the file, not from the "Latitude" input variable on the Location and Resource page.
Best regards,
Paul.
Related to this: can I be confident that even though the GUI is not displaying updated location, that SAM behind the scenes is using the updated latitude, longitude, etc. from the loaded weather file in addition to the irradiance data? Or do I need to change those explicitly using my script?
The location metadata, including latitude and longitude values, that SAM displays in the user interface are from a temporary file (SolarResourceData.csv, in C:\Users\[windows-user-name]l\AppData\Local\SAM\sam-2014.11.24) that SAM creates on installation and again anytime you click Refresh Library on the Location and Resource page. The temporary file only lists metadata from files in the solar resource library. The file makes it possible for SAM to quickly display those values when you move your cursor through the list of locations in the library list -- its only purpose is for displaying values in the UI.
If you choose the User a specific weather file on disk option on the Location and Resource page, SAM does not display location data from that file on the input page. We included that option for LK scripters because the LK script does not interact with the library.
When you run a simulation, SAM takes the latitude, longitude, and elevation values from the weather file, not the temporary file.
In your LK script, to read the latitude value from the weather file, you'll have to read it directly from the file, not from the "Latitude" input variable on the Location and Resource page.
Best regards,
Paul.
Please Log in or Create an account to join the conversation.
- pgilman
- Topic Author
Less
More
- Posts: 5423
29 Dec 2014 10:10 #2862
by pgilman
Replied by pgilman on topic SAM Access to Metadata from Weather Files on Disk
Here is a sample LK script that shows one way to read the weather file metadata directly from the weather file:
//make sure option on Location and Resource page is to use a specific
// weather file on disk
weather_mode = get('use_specific_weather_file');
if ( weather_mode != 1 ) {
outln("Weather file mode on Location and Resource page must be \"Use specific weather file.\"");
}
//open the weather file and get the first two lines
weather_file = get('user_specified_weather_file');
line="";
w=open(weather_file, "r");
if ( w == 0 ) {
outln("Could not open weather file for reading. Is a file name shown for the file on disk on the Location and Resource page?");
}
line_number = 0;
while ( read_line(w,line) && line_number < 2) {
meta_data[line_number] = line;
line_number++;
}
close(w);
//simple test to see if file is likely to be in SAM CSV format
test_row = split(meta_data[0],',');
if ( #test_row != 9 ) {
outln("File does not appear to be a file in the SAM CSV format.");
outln();
}
//display the contents of the first two lines
outln(meta_data[0]);
outln(meta_data[1]);
//make sure option on Location and Resource page is to use a specific
// weather file on disk
weather_mode = get('use_specific_weather_file');
if ( weather_mode != 1 ) {
outln("Weather file mode on Location and Resource page must be \"Use specific weather file.\"");
}
//open the weather file and get the first two lines
weather_file = get('user_specified_weather_file');
line="";
w=open(weather_file, "r");
if ( w == 0 ) {
outln("Could not open weather file for reading. Is a file name shown for the file on disk on the Location and Resource page?");
}
line_number = 0;
while ( read_line(w,line) && line_number < 2) {
meta_data[line_number] = line;
line_number++;
}
close(w);
//simple test to see if file is likely to be in SAM CSV format
test_row = split(meta_data[0],',');
if ( #test_row != 9 ) {
outln("File does not appear to be a file in the SAM CSV format.");
outln();
}
//display the contents of the first two lines
outln(meta_data[0]);
outln(meta_data[1]);
Please Log in or Create an account to join the conversation.
Moderators: pgilman