Pvwattsv8 solar_resouce_data not working

  • isaiahgarcia
  • Topic Author
More
19 Jun 2024 20:08 #13269 by isaiahgarcia
Pvwattsv8 solar_resouce_data not working was created by isaiahgarcia
Hello! I am currently using PySAM.PSSC and PySAM.Pvwattsv8 and I am running into issues when using solar_resource_data instead of solar_resource_file.

Essentially, I have a weather dataset as a Pandas.dataframe created from this NREL API ( developer.nrel.gov/api/nsrdb/v2/solar/psm3-2-2-download.csv ). Instead of converting that dataframe to csv in my local storage and declaring the solar_resource_file field, I just want to populate solar_resource_data with my weather data.

Here is the specific code block I am using:
Code:
import PySAM.PySSC as pssc import PySAM.Pvwattsv8 as pv8 from datetime import datetime, timedelta start_time = datetime(2022, 1, 1) time_delta = timedelta(hours=1) num_hours = 8760 solar_resource_data = { "lat": info["Latitude"][0], "lon": info["Longitude"][0], "tz": info["Time Zone"][0], "elev": info["Elevation"][0], "year": [], "month": [], "day": [], "hour": [], "minute": [30] * num_hours, # "dn": list(site_generation["DNI"]), # "df": list(site_generation["DHI"]), # "gh": list(site_generation["GHI"]), # "wspd": list(site_generation["Wind Speed"]), # "tdry": list(site_generation["Temperature"]) "dn": [500]*num_hours, # Example values, replace with actual data "df": [100]*num_hours, # Example values, replace with actual data "gh": [600]*num_hours, # Example values, replace with actual data "wspd": [3]*num_hours, # Example values, replace with actual data "tdry": [20]*num_hours # Example values, replace with actual data } for hour in range(num_hours): current_time = start_time + time_delta * hour solar_resource_data["year"].append(current_time.year) solar_resource_data["month"].append(current_time.month) solar_resource_data["day"].append(current_time.day) solar_resource_data["hour"].append(current_time.hour) pv_model = pv8.new() pv_dat = pssc.dict_to_ssc_table(pvwatts_json, "pvwattsv8") pv_model = pv8.wrap(pv_dat) pv_model.SolarResource.assign({"solar_resource_data": solar_resource_data}) pv_model.execute() pv_model.Outputs.dc

When I print out the dc/ac electricity values, I am seeing a list of all 0.0. I tried out the same exact code block replacing solar_resource_data with the solar_resource_file I create, and that works correctly because I am seeing expected outputs. 

My main question is if the solar_resource_data is no longer a viable use case for this version of Pvwattsv8?

Please Log in or Create an account to join the conversation.

  • pgilman
More
20 Jun 2024 12:01 #13270 by pgilman
Replied by pgilman on topic Pvwattsv8 solar_resouce_data not working
Hi Isaiah,

The 'solar_resource_data' variable is an input to the Pvwattsv8 module:

nrel-pysam.readthedocs.io/en/main/modules/Pvwattsv8.html#PySAM.Pvwattsv8.Pvwattsv8.SolarResource.solar_resource_data

Please make sure that your 'pvwatts_json' file does not assign a value to 'solar_resource_file'. The model determines whether to use the weather file or the dictionary based on which variable is assigned: It first checks to see if 'solar_resource_file' is assigned and uses it if assigned, then checks 'solar_resource_data' to see if it is assigned. This means that if the JSON assigns a value to 'solar_resource_file', it will ignore the 'solar_resource_data' variable.

The source code for this behavior is here:

github.com/NREL/ssc/blob/9cadfe3d36a74614a2550065f37388bc8aa2aecf/shared/lib_pv_io_manager.cpp#L125

Best regards,
Paul.

Please Log in or Create an account to join the conversation.

  • isaiahgarcia
  • Topic Author
More
20 Jun 2024 13:08 - 09 Jul 2024 11:31 #13272 by isaiahgarcia
Replied by isaiahgarcia on topic Pvwattsv8 solar_resouce_data not working
Hi Paul, 

Thank you for replying! I can confirm that I do not have a 'solar_resource_file'  value defined in my pvwatts_json file. I can confirm this by printing out 'PySAM.Pvwattsv8.Pvwattsv8.SolarResource.solar_resource_file' and it gives me an error because it is not assigned (which is what I want).

I can also confirm that my 'solar_resource_data' is properly assigned after I run this line:
Code:
Pvwattsv8.SolarResource.assign({'solar_resource_data': solar_resource_data_var})

My guess at this point is the dictionary is not in the correct format/structure. I attached a link of my example 'solar_resouce_data' dictionary.
Attachments:
Last edit: 09 Jul 2024 11:31 by pgilman. Reason: Format code section

Please Log in or Create an account to join the conversation.

  • pgilman
More
24 Jun 2024 09:13 #13274 by pgilman
Replied by pgilman on topic Pvwattsv8 solar_resouce_data not working
Hi Isaiah,

Here is some code that I think does what you want:

Code:
import PySAM.Pvwattsv8 as pv8 import json from datetime import datetime, timedelta start_time = datetime(2022, 1, 1) time_delta = timedelta(hours=1) num_hours = 8760 solar_resource_data = {     "lat": 0,     "lon": 0,     "tz": 0,     "elev": 0,     "year": ,     "month": ,     "day": ,     "hour": ,     "minute": [30] * num_hours,     # "dn": list(site_generation["DNI"]),     # "df": list(site_generation["DHI"]),     # "gh": list(site_generation["GHI"]),     # "wspd": list(site_generation["Wind Speed"]),     # "tdry": list(site_generation["Temperature"])     "dn": [500]*num_hours, # Example values, replace with actual data     "df": [100]*num_hours, # Example values, replace with actual data     "gh": [600]*num_hours, # Example values, replace with actual data     "wspd": [3]*num_hours, # Example values, replace with actual data     "tdry": [20]*num_hours # Example values, replace with actual data } for hour in range(num_hours):     current_time = start_time + time_delta * hour     solar_resource_data["year"].append(current_time.year)     solar_resource_data["month"].append(current_time.month)     solar_resource_data["day"].append(current_time.day)     solar_resource_data["hour"].append(current_time.hour) pv_model = pv8.default("PVWattsNone") # see https://nrel-pysam.readthedocs.io/en/main/sam-configurations.html print("== Test with no weather data ==") # model will fail because defaults do not include weather verbose_simulation = 1 try:     pv_model.execute(verbose_simluation) except:     print("\npv_model failed") print("\n== Test with constructed data =="); # assign resource data constructed above pv_model.SolarResource.assign({"solar_resource_data": solar_resource_data}) print("\nDNI from inputs:") print(pv_model.SolarResource.solar_resource_data["dn"][0:23]) pv_model.execute() print("\nDC output:") print(pv_model.Outputs.dc[0:23]) print("\nDNI from outputs:") print(pv_model.Outputs.dn[0:23]) print("\n== Test with data from JSON =="); with open( 'example.json', 'r') as f:         pv_inputs = json.load( f ) print("\nDNI from inputs:") print(pv_model.SolarResource.solar_resource_data["dn"][0:23]) pv_model.execute() print("\nDC output:") print(pv_model.Outputs.dc[0:23]) print("\nDNI from outputs:") print(pv_model.Outputs.dn[0:23])

Best regards,
Paul.

Please Log in or Create an account to join the conversation.

Moderators: pgilman
Powered by Kunena Forum