Pvsamv1 CEC Performance Model with User Entered Specifications Option and PySAM

  • pgilman
  • Topic Author
More
13 Nov 2024 17:16 - 04 Dec 2024 17:42 #13594 by pgilman
When you use SAM's code generator with the "PySAM JSON" option, it generates two JSON files: One with the case name, such as "untitled.json" and one with the case name and "_pvsamv1" appended, such as "untilted_pvsamv1.json". The latter file uses 'sixpar_' as required by PySAM, and indicated in the documentation of the Pvsamv1 user-specified module parameters variables .

Here's a Python script you can use to test that. First, in SAM, create a default Detailed PV / No Financial case, and then go to the Module page and choose the CEC Performance Model with User Entered Specifications option from the blue list at the top of the page. Then, on the Case menu, click Generate code, PySAM JSON.


Code:
import json import PySAM.Pvsamv1 as PV # create a new pvsamv1 model pv = PV.new() # assign inputs from JSON generated by SAM with open("untitled_pvsamv1.json", "r") as file:     data = json.load(file) # loop through each key-value pair for k, v in data.items():     if 'adjust_' in k: # workaround for https://github.com/NREL/pysam/issues/164         k = k.replace('adjust_', '')         if k != "number_inputs":             pv.value(k, v) # print inputs for user-specified module parameters option to verify "sixpar" in variable names print(pv.CECPerformanceModelWithUserEnteredSpecifications.export()) # run pvsamv1 for no bifacial pv.execute() # print some results print(pv.value("annual_dc_net")) print(pv.value("annual_ac_gross")) # change user-specified module bifacial parameter pv.value("sixpar_is_bifacial", 1) # print inputs to confirm bifacial mode is enabled print(pv.CECPerformanceModelWithUserEnteredSpecifications.export()) # run pvsamv1 for bifacial pv.execute() # print results -- should be higher than non-bifacial print(pv.value("annual_dc_net")) print(pv.value("annual_ac_gross"))



Best regards,
Paul.
Last edit: 04 Dec 2024 17:42 by pgilman.

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

  • jesus.polo@ciemat.es
More
04 Dec 2024 08:10 #13631 by jesus.polo@ciemat.es
I get an error in the part pv.value(k,v),

The error is:  'utf-8' codec can't decode byte 0xff in position 42: invalid start byte

In theory I can create a pv model using pvsamv1.default() and I will have all the parameters by default, annd then I can rewirte some of the parameters from the json file I create from the SAM gui, but I always get the error I mentioned

Any idea of what to do?

Thanks a lot

Jesus
 

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

  • pgilman
  • Topic Author
More
04 Dec 2024 17:45 #13634 by pgilman
Hi Jesus,

Could you attach the files you are using for your test (preferrably a minimal code example)? You could compress the .py and .json file into a .zip file to make it easier for me to try to replicate this issue.

Best regards,
Paul.

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

  • jesus.polo@ciemat.es
More
05 Dec 2024 02:35 #13637 by jesus.polo@ciemat.es
 

File Attachment:

File Name: Sistema co...eria.zip
File Size:39 KB

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

  • pgilman
  • Topic Author
More
05 Dec 2024 10:22 #13639 by pgilman
Hi Jesus,

Thank you for attaching the files. Could you also send the .sam file you used to generate the JSON input file?

The UTF-8 Codec error is caused by PySAM attempting to read a variable that it does not recognize. We hope to fix this so that it generates a more meaningful error message.

You can find the variable that is causing the error by adding 'print(k)' in the loop that sets the module inputs:
Code:
for k, v in pv_inputs.items():     print(k)     if k != 'number_inputs':         pv_model.value(k, v)

From the discussion above, we know that the variable names starting with  "6par" are not valid PySAM variable names. We can fix that by replacing "6par" with "sixpar". There is a separate issue with variable names that start with "adjust." To fix those issues:
Code:
for k, v in pv_inputs.items():     print(k)     if '6par' in k:         k = k.replace('6par','sixpar')     if 'adjust_' in k:         k =  k.replace('adjust_', '') # fix from https://github.com/NREL/pysam/issues/164     if k != 'number_inputs':         pv_model.value(k, v)

There are some additional variables causing problems in your JSON file, so please share the .sam file that you used to generate the JSON if you would like me to help troubleshoot.

Best regards,
Paul.

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

  • jesus.polo@ciemat.es
More
08 Dec 2024 23:51 #13664 by jesus.polo@ciemat.es
Hi Paul

Thanks a lot for your help. Here is the .sam file 

Jesus

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

Moderators: pgilman
Powered by Kunena Forum