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…

Lessons I have learnt during E3SM development

I have been involved with the E3SM development since I joined PNNL as a postdoc. Over the course of time, I have learnt a lot from the E3SM model. I also found many issues within the model, which reflects lots of similar struggles in the lifespan of software engineering.

Here I list a few major ones that we all dislike but they are around in almost every project we have worked on.

Excessive usage of existing framework even it is not meant to Working in a large project means that you should NOT re-invent the wheels if they are already there. But more often, developers tend to use existing data types and functions even when they were not designed to do so. The reason is simple: it is easier to use existing ones than to create new ones. For example, in E3SM, there was not a data type to transfer data between river and land. Instead, developers use the data type designed for atmosphere and land to do the job. While it is ok to do so, it added unnecessary confusion for future development a…