Skip to main content

Spatial datasets operations: From MODIS HDF to Binary file

MODIS products are widely used in Earth Science, here I present some typical demos and tryouts to deal with MODIS datasets.

All the MODIS products datasets are distributed in HDF format.
To get familiar with HDF, you can go to:

MODIS land surface products usually have a different map projection than most of our projects.
Here are some information of this projection:
Therefore, a re-project is needed to convert HDF datasets to our projects.

There are quite a few tools available to operate on HDF files, but most of them are not efficient enough. You have to repeat the same set of operations. Therefore, using IDL or ArcObject based script/program is desirable.

The first step is to extract the datasets from HDF, and we also need to define the projection as exactly the same with HDF. Below is a very simple way to do so. You can use ArcMap to open one single HDF file and output the datasets as TIFF or other raster datasets formats.

Fig 1. Convert result from HDF to GeoTIFF in ArcMap 10.1.

Unfortunately, ENVI doesn't support all the MODIS product quite well so far. And the map projection cannot be read after the conversion using ArcMap, see below.

Fig 2. File viewing in ENVI 5.1 of the same file.

Even though ENVI can directly open this file, this does not mean we can open the file using ENVI/IDL
  IF FILE_TEST(filename_in) EQ 1 THEN BEGIN
        PRINT, filename_in    
        ENVI_OPEN_FILE, filename_in, r_fid = r_fid
        IF r_fid NE -1 THEN BEGIN
          ENVI_FILE_QUERY, r_fid, dims = dims, nb = nb
          pos = LINDGEN(nb)
          filename_out = year_out + !slash + prefix_out + year_str + day_str + extension_envi
          ENVI_CONVERT_FILE_MAP_PROJECTION, background = missing_value, $
            dims = dims, $
            fid = r_fid, $
            grid = [10, 10], $
            o_pixel_size = o_pixel_size, o_proj = map_info, out_name = filename_out, $
            pos = pos, $
            resampling = 0, $
            warp_method = 0
          ENVI_FILE_MNG, id = r_fid, /remove
          PRINT, 'Cannot open the file!'

For the same file, above script will print "Cannot open the file!"

A workaround method is using the GeoTIFF instead of native ENVI dat file.
You can pass either the geotag using a filename or a struct in the ENVI/IDL script.
After this, you will get a binary dat file with a header file which contains the map projection information.

The bottom line is that you can prepare individual files (for parameters) using ArcMap and run ENVI/IDL scripts on HPC. In this case, you gain both flexibility and efficiency.


Popular posts from this blog

Spatial datasets operations: mask raster using region of interest

Climate change related studies usually involve spatial datasets extraction from a larger domain.
In this article, I will briefly discuss some potential issues and solutions.

In the most common scenario, we need to extract a raster file using a polygon based shapefile. And I will focus as an example.

In a typical desktop application such as ArcMap or ENVI, this is usually done with a tool called clip or extract using mask or ROI.

Before any analysis can be done, it is the best practice to project all datasets into the same projection.

If you are lucky enough, you may find that the polygon you will use actually matches up with the raster grid perfectly. But it rarely happens unless you created the shapefile using "fishnet" or other approaches.

What if luck is not with you? The algorithm within these tool usually will make the best estimate of the value based on the location. The nearest re-sample, but not limited to, will be used to calculate the value. But what about the outp…

Numerical simulation: ode/pde solver and spin-up

For Earth Science model development, I inevitably have to deal with ODE and PDE equations. I also have come across some discussion related to this topic, i.e.,

In an attempt to answer this question, as well as redefine the problem I am dealing with, I decided to organize some materials to illustrate our current state on this topic.

Models are essentially equations. In Earth Science, these equations are usually ODE or PDE. So I want to discuss this from a mathematical perspective.

Ideally, we want to solve these ODE/PDE with initial condition (IC) and boundary condition (BC) using various numerical methods.

Because of the nature of geology, everything is similar to its neighbors. So we can construct a system of equations which may have multiple equation for each single grid cell. Now we have an array of equation…

Watershed Delineation On A Hexagonal Mesh Grid: Part A

One of our recent publications is "Watershed Delineation On A Hexagonal Mesh Grid" published on Environmental Modeling and Software (link).
Here I want to provide some behind the scene details of this study.

(The figures are high resolution, you might need to zoom in to view.)

First, I'd like to introduce the motivation of this work. Many of us including me have done lots of watershed/catchment hydrology modeling. For example, one of my recent publications is a three-dimensional carbon-water cycle modeling work (link), which uses lots of watershed hydrology algorithms.
In principle, watershed hydrology should be applied to large spatial domain, even global scale. But why no one is doing it?  I will use the popular USDA SWAT model as an example. Why no one is setting up a SWAT model globally? 
There are several reasons we cannot use SWAT at global scale: We cannot produce a global DEM with a desired map projection. SWAT model relies on stream network, which depends on DEM.…