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!
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
. 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! 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!
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
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 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?