Demo calculation precipitation deficit
This tutorial shows how to develop a simple calculation and deploy it to Nexus so that it can run real time on the incoming data stream.
Info
This tutorial assumes that you have:
- Python installed on your computer
- Docker Desktop installed on your computer
- a Nexus account with Expert privileges
Let's develop a simple calculation in Python¶
Instead of starting from scratch, we're going to use a simple code already developed for you as an example. Download the demo code here and unzip the file on your computer.
Open a command prompt or terminal and navigate to the directory where you unzipped the file. Then install required packages:
pip install -r requirements.txt
Next, open your favorite code editor and edit the file config.py. Enter the developer credentials you
received by email for variables DB_USER, DB_PASSWORD and WEB_API_TOKEN.
Then inspect the file called main.py. Essentially the only thing happening in this calculation is that a table is
created in the output_schema of Nexus Database, containing the calculated precipitation deficit for each weather
station in the 'sandbox' world.
Execute the file and notice that it will only take a couple of seconds to finish. Now when you check Nexus Database, you should see that there is a table called 'prec_def_cum_ytd_mm' in the schema 'sandbox_demo_precipitation_deficit' containing the precipitation deficit during the growing season for each weather station in the 'sandbox' world as dummy content. To display the calculated result, open DBeaver, navigate to the table, then right-click 'View/Edit Data' > 'First 100 Rows'.
That is it! You have just successfully run your first calculation. Easy, wasn't it?
Deploy it to Nexus¶
So far we have run the calculation locally on our desktop environment. However, we want an up-to-date calculation result for every day from now on, using the latest meteorological measurements. To achieve that, we want to deploy the calculation to Nexus and make sure that it is automatically executed whenever the input data changes.
To deploy your calculation, open a command prompt or terminal and make sure you are navigated to the calculation directory. Then execute the following command:
deploy demo_precipitation_deficit {web_api_token}
Run it in the cloud¶
When the calculation is ready and deployed for operational use, email StellaSpark to activate it and have it executed every time the input data changes or on a fixed timed interval (for example every day, every hour or whatever fits your need).