Skip to content

Vortex calculator scripting example

Thomas Brauer edited this page Feb 2, 2023 · 2 revisions

The Vortex API is written in java allowing access via jython scripting. The following example demonstrates running a batch calculation on gridded DSS records via a jython script.

This batch script example uses two scripting files:

  1. A *.py file that contains the scripting logic
  2. A *.bat file that sets the environment and executes the python script

In addition to the script files, two jars were used:

  1. A version of vortex
  2. A version of jython

The jython script my_batch_calculation.py multiplies all records in a DSS file by a constant using the Vortex Java API. The multiplyValue option is used in this example. With the BatchCalculator you can optionally add, subtract, multiply or divide by a constant with the addValue, subtractValue, multiplyValue, or divideValue builder methods. You can only use one of these methods at a time in a batch calculation.

from mil.army.usace.hec.vortex.math import BatchCalculator

path_to_input = 'C:/Temp/truckee_2016.dss'

destination = 'C:/Temp/truckee_2016_x2.dss'

write_options = {'partF': 'multiplied by 2'}

myCalculator = BatchCalculator.builder() \
    .pathToInput(path_to_input) \
    .selectAllVariables() \
    .multiplyValue(2.0) \
    .destination(destination) \
    .writeOptions(write_options) \
    .build()

myCalculator.process()

The batch script my_batch_calculation.bat sets the environment and executes the script:

set "VORTEX_HOME=C:\Programs\vortex-0.10.32"
set "PATH=%VORTEX_HOME%\bin;%VORTEX_HOME%\bin\gdal;%PATH%"
set "GDAL_DATA=%VORTEX_HOME%\bin\gdal\gdal-data"
set "PROJ_LIB=%VORTEX_HOME%\bin\gdal\projlib"
set "CLASSPATH=%VORTEX_HOME%\lib\*"
C:\Programs\jython2.7.2\bin\jython.exe -Djava.library.path=%VORTEX_HOME%\bin;%VORTEX_HOME%\bin\gdal my_batch_calculation.py