Skip to content

Vortex grid to point converter example

Daniel Hamill edited this page Apr 28, 2021 · 1 revision

The Vortex API is written in java allowing access via jython scripting. The following example demonstrates converting between DSS grid records to a zonal statistic derived time series.

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 batch script grid_to_point_Converter.bat sets the environment and executes the script:

set "VORTEX_HOME=C:\workspace\git_clones\vortex-0.10.20-win-x64\vortex-0.10.20"
set "PATH=%VORTEX_HOME%\bin;%VORTEX_HOME%\bin\gdal;%PATH%"
set "GDAL_DRIVER_PATH=%VORTEX_HOME%\bin\gdal\gdalplugins"
set "GDAL_DATA=%VORTEX_HOME%\bin\gdal\gdal-data"
set "PROJ_LIB=%VORTEX_HOME%\bin\gdal\projlib"
set "CLASSPATH=%VORTEX_HOME%\lib\*"

C:\jython2.7.2\bin\jython.exe -J-Xmx10g -Djava.library.path=%VORTEX_HOME%\bin;%VORTEX_HOME%\bin\gdal C:\workspace\git_clones\Vortex\examples\src\main\jython\grid_to_point_Converter.py
cmd /k

The python script grid_to_point_Converter.py converts all dss grids to a timeseries by interacting with the Vortex API:

from mil.army.usace.hec.vortex.convert import GridToPointConverter
from mil.army.usace.hec.vortex import Options
from mil.army.usace.hec.vortex.io import DataReader
import os
from glob import glob
from java.nio.file import Path
from java.nio.file import Paths

#DSS Grid Files to convert to time series
d_files = glob(r"G:\UA\*_noData.dss")

#Output DSS File
output_dss = Paths.get(r"G:\UA\ts\UA_SWE_Depth_MoRiverBasin.dss")

#Shapefile
clip_shp = Paths.get("C:\workspace\Mo River\shp\MissouriRiverBasin_alb.shp")

#Shapefile attribute for zonal statistics
name = 'NAME'

#Output DSS file path partA
basin = 'MISSOURI RIVER BASIN'
ds = 'UA_sanitized'

#Loop through each dss file
for dss_file in d_files:

    #Get dss pathnames
    sourceGrids = DataReader.getVariables(dss_file)

    #Output DSS wite options
    write_options = Options.create()
    write_options.add('partF', ds )
    write_options.add('partA', 'SHG')
    write_options.add('partB', basin)

    #Convert the Data
    myImport = GridToPointConverter.builder()\
            .pathToGrids(dss_file)\
            .variables(sourceGrids)\
            .pathToFeatures(clip_shp)\
            .field(name)\
            .destination(output_dss)\
            .writeOptions(write_options).build()
    myImport.convert()