NASA Distributed Active Archive Center (DAAC) at NSIDC

MODIS Data

Moderate Resolution Imaging Spectroradiometer

MS2GT: The MODIS Swath-to-Grid Toolbox

* Documentation for this product is in development. *
Please contact NSIDC User Services.


Tutorial 4: Gridding 1 km Sea Ice Data Over the Ross Sea Using mod29.pl

Requirements

The MS2GT installation provides most of the files you will need for the tutorials. The tutorial shows the process you need to use to create the files when performing operations on data files. The MS2GT installation does not provide the data files. Instructions for obtaining the MODIS data you will need for this tutorial are provided below.

In this tutorial, we will put some MODIS 1 km sea ice swath data covering the western portion of the Ross Sea into a Polar Stereographic ellipsoidal projection, centered at the south pole with the parallel of true scale set to 71 S. We want the vertical axis of the grid pointing due north toward the top of the grid and parallel to 180 E, the upper left corner of the grid at exactly 70 S 165 E, and the lower right corner near 79 S 160 W. The grid resolution is 1 km and we will use the WGS84 ellipsoid (equatorial radius of 6378.137 km and an eccentricity of 0.081819190843). We will grid all available MOD29 "channels."

For this tutorial, we can simply use MOD29 data. As you can see in Supported Data Sets, the latlon data are stored at only 5-km resolution in MOD29 granules. We decide that 5-km resolution for the latlon data is good enough for our purposes, so we won't need any MOD03 granules.

NOTE: To run this example, you'll need a machine with at least 100 MB of memory and at least 200 MB of free disk space.

Obtaining the Data

We know that January 24, 2001 was fairly clear over the western Ross Sea and that there was a significant amount of sea ice present. So, we use the NSIDC Data Pool FTP site to download the two MOD29 granules acquired on January 24, 2001 at 1635 and 1640 that appear to cover the Ross Sea.

The FTP directory ftp://n4ftl01u.ecs.nasa.gov/SAN/MOST/MOD29.005/2001.01.24/ contains the MOD29 granules for January 24, 2001. Navigate to this directory with a browser and download the following MOD29 granules to the ms2gt/tutorial_4 folder on your computer:


  • MOD29.A2001024.1635.005.2006348094037.hdf
  • MOD29.A2001024.1640.005.2006348091732.hdf

Creating the mod29.pl Command File

Create a text file in the tutorial_4 directory called wross_2001024_1635.csh containing the following line:

mod29.pl . wross_2001024_1635 listfile.txt WRoss1km.gpd 1234

This command specifies the following information (see mod29.pl):

Parameter Value Description
dirinout "." The current directory will contain the input and output files when wross_2001024_1635.csh is invoked.
tag wross_2001024_1635 All output filenames containing gridded data created by mod29.pl will begin with the string "wross_2001024_1635".
listfile listfile.txt The text file contains a list of the MOD29 files to process. (See Creating the listfile.)
gpdfile WRoss1km.gpd The gdp file contains a specification of the grid and the associated map projection to use in gridding the data. (See Creating the gpd and mpp files.)
chanlist 1234 The text file specifies that all the MOD29 "channels" should be gridded.
latlonlistfile not specified The default value of "none" is used indicating that the 5 km latlon data in the MOD29 files should be used for geolocation.
keep not specified The default value of "0" is used, which indicates that intermediate chan, lat, lon, col, and row files are deleted.
rind not specified The default value of "50" is used. If you see holes in the final grid that seem to correspond to the boundaries between adjacent swath granules, then you can try increasing the rind value.

Make wross_2001024_1635.csh executable by typing:

chmod +x wross_2001024_1635.csh

Creating the listfile

Create a text file called listfile.txt in the tutorial_4 directory containing the following two lines:

MOD29.A2001024.1635.005.2006348094037.hdf
MOD29.A2001024.1640.005.2006348091732.hdf

Note that we list the MOD29 files to be gridded.

Creating the gpd and mpp files

See Points, Pixels, Grids, and Cells: A Mapping and Gridding Primer for a description of the gpd and mpp file formats used by the mapx library in defining a grid and its associated map projection. In Tutorial 3, we created gpd and mpp files from scratch, but we required an exact location for the center of the grid. Here we do something similar, but we specify an exact location for the center of the upper left cell. Start with creating the mpp file called S_stereo.mpp, in the ms2gt/grids directory (or copy S_stereo.mpp from the ms2gt/tutorial_4 directory to the ms2gt/grids directory):

Polar Stereographic ellipsoid
-90.0 0.0 -71.0 lat0 lon0 lat1
180.0           rotation
100.0           scale (km/map unit)
-90.00  0.00    center lat lon
-90.00  -20.00  lat min max
-180.00 180.00  lon min max
 10.00 15.00    grid
0.00    0.00    label lat lon
1 0 0           cil bdy riv
6378.137        Earth equatorial radius (km) -- wgs84
0.081819190843  eccentricity -- wgs84

  • The first line specifies the projection we wish to use: Polar Stereographic. Since we specify ellipsoid, an ellipsoidal projection is used.
  • The first two values on the second line specify the map projection origin: the south pole. The third value specifies the latitude of true scale to be 71 S.
  • The third line specifies the rotation: 180 degrees. This will produce a map with the vertical axis of the grid pointing due north towards the top of the grid and parallel to 180 E.
  • The fourth line specifies an arbitrary scale for the map as opposed to the grid, which will be defined by the gpd file as grid cells per map unit. Here we define a map unit to be 100 km.
  • The fifth line specifies the center of the map, which is usually (but not necessarily) the map projection origin. Here we simply set it equal to the map projection origin: the south pole.
  • The next five lines (the sixth through tenth lines) specify parameters that would be useful to programs that produce graphic overlays. Refer to the Points, Pixels, Grids, and Cells: A Mapping and Gridding Primer document. They are not used by the MS2GT software, but they are present in the mpp file as place holders.
  • The eleventh line, if present, specifies the equatorial radius to use instead of the default 6371.228 km. Here we specify 6378.137 km, which is the equatorial radius of the WGS84 ellipsoid.
  • The twelfth line, if present, specifies the eccentricity to use for ellipsoidal projections instead of the default 0.082271673. Here we specify 0.081819190843, which is the eccentricity of the WGS84 ellipsoid.

In preparing the gpd file that defines the grid, we need to know following:

  • The name of the mpp file that will define our map: S_stereo.mpp.
  • The number of columns and rows. We don't know these yet, but we can calculate approximate values for both in the following way:
    • There are about 40000 km / 360 degrees = 111 km/deg in longitude at the equator or in latitude anywhere.
    • We want our grid to have 1 km per cell.
    • We need to span about 35 degrees in longitude (165 E to 160 W) at about 75 S. This works out to about 35 deg * cos(-75 deg) * 111 km/deg / (1 km/cell) = 1006 cells in longitude = 1006 columns.
    • We need to span about 9 degrees in latitude (70 S to 79 S). This works out to about 9 deg * 111 km/deg / (1 km/cell) = 999 cells in latitude = 999 rows.
    • These are only approximate values. We will determine exact values below.
  • The number of grid cells per map unit. This is equal to 100 km/map unit / (1 km/cell) = 100 cells/map unit
  • The grid cell coordinates of the center of the map. Since we want the center of the upper left cell to be at exactly 70 S 165 E, we will initially make the grid cell coordinates of the center of the map to be 0 0 (i.e. the south pole). Then we use gtest to determine the coordinates of 70 S 165 E. We will then set the grid cell coordinates of the center of the map to be the negative of these coordinates determined by gtest.

We now have all the information we need to create a preliminary gpd file called WRoss1km0.gpd in the ms2gt/grids directory (or copy WRoss1km0.gpd from the ms2gt/tutorial_4 directory to the ms2gt/grids directory):

S_stereo.mpp    map projection parameters       # Western Ross Sea
1006    999     columns rows                    # preliminary values
100             grid cells per map unit         # 1 km
0       0       origin column, row              # origin south pole initially

Once WRoss1km0.gpd has been created in the ms2gt/grids directory, use gtest to determine the negative grid coordinates of the center of the map:

gtest

enter .gpd file name: WRoss1km0.gpd
> assuming old style fixed format file

gpd: WRoss1km0.gpd
mpp:S_stereo.mpp

forward_grid:
enter lat lon: -70 165
col,row = -567.976929 -2119.718262    status = 0
lat,lon = -70.000000 164.999985    status = 1
enter lat lon:

inverse_grid:
enter r s:

enter .gpd file name:

You can see that the grid cell coordinates of the center of the map should be column 567.976929 and row 2119.718262. Edit WRoss1km0.gpd to create WRoss1km1.gpd in the ms2gt/grids directory with the above values (or copy WRoss1km1.gpd from the ms2gt/tutorial_4 directory to the ms2gt/grids directory):

S_stereo.mpp    map projection parameters       # Western Ross Sea
1006    999     columns rows                    # preliminary values
100             grid cells per map unit         # 1 km
567.976929 2119.718262     origin column, row

We still have only approximate values for the number of columns and rows. We use gtest again, this time with WRoss1km1.gpd, to find the grid coordinates of 79 S 160 W, which is close to the center of our lower right cell, and we'll use these grid coordinates to determine the final number of columns and rows for our grid:

gtest

enter .gpd file name: WRoss1km1.gpd
> assuming old style fixed format file

gpd: WRoss1km1.gpd
mpp:S_stereo.mpp

forward_grid:
enter lat lon: -79 -160
col,row = 977.960999 993.297119    status = 1
lat,lon = -79.000000 -160.000000    status = 1
enter lat lon:

inverse_grid:
enter r s:

enter .gpd file name:

So we see that our grid should have round(977.96099) + 1 = 979 columns and round(993.297119) + 1 = 994 rows. Edit WRoss1km1.gpd to create the final gpd file which we'll call WRoss1km.gpd in the ms2gt/grids directory where we have replaced the preliminary numbers of columns and rows with the values 979 and 994, respectively (or, if you don't want to type it in, copy WRoss1km.gpd from the ms2gt/tutorial_4 directory to the ms2gt/grids directory):

S_stereo.mpp    map projection parameters       # Western Ross Sea
979     994     columns rows                    # Polar Stereographic
100             grid cells per map unit         # 1 km
567.976929 2119.718262     origin column, row

We now use gtest a third and final time to check that the upper left and lower right corners of WRoss1km.gpd are where they should be:

gtest

enter .gpd file name: WRoss1km.gpd
> assuming old style fixed format file

gpd: WRoss1km.gpd
mpp:S_stereo.mpp

forward_grid:
enter lat lon:

inverse_grid:
enter r s: 0 0
lat,lon = -70.000000 164.999985    status = 1
col,row = -0.000488 0.000000    status = 1
enter r s: 978 993
lat,lon = -78.997337 -160.003098    status = 1
col,row = 977.999878 993.000488    status = 1
enter r s:

enter .gpd file name:

You can see that the upper left corner values of -70.000000 164.999985 are essentially the same as our target values of 70 S and 165 E and that the lower right corner values of -78.997337 -160.003098 are very close to our target values of 79 S and 160 W.

Running the mod29.pl Command File

Run the shell script containing the mod29.pl command by changing to the tutorial_4 directory, and then typing:

wross_2001024_1635.csh

You'll see messages display while the mod29.pl script runs various IDL and C programs.

In this example, the programs are:

  1. extract_chan - an IDL procedure for extracting channel data and optionally latlon data from a MOD29 file. This program calls another IDL procedure, modis_ice_read. In this example, extract_chan is called twelve times: six times for each of the two MOD29 files; on each call, channel 1, 2, 3, or 4 is extracted. One binary byte file is created per call containing the channel data. In addition, on the first call for each of the MOD29 files, the latitude and longitude data are extracted and two binary floating-point files are created per call, containing latitude and longitude data. The mod29.pl script concatenates the two latitude files and the two longitude files to create a single latitude file and a single longitude file, and the pre-concatenated files are deleted. The mod29.pl script concatenates each pair of channel files, creates six concatenated channel files, and then deletes the pre-concatenated channel files.
  2. ll2cr - a C program for converting latitude, longitude pairs to column, row pairs for a particular grid. The grid specified in this example is WRoss1km.gpd. The concatenated latitude and longitude files are read and two binary floating-point files are created containing column and row numbers, respectively. The mod29.pl script then deletes the concatenated latitude and longitude files.
  3. interp_colrow - an IDL procedure for interpolating column, row pairs from a lower-resolution swath format to a higher-resolution swath format, in this case from 5 km to 1 km. The interpolation must be performed on a scan's worth of data at a time because the column and row numbers have discontinuities at scan boundaries. The interp_colrow procedure calls a function called congridx for each scan's worth of column and row arrays. The congridx function is called once for the column array and once for the row array. The congridx function first performs an extrapolation of the given array to a slightly expanded array, which it then interpolates (bilinear interpolation is used here) to a fully expanded array. The final array is extracted from the fully expanded array. The mod29.pl script then deletes the pre-interpolated column and row files.
  4. fornav - a C program for performing forward navigation from a swath to a grid. In this example, fornav is called six times, once for each of the six concatenated channel files. On each call, the column and row files are read as well. An elliptical weighted maximum algorithm is applied during forward navigation to minimize holes and aliasing in the gridded data. One binary byte file (or, in the case of channel 3 Ice Surface Temperature, one binary 2-byte unsigned integer file) is created per call containing the gridded data. The mod29.pl script then deletes the concatenated channel files as well as the column and row files.

The final message should contain the string:

MOD29: MESSAGE: done

Examining the Results

Enter the command:

ls -l *.img

You should see something like this:

-rw-r--r--    1 haran    nsidc      973126 May  1 13:15 wross_2001024_1635_rawm_icer_00979_00994.img
-rw-r--r--    1 haran    nsidc      973126 May  1 13:16 wross_2001024_1635_rawm_irqa_00979_00994.img
-rw-r--r--    1 haran    nsidc      973126 May  1 13:16 wross_2001024_1635_rawm_itqa_00979_00994.img
-rw-r--r--    1 haran    nsidc     1946252 May  1 13:16 wross_2001024_1635_rawm_temp_00979_00994.img

Each of the first three files listed contains a gridded array of 979 columns and 994 rows of binary byte values (979 * 994 * 1 = 973126 bytes). The fourth file (the "temp" or Ice Surface Temperature file) contains a gridded array of 979 columns and 994 rows of binary, 2-byte unsigned values (979 * 994 * 2 =  1946252 bytes).

The file naming convention for gridded MOD29 files is as follows:

<tag>_<conversion><weight_type>_<chan>_<columns>_<rows>.img