- Posts: 22
Undefined variables when importing
- franmoraga
- Topic Author
Less
More
26 Apr 2021 12:21 #9524
by franmoraga
Undefined variables when importing was created by franmoraga
Dear community,
I need your help please. I have created two simulations in SAM, one PV and the other CSP, then I took the code to Python 3. So far there is no problem. I can see the results in my IDE. However, since the generation is not in the code, I added in each file:
gen_pv = ssc.data_get_array (data, b'gen ');
gen_csp = ssc.data_get_array (data, b'gen ');
And I can also see the hourly generation without problems.
The problem is when from a file (for example CSP.py), I want to call the generation of the other file (gen_pv). That is, I want to import the variable from one file to another.
For example, in the CSP.py file I call a variable from PV.py
from PV import *
There I have "NameError: name 'gen_pv' is not defined".
Each one separately works fine when I add gen_pv and gen_csp, but when I want to import variables, it tells me that it is undefined. The problem is clearly in these variables that I added, maybe they are not in the right place or I have to do something else, like define them.
I hope I was clear.
I attach all the files, in case someone can help me, please.
Thank you very much in advance,
Francisco
I need your help please. I have created two simulations in SAM, one PV and the other CSP, then I took the code to Python 3. So far there is no problem. I can see the results in my IDE. However, since the generation is not in the code, I added in each file:
gen_pv = ssc.data_get_array (data, b'gen ');
gen_csp = ssc.data_get_array (data, b'gen ');
And I can also see the hourly generation without problems.
The problem is when from a file (for example CSP.py), I want to call the generation of the other file (gen_pv). That is, I want to import the variable from one file to another.
For example, in the CSP.py file I call a variable from PV.py
from PV import *
There I have "NameError: name 'gen_pv' is not defined".
Each one separately works fine when I add gen_pv and gen_csp, but when I want to import variables, it tells me that it is undefined. The problem is clearly in these variables that I added, maybe they are not in the right place or I have to do something else, like define them.
I hope I was clear.
I attach all the files, in case someone can help me, please.
Thank you very much in advance,
Francisco
Please Log in or Create an account to join the conversation.
- pgilman
Less
More
- Posts: 5447
26 Apr 2021 12:34 #9526
by pgilman
Replied by pgilman on topic Undefined variables when importing
Hi Francisco,
This seems like a Python coding question rather than a question about SAM.
Be sure to run the SSC simulation before trying to read the value of 'gen'. Your code should follow these steps:
1. Set inputs for the CSP model.
2. Run a simulation for the CSP model.
3. Store the CSP model generation data.
4. Repeat Steps 1-3 for the PV model.
5. Add the generation data from the two models.
Best regards,
Paul.
This seems like a Python coding question rather than a question about SAM.
Be sure to run the SSC simulation before trying to read the value of 'gen'. Your code should follow these steps:
1. Set inputs for the CSP model.
2. Run a simulation for the CSP model.
3. Store the CSP model generation data.
4. Repeat Steps 1-3 for the PV model.
5. Add the generation data from the two models.
Best regards,
Paul.
Please Log in or Create an account to join the conversation.
- franmoraga
- Topic Author
Less
More
- Posts: 22
26 Apr 2021 13:04 #9527
by franmoraga
Replied by franmoraga on topic Undefined variables when importing
Thank you dear Paul,
I use the default values in the code, which are the ones brought from SAM. With that I can get results without problems. Should I enter any other input?
The problem is when I add new lines of code, which do not come from the original code generated by SAM.
Request the hourly generation as:
gen_pv = ssc.data_get_array (data, b'gen ')
do you think it's okay?
Thanks
I use the default values in the code, which are the ones brought from SAM. With that I can get results without problems. Should I enter any other input?
The problem is when I add new lines of code, which do not come from the original code generated by SAM.
Request the hourly generation as:
gen_pv = ssc.data_get_array (data, b'gen ')
do you think it's okay?
Thanks
Please Log in or Create an account to join the conversation.
- pgilman
Less
More
- Posts: 5447
26 Apr 2021 13:27 #9528
by pgilman
Replied by pgilman on topic Undefined variables when importing
Hi Francisco,
That should work, provided you ran a simulation for the pvsamv1 (or pvwattsv7) module before making that variable assignment.
Best regards,
Paul.
That should work, provided you ran a simulation for the pvsamv1 (or pvwattsv7) module before making that variable assignment.
Best regards,
Paul.
Please Log in or Create an account to join the conversation.
Moderators: pgilman