MODIS

From MRC Centre for Outbreak Analysis and Modelling
Revision as of 16:29, 17 March 2017 by Admin (talk | contribs) (→‎C)
Jump to navigation Jump to search

About

MODIS data is collected by two satellites called Aqua (MOLA/MYD) and Terra (MOLT/MOD). Each satellite uses a 16 day period, and they are in antiphase, giving 8-day resolution. Some products are already combined into single datasets (MCD). A variety of fields are available. This document will describe the generic things about the dataset.

Getting Access

You need to sign up for a password, but after that, downloads are free. The download process is a bit tedious too, so scripting is the way. The source folders we've had reason to use are:

https://e4ftl01.cr.usgs.gov/MOLA/MYD11A2.006/ MODIS/Aqua Land Surface Temperature and Emissivity 8-Day L3 Global 1 km Grid SIN V006
https://e4ftl01.cr.usgs.gov/MOLT/MOD11A2.006/ MODIS/Terra Land Surface Temperature and Emissivity 8-Day L3 Global 1 km Grid SIN V006
https://e4ftl01.cr.usgs.gov/MOLA/MYD13A2.006/ MODIS/Aqua Vegetation Indices 16-Day L3 Global 1km Grid SIN V006
https://e4ftl01.cr.usgs.gov/MOLT/MOD13A2.006/ MODIS/Terra Vegetation Indices 16-Day L3 Global 1km Grid SIN V006
https://e4ftl01.cr.usgs.gov/MOTA/MCD12Q1.051/ MODIS Combined Land Cover Type Yearly L3 Global 500 m SIN Grid

File Format

The file format is the HDF format. More details to follow, as I discover what exactly it is and how to interpet it.


Example Code

C

Two versions of HDF seem to be common: HDF4 and HDF5. I'm not clear yet which MODIS uses when they call theirs "HDF-EOS". But anyway. There are some ready-built binary libraries for both HDF4 and HDF5 which look promising. Some linux builds, and also Windows builds in release mode, both 32-bit and 64-bit, built with Visual Studio 2013 and 2015. That's more helpful than most. So.... Here are windows instructions. If you do this for linux, tell me how and I'll add instructions.

  • Download the Library above, 64-bit, and the Visual Studio you're using, extract it, and run the installer, which unzips the library to a place of your choice. I recommend a place without spaces in the directory names - it usually makes things simpler somewhere along the lines. For this example, suppose you install it in C:\Lib\HDF.
  • Get your project open in Visual Studio, and get into Release x64 bit mode. Open a C file, so you get the right project preferences, and then...
  • Open Project Preferences - check it's still configuring 64-bit Release mode.
  • In C/C++, General, Additional Include Directories, insert C:\Lib\HDF\include; (for example)
  • In Linker, Input, Additional Dependencies, insert libxdr.lib;libszip.lib;libjpeg.lib;libzlib.lib;libmfhdf.lib;libhdf.lib; - which is a bit eye-boggling.
  • In Linker, General, Additional Library Directories, insert (for example) C:\Lib\HDF\lib;

Then, here is some very simple code to read some day-time temperature data, which we know is 1200x1200 unsigned shorts.

#include "mfhdf.h"
#pragma comment(lib, "Ws2_32.lib")

void loadFromHDF(char* file_name, char* sds_name1, void* buffer, int _nrows, int _ncols, int _dsize) {

  int32 sd_id, sds_id, sds_index, rank, data_type, n_attrs;
  int32 dim_sizes[2];
  int32 start[2];
  int32 stride[2];
  int32 edges[2];
  int32 nrows, ncols;
  char sds_name[100];
  strcpy(sds_name, sds_name1);
   
  sd_id = SDstart(file_name, DFACC_READ);
  sds_index = SDnametoindex(sd_id, sds_name);
  sds_id = SDselect(sd_id, sds_index);
  SDgetinfo(sds_id, sds_name, &rank, dim_sizes, &data_type, &n_attrs);
  nrows = dim_sizes[0];
  ncols = dim_sizes[1];
  if ((nrows != _nrows) || (ncols != _ncols)) printf("Dimensions not as expected!");
  if (_dsize != DFKNTsize(data_type)) printf("Data Type size not as expected!");
  start[0] = 0;  /* index of first row to read */
  start[1] = 0;  /* index of first column to read */
  edges[0] = dim_sizes[0];    /* the number of rows to read */
  edges[1] = dim_sizes[1];    /* the number of cols to read */
  stride[0] = 1;
  stride[1] = 1;
  SDreaddata(sds_id, start, stride, edges, (VOIDP)buffer);
  SDendaccess(sds_id);
  SDend(sd_id);
}
 
int main() {
  unsigned short* buffer = new unsigned short[1440000]; // 1200 * 1200 - get memory in advance. 
  loadFromHDF("MOD11A2.A2000065.h00v08.005.2007176172310.hdf", "LST_Day_1km", buffer, 1200, 1200, 2);
}

Citation

For the datasets we used above:-

Z. Wan, S. H., G.Hulley. (2015). MYD11A2 MODIS/Aqua Land Surface Temperature/Emissivity 8-Day L3 Global 1km SIN Grid V006. NASA EOSDIS Land Processes DAAC. https://doi.org/10.5067/MODIS/MYD11A2.006

Z. Wan, S. H., G.Hulley. (2015). MOD11A2 MODIS/Terra Land Surface Temperature/Emissivity 8-Day L3 Global 1km SIN Grid V006. NASA EOSDIS Land Processes DAAC. https://doi.org/10.5067/MODIS/MOD11A2.006

K. Didan. (2015). MYD13A2 MODIS/Aqua Vegetation Indices 16-Day L3 Global 1km SIN Grid V006. NASA EOSDIS Land Processes DAAC. https://doi.org/10.5067/MODIS/MYD13A2.006

K. Didan. (2015). MOD13A2 MODIS/Terra Vegetation Indices 16-Day L3 Global 1km SIN Grid V006. NASA EOSDIS Land Processes DAAC. https://doi.org/10.5067/MODIS/MOD13A2.006

(No specific citation for the MCD dataset)