From the PO.DAAC Cookbook, to access the GitHub version of the notebook, follow this link.

GDAL NetCDF to Geotiff Conversion

Authored by Nicholas Tarpinian, PO.DAAC

Summary

The following workflow lets you transform SWOT_L2_HR_Raster_2.0 NetCDF raster image to a GeoTIFF image, while extracting the variable of interest of WSE (Water Surface Elevation).

Utiliziing the PODAAC Data Subscriber tool to download SWOT files onto your system.


Requirements

  1. This tutorial can be run in both a Windows & Mac environment. (Both subscriber tool and GDAL.)

  2. First install GDAL and the GDAL Command Line Interface (CLI) onto your system. The GDAL CLI is a tool that lets your perform a variety of geospatial transformations and analysis with geospatial raster and vector data.

  3. Earthdata Login - An Earthdata Login account is required to access data, as well as discover restricted data, from the NASA Earthdata system. Thus, to access NASA data, you need Earthdata Login. Please visit https://urs.earthdata.nasa.gov to register and manage your Earthdata Login account. This account is free to create and only takes a moment to set up.

  4. netrc File - You will need a .netrc file containing your NASA Earthdata Login credentials in order to execute the notebooks. A .netrc file can be created manually within text editor and saved to your home directory. For additional information see: Authentication for NASA Earthdata tutorial.

  5. PODAAC Data Subscriber tool - To download the latest PO.DAAC datasets to your system proceed to the podaac-data-subscriber package to properly install onto your system.


Learning Objectives

  • Downloading SWOT data using the podaac-data-downloader.
  • Utilizing GDAL (Geospatial Data Abstraction Library) to convert NetCDF files to GeoTIFF.
  • Specifiying which variable to convert to a single band image.
  • Also converting a folder of NetCDF files to GeoTIFF.

Calling the Data Subscriber

After installing the podaac-data-subscriber, the following command can be used in the Windows CLI Command Prompt interface to download the latest SWOT data.

For more info on the PODAAC Data Downloader.

podaac-data-downloader -c SWOT_L2_HR_Raster_2.0 -d Output Directory -sd 2024-02-15T15:15:00Z -ed 2024-02-15T15:16:00Z

GDAL Transformation

Transformation of the dataset is being done in the GDAL CLI.

GDALMDIMTRANSLATE converts multidimenstional data between different formats.

E.g. gdalmdimtranslate -of (output format) -co (creation option) -array (variable name) Input_FileName.nc Output_FileName.tif

Using gdalmdimtranslate to convert a single NetCDF file to GeoTIFF. We are choosing the water surface elevation (wse) variable to transform.

gdalmdimtranslate -of GTiff -co COMPRESS=LZW -array wse 'input_SWOT_NetCDF_file/SWOT_Raster_NetCDF/SWOT_L2_HR_Raster_100m_UTM13U_N_x_x_x_011_022_033F_20240215T151541_20240215T151602_PIC0_01.nc' 'output_path/wse_swot.tif'

To convert multiple NetCDF files within a folder, you can run a batch process of gdalmdimtranslate with a For Loop within the GDAL CLI. ’*.nc’ searching for all files containing a NetCDF extension within the folder.

for %f in ('input_SWOT_Folder\SWOT_Raster_NetCDF\*.nc') do (
gdalmdimtranslate -of GTiff -co COMPRESS=LZW -array wse NETCDF:"%f" "path_to_output_folder\SWOT_GeoTIFF\%~nf.tif"
)