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 2: Gridding MODIS 250 m Level-1B Data Over Greenland Using mod02.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.

For this tutorial, we will put some MODIS 250 m Level-1B swath data covering all of Greenland into the same grid used in Tutorial 1, except that we will change the resolution of the grid from 1.25 km to 250 m. We want to grid reflective Channels 1 and 2, which are the only MODIS channels available at 250 m. We need to order MOD02QKM data. As you can see in Supported Data Sets, the lat-lon data are stored at only 1 km resolution in MOD02QKM granules. Therefore, mod02.pl will need to interpolate the 1 km lat-lon data in the MOD02QKM granules to 250 m resolution. There is no need to work with MOD03 granules because the lat-lon data are also at 1 km resolution and we're not gridding any ancillary data.

Note: To run this example, you need a machine with at least 750 MB of memory and about 1.5 GB of free disk space.

Obtaining the Data

For this tutorial we will use data from the same date and time as in Tutorial 1, except from MOD02QKM granules instead of MOD021KM and MOD03. We will use the FTP site at the Level 1 Atmospheres Archives and Distribution System (LAADS) data pool to download two MOD02QKM granules acquired on June 1, 2000 at 1445 and 1450 that appear to cover Greenland.

The FTP directory ftp://ladsweb.nascom.nasa.gov/allData/5/MOD02QKM/2000/153/ contains the MOD02QKM data granules for Julian day 153 (June 1) of the year 2000. Navigate to this directory with a browser and download the following granules to the ms2gt/tutorial_2 folder on your computer:


  • MOD02QKM.A2000153.1445.005.2010038130400.hdf
  • MOD02QKM.A2000153.1450.005.2010038131118.hdf

Creating the mod02.pl Command File

In the tutorial_2 directory, create a text file named gl250_2000153_1445.csh, and add the following line:

mod02.pl . gl250_2000153_1445 listfile.txt Gl0250.gpd chanfile.txt none Q

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

Parameter Value Description
dirinout "." The current directory will contain the input and output files when gl1_2000153_1445.csh is invoked.
tag gl1_2000153_1445 All output filenames containing gridded data created by mod02.pl will begin with the string gl250_2000153_1445.
listfile listfile.txt The text file contains a list of the MOD02 files to process. See Creating the listfile.
gpdfile Gl0250.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.
chanfile chanfile.txt The text file contains a list of the channels to be gridded, and specifies how to process each channel. See Creating the chanfile.
ancilfile none The text file contains a list of the ancillary parameters to grid, as well as how to process each ancillary parameter. (No ancillary files are processed in this tutorial.)
latlon_src Q The value indicates that the 1-km latitude and longitude data in the MOD02QKM files should be used.
ancil_src not specified Since the value for ancilfile is none, ancil_src is ignored.
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 gl250_2000153_1445.csh executable by typing:

chmod +x gl250_2000153_1445.csh

Creating the listfile

In the tutorial_2 directory, create a text file called listfile.txt, and add the following two lines:

MOD02QKM.A2000153.1445.005.2010038130400.hdf
MOD02QKM.A2000153.1450.005.2010038131118.hdf

Note that we list the MOD02QKM files to be gridded.

Creating the gpd and mpp files

Let's review the Gl1250.gpd file we created in Tutorial 1:

N200correct.mpp map projection parameters       # EASE-Grid
1860 1740       columns rows                    # Greenland
160             grid cells per map unit         # 1.25 km
1949.5  -250.5  map origin column,row

Now we want to create a Gl0250.gpd that will specify the same grid, but at 250-m resolution rather than 1.25-km resolution. The mpp file will be the same (N200correct.mpp).

Note that 1250 / 250 = 5, so the number of columns and rows in Gl0250.gpd will be 5 * 1860 = 9300 columns.

5 * 1740 = 8700 rows.

The grid cells per map unit will be 5 * 160 = 800.

The map origin column will be 5 * (1949.5 + 0.5) - 0.5 = 9749.5

The map origin row will be 5 * (-250.5 + 0.5) - 0.5 = -1250.5.

We now have all the information we need to create Gl0250.gpd in the ms2gt/grids directory. If you don't want to re-recreate the file, just copy Gl0250.gpd from the ms2gt/tutorial_2 directory to the ms2gt/grids directory:

N200correct.mpp map projection parameters       # EASE-Grid
9300 8700       columns rows                    # Greenland
800             grid cells per map unit         # 250 m
9749.5  -1250.5 map origin column,row

Once Gl0250.gpd has been created in the ms2gt/grids directory, we can use gtest to check that the latitude and longitude values of the upper left and lower right corners match those in Gl1250.gpd:

gtest

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

gpd: /hosts/snow/AVHRR/pathfinder/grids/Gl1250.gpd
mpp:/hosts/snow/AVHRR/pathfinder/grids/N200correct.mpp

forward_grid:>
enter lat lon:

inverse_grid:
enter r s: -0.5 -0.5
lat,lon = 67.700233 -82.694237    status = 1
col,row = -0.500000 -0.499863    status = 1
enter r s: 1859.5 1739.5
lat,lon = 67.400612 -2.589502    status = 1
col,row = 1859.500000 1739.500000    status = 0
enter r s:

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

gpd: Gl0250.gpd
mpp:/hosts/snow/AVHRR/pathfinder/grids/N200correct.mpp

forward_grid:
enter lat lon:

inverse_grid:
enter r s: -0.5 -0.5
lat,lon = 67.700233 -82.694237    status = 1
col,row = -0.500000 -0.499390    status = 1
enter r s: 9299.5 8699.5
lat,lon = 67.400612 -2.589502    status = 1
col,row = 9299.500000 8699.500000    status = 0
enter r s:

enter .gpd file name:

Note that we used -0.5 -0.5 to specify the upper left corner of the upper left pixel (rather than <0 0, which would be the center of the upper left pixel) for both Gl1250.gpd and Gl0250.gpd, and that the resulting latitude and longitude values were the same: 67.700233 N and 82.694237 W.

Similarly, we used 1859.5 1739.5 for the lower right corner of the lower right pixel for Gl1250.gpd and 9299.5 8699.5 for the lower right corner of the lower right pixel for Gl0250.gpd, and that the resulting latitude and longitude values were the same: 67.400612 N and 2.589502 W.

Creating the chanfile

In the tutorial_2 directory, create a text file called chanfile.txt, and add the following two lines:

1 reflectance
2 reflectance

Here we specify that we want two output grids to be created. The grids contain Channel 1 and Channel 2 reflectance, respectively. Each file will consist of an array of binary floating-point numbers. Since we didn't specify weight type or fill, they are set to their default values, avg and 0.

Running the mod02.pl Command File

Run the shell script containing the mod02.pl command by changing to the tutorial_2 directory, and typing:

gl250_2000153_1445.csh

You'll see messages display while the mod02.pl script runs various IDL and C programs. In this example, the programs include:

  1. extract_latlon - an IDL procedure for extracting latitude and longitude data from a MOD02 or MOD03 file. This program calls another IDL procedure, modis_ancillary_read. In this example, extract_latlon is called twice, once for each of the two MOD02QKM files. Two binary floating-point files are created per call containing latitude and longitude data, respectively. The mod02.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.
  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 Gl0250.gpd. The concatenated latitude and longitude files are read and two binary floating-point files are created containing column and row numbers, respectively. The mod02.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 1 km to 250 m. 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 (bicubic interpolation is used here) to a fully expanded array. The final array is extracted from the fully expanded array. The mod02.pl script then deletes the pre-interpolated column and row files.
  4. extract_chan - an IDL procedure for extracting channel data from a MOD02 file. This program calls another IDL procedure, modis_level1b_read. In this example, extract_chan is called two times, once for each of the two MOD02QKM files; on each call, channel 1 or channel 2 is extracted, and the result is converted to reflectance. One binary floating-point file is created per call containing the channel data. The mod02.pl script concatenates the pair of channel files, creates one concatenated channel file, and then deletes the pre-concatenated channel files.
  5. fornav - a C program for performing forward navigation from a swath to a grid. In this example, fornav is called two times, once for each of the two concatenated channel files. On each call, the interpolated column and row files are read as well. An elliptical weighted averaging algorithm is applied during forward navigation to minimize holes and aliasing in the gridded data. One binary floating-point file is created per call containing the gridded data. The mod02.pl script then deletes the concatenated channel files as well as the interpolated column and row files.

The final message should contain the string:

MOD02: MESSAGE: done

Examining the Results

Enter the command:

ls -l *.img

You should see something like the following:

-rw-r--r--    1 haran    nsidc     323640000 Apr 23 13:26 gl250_2000153_1445_refa_ch01_09300_08700.img
-rw-r--r--    1 haran    nsidc     323640000 Apr 23 13:29 gl250_2000153_1445_refa_ch02_09300_08700.img

Each file contains a gridded array of 9300 columns and 8700 rows of binary floating-point values (9300 * 8700 * 4 = 323640000 bytes).

The file naming convention for gridded channel files can be found in Tutorial 1.