How do I convert SNODAS binary files to GeoTIFF or NetCDF?

This article describes the use of Geospatial Data Abstraction Library (GDAL) tools for converting SNODAS binary files to NetCDF or GeoTIFF.

Before working through the rest of this tutorial, we would like to make you aware of a small spatial data shift that occurs on 01 October 2013 in the SNODAS period of record. On this date, the data provider, National Operational Hydrologic Remote Sensing Center (NOHRSC) slightly changed the center coordinates of the grid to align with an integer value of latitude and longitude. The resulting shift is minute, and on the order of ~5% of a 1km grid cell. Therefore, please note that the date of the file(s) you wish to convert will determine which set of coordinates you use in this tutorial, examples for files before and after 01 October 2013 are provided.

 

You will first need to have GDAL installed on your system before proceeding on to the following steps. NSIDC User Services is not able to provide support for installing GDAL, but we have found using a package manager such as MacPorts simplifies the installation process on a Mac. There are additional package managers available for Linux users. Additional details on downloading GDAL can be found on the GDAL website. A good way to test whether or not you have installed GDAL correctly is to issue the 'gdalinfo --version' command. This should return the version of your installation. 

The instructions for the masked (files beginning with 'us') and unmasked (files beginning with 'zz') files are slightly different, so please find separate instructions below for the masked and unmasked files:

Masked files

1. Unzip and untar all data if you have not already: 'gunzip *.gz' should do the trick if you work in a linux environment. Then, 'tar -zxvf *.tar'.

2. Using a text editor, create an ENVI header file (.hdr) with the following information:

ENVI
samples = 6935
lines = 3351
bands = 1
header offset = 0
file type = ENVI Standard
data type = 2
interleave = bsq
byte order = 1

3. Save the header file using the exact same file name as the data file you are converting, but with a .hdr extension. For example, the "us_ssmv01025SlL01T0024TTNATS2020012205DP001.dat" filename is used to create "us_ssmv01025SlL01T0024TTNATS2020012205DP001.hdr".

4. Ensure your working directory contains both the .hdr file and the .dat file. Issue one of the gdal_translate commands listed below. The coordinates used in the -a_ullr flag are slightly different for files before and after 01 October 2013.

For files prior to 01 October 2013:

GeoTIFF

gdal_translate -of GTiff -a_srs '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs' -a_nodata -9999 -a_ullr -124.73375000000000 52.87458333333333 -66.94208333333333 24.94958333333333 <input.dat> <output.tif>

NetCDF

gdal_translate -of NetCDF -a_srs '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs' -a_nodata -9999 -a_ullr -124.73375000000000 52.87458333333333 -66.94208333333333 24.94958333333333 <input.dat> <output.nc>

For files from 01 October 2013 onwards:

GeoTIFF

gdal_translate -of GTiff -a_srs '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs' -a_nodata -9999 -a_ullr -124.73333333333333 52.87500000000000 -66.94166666666667 24.95000000000000 <input.dat> <output.tif>

NetCDF

gdal_translate -of NetCDF -a_srs '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs' -a_nodata -9999 -a_ullr -124.73333333333333 52.87500000000000 -66.94166666666667 24.95000000000000 <input.dat> <output.nc>

Below is an example command for converting a masked file from 22 January 2020 into a geoTIFF:

gdal_translate -of GTiff -a_srs '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs' -a_nodata -9999 -a_ullr -124.73333333333333 52.87500000000000 -66.94166666666667 24.95000000000000 us_ssmv01025SlL01T0024TTNATS2020012205DP001.dat 1025_20200122.tif

If you would like to add the time and date information from the .txt metadata file to the metadata in the GeoTIFF or NetCDF, please see Appendix 1 at the bottom of this article.

Please note if you are using an OSGEO4W shell to execute the gdal_translate command then the apostrophes around the text used to define the projection for the -a_srs option can cause an issue. So, if the command fails we recommend trying the following command instead:
gdal_translate -of NetCDF -a_srs EPSG:4326 -a_nodata -9999 -a_ullr -124.73333333333333 52.87500000000000 -66.94166666666667 24.95000000000000 <input.dat> <output.nc>

Unmasked files

1. Unzip and untar all data if you have not already: 'gunzip *.gz' should do the trick if you work in a linux environment. Then, 'tar -zxvf *.tar'.

2. Using a text editor, create an ENVI header file (.hdr) with the following information:

ENVI
samples = 8192
lines = 4096
bands = 1
header offset = 0
file type = ENVI Standard
data type = 2
interleave = bsq
byte order = 1

3. Save the header file using the exact same file name as the data file you are converting, but with a .hdr extension. For example, the "zz_ssmv01025SIL00T0024TTNATS2016070905DP001.dat" filename is used to create "zz_ssmv01025SIL00T0024TTNATS2016070905DP001.hdr".

4. Ensure your working directory contains both the .hdr file and the .dat file. Issue one of the gdal_translate commands listed below. The coordinates used in the -a_ullr flag are slightly different for files before and after 01 October 2013.

For files prior to 01 October 2013:

GeoTIFF

gdal_translate -of GTiff -a_srs '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs' -a_nodata -9999 -a_ullr -130.51708333333333 58.23291666666667 -62.25041666666667 24.09958333333333 <input.dat> <output.tif>

NetCDF

gdal_translate -of NetCDF -a_srs '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs' -a_nodata -9999 -a_ullr -130.51708333333333 58.23291666666667 -62.25041666666667 24.09958333333333 <input.dat> <output.nc>

For files from 01 October 2013 onwards:

GeoTIFF

gdal_translate -of GTiff -a_srs '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs' -a_nodata -9999 -a_ullr -130.51666666666667 58.23333333333333 -62.25000000000000 24.10000000000000 <input.dat> <output.tif>

NetCDF

gdal_translate -of NetCDF -a_srs '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs' -a_nodata -9999 -a_ullr -130.51666666666667 58.23333333333333 -62.25000000000000 24.10000000000000 <input.dat> <output.nc>

Below is an example command that converts an unmasked file from 9th July 2016 to a geoTIFF:

gdal_translate -of GTiff -a_srs '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs' -a_nodata -9999 -a_ullr  -130.51666666666667 58.23333333333333 -62.25000000000000 24.100000000000000 zz_ssmv01025SIL00T0024TTNATS2016070905DP001.dat 1025_20160709.tif

If you would like to add the time and date information from the .txt metadata file to the metadata in the GeoTIFF or NetCDF, please see Appendix 1.

Appendix 1. Adding date and time information to the GeoTIFF or netCDF

The date and time the file was created can be found on lines 5-10 in the .txt metadata file. If you would like to add the date and time information to the GeoTIFF or NetCDF file you can use an additional flag in the gdal_translate command, -mo. An example command with the additional flag highlighted in bold is shown below:

gdal_translate -of NetCDF -a_srs '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs' -a_nodata -9999 -a_ullr -124.73333333333333 52.87500000000000 -66.94166666666667 24.95000000000000 -mo 'DATETIME=2020:01:22 05:29:56' us_ssmv11034tS__T0001TTNATS2020012205HP001.dat 1034_20200122.nc

Last Updated October 2020