- Posts: 9
Running SAM .lk script from Python
- joel3003
- Topic Author
Less
More
09 Dec 2020 23:38 #9090
by joel3003
Running SAM .lk script from Python was created by joel3003
Hi, I am looking for some advice. I am currently trying to develop a program in python which uses Scipy optimise to minimise a particular result I get out of my .LK script. In doing so,I need a way to open and run my .LK script in SAM using my python program. Initially I was going to create a batch file which would contain the command line commands to open SAM and the LK script, however, this doesn't let me open the particular .sam file that I need to run the script. I was wondering if anyone had any other suggestions in going about this? Some ideas I was thinking were:
1. Would it be possible to alter my .lk script to allow it to run without needing the particular .sam file open?
2. Does .lk language have optimisation functionality built in or can I import external c++ libraries into my .lk file
3. Any other ideas welcome!
Thanks
Joel
1. Would it be possible to alter my .lk script to allow it to run without needing the particular .sam file open?
2. Does .lk language have optimisation functionality built in or can I import external c++ libraries into my .lk file
3. Any other ideas welcome!
Thanks
Joel
Please Log in or Create an account to join the conversation.
- pgilman
Less
More
- Posts: 5423
10 Dec 2020 10:20 #9095
by pgilman
Replied by pgilman on topic Running SAM .lk script from Python
Hi Joel,
Here are some ideas:
Dispense with LK altogether, and use PySAM. PySAM is a Python package that provides direct access to the SSC API, which is the underlying simulation engine behind SAM. To learn more, see sam.nrel.gov/software-development-kit-sdk/pysam.html . I think this might be the best approach because it allows you to write all of your code in Python.
Use SSC objects in LK to store and manipulate SAM inputs. Click Functions in the LK editor and search the function reference for "ssc".
See Chapter 10 in the LK manual (click Scripting Reference in the LK editor) for a description of how to write extensions.
The Latin Hypercube Sampling (LHS) LK functions might be helpful for optimization -- search the function reference for "LHS" to find those.
Thanks,
Paul.
Here are some ideas:
Dispense with LK altogether, and use PySAM. PySAM is a Python package that provides direct access to the SSC API, which is the underlying simulation engine behind SAM. To learn more, see sam.nrel.gov/software-development-kit-sdk/pysam.html . I think this might be the best approach because it allows you to write all of your code in Python.
Use SSC objects in LK to store and manipulate SAM inputs. Click Functions in the LK editor and search the function reference for "ssc".
See Chapter 10 in the LK manual (click Scripting Reference in the LK editor) for a description of how to write extensions.
The Latin Hypercube Sampling (LHS) LK functions might be helpful for optimization -- search the function reference for "LHS" to find those.
Thanks,
Paul.
Attachments:
Please Log in or Create an account to join the conversation.
- joel3003
- Topic Author
Less
More
- Posts: 9
10 Dec 2020 18:38 #9097
by joel3003
Replied by joel3003 on topic Running SAM .lk script from Python
Thanks Paul! One other thing I am trying to replicate in python is the ability to change the desired dcac ratio. In .LK I can do this by using set('desired_dcac_ratio', value). How would I do this in python as I can't seem to see a dcac variable in the JSON for inputs to manipulate? Thanks!
Please Log in or Create an account to join the conversation.
- joel3003
- Topic Author
Less
More
- Posts: 9
10 Dec 2020 22:43 #9098
by joel3003
Replied by joel3003 on topic Running SAM .lk script from Python
Continued Note: I am currently using PySAM.Pvsamv1 in Python. Is it possible to alter the dcac ratio from here or from another library import?
Please Log in or Create an account to join the conversation.
- pgilman
Less
More
- Posts: 5423
11 Dec 2020 16:52 #9103
by pgilman
Replied by pgilman on topic Running SAM .lk script from Python
Hi Joel,
The DC / AC ratio is not an input to the pvsamv1 model. There are a couple of ways to verify that. One is in the PySAM module documentation here: nrel-pysam.readthedocs.io/en/master/py-modindex.html (follow the link to the pvsamv1 module), and the other is to use module browser in the SDKtool application that comes with the SAM desktop application as described under "SDKtool" here: sam.nrel.gov/software-development-kit-sdk.html .
The desired_dcac_ratio input in LK is part of the SAM desktop application's user interface, but not an input to the underlying SSC module. The SAM user interface has some functions that are not available in SSC. Examples of those are the PV size estimator on the System Design page and the weather data download functions on the Location and Resource page.
To set the DC / AC ratio, you'll have to write your own code to set the number of inverters, modules per string, and strings in parallel to achieve the desired DC / AC ratio. The variables you will need to use for that calculation, assuming your array has one subarray, are:
You will also need to know the inverter and module rated AC and DC power, respectively, which depends on the inverter and module model you are using:
For the Sandia inverter model:
For the CEC Module Model with Database Parameters, you can calculated the module rated power by multiplying
and
.
When you set the number of modules per string, you may want to compare the Vmp and Voc ratings to the inverter minimum and maximum Vmppt ratings to ensure the voltage ratings are within specifications.
If this is more detail than you need, you could use the pvwattsv7 module instead, where the system size is defined more simply using a DC power rating and DC / AC ratio.
Thanks,
Paul.
The DC / AC ratio is not an input to the pvsamv1 model. There are a couple of ways to verify that. One is in the PySAM module documentation here: nrel-pysam.readthedocs.io/en/master/py-modindex.html (follow the link to the pvsamv1 module), and the other is to use module browser in the SDKtool application that comes with the SAM desktop application as described under "SDKtool" here: sam.nrel.gov/software-development-kit-sdk.html .
The desired_dcac_ratio input in LK is part of the SAM desktop application's user interface, but not an input to the underlying SSC module. The SAM user interface has some functions that are not available in SSC. Examples of those are the PV size estimator on the System Design page and the weather data download functions on the Location and Resource page.
To set the DC / AC ratio, you'll have to write your own code to set the number of inverters, modules per string, and strings in parallel to achieve the desired DC / AC ratio. The variables you will need to use for that calculation, assuming your array has one subarray, are:
Code:
inverter_count
Code:
subarray1_modules_per_string
Code:
subarray1_nstrings
You will also need to know the inverter and module rated AC and DC power, respectively, which depends on the inverter and module model you are using:
For the Sandia inverter model:
Code:
inv_snl_paco
For the CEC Module Model with Database Parameters, you can calculated the module rated power by multiplying
Code:
cec_i_mp_ref
Code:
cec_v_mp_ref
When you set the number of modules per string, you may want to compare the Vmp and Voc ratings to the inverter minimum and maximum Vmppt ratings to ensure the voltage ratings are within specifications.
If this is more detail than you need, you could use the pvwattsv7 module instead, where the system size is defined more simply using a DC power rating and DC / AC ratio.
Thanks,
Paul.
Please Log in or Create an account to join the conversation.
- joel3003
- Topic Author
Less
More
- Posts: 9
15 Dec 2020 21:36 #9118
by joel3003
Replied by joel3003 on topic Running SAM .lk script from Python
Hi Paul,
Thanks for the help. This is very useful. Would there happen to be a formula to calculate DCAC ratio from these variables? i.e. How does pvsamv1 or PySAM in general calculate the DCAC ratio from these variables?
Thanks,
Joel
Thanks for the help. This is very useful. Would there happen to be a formula to calculate DCAC ratio from these variables? i.e. How does pvsamv1 or PySAM in general calculate the DCAC ratio from these variables?
Thanks,
Joel
Please Log in or Create an account to join the conversation.
Moderators: pgilman