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

Search and Download SWOT Data via earthaccess

Author: Cassandra Nickles, PO.DAAC

Summary

This notebook will find and download pre-validated SWOT hydrology data (v2.0) programmatically via earthaccess python library. For more information about earthaccess visit: https://nsidc.github.io/earthaccess/

Requirements

1. Compute environment

This tutorial can be run in the following environments: - Local compute environment e.g. laptop, server: this tutorial can be run on your local machine

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.

Import libraries

[1]:
import geopandas as gpd
import glob
from pathlib import Path
import pandas as pd
import os
import zipfile
import earthaccess

In this notebook, we will be calling the authentication in the below cell.

[2]:
auth = earthaccess.login()

SWOT Level 2 KaRIn High Rate Version 2.0 Datasets:

  • Water Mask Pixel Cloud NetCDF - SWOT_L2_HR_PIXC_2.0

  • Water Mask Pixel Cloud Vector Attribute NetCDF - SWOT_L2_HR_PIXCVec_2.0

  • River Vector Shapefile - SWOT_L2_HR_RiverSP_2.0

  • Lake Vector Shapefile - SWOT_L2_HR_LakeSP_2.0

  • Raster NetCDF - SWOT_L2_HR_Raster_2.0

Let’s start our search for River Vector Shapefiles with a particular pass, pass 013. SWOT files come in “reach” and “node” versions in the same collection, here we want the 10km reaches rather than the nodes. We will also only get files for North America, or ‘NA’ and call out a specific pass number that we want.

[3]:
results = earthaccess.search_data(short_name = 'SWOT_L2_HR_RIVERSP_2.0',
                                  #temporal = ('2024-02-01 00:00:00', '2024-02-29 23:59:59'), # can also specify by time
                                  granule_name = '*Reach*_013_NA*') # here we filter by Reach files (not node), pass=013, continent code=NA
Granules found: 6

During the science orbit, a pass will be repeated once every 21 days. A particular location may have different passes observe it within the 21 days, however. See the SWOT swath visualizer for your location!

[7]:
earthaccess.download(results, "./datasets/data_downloads/SWOT_files/")
folder = Path("./datasets/data_downloads/SWOT_files")
 Getting 6 granules, approx download size: 0.0 GB
Accessing cloud dataset using dataset endpoint credentials: https://archive.swot.podaac.earthdata.nasa.gov/s3credentials
Downloaded: ./datasets/data_downloads/SWOT_files/SWOT_L2_HR_RiverSP_Reach_007_013_NA_20231123T210452_20231123T210454_PIC0_01.zip
Downloaded: ./datasets/data_downloads/SWOT_files/SWOT_L2_HR_RiverSP_Reach_008_013_NA_20231214T174955_20231214T174957_PIC0_01.zip
Downloaded: ./datasets/data_downloads/SWOT_files/SWOT_L2_HR_RiverSP_Reach_009_013_NA_20240104T143502_20240104T143504_PIC0_01.zip
Downloaded: ./datasets/data_downloads/SWOT_files/SWOT_L2_HR_RiverSP_Reach_010_013_NA_20240125T112008_20240125T112010_PIC0_01.zip
Downloaded: ./datasets/data_downloads/SWOT_files/SWOT_L2_HR_RiverSP_Reach_010_013_NA_20240125T112008_20240125T112010_PIC0_02.zip
Downloaded: ./datasets/data_downloads/SWOT_files/SWOT_L2_HR_RiverSP_Reach_011_013_NA_20240215T080513_20240215T080514_PIC0_01.zip
[8]:
for item in os.listdir(folder): # loop through items in dir
    if item.endswith(".zip"): # check for ".zip" extension
        zip_ref = zipfile.ZipFile(f"{folder}/{item}") # create zipfile object
        zip_ref.extractall(folder) # extract file to dir
        zip_ref.close() # close file
[9]:
os.listdir(folder)
[9]:
['SWOT_L2_HR_RiverSP_Reach_008_013_NA_20231214T174955_20231214T174957_PIC0_01.prj',
 'SWOT_L2_HR_RiverSP_Reach_008_013_NA_20231214T174955_20231214T174957_PIC0_01.dbf',
 'SWOT_L2_HR_RiverSP_Reach_009_013_NA_20240104T143502_20240104T143504_PIC0_01.shx',
 'SWOT_L2_HR_RiverSP_Reach_010_013_NA_20240125T112008_20240125T112010_PIC0_02.zip',
 'SWOT_L2_HR_RiverSP_Reach_009_013_NA_20240104T143502_20240104T143504_PIC0_01.zip',
 'SWOT_L2_HR_RiverSP_Reach_010_013_NA_20240125T112008_20240125T112010_PIC0_02.shx',
 'SWOT_L2_HR_RiverSP_Reach_010_013_NA_20240125T112008_20240125T112010_PIC0_01.dbf',
 'SWOT_L2_HR_RiverSP_Reach_010_013_NA_20240125T112008_20240125T112010_PIC0_01.prj',
 'SWOT_L2_HR_RiverSP_Reach_010_013_NA_20240125T112008_20240125T112010_PIC0_02.shp',
 'SWOT_L2_HR_RiverSP_Reach_009_013_NA_20240104T143502_20240104T143504_PIC0_01.shp',
 'SWOT_L2_HR_RiverSP_Reach_007_013_NA_20231123T210452_20231123T210454_PIC0_01.shx',
 'SWOT_L2_HR_RiverSP_Reach_007_013_NA_20231123T210452_20231123T210454_PIC0_01.zip',
 'SWOT_L2_HR_RiverSP_Reach_007_013_NA_20231123T210452_20231123T210454_PIC0_01.shp',
 'SWOT_L2_HR_RiverSP_Reach_010_013_NA_20240125T112008_20240125T112010_PIC0_01.shp.xml',
 'SWOT_L2_HR_RiverSP_Reach_011_013_NA_20240215T080513_20240215T080514_PIC0_01.shx',
 'SWOT_L2_HR_RiverSP_Reach_011_013_NA_20240215T080513_20240215T080514_PIC0_01.zip',
 'SWOT_L2_HR_RiverSP_Reach_008_013_NA_20231214T174955_20231214T174957_PIC0_01.shp.xml',
 'SWOT_L2_HR_RiverSP_Reach_011_013_NA_20240215T080513_20240215T080514_PIC0_01.shp',
 'SWOT_L2_HR_RiverSP_Reach_007_013_NA_20231123T210452_20231123T210454_PIC0_01.shp.xml',
 'SWOT_L2_HR_RiverSP_Reach_010_013_NA_20240125T112008_20240125T112010_PIC0_02.dbf',
 'SWOT_L2_HR_RiverSP_Reach_010_013_NA_20240125T112008_20240125T112010_PIC0_02.prj',
 'SWOT_L2_HR_RiverSP_Reach_011_013_NA_20240215T080513_20240215T080514_PIC0_01.shp.xml',
 'SWOT_L2_HR_RiverSP_Reach_009_013_NA_20240104T143502_20240104T143504_PIC0_01.prj',
 'SWOT_L2_HR_RiverSP_Reach_009_013_NA_20240104T143502_20240104T143504_PIC0_01.dbf',
 'SWOT_L2_HR_RiverSP_Reach_010_013_NA_20240125T112008_20240125T112010_PIC0_01.zip',
 'SWOT_L2_HR_RiverSP_Reach_010_013_NA_20240125T112008_20240125T112010_PIC0_01.shx',
 'SWOT_L2_HR_RiverSP_Reach_009_013_NA_20240104T143502_20240104T143504_PIC0_01.shp.xml',
 'SWOT_L2_HR_RiverSP_Reach_010_013_NA_20240125T112008_20240125T112010_PIC0_01.shp',
 'SWOT_L2_HR_RiverSP_Reach_007_013_NA_20231123T210452_20231123T210454_PIC0_01.prj',
 'SWOT_L2_HR_RiverSP_Reach_010_013_NA_20240125T112008_20240125T112010_PIC0_02.shp.xml',
 'SWOT_L2_HR_RiverSP_Reach_007_013_NA_20231123T210452_20231123T210454_PIC0_01.dbf',
 'SWOT_L2_HR_RiverSP_Reach_008_013_NA_20231214T174955_20231214T174957_PIC0_01.zip',
 'SWOT_L2_HR_RiverSP_Reach_008_013_NA_20231214T174955_20231214T174957_PIC0_01.shx',
 'SWOT_L2_HR_RiverSP_Reach_008_013_NA_20231214T174955_20231214T174957_PIC0_01.shp',
 'SWOT_L2_HR_RiverSP_Reach_011_013_NA_20240215T080513_20240215T080514_PIC0_01.dbf',
 'SWOT_L2_HR_RiverSP_Reach_011_013_NA_20240215T080513_20240215T080514_PIC0_01.prj']