podaac-data-subscriber NetCDF to Geotiff Conversion

Author: Jack McNelis, PO.DAAC

Summary

The following workflow extracts a single variable of interest (water surface elevation (wse)) from the SWOT_L2_HR_Raster_2.0 and writes the original raster netCDF it to a geotiff via the podaac-data-subscriber tool.

Requirements

  1. This tutorial can be run in any Linux environment. (The subscriber tool can be run in any environment, not just Linux, but the bash script used as the process will only work in a Linux environment.)

  2. 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.

  3. 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.

Learning Objectives

  • Use the “–process” option in the podaac-data-subscriber
  • Convert netCDF files to geotiff files using gdalmdimtranslate in a bash script

Create a Bash Script

Inside a bash script entitled, test.sh, set up the following command which calls gdalmdimtranslate to write the wse variable in the downloaded netcdf file to a new geotiff in the same directory:

#!/bin/bash
gdalmdimtranslate \
    -of "GTiff" \
    -co "COMPRESS=LZW" \
    -array "wse" \
    ${1} $(basename $1 | sed 's/.nc/.wse.tif/g')

Call the Data Subscriber

Then, after installing the podaac-data-subscriber package, write the following command in your terminal that uses the podaac-data-subscriber to run the bash script:

podaac-data-downloader -c SWOT_L2_HR_Raster_2.0 -d ~/test_podaac/ -sd 2024-02-15T15:15:00Z -ed 2024-02-15T15:16:00Z --process "${PWD}/test.sh"

If you get a permission denied error for test.sh, Make sure the permissions on the .sh file are set to read, write & executable. If you are unsure what your permissions are, in the command prompt you can execute “chmod 0755 test.sh” and permissions should be updated.

Listed Results from the above command should be as follows:

$ ls
SWOT_L2_HR_Raster_100m_UTM13U_N_x_x_x_011_022_030F_20240215T151441_20240215T151502_PIC0_01.nc
SWOT_L2_HR_Raster_100m_UTM13U_N_x_x_x_011_022_030F_20240215T151441_20240215T151502_PIC0_01.wse.tif
SWOT_L2_HR_Raster_100m_UTM13U_N_x_x_x_011_022_031F_20240215T151501_20240215T151522_PIC0_01.nc
SWOT_L2_HR_Raster_100m_UTM13U_N_x_x_x_011_022_031F_20240215T151501_20240215T151522_PIC0_01.wse.tif
SWOT_L2_HR_Raster_100m_UTM13U_N_x_x_x_011_022_032F_20240215T151521_20240215T151542_PIC0_01.nc
SWOT_L2_HR_Raster_100m_UTM13U_N_x_x_x_011_022_032F_20240215T151521_20240215T151542_PIC0_01.wse.tif
SWOT_L2_HR_Raster_100m_UTM13U_N_x_x_x_011_022_033F_20240215T151541_20240215T151602_PIC0_01.nc
SWOT_L2_HR_Raster_100m_UTM13U_N_x_x_x_011_022_033F_20240215T151541_20240215T151602_PIC0_01.wse.tif
SWOT_L2_HR_Raster_250m_UTM13U_N_x_x_x_011_022_030F_20240215T151441_20240215T151502_PIC0_01.nc
SWOT_L2_HR_Raster_250m_UTM13U_N_x_x_x_011_022_030F_20240215T151441_20240215T151502_PIC0_01.wse.tif
SWOT_L2_HR_Raster_250m_UTM13U_N_x_x_x_011_022_031F_20240215T151501_20240215T151522_PIC0_01.nc
SWOT_L2_HR_Raster_250m_UTM13U_N_x_x_x_011_022_031F_20240215T151501_20240215T151522_PIC0_01.wse.tif
SWOT_L2_HR_Raster_250m_UTM13U_N_x_x_x_011_022_032F_20240215T151521_20240215T151542_PIC0_01.nc
SWOT_L2_HR_Raster_250m_UTM13U_N_x_x_x_011_022_032F_20240215T151521_20240215T151542_PIC0_01.wse.tif
SWOT_L2_HR_Raster_250m_UTM13U_N_x_x_x_011_022_033F_20240215T151541_20240215T151602_PIC0_01.nc
SWOT_L2_HR_Raster_250m_UTM13U_N_x_x_x_011_022_033F_20240215T151541_20240215T151602_PIC0_01.wse.tif
test.sh