-
Notifications
You must be signed in to change notification settings - Fork 7
Vortex importer scripting example
Thomas Brauer edited this page Aug 2, 2023
·
6 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:
- A version of vortex
- A version of jython-standalone.jar
The python script met_data_import.py imports a grib file to a dss by interacting with the Vortex API:
from mil.army.usace.hec.vortex.io import BatchImporter
from mil.army.usace.hec.vortex.geo import WktFactory
in_files = ['C:/Temp/MRMS_GaugeCorr_QPE_01H_00.00_20170102-120000.grib2']
variables = ['GaugeCorrQPE01H_altitude_above_msl']
clip_shp = 'C:/Temp/Truckee_River_Watershed_5mi_buffer.shp'
geo_options = {
'pathToShp': clip_shp,
'targetCellSize': '2000',
'targetWkt': WktFactory.shg(),
'resamplingMethod': 'Bilinear'
}
destination = 'C:/Temp/myPythonImport.dss'
write_options = {'partF': 'my script import'}
myImport = BatchImporter.builder() \
.inFiles(in_files) \
.variables(variables) \
.geoOptions(geo_options) \
.destination(destination) \
.writeOptions(write_options) \
.build()
myImport.process()
The batch script met_data_import.bat sets the environment and executes the script:
set "VORTEX_HOME=C:\Programs\vortex-0.11.2"
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=C:\Programs\jython-standalone-2.7.2.jar;%VORTEX_HOME%\lib\*"
%VORTEX_HOME%\jre\bin\java.exe -Xmx2g -Djava.library.path=%VORTEX_HOME%\bin;%VORTEX_HOME%\bin\gdal org.python.util.jython met_data_import.py
This example can be found on github.
That's all there is to it. Happy scripting!