Enhance SAM with features tailored to your specific needs! We collaborate with companies, universities, and organizations to privately fund new capabilities or analyses. Your investment drives innovation while benefiting the broader energy community. Email us to learn more.

Importing SAM configuration: JSON to python

  • Ana
  • Topic Author
More
19 Mar 2025 17:53 #13965 by Ana
Hi! After attending the webinar today, I'm trying to configure a residential solar + storage setup, now aided by parameters configured in the SAM UI, exported as JSON, and imported into my python notebook for use.

I am importing them like this, as specified on the SAM defaults documentation

Code:
import json import PySAM.Pvsamv1 as PV # Adjusted from Pvwattsv8 since I noticed that this was not one of the exported JSON files import PySAM.Grid as Grid import PySAM.Utilityrate5 as UtilityRate import PySAM.Cashloan as Cashloan pv = PV.new() grid = Grid.from_existing(pv) ur = UtilityRate.from_existing(pv) cl = Cashloan.from_existing(pv) dir = "SAM_configuration/" file_names = ["untitled_pvsamv1"] # "untitled_grid", "untitled_utilityrate5", "untitled_cashloan", modules = [pv] # grid, ur, cl for f, m in zip(file_names, modules): with open(dir + f + ".json", 'r') as file: data = json.load(file) print(file) for k, v in data.items(): print(k) print(v) if k != "number_inputs": m.value(k, v)

Running this code I get an error:
Code:
--------------------------------------------------------------------------- AttributeError                            Traceback (most recent call last) Cell In[29], line 14      12 print(v)      13 if k != "number_inputs": ---> 14     m.value(k, v) AttributeError: "value" error, could not find attribute by that name


It appears to fail on setting: 
Code:
batt_adjust_constant 0

after setting all previous parameters as expected.

Is there an issue with the parameter import / setup, or is there a workaround I could pursue?

Relatedly, how could I access details regarding the battery? Even though I have configured it in the SAM UI, it does not appear to have an associated JSON configuration that is exported.

Using SAM: 
```
Version 2024.12.12, 64 bit

SSC Version 298: OS X 64 bit GNU/C++ Dec 11 2024 22:29:29
wxWidgets 3.2.6 on macOS Sonoma Version 14.5 (Build 23F79)
Internet connection method: default
Display: 1512 x 982, magnification 1x
```
Attached: JSON files generated by SAM, not including utitled.json, also sccapi.h and scc.dylib. Screenshot of battery configuration in UI. 

 

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

  • Paul Gilman
More
20 Mar 2025 17:53 #13966 by Paul Gilman
Replied by Paul Gilman on topic Importing SAM configuration: JSON to python
Hi Ana,

There seems to be a problem with the battery_adjust variables. As a workaround, please try deleting the following variables from the untitled_pvsamv1.json file:

batt_adjust_constant
batt_adjust_en_timeindex
batt_adjust_en_periods
batt_adjust_timeindex
batt_adjust_periods

After deleting those files, you'll need to do the following to get a test pvsamv1 simulation to run:

1. Set the value of 'load' in the untitled_pvsamv1.json file to an array with the same length as 'crit_load'.
2. Set the value of 'solar_resource_file' to a valid path to a solar resource CSV file.

Then, you should be able to run the PV model and show results with:

pv.execute()
print(pv.value('annual_ac_gross'))

The battery inputs are in the untitled_pvsamv1.json file. Many of them have a "batt_" prefix. The are listed in the PySAM documentation for the Pvsamv1 moudule here:

nrel-pysam.readthedocs.io/en/main/modules/Pvsamv1.html#batterycell-group
nrel-pysam.readthedocs.io/en/main/modules/Pvsamv1.html#batterydispatch-group

By the way, those ssc_api.h and ssc.dylib files are not required to run PySAM.

Best regards,
Paul.
 

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

Moderators: Paul Gilman
Powered by Kunena Forum