-
Notifications
You must be signed in to change notification settings - Fork 7
Vortex normalizer scripting example
Thomas Brauer edited this page Feb 12, 2021
·
4 revisions
The Vortex API is written in java allowing access via jython scripting. The following example demonstrates importing a grib file via jython script.
This batch script example uses two scripting files:
- A *.py file that contains the scripting logic
- A *.bat file that sets the environment and executes the python script
In addition to the script files, two jars were used:
The python script normalize.py imports a grib file to a dss by interacting with the Vortex API:
from mil.army.usace.hec.vortex.math import Normalizer
from mil.army.usace.hec.vortex.io import DataReader
from java.time import ZonedDateTime
from java.time import LocalDateTime
from java.time import ZoneId
from java.time import Duration
source = 'C:/Temp/qpe.dss'
normals = 'C:/Temp/prism.dss'
sourceGrids = DataReader.getVariables(source)
normalGrids = DataReader.getVariables(normals)
start = ZonedDateTime.of(LocalDateTime.of(2017, 1, 1, 0, 0), ZoneId.of("UTC"))
end = ZonedDateTime.of(LocalDateTime.of(2017, 1, 3, 0, 0), ZoneId.of("UTC"))
interval = Duration.ofDays(1)
destination = 'C:/Temp/normalized.dss'
options = {'partF': 'my normalized grids'}
normalizer = Normalizer.builder() \
.startTime(start) \
.endTime(end) \
.interval(interval) \
.pathToSource(source) \
.sourceVariables(sourceGrids) \
.pathToNormals(normals) \
.normalsVariables(normalGrids) \
.destination(destination) \
.writeOptions(options) \
.build()
normalizer.normalize()
The batch script normalize.bat sets the environment and executes the script:
set "VORTEX_HOME=C:\Programs\vortex-0.10.16"
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 -J-Xmx2g -Djava.library.path=%VORTEX_HOME%\bin;%VORTEX_HOME%\bin\gdal normalize.py
This example can be found on github.
That's all there is to it. Happy scripting!