Adjusting Weather Data

4 posts / 0 new
Last post
Adjusting Weather Data

I get the following error when I do Simulate:

exec fail(pvsamv1): electric load profile must have same number of values as weather file, or 8760
Simulation pvsamv1 failed.

I understand that the weather file must be adjusted to align with my 15-minute load data. Can you provide a step-by-step overview of using the LK Script for converting the weather file to 15-minute intervals?


Paul Gilman


1. Go to the LK Cookbook, and download the file. (It is listed as #2 at the moment.)

2. Locate the hourly weather file you want to convert. If it is one of the files that comes with SAM, you can find those files in the solar_resource folder of your SAM installation (C:/SAM/2016.3.14/solar_resource by default in windows, see this post to find the folder in OS X).

3. Copy the file from Step 2 to your SAM weather file folder. If you do not have such a folder, create one in your Documents folder or a folder that you have full access to.

4. Start SAM, and on the Welcome page, click Open script, and open the .lk file you downloaded in Step 1. If SAM is already running, you can open the file from the File menu.

5. In the Script window, click Run at the top of the window, and open the weather file from Step 3. The script will work with any hourly weather file, as long as it is in the SAM CSV format. (You can use the Solar Resource File converter macro that comes with SAM to convert a file from some common formats to SAM CSV.) The script displays a message in the console telling you whether it converted the file, and that it saved it in the same folder as the hourly file.

6. In SAM, open your .sam file (or create a new one) and go to the Location and Resource page. If you created a new folder for the weather file, click Folder settings and add that folder to the list of folders SAM searches for weather files, and then click Refresh library.

7. Choose the converted 15-minute weather file from the solar resource library list. If you do not see the file, you may need to refresh the library to ensure that SAM adds it to the solar resource library.

You can see the converted data by clicking View data on the Location and Resource page, or by opening the file in a spreadsheet program or text editor.

The script works by making a four copies of each hourly record to represent the 15-minute data. For example, if the direct normal irradiance (DNI) for Noon on January 1 in the hourly file is 200 W/m2, the DNI in the 15-minute converted file will by 200 W/m2 for 12:00, 12:15, 12:30 and 12:45.

If you are comfortable with scripting or programming languages, you can modify the .lk script to convert to different time steps, or to use a different method for the conversion.

Best regards,


There's a bug in the script - it puts a "Minute" value of 0 in all rows of the output file. The fix is to move these two lines:

minute = j*15;
newWF{"Minute"}[wi] = minute;

After these lines:

for( k=0; k<#oldLabels; k++){
newWF{ oldLabels[k] }[wi] = wf{oldLabels[k]}[i];

The way it was, it was setting newWF{"Minute"}[wi] to the correct value, then overwriting it with the value from the original file, which is always 0 since it's an hourly file.

Also, this section should be removed:

SIZE = 8760 * 4; // 15 minute data
newLabels = ['Year','Month','Day','Hour','Minute','GHI','DNI','DHI','Tdry','Tdew','RH','Pres','Wspd','Wdir','Snow Depth'];
newWF = {};

for( i=0; i<#newLabels; i++){
newWF{ newLabels[i] } = alloc(SIZE);

I don't see any reason to initialize the table, and doing it with a pre-set list of labels results in extra columns of null's if the input file doesn't have all of these columns. If you delete the above lines, the output file will have the same columns as the input file.

Final note - the script reorders the columns, but I'm guessing that doesn't matter to SAM.

Paul Gilman

Thanks. I'll update the script when I get a chance.

Best regards,

Theme by Danetsoft and Danang Probo Sayekti inspired by Maksimer