X

NV5 Geospatial Blog

Each month, NV5 Geospatial posts new blog content across a variety of categories. Browse our latest posts below to learn about important geospatial information or use the search bar to find a specific topic or author. Stay informed of the latest blog posts, events, and technologies by joining our email list!



Not All Supernovae Are Created Equal: Rethinking the Universe’s Measuring Tools

Not All Supernovae Are Created Equal: Rethinking the Universe’s Measuring Tools

6/3/2025

Rethinking the Reliability of Type 1a Supernovae   How do astronomers measure the universe? It all starts with distance. From gauging the size of a galaxy to calculating how fast the universe is expanding, measuring cosmic distances is essential to understanding everything in the sky. For nearby stars, astronomers use... Read More >

Using LLMs To Research Remote Sensing Software: Helpful, but Incomplete

Using LLMs To Research Remote Sensing Software: Helpful, but Incomplete

5/26/2025

Whether you’re new to remote sensing or a seasoned expert, there is no doubt that large language models (LLMs) like OpenAI’s ChatGPT or Google’s Gemini can be incredibly useful in many aspects of research. From exploring the electromagnetic spectrum to creating object detection models using the latest deep learning... Read More >

From Image to Insight: How GEOINT Automation Is Changing the Speed of Decision-Making

From Image to Insight: How GEOINT Automation Is Changing the Speed of Decision-Making

4/28/2025

When every second counts, the ability to process geospatial data rapidly and accurately isn’t just helpful, it’s critical. Geospatial Intelligence (GEOINT) has always played a pivotal role in defense, security, and disaster response. But in high-tempo operations, traditional workflows are no longer fast enough. Analysts are... Read More >

Thermal Infrared Echoes: Illuminating the Last Gasp of a Dying Star

Thermal Infrared Echoes: Illuminating the Last Gasp of a Dying Star

4/24/2025

This blog was written by Eli Dwek, Emeritus, NASA Goddard Space Flight Center, Greenbelt, MD and Research Fellow, Center for Astrophysics, Harvard & Smithsonian, Cambridge, MA. It is the fifth blog in a series showcasing our IDL® Fellows program which supports passionate retired IDL users who may need support to continue their work... Read More >

A New Era of Hyperspectral Imaging with ENVI® and Wyvern’s Open Data Program

A New Era of Hyperspectral Imaging with ENVI® and Wyvern’s Open Data Program

2/25/2025

This blog was written in collaboration with Adam O’Connor from Wyvern.   As hyperspectral imaging (HSI) continues to grow in importance, access to high-quality satellite data is key to unlocking new insights in environmental monitoring, agriculture, forestry, mining, security, energy infrastructure management, and more.... Read More >

1345678910Last
13826 Rate this article:
5.0

Speeding up linear gridding of irregular points with multiple values (GRIDDATA)

Anonym

Gridding or interpolating large amounts of data is a common task for some IDL and ENVI users. Here, I am showing a trick that can speed up bi-linear interpolation using a triangulated collection of irregularly gridded points in 2-D. The assumption here is that there are multiple values for each distinct point (x,y), and instead of using GRIDDATA repeatedly for several hundred values at the same locations, the code is pre-computing weights for the triangle corners. This saves computations in the final step and thus achieves a nice speed improvement.

The speed improvement on my computer was going from 31.4 seconds to 8.4 seconds. Here is the output produced by the example code:

 

IDL> grid_speed

% Compiled module: GRID_SPEED.

% Time elapsed: 31.422000 seconds.

% Time elapsed: 8.4380002 seconds.

Mean, Variance, Skewness, Kurtosis

    0.426667    0.0376666      1.26416     0.492909

    0.426667    0.0376666      1.26416     0.492909

 

min, mean, max difference

-1.19209e-007 1.24474e-011 1.19209e-007

 

 

Here is the example code:

 

 

pro grid_speed

 compile_opt idl2,logical_predicate

 

 ;Set up random data points

 ;Let's say 200,000 spatial (X,Y) points with 400 measurements each

 npts = 200000

 nbands = 400

 im = randomu(seed, npts, nbands)

 x = randomu(seed, npts)

 y = randomu(seed, npts)

 

 ;Set up an output gridded space for desired locations

 nx = 768

 ny = 768

 start = [0,0]

 delta = 1d / [nx, ny]

 dim = [nx, ny]

 gridIm1 = fltarr(nx, ny, nbands)

 gridIm2 = fltarr(nx, ny, nbands)

 

 ;traditional approach for bilinear gridding

 tic

 triangulate, x, y, tr

 for i=0, nbands-1 do begin

   gridIm1[0,0,i] = griddata(x, y, im[*,i], triangles=tr, /linear, $

     start=start, delta=delta, dimension=dim)

 endfor

 toc

 

 tic

 triangulate, x, y, tr

 

 ;compute triangle numbers for each input point

 ;multiply by 3 so that triangles are numbered

 ;by the starting index 0, 3, 6, 9, ...

 index = lindgen(n_elements(tr))/3*3

 xt = x[tr[*]]

 yt = y[tr[*]]

 linTr = lindgen(size(tr, /dimensions))

 tr_num = round( $

   griddata(xt, yt, float(index),triangles=linTr, /linear, $

     start=start, delta=delta, dimension=dim))

 

 ;Compute weights for each of the 3 points in the enclosing triangle

  wts = ptrarr(3)

 for i=0, 2 do begin 

   w = griddata(xt, yt, lindgen(n_elements(xt)) mod 3 eq i, $

     triangles=linTr, /linear, $

     start=start, delta=delta, dimension=dim)

   wts[i] = ptr_new(w, /no_copy)

 endfor

 

 ;Compute interpolation for all bands using weights

 ;instead of GRIDDATA

 for i=0, nbands-1 do begin

   gridIm2[0,0,i] = im[tr[tr_num] + i*n_elements(x)] * (*wts[0])

   gridIm2[*,*,i] += im[tr[tr_num+1] + i*n_elements(x)] * (*wts[1])

   gridIm2[*,*,i] += im[tr[tr_num+2] + i*n_elements(x)] * (*wts[2])

 endfor

 toc

 

 ;Verify that the results are the same for both

 ;methods.

 print, 'Mean, Variance,Skewness, Kurtosis'

 print, moment(gridIm1)

 print, moment(gridIm2)

 print

 diff = gridIm2 - gridIm1

 print, 'min, mean, maxdifference'

 print, min(diff, max=maxDiff), mean(diff), maxDiff

end

Please login or register to post comments.