Interpolating 3D Model Data
QUESTION: I have an atmospheric model that produces a three-dimensional array. The first dimension is longitude, sampled at 3.75 degree increments. The second dimension is latitude, also sampled at 3.75 degree increments. The third array dimension is time. The array itself is a 96x48x1812 floating point array. It would be much more convenient for me to have this data sampled at either 2.5 or 5.0 degrees in latitude and longitude. How can I do this? I also need new latitude and longitude vectors that represent the center point of each grid square in the array. I'm not clear how to create these, either.
ANSWER: The Interpolate command can be used to resample the data on a different grid.
First, consider your longitude vector. There are 360 degrees of longitude, divided by 3.75 degrees:
IDL> Print, 360/3.75 96.000
Thus, your first dimension of your array is 96. Similarly, for the latitude vector:
IDL> Print, 180/3.75 48.000
If we want to sample at 5.0 degrees, or at 2.5 degrees, we will have to know how many samples we need. Consider first a 5.0 degree grid
IDL> Print, 'Longitude samples: ', 360/5.0, ' Latitude samples: ', 180/5.0 Longitude samples: 72.0000 Latitude samples: 36.0000
What this tells us is that we need to create location vectors for the Interpolate command that are 72 and 36 elements long. And they have to extend over 96 and 48 elements, respectively.
The easiest way to create such vectors is with the cgScaleVector command.
lon_locations = cgScaleVector(Findgen(72), 0, 96) lat_locations = cgScaleVector(Findgen(36), 0, 48) time_locations = Findgen(1812)
These location vectors tell the Interpolate command where to sample the original array. Note that we have to have a time vector as well, but since we are not resampling time, this is easy to create. To create the resampled array, type this command:
interpArray = Interpolate(array, lon_locations, lat_locations, time_locations, /Grid)
The result is a 72x36x1812 interpolated array.
If you need vectors to go along with this five degree array, centered on each grid square, you can create them like this. Assume the latitude grid goes from -90 to 90, and the longitude grid goes from 0 to 360.
lon = Findgen(72) * 5.0 + (5.0/2.0) lat = Findgen(36) * 5.0 - (90 - 5.0/2.0)
To check:
IDL> print, lon 2.50000 7.50000 12.5000 17.5000 22.5000 27.5000 32.5000 37.5000 42.5000 47.5000 52.5000 57.5000 62.5000 67.5000 72.5000 77.5000 82.5000 87.5000 92.5000 97.5000 102.500 107.500 112.500 117.500 122.500 127.500 132.500 137.500 142.500 147.500 152.500 157.500 162.500 167.500 172.500 177.500 182.500 187.500 192.500 197.500 202.500 207.500 212.500 217.500 222.500 227.500 232.500 237.500 242.500 247.500 252.500 257.500 262.500 267.500 272.500 277.500 282.500 287.500 292.500 297.500 302.500 307.500 312.500 317.500 322.500 327.500 332.500 337.500 342.500 347.500 352.500 357.500 IDL> print, lat -87.5000 -82.5000 -77.5000 -72.5000 -67.5000 -62.5000 -57.5000 -52.5000 -47.5000 -42.5000 -37.5000 -32.5000 -27.5000 -22.5000 -17.5000 -12.5000 -7.50000 -2.50000 2.50000 7.50000 12.5000 17.5000 22.5000 27.5000 32.5000 37.5000 42.5000 47.5000 52.5000 57.5000 62.5000 67.5000 72.5000 77.5000 82.5000 87.5000
Copyright © 2005 David W. Fanning
Last Updated 22 August 2005