Vector field parameters


This Python script calculates divergence, curl magnitude and speed variations along flow lines for a 2D vector field. Input data must be provided as two Arc/Info ASCII grids, storing the x- and y-components of the vector field. The results consist in a series of three Arc/Info ASCII grids, with the resulting curl, divergence and speed variations, as well as a VTK file, storing the input data and the results. The names of input and output files are in a text (parameter) file.
See Glacial flow analysis with open source tools: the case of the Reeves Glacier grounding zone, East Antarctica for script rationale.

Code and use - vers. 2010-10-12
Created and tested with Python 2.6 and numpy in Python(x,y) under Windows Vista.
Released under GNU General Public License v. 3.
Example command line to run the script: par.txt

See Input and output section below for parameter file content specifications.


Divergence and curl are two vector operators widely used in physics and engineering, for example, for the study of water flows. The nabla differential operator allows to calculate these two operators from a vector field:

The divergence is a scalar value derived from the scalar product of nabla and the vector field in the neighborhood of a point (x, y, z):

while the curl is the vector product of nabla and the vector field:

With GIS data, we usually consider 2D dimensionality. Therefore, we only consider partial derivatives with respect to x and y axes. For the curl, we will have a vertical vector (parallel to k), whose magnitude is equal to the last component of the curl formula.

To determine the velocity variations per unit length along flow directions, we modify the equation for a DEM directional slope (Neteler & Mitasova, 2008, eq. A.27):
  velocity change per unit length = (dz/dx) * sin(alpha) + (dz/dy) * cos(alpha)
where alpha is the local orientation of the flow line.
All results will consist of scalar fields, because only curl magnitude is of interest.

Input and output

Input and output file names are in a text parameter file:

input vx grid: ASCII grid with x components of the vector field
input vy grid: ASCII grid with y components of vector field
output divergence grid: ASCII grid with divergence values
output curl grid: ASCII grid with curl magnitudes
output speed variation grid: ASCII grid with speed variation along flow lines
output VTK file: VTK file storing input and output data (null value: -99.0)


My name is Mauro Alberti. I'm a Gis and scientific programmer. My primary specializations are in scientific and GIS programming (OS tools, mainly Python, R, Fortran and C++), Earth Sciences (structural geology, Polar Sciences), geostatistical analysis. About me


Mauro Alberti

mobile: +39 338 8022247
skype: mauro.alberti.siena
Address: Via Canonica 32,
Milano (MI) 20100, Italy

P.I. 01292740527