🔧
Working with scientific data formats in GIS
  • 📔Intro notes
  • 😃"Good" HDF
  • 😁"Good" GRIB
  • 🧐"Not-so-good" NetCDF
  • ☕Reading Sentinel-3 data
Powered by GitBook
On this page
  • Data source
  • QGIS
  • Add data to the map view
  • Check the georeference
  • Export
  • GDAL
  • gdalinfo: view metadata
  • gdalwarp: clip, reproject and save to GeoTiff
  • Batch gdalwarp
  • Metadata

"Good" HDF

Standard MODIS data usually could be easily read and processed with GIS apps

PreviousIntro notesNext"Good" GRIB

Last updated 2 years ago

Data source

/ - daily snow cover, identified using Normalized Difference Snow Index (NDSI). Files could be downloaded directly from NSIDC, or from NASA Earthdata.

For this section h15v14 tile (covering South Georgia) was used.

Files were downloaded from Earthdata with wget. For this reason, the folders structure is the following: MOD10A1/n5eil01u.ecs.nsidc.org/DP4/<sensor code>/<product code>/<YYYY.MM.DD>/<filename>

QGIS

Add data to the map view

This window appears after adding an hdf file to the map: sub-dataset selection is needed. NDSI snow cover data is stored in 'NDSI_Snow_Cover MOD_Grid_Snow_500m (8-bit unsigned integer)' sub-dataset.

Check the georeference

Data is georeferenced correctly, though QGIS doesn't know the MODIS data CRS, as it is not in the EPSG catalog.

Export

Anyway, it is possible to work with this file, for example to reproject it and export to GeoTIFF format.

GDAL

gdalinfo: view metadata

Navigate to your working folder, e.g. cd /mnt/c/my_dir/. Run gdalinfo command on one of the HDF files:

gdalinfo MOD10A1/n5eil01u.ecs.nsidc.org/DP4/MOSA/MYD10A1.061/2023.01.07/MYD10A1.A2023007.h15v14.061.2023009201030.hdf

The output contains all the metadata, but for further work, you need only a correct sub-dataset name. You will find it at the end of the output (SUBDATASET_1_NAME):

Driver: HDF4/Hierarchical Data Format Release 4
Files: MOD10A1/n5eil01u.ecs.nsidc.org/DP4/MOSA/MYD10A1.061/2023.01.07/MYD10A1.A2023007.h15v14.061.2023009201030.hdf
Size is 512, 512
Metadata:
  ...
Subdatasets:
  SUBDATASET_1_NAME=HDF4_EOS:EOS_GRID:"MOD10A1/n5eil01u.ecs.nsidc.org/DP4/MOSA/MYD10A1.061/2023.01.07/MYD10A1.A2023007.h15v14.061.2023009201030.hdf":MOD_Grid_Snow_500m:NDSI_Snow_Cover
  SUBDATASET_1_DESC=[2400x2400] NDSI_Snow_Cover MOD_Grid_Snow_500m (8-bit unsigned integer)
  SUBDATASET_2_NAME=HDF4_EOS:EOS_GRID:"MOD10A1/n5eil01u.ecs.nsidc.org/DP4/MOSA/MYD10A1.061/2023.01.07/MYD10A1.A2023007.h15v14.061.2023009201030.hdf":MOD_Grid_Snow_500m:NDSI_Snow_Cover_Basic_QA
  SUBDATASET_2_DESC=[2400x2400] NDSI_Snow_Cover_Basic_QA MOD_Grid_Snow_500m (8-bit unsigned integer)
  SUBDATASET_3_NAME=HDF4_EOS:EOS_GRID:"MOD10A1/n5eil01u.ecs.nsidc.org/DP4/MOSA/MYD10A1.061/2023.01.07/MYD10A1.A2023007.h15v14.061.2023009201030.hdf":MOD_Grid_Snow_500m:NDSI_Snow_Cover_Algorithm_Flags_QA
  SUBDATASET_3_DESC=[2400x2400] NDSI_Snow_Cover_Algorithm_Flags_QA MOD_Grid_Snow_500m (8-bit unsigned integer)  SUBDATASET_4_NAME=HDF4_EOS:EOS_GRID:"MOD10A1/n5eil01u.ecs.nsidc.org/DP4/MOSA/MYD10A1.061/2023.01.07/MYD10A1.A2023007.h15v14.061.2023009201030.hdf":MOD_Grid_Snow_500m:NDSI
  SUBDATASET_4_DESC=[2400x2400] NDSI MOD_Grid_Snow_500m (16-bit integer)
  SUBDATASET_5_NAME=HDF4_EOS:EOS_GRID:"MOD10A1/n5eil01u.ecs.nsidc.org/DP4/MOSA/MYD10A1.061/2023.01.07/MYD10A1.A2023007.h15v14.061.2023009201030.hdf":MOD_Grid_Snow_500m:Snow_Albedo_Daily_Tile
  SUBDATASET_5_DESC=[2400x2400] Snow_Albedo_Daily_Tile MOD_Grid_Snow_500m (8-bit unsigned integer)
  SUBDATASET_6_NAME=HDF4_EOS:EOS_GRID:"MOD10A1/n5eil01u.ecs.nsidc.org/DP4/MOSA/MYD10A1.061/2023.01.07/MYD10A1.A2023007.h15v14.061.2023009201030.hdf":MOD_Grid_Snow_500m:orbit_pnt
  SUBDATASET_6_DESC=[2400x2400] orbit_pnt MOD_Grid_Snow_500m (8-bit integer)
  SUBDATASET_7_NAME=HDF4_EOS:EOS_GRID:"MOD10A1/n5eil01u.ecs.nsidc.org/DP4/MOSA/MYD10A1.061/2023.01.07/MYD10A1.A2023007.h15v14.061.2023009201030.hdf":MOD_Grid_Snow_500m:granule_pnt
  SUBDATASET_7_DESC=[2400x2400] granule_pnt MOD_Grid_Snow_500m (8-bit unsigned integer)

gdalwarp: clip, reproject and save to GeoTiff

gdalwarp HDF4_EOS:EOS_GRID:"MOD10A1/n5eil01u.ecs.nsidc.org/DP4/MOSA/MYD10A1.061/2023.01.07/MYD10A1.A2023007.h15v14.061.2023009201030.hdf":MOD_Grid_Snow_500m:NDSI_Snow_Cover modis_clip_gdal.tif -t_srs epsg:3031 -cutline SouthGeorgiaExtent.shp -crop_to_cutline -tr 500 500
  • The first parameter is an input file, the sub-dataset specified as it appears in gdalinfo output: HDF4_EOS:EOS_GRID:"MOD10A1/n5eil01u.ecs.nsidc.org/DP4/MOSA/MYD10A1.061/2023.01.07/MYD10A1.A2023007.h15v14.061.2023009201030.hdf":MOD_Grid_Snow_500m:NDSI_Snow_Cover

  • The second parameter is the output file, which will be created in the working directory: modis_clip_gdal.tif

  • -t_srs tag sets output spatial reference (epsg code in this case)

  • -cutline and -crop_to_cutline tags let cropping the image to the vector file extent

  • -tr tag defines target raster resolution (x and y) in CRS specified by -t_srs

To be sure, that this file is processed correctly, add it to the map view:

Batch gdalwarp

To apply the same command to all the downloaded files, we need to amend the previous expression:

for i in MOD10A1/n5eil01u.ecs.nsidc.org/DP4/MOS*/M*D10A1.061/*/*.hdf
do
gdalwarp -t_srs epsg:3031 -cutline SouthGeorgiaExtent.shp -crop_to_cutline -te_srs epsg:3031 -tr 500 500 HDF4_EOS:EOS_GRID:"$i":MOD_Grid_Snow_500m:NDSI_Snow_Cover $i.tif
done

This command creates GeoTIFF files with the same names and the same directories as HDF files. To move them to another folder:

mkdir MOD10A1_tiff
mv MOD10A1/n5eil01u.ecs.nsidc.org/DP4/MOS*/M*D10A1.061/*/*.tif MOD10A1_tiff/

Metadata

You probably have already noticed, that the NDSI snow cover layer has 8-bit values from 0 to 250, but it is not clear what these values stand for. The answer could be found with QGIS or GDAL.

Open HDF layer properties in QGIS and in "More information" section find 'Key= 0-100=NDSI snow, 200=missing data, 201=no decision, 211=night, 237=inland water, 239=ocean, 250=cloud, 254=detector saturated, 255=fill'.

The same output you can get if run gdalinfo on a specified sub-dataset:

gdalinfo HDF4_EOS:EOS_GRID:"MOD10A1/n5eil01u.ecs.nsidc.org/DP4/MOSA/MYD10A1.061/2023.01.07/MYD10A1.A2023007.h15v14.061.2023009201030.hdf":MOD_Grid_Snow_500m:NDSI_Snow_Cover

What if you need to process this way not only 1 file but at least 100? GDAL command line tool could be a better solution for this. GDAL installation instructions are on the page.

command is used to reproject data with the option to clip the image to a certain extent. The full expression is the following

😃
gdalwarp
MOD10A
MYD10A
first
QGIS dialog window for sub-dataset selection
MYD10A hdf file added to a map in EPSG:3031
Exporting MODIS HDF to GeoTIFF and clipping to vector data extent
Processed file in the map view