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 1: Gridding MODIS 1 km 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 place some MODIS 1 km Level-1B swath data covering all of Greenland into a 1.25 km north polar EASE-Grid. We want to grid reflective Channels 1 and 2, Thermal Channels 31 and 32, and Ancillary Data Channels sensor zenith and solar zenith. You will need to download MOD021KM data and the corresponding MOD03 granules (see below).

We could use just the MOD021KM data; but as the Supported Data Sets table indicates, both the ancillary and lat-lon data in MOD021KM granules are stored at 5 km resolution. We could have mod02.pl work with only the MOD021KM granules (by setting both latlon_src and ancil_src to 1), but adding the corresponding MOD03 granules minimizes interpolation error.

Note: To run this example, you will need a computer with at least 100 MB of memory and about 1 GB of free disk space.

Obtaining the Data

We know that the afternoon of June 1, 2000 was fairly clear, so we use the FTP site at the Level 1 Atmospheres Archives and Distribution System (LAADS) data pool to download two MOD021KM granules and the two corresponding MOD03 granules, that were acquired at 1445 and 1450 on June 1, 2000 and appear to cover Greenland.

The FTP directory ftp://ladsweb.nascom.nasa.gov/allData/5/MOD021KM/2000/153/ contains the MOD021KM 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_1 folder on your computer:


  • MOD021KM.A2000153.1445.005.2010038130400.hdf
  • MOD021KM.A2000153.1450.005.2010038131118.hdf

Similarly, LAADS archives the MOD03 granules you will need for the tutorial in the ftp://ladsweb.nascom.nasa.gov/allData/5/MOD03/2000/153/ directory. Navigate to this directory with your browser and download the following granules to the ms2gt/tutorial_1 folder on your computer:


  • MOD03.A2000153.1445.005.2010036180930.hdf
  • MOD03.A2000153.1450.005.2010036174722.hdf

Creating the mod02.pl Command File

In the tutorial_1 directory, create a text file and name it gl1_2000153_1445.csh. In the file, add the following two lines:

mod02.pl . gl1_2000153_1445 listfile.txt Gl1250.gpd chanfile.txt\
         ancilfile.txt 33

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 gl1_2000153_1445.
listfile listfile.txt The text file contains a list of the MOD02 files to process. See Creating the listfile.
gpdfile Gl1250.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 ancilfile.txt The text file contains a list of the ancillary parameters to grid, as well as how to process each ancillary parameter. See Creating the ancilfile.
latlon_src 3 The value indicates that for each MOD021KM file specified in the listfile, a corresponding MOD03 file is read, and the 1 km latitude and longitude data in the MOD03 file is used instead of the 5 km latitude and longitude data in the MOD021KM file.
ancil_src 3 The value indicates that for each MOD021KM file specified in the listfile, a corresponding MOD03 file is read, and the 1 km ancillary data in the MOD03 file is used instead of the 5 km ancillary data in the MOD021KM file.
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 gl1_2000153_1445.csh executable by typing:

chmod +x gl1_2000153_1445.csh>

Creating the listfile

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

MOD021KM.A2000153.1445.005.2010038130400.hdf
MOD021KM.A2000153.1450.005.2010038131118.hdf

Note that we list only the MOD021KM files to be gridded, not the MOD03 files, since we are gridding channel data as well as ancillary data. If we were gridding only 1 km ancillary data, then we would list the MOD03 files in listfile since there would be no need for reading the MOD021KM files.

Creating the gpd and mpp files

Before you Begin

To learn about gdp and mpp files used by the mapx library in defining a grid and its associated map projection, refer to the Points, Pixels, Grids, and Cells: A Mapping and Gridding Primer document.

For a description of the AVHRR Polar Pathfinder 1.25 km Northern Hemisphere EASE-Grid, see All About EASE-Grid. The grid parameter definitions file is Na1.gpd, which refers to the N200correct.mpp. These files were installed in the /ms2gt/grids directory. Note that Na1.gpd defines a 7220 column x 7220 row grid.

Using gtest to Find Column and Row Numbers for Coordinates

By consulting a map of Greenland oriented in the same way as shown in All About EASE-Grid, we determine that the upper left corner of our grid should be at about 67.70 N, 82.68 W and the lower right corner should be at about 67.41 N and 2.60 W.

The Gl1250.gpd was installed in the ms2gt/tutorial_1 directory. This file defines a region within the grid that contains Greenland. The file defines what column and row numbers in Na1.gpd have the previously defined coordinates.

The following steps will create a gpd file that we will name Gl1250.gpd. This file defines a region within the grid that contains Greenland.

An interactive program, gtest, was built during the MS2GT installation. We will use gtest to find out what column and row numbers in Na1.gpd have the previously defined coordinates. The gtest program can perform forward (lat-lon to col-row) and inverse (col-row to lat-lon) calculations given a gpd file. The following example is a transcript of a gtest session. (The bold is the text that you enter):

gtest

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

gpd: /export/data/ms2gt/grids/Na1.gpd<
mpp:/export/data/ms2gt/grids/N200correct.mpp

forward_grid:
enter lat lon: 67.70 -82.68
col,row = 1659.541626 3859.987305    status = 1
lat,lon = 67.699997 -82.680000    status = 1
enter lat lon: 67.41 -2.60
col,row = 3519.172363 5598.667480    status = 1
lat,lon = 67.410004 -2.600002    status = 1
enter lat lon:

inverse_grid:
enter r s:

enter .gpd file name:

Rounding off these column and row values, we see that:

upper left corner is at column 1660, row 3860

lower right corner is at column 3519, row 5599.

Thus, the dimensions of our region are 3519 - 1660 + 1 = 1860 columns and 5599 - 3860 + 1 = 1740 rows.

Note that the origin (in this case the north pole) of Na1.gpd is at column 3609.5, row 3609.5. Thus the origin of our region will be at 3609.5 - 1660 = column 1949.5 and 3609.5 - 3860 = row -250.5.

We now have all the information we need to create Gl1250.gpd in the ms2gt/grids directory. The text of the file is contained in Gl1250.gpd from the ms2gt/tutorial_1 directory to the ms2gt/grids directory:

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

We can view N200correct.mpp by typing:

cat $PATHMPP/N200correct.mpp
Azimuthal Equal-Area
90.0    0.0     lat0 lon0
0.0             rotation
200.5402        scale (km/pixel)
90.00   00.00   center lat lon<
0.00   90.00    lat min max
-180.00  180.00 lon min max
15.00 30.00     grid
0.00    00.00   label lat lon
0 0           cil bdy riv

Note that N200correct.mpp defines the same map projection (an Azimuthal Equal Area projection centered at the north pole with 0 degrees longitude extending straight down) in Gl1250.gpd as in Na1.gpd, and that the resolution (200.5402 km/pixel from N200correct.mpp divided by 160 grid cells per map unit =~ 1.25 km/pixel) is also the same. Once Gl1250.gpd has been created in the ms2gt/grids directory, use gtest again to check that the latitude and longitude values of the upper left and lower right corners are as expected:

gtest

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

gpd: /export/data/ms2gt/grids/Gl1250.gpd
mpp:/export/data/ms2gt/grids/N200correct.mpp

forward_grid:
enter lat lon:

inverse_grid:
enter r s: 0 0
lat,lon = 67.705200 -82.677933    status = 1
col,row = 0.000000 -0.000092    status = 1
enter r s: 1859 1739
lat,lon = 67.406090 -2.604522    status = 1
col,row = 1859.000000 1739.000244    status = 1
enter r s:

enter .gpd file name:

Note that the upper left corner (column 0, row 0) is close to 67.70N, 82.68 W, and that the lower right corner (column 1859, row 1739) is close to 67.41 N and 2.60 W.

Creating the chanfile

Create a text file in the tutorial_1 directory called chanfile.txt. Enter the following four lines in the file:

1 reflectance
2 reflectance
31 temperature
32 temperature

The lines above specify that we want four output grids to be created containing Channel 1 reflectance, Channel 2 reflectance, Channel 31 temperature, and Channel 32 temperature, 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, namely avg and 0. The weight type parameter refers to the kind of subsampling that will be employed. For data parameters that have continuous values, weighted average subsampling is best. For data parameters that have discreet values, for example coded data, maximum weighting should be used since this will not introduce any intermediate values that may not be valid codes. The fill value refers to the output value to which input data having a value of fill will be mapped. Input fill values are specified in the input hdf files.

Creating the ancilfile

Create a text file in the tutorial_1 directory called ancilfile.txt containing the following two lines:

seze scaled
soze scaled

Here we specified that we want to create two more output grids in addition to the four grids we specified in the chanfile. These grids contain sensor zenith and solar zenith, respectively. Each file consists of an array of binary floating-point numbers in degrees. Since we didn't specify weight type or fill, they are set to their default values, avg and 0, just as in chanfile.

Running the mod02.pl Command File

To run the shell script containing the mod02.pl command, change to the tutorial_1 directory, and then type:

gl1_2000153_1445.csh

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 MOD03 files. Two binary floating-point files are created per call, containing latitude and longitude data. 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 Gl1250.gpd. The concatenated latitude and longitude files are read and two binary floating-point files are created, containing column and row numbers. The mod02.pl script then deletes the concatenated latitude and longitude files.
  3. 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 eight times: four times for each of the two MOD021KM files; on each call, channel 1, channel 2, channel 31, or channel 32 is extracted, and the result is converted to reflectance (channels 1 and 2) or temperature (channels 31 and 32). One binary floating-point file is created per call, containing the channel data. The mod02.pl script concatenates each pair of channel files, creates four concatenated channel files, then deletes the pre-concatenated channel files.
  4. extract_ancil - an IDL procedure for extracting ancillary data from a MOD02 or MOD03 file. This program calls another IDL procedure, modis_ancillary_read. In this example, extract_ancil is called four times: twice for each of the two MOD03 files; on each call, sensor zenith or solar zenith is extracted, and the result is converted to degrees. One binary floating-point file is created per call, containing the ancillary data. The mod02.pl script concatenates each pair of ancillary files, creates two concatenated ancillary files, then deletes the pre-concatenated ancillary files.
  5. 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 four concatenated channel files and the two concatenated ancillary files. On each call, the column and row files are read. 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 and ancillary files as well as the 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 this:

-rw-r--r--    1 haran    nsidc     12945600 Apr 19 14:24 gl1_2000153_1445_refa_ch01_01860_01740.img
-rw-r--r--    1 haran    nsidc     12945600 Apr 19 14:24 gl1_2000153_1445_refa_ch02_01860_01740.img
-rw-r--r--    1 haran    nsidc     12945600 Apr 19 14:25 gl1_2000153_1445_scaa_seze_01860_01740.img
-rw-r--r--    1 haran    nsidc     12945600 Apr 19 14:25 gl1_2000153_1445_scaa_soze_01860_01740.img
-rw-r--r--    1 haran    nsidc     12945600 Apr 19 14:24 gl1_2000153_1445_tema_ch31_01860_01740.img
-rw-r--r--    1 haran    nsidc     12945600 Apr 19 14:25 gl1_2000153_1445_tema_ch32_01860_01740.img

Each file contains a gridded array of 1860 columns and 1740 rows of binary floating-point values (1860 * 1740 * 4 = 12945600 bytes).

The file naming convention for gridded MOD02 channel files is as follows:

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

  • <tag> is the mod02.pl tag parameter
  • <conversion> is one of the following types:
    • raw - raw (2-byte unsigned integers)
    • cor - corrected (4-byte floating-point)
    • rad - radiance (4-byte floating-point)
    • ref - reflectance (4-byte floating-point)
    • tem - temperature (4-byte floating-point)
  • <weight_type> is one of:
    • a - averaged
    • m - maximum
  • <chxx> is the channel number: ch01-ch36
  • <columns> is the number of columns in the grid
  • <rows> is the number of rows in the grid

The file naming convention for gridded MOD02 and MOD03 ancillary files is as follows:

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

  • <tag> is the mod02.pl tag parameter
  • <conversion> is one of:
    • raw - raw (2-byte signed integers except that Range is 2-byte unsigned integer and Land/SeaMask and gflags are unsigned bytes)
    • sca - scaled (4-byte floating-point) (raw values multiplied by a parameter-specific scale factor. Note that scaling factor for Height, Land/SeaMask, and gflags is 1)
  • <weight_type> is one of:
    • a - averaged
    • m - maximum
  • <ancil> is an ancilfile param code:
    • hght - Height
    • seze - SensorZenith
    • seaz - SensorAzimuth
    • rang - Range
    • soze - SolarZenith
    • soaz - SolarAzimuth
    • lmsk - Land/SeaMask (available in MOD03 only)
    • gflg - gflags
  • <columns> is the number of columns in the grid
  • <rows> is the number of rows in the grid

Geolocating the Results

Suppose you want to know the latitude and longitude of each cell in the grid defined by Gl1250.gpd. For individual cells in the grid, use gtest as described in Creating the gpd and mpp files, above. If you want to know the latitude and longitude of every cell in the grid, use a C program called gridloc that was built during the MS2GT installation. This program creates binary floating-point arrays of latitude and longitude values. You can view the usage of gridloc by typing it without any arguments:

gridloc
usage: gridloc [-pmq -o output_name] file.gpd

 input : file.gpd  - grid parameters definition file

 output: grid of signed decimal latitudes and/or longitudes
         4 byte floats by row

 option: o - write data to file output_name.WIDTHxHEIGHTxNBANDS.float
            otherwise output goes to stdout
         p - do latitudes only
         m - do longitudes only
         pm - do latitudes followed by longitudes
         mp - do longitudes followed by latitudes (default)
         q - quiet

To create latitude and longitude files for the Gl1250.gpd grid, type the following two commands:

gridloc -p Gl1250.gpd >gl1_lat_01860_01740.img
gridloc -m Gl1250.gpd >gl1_lon_01860_01740.img

Each of these commands creates a gridded array containing 1860 columns and 1740 rows of binary floating-point values. The latitude values are stored in gl1_lat_01860_01740.img and the longitude values in gl1_lon_01860_01740.img.