- Posts: 6
Importing JSON Input files into PVSAMV1
- farhad.daruwala@paconsulting.com
- Topic Author
Less
More
25 Oct 2021 15:46 #10183
by farhad.daruwala@paconsulting.com
Importing JSON Input files into PVSAMV1 was created by farhad.daruwala@paconsulting.com
Hello,
I am trying to import a "JSON Inputs" file that I exported from the GUI into PVSAMV1. The model I selected in the GUI is the Detailed PV Model without any financials.
It's a bit challenging to code all the inputs as you cannot select the Module and Inverted from a dropdown and things don't update automatically based on your selections. Hence, I decided to build the model in the GUI and then export to JSON so I can iterate many times in PVSAMV1.
Unfortunately, when I try to import the data like was shown in the example, I got an error. How can you import the JSON Inputs file into a PVSAMV1 Module?
Thank you!
Traceback (most recent call last):
File "<ipython-input-5-fa388f6361de>", line 6, in <module>
m.value(k, v)
AttributeError
I am trying to import a "JSON Inputs" file that I exported from the GUI into PVSAMV1. The model I selected in the GUI is the Detailed PV Model without any financials.
It's a bit challenging to code all the inputs as you cannot select the Module and Inverted from a dropdown and things don't update automatically based on your selections. Hence, I decided to build the model in the GUI and then export to JSON so I can iterate many times in PVSAMV1.
Unfortunately, when I try to import the data like was shown in the example, I got an error. How can you import the JSON Inputs file into a PVSAMV1 Module?
Thank you!
Code:
for f, m in zip(json_input_file_names, modules):
with open(json_input_dir + f + ".json", 'r') as file:
data = json.load(file)
for k, v in data.items():
if k != "number_inputs":
m.value(k, v)
File "<ipython-input-5-fa388f6361de>", line 6, in <module>
m.value(k, v)
AttributeError
Code:
import json
import pandas as pd
import numpy as np
import PySAM.Pvsamv1 as pv
import glob
import random
import PySAM.ResourceTools as tools
# create a blank module for Assembly 1
m_assembly1 = pv.new()
blank_values = m_assembly1.export()
# see this link for help on importing JSON input files that were exported from the GUI
# https://nrel-pysam.readthedocs.io/en/master/Import.html
# create a variable to hold the dir for where the JSON inputs are stored
json_input_dir = "C:/Users/DENFD/OneDrive - PA Consulting Group/NREL SAM/GUI Code Exports/Assembly_1/"
# create a list of the JSON input files that we need to load
json_input_file_names = ["Assembly_1__S_"]
# create a list of the various modules in which we want to import the data
# make sure the order aligns with the input files list above
modules = [m_assembly1]
# loop through the lists and import each JSON file into the appropriate module
for f, m in zip(json_input_file_names, modules):
with open(json_input_dir + f + ".json", 'r') as file:
data = json.load(file)
for k, v in data.items():
if k != "number_inputs":
m.value(k, v)
# export the value of the inputs
imported_values = m_assembly1.export()
# execute the model
m_assembly1.execute(1)
# look at the annual energy output
print('Annual AC energy gross [kWh/yr]: ', m_assembly1.Outputs.annual_ac_gross)
print('Annual DC energy gross [kWh/yr]: ', m_assembly1.Outputs.annual_dc_gross)
Please Log in or Create an account to join the conversation.
- pgilman
Less
More
- Posts: 5447
25 Oct 2021 17:59 #10187
by pgilman
Replied by pgilman on topic Importing JSON Input files into PVSAMV1
Hi Farhad,
You should use the "PySAM JSON" option (not "JSON for inputs") in SAM's Code Generator for Python with the PySAM package as described in these instructions:
nrel-pysam.readthedocs.io/en/master/Import.html
Best regards,
Paul.
You should use the "PySAM JSON" option (not "JSON for inputs") in SAM's Code Generator for Python with the PySAM package as described in these instructions:
nrel-pysam.readthedocs.io/en/master/Import.html
Best regards,
Paul.
Please Log in or Create an account to join the conversation.
- proman
Less
More
- Posts: 2
02 Nov 2021 10:05 - 03 Nov 2021 15:54 #10223
by proman
Replied by proman on topic Importing JSON Input files into PVSAMV1
Attachments:
Last edit: 03 Nov 2021 15:54 by pgilman.
Please Log in or Create an account to join the conversation.
- pgilman
Less
More
- Posts: 5447
03 Nov 2021 16:31 #10229
by pgilman
Replied by pgilman on topic Importing JSON Input files into PVSAMV1
Hi Paco,
Only part of your screenshot was uploaded to your post. It is best to attach an image as a file and then insert it into the post rather than cutting and pasting directly in the editor.
I am investigating this issue and will follow up when I learn more.
Best regards,
Paul.
Only part of your screenshot was uploaded to your post. It is best to attach an image as a file and then insert it into the post rather than cutting and pasting directly in the editor.
I am investigating this issue and will follow up when I learn more.
Best regards,
Paul.
Please Log in or Create an account to join the conversation.
- Moseley
Less
More
- Posts: 3
21 Feb 2022 17:18 #10615
by Moseley
Replied by Moseley on topic Importing JSON Input files into PVSAMV1
Hi Paul,
I believe I am having the same "Attribute Error" issue when using the PySAM JSON Generate code option. I am following the Export SAM from GUI example ( To import a case from the SAM GUI — NREL-PySAM 3.0.0 documentation ), adapting for a PV-Battery, Single owner case. The code I am running is:
import json
import PySAM.Pvsamv1 as Pvsamv1
import PySAM.Grid as Grid
import PySAM.Utilityrate5 as UtilityRate
import PySAM.Singleowner as Singleowner
pv = Pvsamv1.new()
grid = Grid.from_existing(pv)
ur = UtilityRate.from_existing(pv)
so = Singleowner.from_existing(pv)
dir = "dummydir"
file_names = ["Phoenix_PV_plus_Storage_v1_pvsamv1",
"Phoenix_PV_plus_Storage_v1_grid",
"Phoenix_PV_plus_Storage_v1_utilityrate5",
"Phoenix_PV_plus_Storage_v1_singleowner"]
modules = [pv, grid, ur, so]
for f, m in zip(file_names, modules):
with open(dir + f + ".json", 'r') as file:
data = json.load(file)
for k, v in data.items():
if k != "number_inputs":
m.value(k, v)
Thanks in advance if you have time to look into this issue.
John
I believe I am having the same "Attribute Error" issue when using the PySAM JSON Generate code option. I am following the Export SAM from GUI example ( To import a case from the SAM GUI — NREL-PySAM 3.0.0 documentation ), adapting for a PV-Battery, Single owner case. The code I am running is:
import json
import PySAM.Pvsamv1 as Pvsamv1
import PySAM.Grid as Grid
import PySAM.Utilityrate5 as UtilityRate
import PySAM.Singleowner as Singleowner
pv = Pvsamv1.new()
grid = Grid.from_existing(pv)
ur = UtilityRate.from_existing(pv)
so = Singleowner.from_existing(pv)
dir = "dummydir"
file_names = ["Phoenix_PV_plus_Storage_v1_pvsamv1",
"Phoenix_PV_plus_Storage_v1_grid",
"Phoenix_PV_plus_Storage_v1_utilityrate5",
"Phoenix_PV_plus_Storage_v1_singleowner"]
modules = [pv, grid, ur, so]
for f, m in zip(file_names, modules):
with open(dir + f + ".json", 'r') as file:
data = json.load(file)
for k, v in data.items():
if k != "number_inputs":
m.value(k, v)
Thanks in advance if you have time to look into this issue.
John
Please Log in or Create an account to join the conversation.
- proman
Less
More
- Posts: 2
11 Apr 2023 10:42 #12050
by proman
Replied by proman on topic Importing JSON Input files into PVSAMV1
Hello,
I am trying to import a json from SAM Detailed model with
"Solar Azimuth by Altitude Beam Irradiance Shade Loss Table"
enebled,
'''import jsonimport PySAM.Pvsamv1 as pv # import the Pvsamv1 module from PySAM# create a new instance of the Pvsamv1 modulepv_model = pv.new() # get the inputs from the JSON filewith open( 'untitled_pvsamv1.json', 'r') as f:pv_inputs = json.load( f ) # iterate through the input key-value pairs and set the module inputsfor k, v in pv_inputs.items():if k != 'number_inputs':pv_model.value(k, v) # run the modulepv_model.execute()
'''
but i get ...'''
AttributeError: 'value' error, could not find attribute: subarray1_string_option
'''
thanks in advance, best regards.
PRoman
I am trying to import a json from SAM Detailed model with
"Solar Azimuth by Altitude Beam Irradiance Shade Loss Table"
enebled,
'''import jsonimport PySAM.Pvsamv1 as pv # import the Pvsamv1 module from PySAM# create a new instance of the Pvsamv1 modulepv_model = pv.new() # get the inputs from the JSON filewith open( 'untitled_pvsamv1.json', 'r') as f:pv_inputs = json.load( f ) # iterate through the input key-value pairs and set the module inputsfor k, v in pv_inputs.items():if k != 'number_inputs':pv_model.value(k, v) # run the modulepv_model.execute()
'''
but i get ...'''
AttributeError: 'value' error, could not find attribute: subarray1_string_option
'''
thanks in advance, best regards.
PRoman
Please Log in or Create an account to join the conversation.
Moderators: pgilman