The ModelChain
Endpoint Tutorial
Note
This tutorial assumes you have already set up a Python environment on your machine. If not, see Setting up a Python Environment for help on how to set this up.
Definition
See the ModelChain Endpoint for a definition of this endpoint.
Basically this is the endpoint to use for running 2D calculations. It runs synchronously (you must wait for it to return).
Tutorial
We have provided some files for the tutorial. These were generated from the SolarFarmer desktop application (see Generating API input files from the SolarFarmer desktop application for how to do this yourself) for a simple fixed-tilt racks site that looks like this:
It is a fictitious fixed-tilt rack site. 3 inverters. Racks are 30 modules long, 3 module high. String length is 30.
Create a new empty folder (e.g. in
C:\Temp\Tutorials
)Open the following link in a new tab: ModelChainEndpointTutorial.py
- Select all the text and copy it to the clipboard
- Create an empty text file in your new empty folder and paste the script text into your empty text file and save
it as a Python file (e.g. as
"ModelChainEndpointTutorial.py"
) - Replace the text 'ENTER YOUR API TOKEN HERE!!!' with your personal API token (encase it in single quotes)
Download the following file: Inputs.zip
- Unzip it into your folder. So you should have an
Inputs
sub-folder. This contains the input files needed to run the ModelChain endpoint for this tutorial. - The
EnergyCalculationInputs
object required was saved to the"EnergyCalcInputs.json"
file for this tutorial rather than created manually in python. Open it in a text editor to examine its contents.
- Unzip it into your folder. So you should have an
Open a command prompt in the folder
Type
python ModelChainEndpointTutorial.py
and hit Return to run the script.It may take around 10 seconds to run, and you should see output similar to this:
Sending POST request to https://solarfarmer.dnv.com/api/ModelChain... Request has returned... SUCCESS: Calculation returned successfully Energy yield results totals for year: { "recordCount": 8760, "percentComplete": 99.99999999999983, "averageTemperature": 10.607920426907318, "ghi": 1192.7340000000002, "gi": 1373.3998258765305, "giWithHorizon": 1373.3998258765307, "gainOnTiltedPlane": 0.15147201796589194, "globalEffectiveIrradiance": 1298.0776775552472, "modulePower": 556298.973838618, "modulePowerAtSTC": 578372.3684781528, "nominalEnergy": 578293.605350863, "pdc": 535663.7904797235, "pac": 519353.412220547, "performanceRatio": 0.8218792979786185, "netEnergy": 502.86653814960306, "energyYield": 1128.7688847353597 } Saved annual energy yield results to C:\Temp\Tutorials\Outputs\AnnualEnergyResults.json Sum EOutInv column in PVsyst format results to get total AC annual energy: 519353.579879 kWh Saved PVsyst results file to C:\Temp\Tutorials\Outputs\PVsystResults.csv Saved timeseries results file to C:\Temp\Tutorials\Outputs\TimeSeriesResults.tsv Saved loss tree results file to C:\Temp\Tutorials\Outputs\LossTreeResults.tsv Saved system attributes to C:\Temp\Tutorials\Outputs\System attributes.json
There should be an
Outputs
folder now in your folder. This will contain 5 files containing the results extracted from theModelChainResponse
object returned.See the Outputs section in ModelChain Endpoint for more detailed information on these outputs.
A quick summary:
AnnualEnergyResults.json
- this is the annual energy results for the yearPVsystResults.csv
- the PVsyst results file.- To view in Excel:
- Create a new Excel workbook
- Go to the Data ribbon and click the 'From Text/CSV' button
- Select the
PVsystResults.csv
file that was written and click 'Import' - It should automatically detect that the Semicolon is the delimiter.
- Click 'Load' to load it
- To view in Excel:
TimeSeriesResults.tsv
- time series results file (tab separated data).LossTreeResults.tsv
- loss tree results (tab separated data).System attributes.json
- details of some of the system attributes of the calculation that was run.
If you have this up and running then you can successfully run a simple energy calculation! Well done.
The next step for you will be to start constructing your own inputs and analyzing the output results for yourself. Good luck!