- Posts: 2
Importing input files from json to PySAM for Pvwattsv8
- Jaco
- Topic Author
        Less
        More
        
            
    
        
            
        
                12 Mar 2024 22:58         -  13 Mar 2024 16:12        #12978
        by Jaco
    
    
 	
					
                    	
            			
							    
    
            
            
            
            
                                
    
                                                
    
        Importing input files from json to PySAM for Pvwattsv8 was created 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?
 
Thanks in advance for your help.
Jaco
    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?
Code:
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
        Last edit: 13 Mar 2024 16: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
        Less
        More
        
            
    
        - Posts: 5665
            
        
                13 Mar 2024 16:17                #12982
        by Paul Gilman
    
    
            
            
            
            
            
                                
    
                                                
    
        Replied by Paul Gilman on topic Importing input files from json to PySAM for Pvwattsv8            
    
        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 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
        Less
        More
        
            
    
        - Posts: 2
            
        
                13 Mar 2024 18:34                #12983
        by Jaco
    
    
 	
					
                                	
			
				    
            
            
            
            
            
                                
    
                                                
    
        Replied by Jaco on topic Importing input files from json to PySAM for Pvwattsv8            
    
        Hi Paul, 
Please find attached.
Kind Regards,
Jaco
    Please find attached.
Kind Regards,
Jaco
Attachments:
            	      
												
            	
            	Please Log in or Create an account to join the conversation.
- Paul Gilman
        Less
        More
        
            
    
        - Posts: 5665
            
        
                15 Mar 2024 10:40         -  15 Mar 2024 10:42        #12986
        by Paul Gilman
    
    
    
            
            
            
            
                                
    
                                                
    
        Replied by Paul Gilman on topic Importing input files from json to PySAM for Pvwattsv8            
    
        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:
Best regards,
Paul.
     
    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:
Code:
"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 10:42  by Paul Gilman.            
            Please Log in or Create an account to join the conversation.
- Paul Gilman
        Less
        More
        
            
    
        - Posts: 5665
            
        
                21 Mar 2024 09:35         -  21 Mar 2024 09:36        #13014
        by Paul Gilman
    
    
    
            
            
            
            
                                
    
                                                
    
        Replied by Paul Gilman on topic Importing input files from json to PySAM for Pvwattsv8            
    
        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:
Sorry about that! Thank you for helping us find this problem.
Best regards,
Paul.
     
    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:
Code:
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 09:36  by Paul Gilman.            
            Please Log in or Create an account to join the conversation.
- Joseph Dvorak
        Less
        More
        
            
    
        - Posts: 3
            
        
                11 Jun 2024 08:07                #13247
        by Joseph Dvorak
    
    
            
            
            
            
            
                                
    
                                                
    
        Replied by Joseph Dvorak on topic Importing input files from json to PySAM for Pvwattsv8            
    
        I ran into the same issue. 
However, I had to adjust the workaround as the provided code triggered on "cec_adjust" in my json file. I added the underscore after adjust to prevent it from triggering on that entry.
Here is the code I had to use:
I'm just providing this in case someone else had a similar issue.
    However, I had to adjust the workaround as the provided code triggered on "cec_adjust" in my json file. I added the underscore after adjust to prevent it from triggering on that entry.
Here is the code I had to use:
Code:
    for k, v in pv_inputs.items():
        if k != 'number_inputs':
            if 'adjust_' in k:
                k = k.split('adjust_')[1]
            pv_model.value(k, v)
I'm just providing this in case someone else had a similar issue.
Please Log in or Create an account to join the conversation.
        Moderators: Paul Gilman    
 
  
 















