Importing input files from json to PySAM for Pvwattsv8

  • Jaco
  • Topic Author
More
13 Mar 2024 04:58 - 13 Mar 2024 22:12 #12978 by Jaco
Hello, 
There are two parts to my question. 
The first is that I am unable to achieve comparable results when building a Pvwattsv8  No financial model in pySAM compared to those obtained in the SAM application. Specifically comparing achieved capacity factors. The pySAM model consistently produces lower capacity factors compared to the SAM application. 

 

 

A link to those files can be found here

The second part is in regard to issues when importing JSON inputs. 
This was done following the example code from the documentation below, however I encounter the error: 
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb0 in position 41: invalid start byte. 
The json file was downloaded from the code generator, and the SAM application and pySAM versions are 2023.12.17. and v5.0
Could you please advise on what might be causing this problem? 
import json
import PySAM.Pvwattsv8 as pv # import the PVWatts module from PySAM

# create a new instance of the Pvwattsv8 module
pv_model = pv.new()
# get the inputs from the JSON file
with open( 'untitled1_pvwattsv8.json', 'r') as f:
        pv_inputs = json.load( f )

# iterate through the input key-value pairs and set the module inputs
for k, v in pv_inputs.items():
    if k != 'number_inputs':
        pv_model.value(k, v)

# run the module
pv_model.execute()

# print results
print('Annual AC output for {capacity:,.2f} kW system is {output:,.0f} kWh.\n'.format(capacity = pv_model.value('system_capacity'), output = pv_model.Outputs.ac_annual) )


 

Thanks in advance for your help. 
Jaco
Attachments:
Last edit: 13 Mar 2024 22:12 by Paul Gilman. Reason: Please attach images as files and then insert them into your message

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

  • Paul Gilman
More
13 Mar 2024 22:17 #12982 by Paul Gilman
Hi Jaco,

Please attach the .json and .sam files for the first part of your question, and the .json file for the second part if you would like me to help troubleshoot. I could not access the files the Google Drive link you provided.

You should be able to attach each file individually, or you can zip them into an archive and attach the .zip file.

Best regards,
Paul.

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

  • Jaco
  • Topic Author
More
14 Mar 2024 00:34 #12983 by Jaco
Hi Paul, 

Please find attached. 

Kind Regards, 
Jaco

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

  • Paul Gilman
More
15 Mar 2024 16:40 - 15 Mar 2024 16:42 #12986 by Paul Gilman
Hi Jaco,

Thank you for attaching the files.

For the first question, in your SAM file, the array type is set to "1-axis tracking." In the Python script, array_type = 1, which is the fixed roof mount option. That explains the difference in capacity factor between the two.

For the second question, we are investigating this UnicodeDecodeError. I think you can work around the problem by deleting the five "adjust" variables from the JSON file:
"adjust_constant" : 0,
"adjust_en_timeindex" : 0,
"adjust_en_periods" : 0,
"adjust_timeindex" : [ 0 ],
"adjust_periods" : [ [ 0, 0, 0 ] ]

Best regards,
Paul.
 
Last edit: 15 Mar 2024 16:42 by Paul Gilman.

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

  • Paul Gilman
More
21 Mar 2024 15:35 - 21 Mar 2024 15:36 #13014 by Paul Gilman
Hi Jaco,

It turns out that the SSC variable names that start with 'adjust_' are named without the "adjust_" in PySAM. For example, for Pvwattsv8, 'adjust_constant' in SSC (the name used for defaults and JSON generated by SAM) is 'constant' in PySAM.

We will fix this in an update to PySAM: github.com/NREL/pysam/issues/164.

For now the workaround is to rename the "adjust" variables when you read them from defaults or a SAM-generated JSON file. For example:

for k, v in pv_inputs.items():
    if 'adjust' in k:
        k = k.split('adjust_')[1]


Sorry about that! Thank you for helping us find this problem.

Best regards,
Paul.

 
Last edit: 21 Mar 2024 15:36 by Paul Gilman.

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

Moderators: Paul Gilman
Powered by Kunena Forum