Tutorial 1: Gridding MODIS 1 km Level 1b Data over Greenland Using mod02.pl
Requirements
Suppose we want to put some MODIS 1 km Level 1b swath data covering all
of Greenland into a region of the same grid used by the AVHRR
Polar Pathfinder Twice-Daily 1.25 km EASE-Grid Composites. We
want to grid reflective channels 1 and 2, thermal channels 31 and 32, and
ancillary data channels sensor zenith and solar zenith. We could simply
order MOD021KM
data; however, as we can see in Supported
Data Sets, both the ancillary data and the lat-lon data are stored at
only 5 km resolution in MOD021KM
granules. We could have mod02.pl work with
only the MOD021KM
granules (i.e. by setting both latlon_src and ancil_src to 1); however
we decide to order the corresponding MOD03
granules as well in order to minimize interpolation error.
NOTE: To run this example, you'll need a machine with at least 100 MB
of memory and about 1 GB of free disk space.
Searching for the Data
Let's assume that we happen to know that the afternoon of June 1, 2000
was fairly clear, so we use the EDG
to order two MOD021KM
and the corresponding two MOD03
granules acquired on June 1, 2000 at 1445 and 1450 that appear to cover
Greenland. You can use the following values for performing the search using
the EDG:
Data Set
MODIS/TERRA CALIBRATED RADIANCES 5-MIN L1B SWATH 1KM
MODIS/TERRA GEOLOCATION FIELDS 5-MIN L1A SWATH 1KM
Search Area
Type in Lat/Lon Range:
Northern latitude: 85.0000
Southern latitude: 60.0000
Western longitude: -80.0000
Eastern longitude: 10.0000
Start Date: 2000-06-01 Time (UTC): 14:00:00
End Date: 2000-06-01 Time (UTC): 15:00:00
The search should find four granules having the following names:
MOD021KM.A2000153.1445.002.2000156075718.hdf
MOD021KM.A2000153.1450.002.2000156075717.hdf
MOD03.A2000153.1445.002.2000156061125.hdf
MOD03.A2000153.1450.002.2000156062025.hdf
Note that June 1, 2000 is day-of-year 153.
Ordering and Downloading the Data
Order and download the above files to some directory we'll call the tutorial_1
directory where you have at least 1 GB of free disk space. Note that you
can also download the *.met files that accompany the *.hdf files, but the
MS2GT software doesn't use them.
Creating the mod02.pl Command File
Create a text file in the tutorial_1 directory called gl1_2000153_1445.csh
containing the following two lines:
mod02.pl . gl1_2000153_1445 listfile.txt Gl1250.gpd chanfile.txt
\
ancifile.txt 3
3
This command specifies the following information (see mod02.pl):
-
dirinout is "." indicating that the current directory in effect when gl1_2000153_1445.csh
is invoked will contain the input and output files.
-
tag is "gl1_2000153_1445" indicating that all output filenames containing
gridded data created by mod02.pl will begin
with the string "gl1_2000153_1445".
-
listfile is "listfile.txt" containing a list of the MOD02 files to be processed
(see Creating the listfile).
-
gpdfile is "Gl1250.gpd" containing a specification of the grid and its
associated map projection to use in gridding the data (see Creating
the gpd and mpp files).
-
chanfile is "chanfile.txt" containing a list of the channels to be gridded
as well as specifying how each channel should be processed (see Creating
the chanfile).
-
ancilfile is "ancilfile.txt" containing a list of the ancillary parameters
to be gridded as well as how each ancillary parameter should be processed
(see Creating the ancilfile).
-
latlon_src is "3" indicating that for each MOD021KM
file specified in the listfile, a corresponding MOD03
file should be read, and the 1 km latitude and longitude data in the MOD03
file should be used instead of the 5 km latitude and longitude data in
the MOD021KM
file.
-
ancil_src is "3" indicating that for each MOD021KM
file specified in the listfile, a corresponding MOD03
file should be read, and the 1 km ancillary data in the MOD03
file should be used instead of the 5 km ancillary data in the MOD021KM
file.
-
keep is not specified, so the default value of "0" is used indicating that
intermediate chan, lat, lon, col, and row files should be deleted.
-
rind is not specified, so 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 might 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.002.2000156075718.hdf
MOD021KM.A2000153.1450.002.2000156075717.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 only gridding 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
See Points,
Pixels, Grids, and Cells for a description of the gpd and mpp file
formats used by the mapx library in defining a grid and its associated
map projection. See Summary
of NOAA/NASA Polar Pathfinder Grid Relationships for a description
of the AVHRR Polar Pathfinder 1.25 km Northern Hemisphere EASE-Grid whose
grid parameter definitions file is Na1.gpd
which in turn refers to N200correct.mpp
which defines the associated map projection. Both of these files are included
in the ms2gt/grids directory. Note that Na1.gpd
defines a 7220 column x 7220 row grid. We wish to create a gpd file that
we'll call Gl1250.gpd that defines a region within this grid that contains
Greenland. By consulting a map of Greenland oriented in the same way as
shown in Summary
of NOAA/NASA Polar Pathfinder Grid Relationships, 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. We would
like to know what column and row numbers in Na1.gpd
have these coordinates. To do this we can use an interactive program called
gtest that was built during the MS2GT
installation. This program can perform forward (lat-lon to col-row) and
inverse (col-row to lat-lon) calculations given a gpd file. Here is a transcript
of a gtest session that does what we want (what we type is shown in bold):
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 the upper left
corner our region is at column 1660, row 3860, and the 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 (if you don't want to type the file in, then just copy Gl1250.gpd
from the ms2gt/tutorial_1 directory to the ms2gt/grids directory):
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
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
1 0 0
cil bdy riv
Note that N200correct.mpp
is used to define 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, we can use
gtest again to check that the latitude and longitude values of the upper
left and lower right corners are about what we expect:
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 containing
the following four lines:
1 reflectance
2 reflectance
31 temperature
32 temperature
Here we 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 (i.e. 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 specify that we want two more output grids (in addition to the
four grids we specified in the chanfile) to be created containing sensor
zenith and solar zenith, respectively. Each file will consist 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, namely "avg" and "0",
just as they were in chanfile.
Running the mod02.pl Command File
Run the shell script containing the mod02.pl
command by changing to the tutorial_1 directory, and then typing:
gl1_2000153_1445.csh
You'll see lots of messages displayed while the mod02.pl
script runs various IDL and C programs. In this example, the programs include:
-
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, 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.
-
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,
respectively. The mod02.pl script then deletes
the concatenated latitude and longitude files.
-
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, and then deletes the pre-concatenated channel files.
-
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, and then deletes the pre-concatenated ancillary files.
-
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 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 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:
-
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:
-
<chxx> is he 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:
-
<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 would like to know the latitude and longitude of each cell
in the grid defined by Gl1250.gpd. For individual cells in the grid, you
can 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, you can use a C program called gridloc that was
built
during the MS2GT installation. This program can create 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
So 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.
Last updated: May 31, 2001 by
Terry Haran
NSIDC-CIRES
449 UCB
University of Colorado
Boulder, CO 80309-0449
303-492-1847
tharan@colorado.edu