Importing inputs from SAM GUI to PySAM TcsmoltenSalt module

  • Westphal
  • Topic Author
More
15 May 2024 14:14 #13163 by Westphal
Hello, 

According to TcsmoltenSalt documentation, the TcsmoltenSalt.assign() function requires a nested dictionary of Group names paired with a dictionary of variable name/value pairs.assign(dict)→ None Assign attributes from nested dictionary, except for Outputs
Code:
nested_dict = { 'Solar Resource': { var: val, ...}, ...}
The "Generate Code - PySAM JSON' option in the SAM GUI provides a JSON that is only a flat dictionary with no Group names. Therefore reading the JSON into the TcsmoltenSalt module does not work as there are no group names associated with the variable name/value pairs.

Is there a workaround for this or a better way to import inputs into the module?

Thanks!
Evan

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

  • pgilman
More
16 May 2024 11:02 - 05 Jun 2024 17:03 #13166 by pgilman
Hi Evan,

See the PySAM documentation for a description of different ways to import inputs:  nrel-pysam.readthedocs.io/en/main/inputs-from-sam.html

The group names are defined internally, not by the JSON structure. You can use the export() function to see all of the variables in a group. For example, to see the variables in the "SolarResource" group for the TcsmoltenSalt module with inputs exported to "untitled_tcsmolten_salt.json" using the 'PySAM JSON" option in SAM's code generator:

Code:
import json import PySAM.TcsmoltenSalt as tcsmoltensalt tower = tcsmoltensalt.new() with open("untitled_tcsmolten_salt.json", "r") as file:     data = json.load(file)     for k, v in data.items():         # temporary fix for https://github.com/NREL/pysam/issues/164         if 'adjust_' in k:             k = k.replace('adjust_')[1]         if k != "number_inputs":             tower.value(k,v) print( tower.SolarResource.export())

Note the "adjust" workaround as described here: github.com/NREL/pysam/issues/164 .

Best regards,
Paul.
Last edit: 05 Jun 2024 17:03 by pgilman.

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

  • Westphal
  • Topic Author
More
16 May 2024 16:45 - 05 Jun 2024 17:00 #13168 by Westphal
Hi Paul,

Thanks for your reply, I should have mentioned that I first started by trying the value() function with the temporary fix but had no luck so was trying the assign() function. I am getting an unnamed attribute error when trying to run the code in your reply. For testing purposes I just generated the" JSON for inputs"  as "untitled.json" for the default CSP Tower Molten Salt Single Owner model from SAM 2023.12.17 GUI.

Edited 6/5/2024: Note that the workaround should use replace() instead of split():

The line
Code:
k = k.split('adjust_', '')

should be
Code:
k = k.replace('adjust_', '').

 
Last edit: 05 Jun 2024 17:00 by pgilman. Reason: Please attach images as files and then insert them into your message

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

  • pgilman
More
17 May 2024 10:03 #13170 by pgilman
Hi Evan,

Part of your screenshot got cut off -- it's best to attach images as files and then insert them into your message. Cutting and pasting images into the editor does not work reliably.

Please check that you are using PySAM 5.1.0, using the "PySAM JSON" option to export the inputs, and using SAM 2023.12.17 r1.

If you continue to have trouble, please attach a copy of the JSON file (please zip it before attaching if you get a message about file type).

Best regards,
Paul.

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

  • Westphal
  • Topic Author
More
21 May 2024 14:32 #13186 by Westphal
Ah thank you, I was trying to follow the "JSON for Inputs" method as detailed at 
nrel-pysam.readthedocs.io/en/main/inputs-from-sam.html

My code is working now by looping through the PySAM JSON files, though is it possible to use the single JSON for Inputs file for the TcsmoltenSalt module?

I am writing code to loop through several different SAM cases and preferably would have only JSON file associated with each case to simplify things.

Thank you, 
Evan

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

  • pgilman
More
23 May 2024 11:01 #13196 by pgilman
Hi Evan,

You should be able to manually create a single JSON file by copying and pasting the separate files, as long as you heed the warning in the "PySAM JSON" section of Importing Inputs from SAM about loading all inputs and setting their values before running the compute modules. The different files may include copies of the same variable, so you'll need to be careful that those variables are set correctly.

Best regards,
Paul.

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

Moderators: pgilman
Powered by Kunena Forum