0% found this document useful (0 votes)
128 views

Mod Is Tutorials

This document provides instructions for summarizing a MODIS and SeaDAS tutorial being held at Oregon State University. It describes loading and displaying MODIS level 2 and level 3 ocean data products in SeaDAS and IDL, including how to read HDF files, load products and quality flags, remap data, generate true color images, and perform batch processing. The tutorial will cover basic procedures for working with MODIS ocean data products using SeaDAS, IDL, and MATLAB software.

Uploaded by

Raskiban Kedung
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
128 views

Mod Is Tutorials

This document provides instructions for summarizing a MODIS and SeaDAS tutorial being held at Oregon State University. It describes loading and displaying MODIS level 2 and level 3 ocean data products in SeaDAS and IDL, including how to read HDF files, load products and quality flags, remap data, generate true color images, and perform batch processing. The tutorial will cover basic procedures for working with MODIS ocean data products using SeaDAS, IDL, and MATLAB software.

Uploaded by

Raskiban Kedung
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

Intro-1

MODIS and SeaDAS Tutorial



MODIS Data Products Workshop
September 4-5, 2003
Oregon State University

Instructor: Timothy S. Moore

This tutorial is designed to take you through a few basic procedures that are commonly
used when working with MODIS Ocean data products. Many of you may already be
familiar with SeaDAS, IDL, and Matlab. We will guide you through the steps involved
in using these programs with MODIS Ocean data. There are several steps that are unique
to MODIS Ocean data, and thus even the most experienced programmers will need to
know about these procedures.

This handout contains the following sections which we will follow in the order listed
here:

I. MODIS Oceans HDF file descriptions
II. Using SeaDAS and MODIS Oceans products
i. Load and display products.
ii. Load and display quality flags.
iii. Remapping.
iv. True Color generation.
v. Batch-mode processing

III. Using IDL and MODIS Oceans products
i. Load HDF files.
ii. Product and Quality flag display.



Intro-2
Further information may be found at the following websites:

1. An Introduction to HDF:

http://www.swa.com/meteorology/hdf/tutorial/Intro.htm

2. An Introduction to HDF-EOS:

http://www.swa.com/meteorology/hdf/tutorial/Intro_EOS.htm

3. Visualizing and Working with MODIS Ocean Data:

http://modis-ocean.gsfc.nasa.gov/tools.html

4. Level 2 Quality-Level Flags:

http://modis-ocean.gsfc.nasa.gov/qa/L2QLflags.V3.html

5. MODIS Ocean Parameters:

http://modis-ocean.gsfc.nasa.gov/parameters.html

6. Reading an HDF-EOS Swath with the New MATLAB High-Level Interface:

http://www.mathworks.com/support/author/ip/hdfeos/HDF-EOS-2000/swath.htm

7. IDL example for Filtering Level 2 Data by Quality Level:

http://modis-ocean.gsfc.nasa.gov/qualfilter/idllevel2.html

8. SIMAP, a simple MODIS-Mapper:

http://daac.gsfc.nasa.gov/MODIS/simap




I - 1
I. MODIS Data Products: File Descriptions

MODIS Level 2 data

MODIS level 2 granules are available by ordering from the Goddard DAAC (GDAAC) at
http://acdisx.gsfc.nasa.gov/data/dataset/MODIS/index.html. These granules are at 1 km
2

resolution and each contains 5 minutes of collected data.

The MODIS Oceans level 2 products are grouped together into several HDF files. The
GDAAC has recently implemented a capability to order individual products for a
prescribed geographic area and time. However, here we describe the HDF files in which
products are grouped. These are listed below. The list of products in each file are
contained in Appendix #1, and also found at:

http://modis-oceans.gsfc.nasa.gov/parameters.html and
http://picasso.oce.orst.edu/ORSOO/MODIS/code/Table11params.html

The MODIS Oceans Level 2 products are contained within the following HDF files:

MODOCL2 ! Water-leaving radiances and related products
MODOCL2A ! Ocean color group 1 products
MODOCL2B ! Ocean color group 2 products
MOD28L2 ! Sea-surface temperatures and related products
MODOCQC ! Ocean color QC products
MOD28QC ! SST QC products

MOD03 ! Geolocation level 1a file (see *NOTE 1)
MOD09 ! MODIS land products (see **NOTE 2)

*NOTE 1: MODIS Oceans Level 2 files need corresponding geolocation information
(i.e., latitude and longitude) for any remapping. This information is contained in the
MODIS Level 1A MOD03 product (MODOCQC , MOD28QC, and MOD09 also
contain lat/lon products).

**NOTE 2: This file contains atmospherically-corrected radiances for MODIS bands
1-7, generally used for land remote sensing. This file contains a number of high
resolution bands (250m and 500m) which do contain ocean radiances for coastal zones.
This file can also be used to generated true-color composites. These files are NOT
generally available from the GDAAC but can be included in a push order. They are
very large 600Mbytes per granule.

Filename convention

MODIS level 2 filenames all follow a similar convention. The breakdown is illustrated on the
following figure.

I - 2





MODIS Level 3 data

MODIS Level 3 data are available from the GDAAC (4km, 36km and 1 degree
resolution) at http://acdisx.gsfc.nasa.gov/data/dataset/MODIS/index.html and at the
MQABI site (at 36km, 1 degree res.) (http://jeager.gsfc.nasa.gov/browsetool/).


What is HDF?

HDF stands for Hierarchical Data Format. All MODIS level 2 and level 3 data are in this format.
Actually, MODIS data are in HDF-EOS format, which is more of a specialized HDF format.
This format adds new specialized data fields (Point, Swath and Grid) developed for Earth science
data. This format can still be read using regular HDF read commands as SDS (Scientific
Data Set) variables. Several of the websites listed above go into depth on HDF and HDF-EOS.
HDF can be read very easily in SeaDAS, IDL and Matlab.



MODOCL2B.A2002094.1440.004.2002291051607.HDF
year and julian day
of granule capture
MODIS product group and
processing level.
version of processing code.
hour and minute start of the 5
minute granule in GMT.
time stamp of processing
II - 1
II. SeaDAS and MODIS

SeaDAS (SeaWiFS Data Analysis System) is a software package developed and
supported by NASA that is intended to be used with ocean color satellite data. It is freely
available at http://seadas.gsfc.nasa.gov. SeaDAS is built on IDL and runs with a licensed
version of IDL. A version of SeaDAS is also available that used an imbedded IDL core and
does not require an IDL license to run. Both versions can run in Interactive and Command-line
modes, and batch mod processing. The examples that follow are prepared in Interactive mode.

Although it was originally used for SeaWiFS processing, recent upgrades have included the
ability for SeaDAS to read in MODIS level 2 data, display MODIS flags, and remap level 2
granules. It is NOT able to process MODIS data from level 1 to level 2.

NOTES:

1. The MODIS level 2 granules that will be used are in the directory
/home/jimi/scratch/workshop/images/l2.
2. The MODIS level 3 files are in /home/jimi/scratch/workshop/images/l3.


Start SeaDAS At the command prompt, launch SeaDAS by entering seadas <CR>.

Example of loading MODIS Level 3 Mapped products into SeaDAS

The files in the /home/jimi/scratch/images/l3 directory are global 4km monthly and 36km
weekly images. The 4km images are very large.


1. From the seadisp widget, select Load!MODIS Oceans Data.

2. At the MODIS Filename prompt, select
MO04MM26.chlor_a_2.ADD2001121.004.2002211074834.hdf. No geofile is
needed.

3. Set the Pixel Sample Rate and the Line Sample Rate to 4 computer memory isnt
large enough for the full 4km resolution. Setting these to 1 will load the entire
4km global image, but will cause these computers to grind to a halt.

4. Select the chlor_a_2_mean product - the only one (see *NOTE 1), and load it in.
5. To load a color palette, hit the Functions button on this window, and go down to
the Color LUT!Load Color. A window appears with a variety of color palettes.
I recommend either the RAINBOW palette (13
th
in the list), or Miamis palette
Rainbob which is second to last. Once youve highlighted a palette, you need to
hit the apply button for the palette to take effect in the image window.
II - 2
6. The initial look of the image will not be correct when you first display it. The
data needs to be rescaled. To do this, go to the Setups ! Rescale option of the
window with the level 3 image.
7. For Scale Type, select Log. The Scale Min value of 0.01 is good, but the Max
value can be adjusted. Try 65.0, and hit Redisplay.
8. Repeat steps 2-4 to view other products. When two windows are open, they will be
displayed with the same color palette. Theres a way to display two separate color
palettes but that is beyond the scope of this exercise.

*NOTE 1: MODIS Oceans Level 3 products are found in individual files. Thus, there
is only one product per level 3 HDF file.


Example of loading MODIS Level 2 products in SeaDAS

All MODIS product groups can be read into SeaDAS. There are several ways to
get them in. Since they are in HDF format, they can be read in as HDF files. However,
SeaDAS has a special option for reading in MODIS Ocean level 2 granules, which this
example will demonstrate.


1. From the SeaDAS Main Menu widget, select Display!seadisp. The seadisp
widget will appear.

2. From the seadisp widget, select Load!MODIS Oceans Data. Another widget
appears.

3. For the MODIS Filename prompt, select the file
MODOCL2B.A2000294.1600.004.2002259014241.hdf.

4. For the Geolocation Filename, select the file
MOD03.A2000294.1600.004.2003035164647.hdf (see *NOTE 1).

5. Set the Pixel Sample Rate and the Line Sample Rate to 1.


6. Select the chlor_a_2, chlor_a_3, and quality products and then hit the Load
button (see **NOTE 2).

7. A new window appears this is the Band List Selection window which will list
any products loaded into SeaDAS. To display the chlor_a_2 product, highlight it
in the list and then hit the Display button at the bottom of this widget.

II - 3
8. A new window appears with the image in a gray scale. You may need to scroll
around to find familiar features. To expand the window, drag the corner very
slowly!

9. To load a color palette, hit the Functions button on this window, and go down to
the Color LUT!Load Color. A window appears with a variety of color palettes.
I recommend the RAINBOW palette (13
th
in the list). Once youve highlighted a
palette, you need to hit the apply button for the palette to take effect in the image
window.

10. To load a coastline or land mask, go to the Setups button at the top of the image
window. Hit either the Coastline or Land Mask button. A new widget will
appear with a few options. To generate a decent coastline coastline or landmask,
make sure the CIA DB Resolution is set to High (~1km). You can set the
color, line thickness, and other parameters in this window to your choosing. Using
the High resolution database can take a few minutes for coastline or landmask
generation, so proceed at your own risk.

11. The coastline and landmask are actually displayed in a separate plane and are not
part of the image. All graphics generated within SeaDAS are placed in this plane.
To clear the coastline, landmask, or any other graphics, go to the Functions
button on the image window, and select Graphics Control ! Erase All. This
will clear the entire graphics plane without affecting the image itself.

*NOTE 1: MODIS Oceans Level 2 files have geolocation information saved in a
separate file the MOD03 files. These need to be loaded as separate files in SeaDAS
for anything to do with georeferencing (e.g., coastline placement or image re-
mapping).

**NOTE 2: Many Widgets (or Windows) will remain open in SeaDAS after you have
used them. You can Quit any of these after use to reduce the clutter on the
computer screen.



II - 4
Quality flags

Quality flags can be displayed in SeaDAS. All MODIS Quality products have a
value of 0, 1, 2 or 3. In general, the quality levels are described as follows:

0 good
1 questionable
2 cloud
3 bad


Example of Quality Flag display in SeaDAS



1. From the seadisp widget, select Load!MODIS Oceans Data.

2. Hit the first Select button for the MODIS Filename, and select the granule
MODOCL2B.A2000294.1600.004.2002259014241.hdf, and hit the Ok
button.

3. Hit the second Select button for the Geolocation Filename, and select the
granule MOD03. A2000294.1600.004.2003035164647.hdf, and hit the Ok
button.

4. Set the Pixel Sample Rate and the Line Sample Rate to 1.

5. Select the chlor_a_3 and quality products and then hit the Load button.

6. Display the chlor_a_3 product from the Band List Selection window.

7. From the seadisp widget, select Functions!MODIS Quality Flags Display. A
new window appears.

8. You can select from here which quality flags to display in a window with an
image. The data will be sent to the graphics plane. To show where Quality 1
pixels are located, slide the top bar to the band number of the quality flags found
in the Band List Selection (i.e., it is the number to the left of the quality
product).


9. Slide the next bar to the window number containing the chlor_a_3 image, and
Load the image.

10. To display other quality flags, select those from the list and hit Load (see
*NOTE 1).

II - 5
*NOTE 1: In order to load individual flags without displaying any previously loaded
flag, flags must be cleared. This is done by selecting Flag Function Menu! Clear
All Flags from the MODIS Quality Flags Display window.



Remapping

The products of MODIS Oceans Level 2 granules can be remapped to a variety of
projections using SeaDAS. Remapping transforms the original image from satellite
view to a standardized projection. This allows for images from different granules to be
composited, or granules from different days to be put into the same projection. This
example takes you through an interactive session, but this type of activity is well suited
for batch-mode processing.

Example of Remapping MODIS images in SeaDAS


1. Load the chlor_a_2 product in as illustrated in the Loading in Products
example above (skip this if youve already loaded it into SeaDAS).

2. Load the sst product from the MOD28L2 product group.

3. From seadisp widget, select Functions!Projection. A new window appears.

4. From this window, highlight the chlor_a_2 and sst products in the
Selection list at the top (it will automatically be placed in the Selected for
Projection list).

5. Under Map Projection Inputs, set the following values:

a. Projection ! Conic (Lamberts)
b. Center Lat ! 40.0
c. Center Lon ! -70.0
d. Rotation ! 0.0
e. Standard Parallels ! 36.1667, 43.833 (into separate fields)


6. Click the No option for Automatically load defaults line.

7. Select the Set Scale option, and set the Scale to 5.0028125e+06.

8. Set the output size to 1300 x 1300.

9. Hit the Go button this will take a few minutes.
II - 6

10. A new image should eventually appear in the Band List Selection window.

11. Display it, and check it out.


True color generation

True color composite images can be generated by assigning radiance bands as
Red, Green and Blue intensities. These can assigned using level 1b or level 2 data. Here
we will use the MOD09 file (a MODIS Land product) and the MODOCL2 file to
generate true color composites. The advantage of using MOD09 is that you get clouds
and land in the true color scene, whereas with MODOCL2 these are masked out in the
level 2 processing and you are dealing only with radiances from the water pixels. Also,
atmospheric effects are removed using the MODOCL2 file, while some atmosphere is
retained in the MOD09 file.

Example of True Color Generation from MOD09


1. Using Seadisp! Load ! HDF, open
MOD09.A2000294.1600.003.2002197194557.hdf.

2. Select Band 1, 3, and 4 (1km or 500m), and hit load.

3. Bring up the Seadisp!Load!True Color widget.

4. Select the Band List option at the top.

5. Enter the Band number from the Band List Selection as follows:
R band = Reflectance Band 1
G band = Reflectance Band 4
B band = Reflectance Band 3

6. Enter the following numbers for the slope and intercept fields:
Band Slope Intercept
R 4 5
G 4 40
B 4 1

7. Hit Load.

8. A new image will appear in the Band List Selection. Display the image.

9. These numbers may have to be adjusted to get what you think is a correct
looking RGB. Adjust the slope and intercept values, and hit the Go button
II - 7
to generate new RGB images. Let me know if come up with any magic
combination.




Example of True Color Generation from MODOCL2


Repeat steps, except load MODOCL2.A2000294.1600.004.2002259014240.hdf in
step 1, and in step 4, designate nLw_665 (Red), nLw_551 (Green), and nLw_412
(Blue). Start with values of 50 for the Slope and 10 for the Intercept, and
experiment from there.



Batch processing in SeaDAS

Remapping MODIS images using SeaDAS can be done in batch-mode. Batch-
mode processing requires a licensed installation of IDL. Batch-mode programs can be
run from a shell command line, or as an automated cron job. The example that follows
and the routines provided can be setup to run from either.

In this example, select MODIS Level 2 products (i.e., chlor_a2, OCL2B quality,
and SST) to be remapped to a defined projection. The following files in the batch
directory used for the batch job are:

" do_modis_remap1 - starts seadas in batch mode and executes do_modis_remap2
" do_modis_remap2 - compiles and runs inside SeaDAS do_modis_remap3
" do_modis_remap3 - executes the l2_modis_remaps.pro routine

" l2_modis_remaps.pro the control program for remapping MODIS L2 granules.
This routine calls l2_remaps_modis_ocl2b.pro, l2_remaps_modis_sst.pro,
l2_remaps_modis_qual_flags.pro.

" l2_remaps_modis_ocl2b.pro this routine remaps the chlor_a2 product from the
MODOCL2B group to the specified projection. It will generate a composite
remap from the given input files, and save this to a new hdf file. Other products
from this group to be remapped can be added in this file.

" l2_remaps_modis_sst.pro this routine remaps the sst product from the
MOD28L2 group to the specified projection. It will generate a composite remap
following the same granules used in l2_remaps_modis_ocl2b.pro, which is
appended to the same output hdf file. Other products from this group to be
remapped can be added in this file.

II - 8
" l2_remaps_modis_qual_flags.pro this routine remaps the quality flags from
the MODOCL2B group to the specified projection. It will generate a composite
remap from the given input files.

" l2_remaps_modis_mod09.pro this routine remaps bands 1, 3, and 4 at 1km from
the MOD09 group to the specified projection. It will generate a composite remap
from the given input files. These bands can be used to generate true color images.



1. To run the batch job, at a command prompt type do_modis_remap1 from the batch
directory.

2. You can run seadas to check out the output images by loading them in as SeaDAS
Mapped images using Seadisp!Load.





III - 1
III. Reading MODIS files in IDL

Reading MODIS Oceans products (Level 2 and Level 3) into IDL is relatively
simple with the 2 IDL routines provided, which are found on the website Visualizing
and Working with MODIS Ocean Data. http://modis-ocean.gsfc.nasa.gov/tools.html.
In the following example, you will be using these 2 routines to read in MODIS products,
display the images, and use quality flags to extract and plot data. These routines can be
used to read any of the MODIS products and any Level 2 quality flag. Check the web
page for more in-depth information.

Start I DL - Launch IDL by typing idlde from a shell window (NOTE: SeaDAS must not
be running for IDL to launch!).

Example of Reading in products with the Get_SDS function in IDL



1. Define the filename and input directory:

IDL> fname = MODOCL2B.A2000294.1600.004.2002259014241.hdf
IDL> l2dir = /home/jimi/scratch/workshop/images/l2/

2. Load the chlor_a2 data:

IDL> chlor_a2=Get_SDS(l2dir+fname,chlor_a_2)

3. Load the Rainbow color palette:

IDL> loadct, 13

4. Since products are stored as integers in the MODIS HDF files, they must be
converted to floating point values using a translation stored as a Slope and
Intercept value in the HDF file. These values are obtained as follows:

IDL> Get_HDFMeta,l2dir+ fname, chlor_a_2, units, slope, int, equation,
date, prodtime <CR>

5. Translate chlor_a2 integer array into floating point values and reverse the image
(see *NOTE 1).

IDL> chlor_a2 = float(reverse(chlor_a2,2))*slope + int

6. Display the image using the scroll_window routine (see **NOTE 2):

IDL> scroll_window, chl2gry(chlor_a2)

III - 2
* NOTE 1: IDL reads in MODIS hdf images in reverse order.

** NOTE 2: Images can only be displayed as byte arrays. The chl2gry function
translates the image from floating point values to byte values (= 0-255).




Example of Reading in Quality flags using the Bit function in IDL


1. Load the quality byte for the Group 2 Level 2 product (see *NOTE 1):

IDL> quality_ocl2b = Get_SDS(l2dir+fname,quality)

2. The quality flag bit pairs are described on the website Level 2 Quality Flag
Levels. The chlor_a2 quality flags are stored in bits 7 and 8. To access these
bits, use the bit function:

IDL> qual_chlor_a2 = bit(quality_ocl2b,7,2)

The 7 indicates the bit position, and the 2 indicates the number of bits to
extract. This function returns a longword (4 bytes). However, the values
returned are 0, 1, 2 and 3.

3. Reverse the qual_chlor_a2 image and transform it from a longword to a byte:

IDL> qual_chlor_a2 = byte(reverse(qual_chlor_a2,2))

4. Load quality color palette:

IDL> loadct, 56

5. Use the scroll_window routine again to display the image:

IDL> scroll_window,qual_chlor_a2

Color code:

Quality 0: Green
Quality 1: Blue
Quality 2: Red
Quality 3: Black

III - 3
*NOTE 1: The product groups MODOCL2, MODOCL2B, and MOD28L2 each
have a 1-byte quality flag structure. The product group MODOCL2A has a 4-byte
quality flag structure.


Example of mapping L2 image data


This example uses the map_L2 routine from Miami (contained in mocean_l2_map.pro),
and maps a level 2 granule product to a global map. It also displays data associated
with a given quality level.


1. Create some shortcut string arrays for filenames:

IDL> focl2b= MODOCL2B.A2000294.1600.004.2002259014241.hdf
IDL> fgeo= MOD03. A2000294.1600.004.2003035164647.hdf

2. Compile the IDL program file containing map_L2:

IDL> .run mocean_l2_map.pro

3. Call the map_L2 routine to map the chlor_a2 product, with quality=0 data,
within the range of 0 and 3:

IDL> map_L2, l2dir+focl2b, l2dir+fgeo, chlor_a_2, 1, 0.0, 3.0



Example of using Level 3 products with the Get_SDS and Bit functions in IDL



1. Define the filenames:

IDL> fname1 = MO04MM26.chlor_a_2.ADD2001121.004.2002211074022.hdf
IDL> fname2 = MO04QM26.chlor_a_2.ADD2001121.004.2002211074542.hdf
IDL> l3dir = / home/jimi/scratch/workshop/images/l3/

2. Load the chlor_a2 and quality flag products:

IDL> chlor_a2_l3=Get_SDS(l3dir + fname1,chlor_a_2_mean)
IDL> chlor_a2_qual_l3=Get_SDS(l3dir + fname2,chlor_a_2_qual_b)

3. Get slope and intercept data, and transform the image
III - 4

IDL> Get_HDFMeta, l3dir + fname1, chlor_a_2_mean, units, slope, int,
equation


IDL> chlor_a2_l3=reverse(chlor_a2_l3*slope +int,2)
IDL> chlor_a2_qual_l3=reverse(chlor_a2_qual_l3,2)

4. Display the chlor_a2 image using the scroll_window routine:

IDL> loadct,13 ( Rainbow)
IDL> scroll_window, chl2gry(chlor_a2_l3)

5. Display the chlor_a2 quality image using the scroll_window routine:

IDL> loadct,13bin

IDL> scroll_window, chlor_a2_qual_l3





A-1
Appendix A: MODIS Files and Product Groups

Product Group Product Name

MODOCL2 nLw_412
nLw_443
nLw_488
nLw_531
nLw_551
nLw_667
nLw_678
Tau_865
Eps_78
aer_model1
aer_model2
eps_clr_water
common_flags
L2_flags
quality

MODOCL2A CZCS_pigment
chlor_MODIS
pigment_c1_total
chlor_fluor_ht
chlor_fluor_base
chlor_fluor_effic
susp_solids_conc
cocco_pigmnt_conc
cocco_conc_detach
calcite_conc
K_490
phycoeryth_conc
phycou_conc
common_flags
L2_flags
quality

MODOCL2B chlor_a_2
chlor_a_3
ipar
Arp
absorp_coef_gelb
chlor_absorb
tot_absorb_412
tot_absorb_443
tot_absorb_488
tot_absorb_531

A-2
Product Group Product Name

MODOCL2B (cont) tot_absorb_551
common_flags
L2_flags
quality

MOD28L2 sst
sst4
common_flags
L2_flags
quality


MODOCQC U_Wind
V_Wind
Pressure
Humidity
Ozone
Latitude
Longitude
SolarZenith
SolarAzimuth
SatelliteZenith
SatelliteAzimuth
nLw670
La765
Ray443
Lg865
Lf865
aer_model1
aer_model2

MOD28QC bright20
bright22
bright23
bright31
bright32
raw20
raw22
raw23
raw31
raw32
cldmsk_flags
common_flags


MODO3 Latitude

A-3
Longitude
Height
SensorZenith
SensorAzimuth
Range
SolarZenith
SolarAzimuth
Land/SeaMask
gflags
Moon Vector
L1 scan quality
Geo scan quality
orb_pos
orb_vel
Product Group Product Name

MODO3 (cont) attitude_angles
sun_ref
impulse_enc
impulse_time
Scan Type
detector_offsets

MOD09 BAND20ALBEDO
BAND20
BAND31
BAND32
1km Atmospheric Optical Depth Band 1
1km Atmospheric Optical Depth Band 3
1km Atmospheric Optical Depth Band 8
1km Atmospheric Optical Depth Band QA
1km Atmospheric Optical Depth Band CM
1 km latitude
1 km longitude
250m Surface Reflectance Band 1
250m Surface Reflectance Band 2
500m Surface Reflectance Band 1
500m Surface Reflectance Band 2
500m Surface Reflectance Band 3
500m Surface Reflectance Band 4
500m Surface Reflectance Band 5
500m Surface Reflectance Band 6
500m Surface Reflectance Band 7
1km Surface Reflectance Band 1
1km Surface Reflectance Band 2
1km Surface Reflectance Band 3
1km Surface Reflectance Band 4
1km Surface Reflectance Band 5

A-4
1km Surface Reflectance Band 6
1km Surface Reflectance Band 7
1km Surface Reflectance Band 26
500m Reflectance Band Quality
250m Reflectance Band Quality
1km Reflectance Band Quality






Matlab and MODIS

Matlab is commercial software from The Mathworks: www.mathworks.com
A useful accessory for mapping data is the Mapping Toolbox (also from The
Mathworks).

NOTE: Some of the routines used in this tutorial do not work in Matlab 5.3
R11. They do work in Matlab 6.5 R13.

Matlab has internal functions for reading HDF files. The programs
presented in this tutorial were created using these internal functions, and
have been designed specifically for loading MODIS oceans data. Should
you wish to write your own programs, information on the internal HDF
functions can be found by typing help hdf at the matlab prompt.

To start matlab, double-click on the matlab icon.

At the matlab prompt, cd to the directory containing the matlab routines:
cd c:\COAS\matlab



NOTE: These routines must be run in the order presented, without clearing
any variables. Some of the examples use data from previous examples. This
was done to save time in the tutorials.
Example 1: How to load and display MODIS level 2 data

% define the path and filename
mypath=c:\COAS\images\;
fname= MODOCL2B.A2001213.1525.004.2002197063442.hdf;

% load the chlor_a_2 data
chlor_a_2=hdfread([mypath fname],chlor_a_2);

% get the scaling equation from the HDF file
% to convert the data from raw counts to appropriate units
[name, units, slope, int, eq]=get_hdfmeta([mypath fname],chlor_a_2);

% convert the data from raw counts to appropriate units
% IMPORTANT NOTE!!!
% NOT ALL PARAMETERS HAVE LINEAR SCALING EQUATIONS
% - check the contents of the variable eq before proceeding
chlor_a_2=double(chlor_a_2)*double(slope)+double(int);

% open a figure window
figure

% load the rainbob color palette and set the colormap to it
load rainbob
colormap(rainbob)

% display the image with a colorbar
imagesc(chlor_a_2)
colorbar

% change the range of data plotted by the colormap and redraw the colorbar
imagesc(chlor_a_2,[0.001 5])
colorbar

Example 2: How to read in and display the quality flags

% load the quality bytes for the HDF file
% NOTE: MODOCL2, MODOCL2B and MOD28L2 each have a 1-byte
% quality flag structure. MODOCL2A has a 4-byte quality flag structure.
quality_bytes=hdfread([mypath fname],quality);

% pull out the bits that correspond to the quality flag of interest
% (see http://modis-ocean.gsfc.nasa.gov/qa/L2QLflags.V4.html)
% For chlor_a_2, the appropriate bits are 7 & 8.
quality_chlor_a_2=bit(quality_bytes,7,2);
% the above will extract 2 bits starting at bit 7, and will return
% an unsigned byte with values between 0 (good) and 3 (bad).

% open a new figure window
figure

% load the provided quality flag color palette and set the colormap
load quality_colormap
colormap(quality_colormap)

% display the image
image(quality_chlor_a_2)


0=green
1=blue
2=red
3=black
Example 3: How to apply the quality flags to the data

% find all the pixels with a quality of 2 or 3
myquals=find(quality_chlor_a_2 >= 2);

% copy the data to a new array (keep the original)
good_chlor_a_2=chlor_a_2;

% remove all the bad data from this new array
good_chlor_a_2(myquals)=NaN;

% open a figure window
figure

% set the colormap to rainbob
colormap(rainbob)

% display the good image with a colorbar
imagesc(good_chlor_a_2,[0.001 5])
colorbar
Example 4: How to map level 2 data
(This example requires the Mapping Toolbox)

First, we will load the two parameters: Latitude and Longitude from the
MODOCQC or MOD03 file by using hdfread twice. If using the
MODOCQC file, the lat and lon data will need to be converted from raw
counts to appropriate units, as in example 1. The code should look like:

fname=MOD03.A2001213.1525.003.2001321044045.hdf;

% load the chlor_a_2 data
lat=hdfread([mypath fname],Latitude);
lon=hdfread([mypath fname],Longitude);

% change the lat/lon data to double precision
lat=double(lat);
lon=double(lon);

% open a new figure window
figure

% set the projection to equidistant cylindrical
% (available projections can be seen by typing getm mapprojection)
axesm eqdcylin

% set the colormap
colormap(rainbob)

% set the map lat/lon limits
setm(gca,maplatlimit,[min(min(lat)) max(max(lat))]);
setm(gca,maplonlimit,[min(min(lon)) max(max(lon))]);

% plot the data and add a colorbar
surfm(lat,lon,chlor_a_2) % this takes a long time!
set(gca,CLim,[0.001 5])
colorbar(horiz)

% add coastline data to the figure
hold on; % this allows you to plot more than one thing on the same figure
plotm(coast,Color,white,Clipping,on)
Example 5: How to load and display MODIS level 3 data and quality
(This is essentially the same procedure as used for level 2 data.)

% define the path and filenames (data and quality)
l3path=c:\COAS\images\;
fname= MO36MW26.chlor_a_2.ADD2001089.004.2002186192400.hdf;
qname= MO36QW26.chlor_a_2.ADD2001089.004.2002186192356.hdf;


% load the data
chlor_a_2_l3=hdfread([l3path fname],chlor_a_2_mean);
qual_chlor_a_2_l3=hdfread([l3path qname],chlor_a_2_qual_b);

% get the scaling equation from the HDF file
% to convert the data from raw counts to appropriate units
[name, units, slope, int, eq]=get_hdfmeta([l3path
fname],chlor_a_2_mean);

% convert the data from raw counts to appropriate units
% IMPORTANT NOTE!!!
% NOT ALL PARAMETERS HAVE LINEAR SCALING EQUATIONS
% - check the contents of the variable eq before proceeding
chlor_a_2_l3=double(chlor_a_2_l3)*double(slope)+double(int);

% plot the chlor_a_2 data
figure
load rainbob
colormap(rainbob)
imagesc(chlor_a_2_l3,[0.001 1])
colorbar
title(name)

% plot the quality data
figure
load quality_colormap
colormap(quality_colormap)
imagesc(qual_chlor_a_2_l3,[0 3])
title([name : quality])
TIPS FOR BEGINNERS

To start matlab, type matlab at the command prompt (NOTE: on our
system, use matlab6).

For help on any commands, type help command (where command is the
command name) at the matlab prompt.

If a semicolon (;) is placed after a command, the results will not be
displayed. Removing the semicolon causes the results to be shown. For
example:
a=4*6;
will create a variable a, with the value 24, but will not show that on the
screen.
a=4*6
will create the same variable, and will print 24 to the screen.

To change directory, type cd path at the matlab prompt, where path is the
path you wish to change to. You can also use ls and dir.

To see a list of all of your current variables and their dimensions, type
whos.


Arrays are enclosed in square brackets. For example:
a=[1 5 2:9];
creates the array:
1 5 2 3 4 5 6 7 8 9
For a two-dimensional array, use a semicolon to indicate the next line:
a=[1 3 6; 7 9 9; 8 2 1];
Creates:
1 3 6
7 9 9
8 2 1
Arrays can be made in as many dimensions as you like.

To reference the contents of an array, use round brackets:
a(4)
is the fourth entry in array a (the first entry is a(1)). In the first array above,
this would be 3. In the second array, this would be 7. In a two-dimensional
array, the contents can also be referenced as:
a(2,1)
where the first number is the row and the second is the column (all are
numbered starting from 1). This would also return 7 for the second array
above. You can similarly reference a subset of the array:
a(1:2,2:3)
returns:
3 6
9 9

Strings can be created using single quotes:
a=this is a string;
This creates a character array. Substrings can then be referenced just like a
normal array:
b=a(2:4) % this returns the character array: his
Strings can be concatenated by combining two character arrays into one
character array:
c=[b b] % this returns the character array: hishis
Multiple strings can be put in different rows of a single array, but they must
all be the same length. For strings of varying lengths, consider using a cell
array.

The cell array lets you group matrices of different sizes and types together
into a single cell array. Cell arrays are made and referenced using curly
brackets:
c={a b};
creates a cell array containing the two arrays a and b.
c{1}
returns the first array in the cell array (a).
Cell arrays can be multidimensional.



Loops and conditions can be made using if, while, and for statements. For
more information, see the matlab help.

Comments can be made using % , for example:

% this is a comment
a=b+c; % everything after the percent sign is a comment

A series of commands can be put together into a single program. This is
just an ascii file, with the commands listed one after the other like they
would appear after the matlab prompt. The program filename must have the
extension .m. To run the program, simply type the program filename
(without the .m extension) at the command prompt. For example:

% This is a sample program.

% Blank lines will be ignored.
a=3;
b=a-1;
c=b/4 % this will print the value of c

Save this file as sample.m. To run this file, you can either:
1 - cd to the directory where you saved the program (from within matlab),
and type sample, or
2 add the program path to the matlab path using File Set Path (from
the main matlab toolbar), and then type sample at the matlab prompt. This
last option will be saved after you exit matlab, so you can always run
programs in that folder from any directory.
The value 0.5 will print on the screen.

Functions are made similar to programs, but at the start of the program
(after any comments you may wish to include) you type:
function [a,b,c]=myfunction(input1,input2);
where the outputs will be a, b, and c, and the required inputs are input1 and
intput2. You can have as many inputs and outputs as you like (including
none). Save this function file as myfunction.m (or whatever your function is
called). To invoke the function from another program or within matlab, use:
[out1, out2, out3]=myfunction(in1,in2);
Note that the variable names do not have to match, but the correct order and
number of variables must be preserved.

To run a matlab program from the UNIX command line, type:
/path/matlab </progpath/myprogram.m >! /outpath/myoutput.log
where path is the path where matlab resides, progpath is the path where your
program (myprogram.m) resides, and outpath is where you would like the
output (the matlab screen) sent. This output file is useful for debugging.


To stop a program from running, type control-c.

To quit Matlab, type exit.

Some other useful matlab commands you may want to use:
figure (opens a figure window)
plot (for a 2-D plot)
image (for a 3-D surface plot)
set (to change figure and axis properties)
find (to find data within an array that matches your criterion)
save (to output data)
print (to output a figure as a jpeg/tiff/etc)
clear (to delete a parameter from the workspace)
close (to close figure windows)


MODIS GUI and MODIS

The MODIS GUI was designed to interactively load and display MODIS
oceans data. Matlab and the Mapping Toolbox (both from The Mathworks:
http://www.mathworks.com/) are required. The MODIS GUI is available,
along with online help, from:
http://picasso.coas.oregonstate.edu/ORSOO/MODIS/GUIhelp/.

The main features of the MODIS GUI include:
import level 2 and 3 MODIS HDF files (data, flags, and quality)
import subregions of MODIS data
choose the range of values to be plotted
map the data
zoom in or out
change figure colors/projections/labels
mask data
make histograms
make 2D plots
save data
save figures
In addition, data may be edited in the workspace and loaded into the GUI for
mapping. There is no batch processing capability at this time.



For the tutorial, the MODIS GUI code has been placed in the directory:
c:\COAS\modisgui

The MODIS data are in the directory:
c:\COAS\images

To launch the MODIS GUI, first start Matlab by double-clicking on the
Matlab icon. Then start the MODIS GUI by typing:
>> cd c:\COAS\modisgui
>> MODISGUI
Example 1: How to load and display MODIS oceans level 2 data.

1. In the upper section, Load MODIS HDF file, choose the level 2 file:
c:\COAS\images\
MODOCL2B.A2000294.1600.004.2002259014241.hdf
2. Leave the file type as level 2.
3. Leave the step size at 5. This will load every 5
th
pixel only. To
load all pixels, set this number to 1 (much slower).
4. Hit the GO button.
5. A list of all available parameters in that level 2 file will appear in a
separate window. Select chlor_a_2 and hit GO.
6. The loaded data will appear in the list in the second section (Select
loaded data to plot). The left box contains the filename and
parameter name. The middle box contains the dimensions of the
loaded data (rows x columns). The right box contains the name of the
array in the Matlab workspace, if you want to manipulate the data.
7. Make sure the data you wish to display is highlighted in the list.
8. Set the min and max values to 0.001 and 1 respectively, then hit
GO.
9. In the Make Map section, hit GO.


Example 2: How to map MODIS oceans level 2 data.

1. Follow steps 1-8 in example 1 to load the level 2 chlor_a_2 data.
2. We will now load the corresponding latitude and longitude data. In
the Load MODIS HDF file section, select the corresponding level 2
MODOCQC file:
c:\COAS\images\
MODOCQC.A2000294.1600.004.2002259014241.hdf
(You can also use the level 1b MOD03 file load it as a level 2 file.)
3. Use the same step size as before, and hit GO.
4. Select the two parameters latitude and longitude, and hit GO.
5. Two new datasets will appear in the Select loaded data to plot
section (latitude and longitude). They should have the same
dimensions as your chlor_a_2 data.
6. Make sure the chlor_a_2 dataset is highlighted in the Select loaded
data to plot list.
7. In the Make map section, hit select lat/lon.
8. In the drop-down lists, select the appropriate longitude and latitude
datasets to use, then hit GO.
9. The range of lat/lon values will appear in the Make map section.
10. In the Make map section, hit GO.

Example 3: How to load and display MODIS oceans level 3 data.

1. In the section, Load MODIS HDF file, choose the level 3 file:
c:\COAS\images\
MO04MM26.chlor_a_2.ADD2001121.004.2002211074834.hdf
2. Leave the file type as data (M,N,S) and change the step size to
1.
3. Select the region 30 to 50
o
N, -150 to -110
o
E.
4. Hit the GO button.
5. The loaded data will appear in the list in the Select loaded data to
plot section.
6. Make sure the data you wish to display is highlighted in the list.
7. Set the min and max values to 0.001 and 1 respectively, then hit
GO.
8. In the Make Map section, hit GO.

Example 4: How to mask MODIS oceans level 3 data.

1. In the section, Load MODIS HDF file, load the level 3 file:
c:\COAS\images\
MO36MW26.chlor_a_2.ADD2001089.004.2002186192400.hdf
2. Leave the file type as data (M,N,S), the step size at 5, the
region as global, and hit GO.
3. Now load the corresponding level 3 file with the data you wish to use
as a mask (F,1,2, or 3 file), such as:
c:\COAS\images\
MO36FW26.chlor_a_2. ADD2001089.004.2002186192400.hdf
This time, the file type should be flag (F,1,2,3), and a step size of
5. Hit GO.
4. Eight new datasets will appear in the list in the Select loaded data to
plot section, one for each flag in the file.
5. Make sure the data you wish to mask (the level 3 chlor_a_2 data) is
highlighted in the list.
6. Hit the apply mask button.
7. Select one or two masks to apply from the 8 flags you loaded. The
first mask is called the land mask, but it can be anything. Hit GO.
8. A new masked dataset will appear in the list. Make sure it is
highlighted.
9. In the Make Map section, hit GO.

You might also like