Research‎ > ‎Model‎ > ‎

CustomizeTMY3 function in NREL SAM model

'SamUL Script Created: Wed May 01 22:35:20 2013 by Gang He and Josiah Johnston of Renewable and Appropriate Energy Laboratory(RAEL) at UC Berkeley
'I need convert the EPW weather file to TMY3 file as CSP modeling in SAM can not read EPW file. 
'You can read more about the problem from my conversation with SAM model's super Paul Gilman
'The script gives an example of how to use CustomizeTMY3() function in the SAM model to update weather data you may have that is better than what you have downloaded

SetActivecase("My case")

tmy3_source_dir = "....../SAM/oldTMY3"

tmy3_target_dir = "....../SAM/newTMY3"

weather_file_dir = "....../SAM/weather"

'Read the source tmy3 file name
declare tmy3_source_file_path_list
tmy3_source_file_path_list = DirectoryList(tmy3_source_dir, "csv")

'Loop for file names

for (i=0; i<Length(tmy3_source_file_path_list); i=i+1)
'for (i=0; i<1; i=i+1)  'For one file test use
Outln(tmy3_source_file_path_list[i]) 'Make sure you got the source file name right

weather_file_path = weather_file_dir + "/" + FileNameOnly(tmy3_source_file_path_list[i])
tmy3_target_file_path = tmy3_target_dir + "/" + FileNameOnly(tmy3_source_file_path_list[i])  'New tmy3 file name as the same as old one
'Read weather array data
declare weather_one_record
declare ghi[8760]
declare dni[8760]
declare dhi[8760]
declare dry_bulb[8760]
declare dew_point[8760]
declare rhum[8760]
declare pressure[8760]
declare wspd[8760]
declare alb[8760]

weather_text_blob = ""

ReadTextFile(weather_file_path, weather_text_blob)

weather_text_by_line = Split(weather_text_blob, "\n")
'Weather columns are: GHI, DNI, DHI, Dry-bulb, Dew-point, RHum, Pressure, Wspd, Alb as specified in the SAM Create TMY3 
'Loop each hour
for (h = 0; h < Length(weather_text_by_line); h = h+1)
weather_one_record = Split(weather_text_by_line[h], ",")
ghi[h] = weather_one_record[0]
dni[h] = weather_one_record[1]
dhi[h] = weather_one_record[2]
dry_bulb[h] = weather_one_record[3]
dew_point[h] = weather_one_record[4]
rhum[h] = weather_one_record[5]
pressure[h] = weather_one_record[6]
wspd[h] = weather_one_record[7]
'alb[h] = weather_one_record[8]
'Apply CustomizeTMY3() function
CustomizeTMY3(tmy3_source_file_path_list[i], tmy3_target_file_path, "gh",ghi , "dn",dni, "df",dhi, "tdry",dry_bulb, "twet",dew_point,"relhum",rhum, "pressure",pressure,"wind",wspd )

'Print progress
OutLn(tmy3_target_file_path + " finished")