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

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.

auth = earthaccess.login() 

Download the Data into a folder

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

Shapefiles come in a .zip format, and need to be unzipped in the existing folder

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
os.listdir(folder)
['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']