- Posts: 6
Help me understand interdependent variables
- zippo
- Topic Author
Less
More
10 Jul 2024 14:11 #13293
by zippo
Help me understand interdependent variables was created by zippo
Looking at the documentation example on interdependent variables like system capacity:
[url] nrel-pysam.readthedocs.io/en/main/interdependent-variables.html#pvsamv1-system-nameplate-capacity [/url]
sheds some light but also confuses me.
My mental model of PySAM and its modules is that the variables are calculated from its dependent variables. When a module needs values from another, it makes sense they need to be connected or initiated from another module but within the same modules, the code for updating a value will cause dependent variables to be recalculated. This assumption is not correct it seems.
Is it because the defaults include the values of these dependent variables that fit but if you change something (like the number of modules) then variables dependent on that needs to be manually calculated?
Is there something that stops PySAM from having methods that recalculates the interdependent variables (as SAM itself has code for it)?
[url] nrel-pysam.readthedocs.io/en/main/interdependent-variables.html#pvsamv1-system-nameplate-capacity [/url]
sheds some light but also confuses me.
My mental model of PySAM and its modules is that the variables are calculated from its dependent variables. When a module needs values from another, it makes sense they need to be connected or initiated from another module but within the same modules, the code for updating a value will cause dependent variables to be recalculated. This assumption is not correct it seems.
Is it because the defaults include the values of these dependent variables that fit but if you change something (like the number of modules) then variables dependent on that needs to be manually calculated?
Is there something that stops PySAM from having methods that recalculates the interdependent variables (as SAM itself has code for it)?
Please Log in or Create an account to join the conversation.
- pgilman
Less
More
- Posts: 5447
10 Jul 2024 17:05 #13294
by pgilman
Replied by pgilman on topic Help me understand interdependent variables
Hello,
The example given in the "Interdependent Variables" topic for the Pvsamv1 compute module explains the problem of interdependent variables: 'system_capacity', 'subarray1_modules_per_string' and 'subarray1_nstrings' are all inputs to Pvsamv1. However, the value of 'system_capacity' depends on the values of 'subarray1_modules_per_string' and 'subarray1_nstrings'. In the SAM desktop application, there is code in the user interface that calculates the value of 'system_capacity' from 'subarray1_modules_per_string' and 'subarray1_nstrings' (and other variables) to ensure that the correct values are passed from the user interface to the compute module. This code does not exist within the compute module.
The reason this is a problem is that SAM's compute modules were originally designed before PySAM existed, and we assumed that the interface would be there to manage the input variables. We are working to move the user interface code that manages inputs into the compute modules, but this is a slow process so will take time to finish.
When you export variables from the SAM user interface to JSON for use with PySAM, the values of the interdependent variables should be correct because they were generated by the user interface. However, if you change the value of one of the interdependent variables in your Python script (or by editing the JSON file), you also have to be sure to change the values of other variables that are interdependent. The "Interdependent Variables" topic in the documentation attempts to explain how to do this.
Let me know if you have questions about specific variables.
Best regards,
Paul.
The example given in the "Interdependent Variables" topic for the Pvsamv1 compute module explains the problem of interdependent variables: 'system_capacity', 'subarray1_modules_per_string' and 'subarray1_nstrings' are all inputs to Pvsamv1. However, the value of 'system_capacity' depends on the values of 'subarray1_modules_per_string' and 'subarray1_nstrings'. In the SAM desktop application, there is code in the user interface that calculates the value of 'system_capacity' from 'subarray1_modules_per_string' and 'subarray1_nstrings' (and other variables) to ensure that the correct values are passed from the user interface to the compute module. This code does not exist within the compute module.
The reason this is a problem is that SAM's compute modules were originally designed before PySAM existed, and we assumed that the interface would be there to manage the input variables. We are working to move the user interface code that manages inputs into the compute modules, but this is a slow process so will take time to finish.
When you export variables from the SAM user interface to JSON for use with PySAM, the values of the interdependent variables should be correct because they were generated by the user interface. However, if you change the value of one of the interdependent variables in your Python script (or by editing the JSON file), you also have to be sure to change the values of other variables that are interdependent. The "Interdependent Variables" topic in the documentation attempts to explain how to do this.
Let me know if you have questions about specific variables.
Best regards,
Paul.
Please Log in or Create an account to join the conversation.
- zippo
- Topic Author
Less
More
- Posts: 6
11 Jul 2024 03:28 #13298
by zippo
Replied by zippo on topic Help me understand interdependent variables
Thanks Paul, that is good info! Sounds like a more manual way to understand and check interdependent value impact is to make the changes to a variable and export a JSON before and after that change and do a file diff between those two JSON files to catch what variables need updating.
Some follow up questions:
1. On the 'system_capacity', the SAM help states:
2. When initializing the modules, I noticed that it seems that other modules are typically created from the system module. Are there exceptions to this?
Some follow up questions:
1. On the 'system_capacity', the SAM help states:
Is there a specific reason why the example code multiplies voltage with current (cec_v_mp_ref * cec_i_mp_ref) instead of using the 'cec_p_mp_ref' (Max power for the module) instead? Perhaps not all entries in the module database have the max power field filled out?Nameplate Capacity (kWdc) = Module Maximum Power (Wdc) × 0.001 (kW/W) × Total Modules
2. When initializing the modules, I noticed that it seems that other modules are typically created from the system module. Are there exceptions to this?
Code:
pv_system = pvsamv1.default(model_name)
grid_model = grid.from_existing(pv_system, model_name)
utility_model = utilityrate5.from_existing(pv_system, model_name)
financial_model = cashloan.from_existing(pv_system, model_name)
Please Log in or Create an account to join the conversation.
- pgilman
Less
More
- Posts: 5447
12 Jul 2024 12:34 #13308
by pgilman
Replied by pgilman on topic Help me understand interdependent variables
Hello,
The Pvsamv1 module in PySAM does not have a 'cec_p_mp_ref' input for the module maximum power rating, so it must be calculated from 'cec_i_mp_ref' and 'cec_v_pm_ref'. (In the SAM desktop application, code in the user interface calculates a Pmp value from the Imp and Vmp values in the module library.)
PySAM's 'from_existing()' function is designed to work in the way you describe and as explained in nrel-pysam.readthedocs.io/en/main/defaults.html#accessing-sam-defaults . I can't think of any exceptions to initializing the modules in this way.
Best regards,
Paul.
The Pvsamv1 module in PySAM does not have a 'cec_p_mp_ref' input for the module maximum power rating, so it must be calculated from 'cec_i_mp_ref' and 'cec_v_pm_ref'. (In the SAM desktop application, code in the user interface calculates a Pmp value from the Imp and Vmp values in the module library.)
PySAM's 'from_existing()' function is designed to work in the way you describe and as explained in nrel-pysam.readthedocs.io/en/main/defaults.html#accessing-sam-defaults . I can't think of any exceptions to initializing the modules in this way.
Best regards,
Paul.
Please Log in or Create an account to join the conversation.
Moderators: pgilman