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

SWOT Hydrology Science Application Tutorial on the Cloud

Retrieving SWOT attributes (WSE, width, slope) and plotting a longitudinal profile along a river or over a basin

Requirement

This tutorial can only be run in an AWS cloud instance running in us-west-2: NASA Earthdata Cloud data in S3 can be directly accessed via earthaccess python library; this access is limited to requests made within the US West (Oregon) (code: us-west-2) AWS region.

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.

This code runs using SWOT Level 2 Data Products (Version 2.0).

Notebook Authors: Arnaud Cerbelaud, Jeffrey Wade, NASA Jet Propulsion Laboratory - California Institute of Technology (Mar 2024)

Learning Objectives

  1. Retrieve SWOT hydrological attributes on river reaches within the AWS cloud (Cal/Val data). Query reaches by:
    • River name
    • Spatial bounding box
    • Downstream tracing from reach id (e.g. headwater to outlet) for river longitudinal profiles
    • Upstream tracing from reach id (e.g. outlet to full river network) for watershed analysis
  2. Plot a time series of WSE, width, slope data on the filtered data
  3. Visualize an interactive map of WSE, width, slope data on the filtered data

Import Packages

import fiona
import xarray as xr
import pandas as pd
import geopandas as gpd
import numpy as np
import matplotlib.pyplot as plt
import hvplot.xarray
import earthaccess

pd.set_option('display.max_columns', None) #make sure all columns displayed for shapefiles

Authenticate

Authenticate your Earthdata Login (EDL) information using the earthaccess python package as follows:

earthaccess.login() # Login with your EDL credentials if asked
<earthaccess.auth.Auth at 0x7f2fd5bbf220>

1. Retrieve SWOT hydrological attributes on river reaches within the AWS cloud (Cal/Val data)

What data should we download?

  • Optional step: Get the .kmz file of SWOT passes/swaths for the and import it into Google Earth for visualization
  • Determine which pass number corresponds to the river/basin you want to look at! #### Search for multiple days of data
# Enter pass number
pass_number    = ["341", "576", "298"]   #e.g. 341, 576, 298 for Connecticut in NA, "236", "514", "542", "085", "363", "057", "335", "029" for Rhine in EU
# Enter continent code
continent_code = "NA"     # e.g. "AF", "NA", "EU", "SI", "AS", "AU", "SA", "AR", "GR"

# Retrieves granulev and links list from the passes we want, in this case by passing to `earthdata.search_data` function the data collection shortname and temporal bounds
links_list = []
for p in range(len(pass_number)):
    river_results = earthaccess.search_data(short_name = 'SWOT_L2_HR_RIVERSP_2.0', 
                                        temporal = ('2024-01-25 00:00:00', '2024-03-29 23:59:59'),
                                        granule_name = "*Reach*_" + pass_number[p] + "_" + continent_code + "*")
    for r in range(len(river_results)):
        river_link = earthaccess.results.DataGranule.data_links(river_results[r], access='direct')[0]
        links_list.append(river_link)
Granules found: 2
Granules found: 3
Granules found: 3
# Create fiona session to read data from zip files without download and extraction
fs_s3 = earthaccess.get_s3fs_session(results=river_results)
fiona_session=fiona.session.AWSSession(
        aws_access_key_id=fs_s3.storage_options["key"],
        aws_secret_access_key=fs_s3.storage_options["secret"],
        aws_session_token=fs_s3.storage_options["token"]
    )
links_list
['s3://podaac-swot-ops-cumulus-protected/SWOT_L2_HR_RiverSP_2.0/SWOT_L2_HR_RiverSP_Reach_010_341_NA_20240206T041926_20240206T041927_PIC0_01.zip',
 's3://podaac-swot-ops-cumulus-protected/SWOT_L2_HR_RiverSP_2.0/SWOT_L2_HR_RiverSP_Reach_011_341_NA_20240227T010431_20240227T010433_PIC0_01.zip',
 's3://podaac-swot-ops-cumulus-protected/SWOT_L2_HR_RiverSP_2.0/SWOT_L2_HR_RiverSP_Reach_010_576_NA_20240214T133056_20240214T133057_PIC0_01.zip',
 's3://podaac-swot-ops-cumulus-protected/SWOT_L2_HR_RiverSP_2.0/SWOT_L2_HR_RiverSP_Reach_011_576_NA_20240306T101600_20240306T101602_PIC0_01.zip',
 's3://podaac-swot-ops-cumulus-protected/SWOT_L2_HR_RiverSP_2.0/SWOT_L2_HR_RiverSP_Reach_012_576_NA_20240327T070054_20240327T070055_PIC0_01.zip',
 's3://podaac-swot-ops-cumulus-protected/SWOT_L2_HR_RiverSP_2.0/SWOT_L2_HR_RiverSP_Reach_010_298_NA_20240204T150846_20240204T150850_PIC0_01.zip',
 's3://podaac-swot-ops-cumulus-protected/SWOT_L2_HR_RiverSP_2.0/SWOT_L2_HR_RiverSP_Reach_011_298_NA_20240225T115352_20240225T115356_PIC0_01.zip',
 's3://podaac-swot-ops-cumulus-protected/SWOT_L2_HR_RiverSP_2.0/SWOT_L2_HR_RiverSP_Reach_012_298_NA_20240317T083854_20240317T083858_PIC0_01.zip']

Unzip selected files in Fiona session

# Initialize list of shapefiles containing all dates
SWOT_HR_shps = []

# Loop through queried granules to stack all acquisition dates
for j in range(len(links_list)):
    
    # We use the zip+ prefix so fiona knows that we are operating on a zip file
    river_shp_url = f"zip+{links_list[j]}"
    
    # Read shapefile
    with fiona.Env(session=fiona_session):
        SWOT_HR_shps.append(gpd.read_file(river_shp_url)) 

Aggregate unzipped files into dataframe

# Combine granules from all acquisition dates into one dataframe
SWOT_HR_df = gpd.GeoDataFrame(pd.concat(SWOT_HR_shps, ignore_index=True))

# Sort dataframe by reach_id and time
SWOT_HR_df = SWOT_HR_df.sort_values(['reach_id', 'time'])

SWOT_HR_df
reach_id time time_tai time_str p_lat p_lon river_name wse wse_u wse_r_u wse_c wse_c_u slope slope_u slope_r_u slope2 slope2_u slope2_r_u width width_u width_c width_c_u area_total area_tot_u area_detct area_det_u area_wse d_x_area d_x_area_u layovr_val node_dist loc_offset xtrk_dist dschg_c dschg_c_u dschg_csf dschg_c_q dschg_gc dschg_gc_u dschg_gcsf dschg_gc_q dschg_m dschg_m_u dschg_msf dschg_m_q dschg_gm dschg_gm_u dschg_gmsf dschg_gm_q dschg_b dschg_b_u dschg_bsf dschg_b_q dschg_gb dschg_gb_u dschg_gbsf dschg_gb_q dschg_h dschg_h_u dschg_hsf dschg_h_q dschg_gh dschg_gh_u dschg_ghsf dschg_gh_q dschg_o dschg_o_u dschg_osf dschg_o_q dschg_go dschg_go_u dschg_gosf dschg_go_q dschg_s dschg_s_u dschg_ssf dschg_s_q dschg_gs dschg_gs_u dschg_gssf dschg_gs_q dschg_i dschg_i_u dschg_isf dschg_i_q dschg_gi dschg_gi_u dschg_gisf dschg_gi_q dschg_q_b dschg_gq_b reach_q reach_q_b dark_frac ice_clim_f ice_dyn_f partial_f n_good_nod obs_frac_n xovr_cal_q geoid_hght geoid_slop solid_tide load_tidef load_tideg pole_tide dry_trop_c wet_trop_c iono_c xovr_cal_c n_reach_up n_reach_dn rch_id_up rch_id_dn p_wse p_wse_var p_width p_wid_var p_n_nodes p_dist_out p_length p_maf p_dam_id p_n_ch_max p_n_ch_mod p_low_slp geometry
3738 72120300121 -1.000000e+12 -1.000000e+12 no_data 50.355053 -77.287576 no_data -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 12582912 12582912 3 469762048 -1.000000e+12 2 -999 1 -999 -1.000000e+12 2 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 1 1 72120300206, no_data, no_data, no_data 72120300113, no_data, no_data, no_data 248.199997 0.031587 45.0 217.523 86 228174.350 17135.322465 -1.000000e+12 0 1 1 0 LINESTRING (-77.37319 50.31698, -77.37277 50.3...
4454 72120300121 -1.000000e+12 -1.000000e+12 no_data 50.355053 -77.287576 no_data -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 12582912 12582912 3 469762048 -1.000000e+12 2 -999 1 -999 -1.000000e+12 2 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 1 1 72120300206, no_data, no_data, no_data 72120300113, no_data, no_data, no_data 248.199997 0.031587 45.0 217.523 86 228174.350 17135.322465 -1.000000e+12 0 1 1 0 LINESTRING (-77.37319 50.31698, -77.37277 50.3...
5170 72120300121 -1.000000e+12 -1.000000e+12 no_data 50.355053 -77.287576 no_data -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 12582912 12582912 3 469762048 -1.000000e+12 2 -999 1 -999 -1.000000e+12 2 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 1 1 72120300206, no_data, no_data, no_data 72120300113, no_data, no_data, no_data 248.199997 0.031587 45.0 217.523 86 228174.350 17135.322465 -1.000000e+12 0 1 1 0 LINESTRING (-77.37319 50.31698, -77.37277 50.3...
3739 72120400051 -1.000000e+12 -1.000000e+12 no_data 49.864785 -76.975406 no_data -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 12582912 12582912 3 469762048 -1.000000e+12 2 -999 1 -999 -1.000000e+12 2 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 1 1 72120400063, no_data, no_data, no_data 72120400043, no_data, no_data, no_data 256.399994 2.569541 291.0 19982.483 91 308791.019 18231.842622 -1.000000e+12 0 3 1 0 LINESTRING (-77.06133 49.85771, -77.06092 49.8...
4455 72120400051 -1.000000e+12 -1.000000e+12 no_data 49.864785 -76.975406 no_data -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 12582912 12582912 3 469762048 -1.000000e+12 2 -999 1 -999 -1.000000e+12 2 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 1 1 72120400063, no_data, no_data, no_data 72120400043, no_data, no_data, no_data 256.399994 2.569541 291.0 19982.483 91 308791.019 18231.842622 -1.000000e+12 0 3 1 0 LINESTRING (-77.06133 49.85771, -77.06092 49.8...
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
3128 76500000131 7.630360e+08 7.630361e+08 2024-03-06T10:26:58Z 18.255350 -66.012657 no_data 5.148830e+01 7.147400e-01 7.090500e-01 -1.000000e+12 -1.000000e+12 -1.896964e-03 1.029344e-05 9.846570e-06 -2.579608e-03 -1.000000e+12 1.179402e-01 8.228150e+02 3.330908e+00 -1.000000e+12 -1.000000e+12 9.494502e+06 3.843551e+04 9.472037e+06 3.843550e+04 9.494502e+06 -1.000000e+12 -1.000000e+12 7.219900e+00 2.269424e+02 3.555010e+01 -9.718222e+03 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 25428408 25428408 2 542734 2.366000e-03 0 -999 0 33 5.409836e-01 0 -4.203993e+01 -5.959560e-05 -1.099997e-01 -7.083979e-03 -9.455572e-03 2.673383e-03 -2.300245e+00 -2.157397e-01 -2.978376e-03 3.877690e-01 1 1 76500000141, no_data, no_data, no_data 76500000123, no_data, no_data, no_data 40.600002 43.251021 63.0 1149.474 61 43590.077 12103.909044 -1.000000e+12 0 2 1 0 LINESTRING (-65.99988 18.21743, -66.00022 18.2...
3736 76500000131 7.648387e+08 7.648388e+08 2024-03-27T07:11:56Z 18.255350 -66.012657 no_data 6.214650e+01 2.573330e+00 2.571760e+00 -1.000000e+12 -1.000000e+12 -3.331055e-03 3.849838e-05 3.838132e-05 -3.053041e-03 -1.000000e+12 2.653730e+00 1.336966e+03 4.963007e+00 -1.000000e+12 -1.000000e+12 1.465627e+07 5.440614e+04 1.461890e+07 5.440610e+04 1.465627e+07 -1.000000e+12 -1.000000e+12 6.300200e+00 2.618109e+02 1.134880e+02 -9.406573e+03 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 25428408 25428408 2 575498 2.549000e-03 0 -999 1 25 4.098361e-01 2 -4.208252e+01 -6.235580e-05 7.611858e-02 1.698115e-03 3.022270e-03 1.955032e-03 -2.290476e+00 -1.451549e-01 -6.110505e-03 0.000000e+00 1 1 76500000141, no_data, no_data, no_data 76500000123, no_data, no_data, no_data 40.600002 43.251021 63.0 1149.474 61 43590.077 12103.909044 -1.000000e+12 0 2 1 0 LINESTRING (-65.99988 18.21743, -66.00022 18.2...
2523 76500000141 7.612333e+08 7.612334e+08 2024-02-14T13:41:54Z 18.214094 -65.999696 no_data 7.122600e+01 9.093000e-02 1.299000e-02 -1.000000e+12 -1.000000e+12 -1.424304e-02 3.561229e-05 3.548571e-05 -4.944832e-02 -1.000000e+12 2.070532e-04 2.976488e+02 7.012993e+00 -1.000000e+12 -1.000000e+12 2.374517e+05 5.594670e+03 2.374517e+05 5.594700e+03 2.374517e+05 -1.000000e+12 -1.000000e+12 1.040700e+00 3.071884e+02 3.960115e+01 -9.825143e+03 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 25428408 25428408 2 542730 0.000000e+00 0 -999 0 2 5.000000e-01 0 -4.162250e+01 -1.538206e-04 -1.459826e-01 -1.125507e-02 -9.715600e-03 3.041269e-03 -2.308736e+00 -1.868137e-01 -9.129797e-03 6.605130e-02 2 1 76500000161, 76500000151, no_data, no_data 76500000131, no_data, no_data, no_data 63.100002 20.898301 30.0 415.706 4 44387.835 797.757834 -1.000000e+12 0 1 1 0 LINESTRING (-66.00018 18.21038, -66.00018 18.2...
3129 76500000141 7.630360e+08 7.630361e+08 2024-03-06T10:26:58Z 18.214094 -65.999696 no_data -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 -1.000000e+12 3.717835e+02 7.669814e+00 -1.000000e+12 -1.000000e+12 2.965932e+05 6.118654e+03 2.965932e+05 6.118700e+03 2.965932e+05 -1.000000e+12 -1.000000e+12 0.000000e+00 2.817323e+02 3.577332e+01 -1.006446e+04 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 29360570 29360570 3 503351296 0.000000e+00 0 -999 1 0 0.000000e+00 2 -4.161941e+01 -1.000000e+12 -1.098480e-01 -6.989030e-03 -9.287705e-03 2.667307e-03 -2.297567e+00 -2.175007e-01 -2.980941e-03 4.020248e-01 2 1 76500000161, 76500000151, no_data, no_data 76500000131, no_data, no_data, no_data 63.100002 20.898301 30.0 415.706 4 44387.835 797.757834 -1.000000e+12 0 1 1 0 LINESTRING (-66.00018 18.21038, -66.00018 18.2...
3737 76500000141 7.648387e+08 7.648388e+08 2024-03-27T07:11:56Z 18.214094 -65.999696 no_data 8.508610e+01 9.025000e-02 6.690000e-03 -1.000000e+12 -1.000000e+12 -9.286700e-03 4.201405e-05 4.190681e-05 -1.123384e-02 -1.000000e+12 1.623781e-04 8.786977e+02 1.250254e+01 -1.000000e+12 -1.000000e+12 7.009880e+05 9.974001e+03 7.009880e+05 9.974000e+03 7.009880e+05 -1.000000e+12 -1.000000e+12 1.628500e+00 1.992412e+02 1.928564e+01 -9.878682e+03 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 25428408 25428408 2 540682 0.000000e+00 0 -999 0 3 7.500000e-01 2 -4.163959e+01 -6.160100e-05 7.617028e-02 1.573288e-03 2.859416e-03 1.950453e-03 -2.290005e+00 -1.457697e-01 -6.110666e-03 0.000000e+00 2 1 76500000161, 76500000151, no_data, no_data 76500000131, no_data, no_data, no_data 63.100002 20.898301 30.0 415.706 4 44387.835 797.757834 -1.000000e+12 0 1 1 0 LINESTRING (-66.00018 18.21038, -66.00018 18.2...

5886 rows × 127 columns

Exploring the dataset

What acquisition dates and rivers do our downloaded files cover?

print('Available dates are:')
print(np.unique([i[:10] for i in SWOT_HR_df['time_str']]))
print('Available rivers are:')
print(np.unique([i for i in SWOT_HR_df['river_name']]))
Available dates are:
['2024-02-04' '2024-02-06' '2024-02-14' '2024-02-25' '2024-02-27'
 '2024-03-06' '2024-03-17' '2024-03-27' 'no_data']
Available rivers are:
['Androscoggin River' 'Batten Kill' 'Bras du Nord' 'Canal de fuite'
 "Chenal de l'Est" 'Concord River' 'Concord River; Sudbury River'
 'Connecticut River' 'Connecticut River; Westfield River'
 'Connecticut River; White River' 'Deerfield River' 'Farmington River'
 'Fleuve Saint-Laurent' 'Hoosic River' 'Housatonic River' 'Howells River'
 'Hudson River' 'Hudson River; Indian River' 'Indian River'
 'Komaktorvik River' 'La Grande River' 'Lac Saint-Louis' 'Lamoille River'
 'Magalloway River' 'Merrimack River' 'Missisquoi River' 'Mohawk River'
 'Ottawa River' 'Otter Creek' 'Passumsic River' 'Pemigewasset River'
 'Quinebaug River' 'Racquette River' 'Sacandaga River' 'Saguenay River'
 'Saint Lawrence River' 'Saint Regis River'
 'Saint Regis River; West Branch of the Saint Regis R' 'Shetucket River'
 'South Nation River' 'Sudbury River' 'Thames River'
 'Vieux-Comptoir River' 'Wappinger Creek' 'West River' 'White River'
 'Winooski River' 'Wood Creek' 'no_data']

Filter dataframe by river name of interest and plot selected reaches:

Note: Some rivers have multiple names, hence using the contains function

# Enter river name
river = "Connecticut River"  # e.g. "Rhine", "Connecticut River"

## Filter dataframe
SWOT_HR_df_river = SWOT_HR_df[(SWOT_HR_df.river_name.str.contains(river))]

# Plot geopandas dataframe with 'explore' by reach id
SWOT_HR_df_river[['reach_id','river_name','geometry']].explore('reach_id', style_kwds=dict(weight=6))
Make this Notebook Trusted to load map: File -> Trust Notebook

Filter dataframe by latitude/longitude of interest:

lat_start = {"Connecticut River": 41,
             "Rhine": 46.5
            }
lat_end   = {"Connecticut River": 45,
             "Rhine": 52
            }
lon_start = {"Connecticut River": -73,
             "Rhine": 6
            }
lon_end   = {"Connecticut River": -71,
             "Rhine": 10
            }

## Filter dataframe
SWOT_HR_df_box = SWOT_HR_df[(SWOT_HR_df.p_lat > lat_start[river]) & (SWOT_HR_df.p_lat < lat_end[river]) & (SWOT_HR_df.p_lon > lon_start[river]) & (SWOT_HR_df.p_lon < lon_end[river])]

# Plot geopandas dataframe with 'explore' by river name
SWOT_HR_df_box[['reach_id','river_name','geometry']].explore('river_name', style_kwds=dict(weight=6))
Make this Notebook Trusted to load map: File -> Trust Notebook

2. River longitudinal profile: trace reaches downstream of given starting reach using rch_id_dn field

WARNING: This works as long as the data is exhaustive (no missing SWORD reaches)

First, let’s set up a dictionary relating all reaches in the dataset to their downstream neighbor

Note: rch_dn_dict[rch_id] gives a list of all the reaches directly downstream from rch_id

# Format rch_id_dn for dictionary. Rch_id_dn allows for multiple downstream reaches to be stored
# Also removes spaces in attribute field
rch_id_dn = [[x.strip() for x in SWOT_HR_df.rch_id_dn[j].split(',')] for j in range(0,len(SWOT_HR_df.rch_id_dn))]

# Filter upstream reach ids to remove 'no_data'
rch_id_dn_filter = [[x for x in dn_id if x.isnumeric()] for dn_id in rch_id_dn]

# Create lookup dictionary for river network topology: Downstream
rch_dn_dict = {SWOT_HR_df.reach_id[i]: rch_id_dn_filter[i] for i in range(len(SWOT_HR_df))}

Then, starting from a given reach, let’s trace all connected downstream reaches

# Enter reach_id from which we will trace downstream    (e.g. headwaters of the Connecticut River)
rch_dn_st = {"Connecticut River": '73120000691',
             "Rhine": '23267000651'
            }

# Initialize list to store downstream reaches, including starting reach
rch_dn_list = [rch_dn_st[river]]
# Retrieve first downstream id of starting reach and add to list
rch_dn_next = rch_dn_dict[rch_dn_st[river]][0]

# Trace next downstream reach until we hit the outlet (or here the last reach on file)
while len(rch_dn_next) != 0:
    # Add reach to list if value exists
    if len(rch_dn_next) != 0:
        rch_dn_list.append(rch_dn_next)
    # Recursively retrieve first downstream id of next reach
    # Catch error if reach isn't in downloaded data
    try:
        rch_dn_next = rch_dn_dict[rch_dn_next][0]
    except:
        break

Finally, we filtered our downloaded data by the traced reaches to create a plot

# Filter downloaded data by downstream traced reaches
SWOT_dn_trace = SWOT_HR_df[SWOT_HR_df.reach_id.isin(rch_dn_list)]

# Remove reaches from rch_dn_list that are not present in SWOT data
rch_dn_list = [rch for rch in rch_dn_list if rch in SWOT_HR_df.reach_id.values]

SWOT_dn_trace[['reach_id','river_name','geometry']].explore('river_name', style_kwds=dict(weight=6))
Make this Notebook Trusted to load map: File -> Trust Notebook

It looks like the data was cut short!

Must be an error in the SWORD Database. Let’s check by singling out the reach it left off on.

It looks like reach ‘73120000531’ at the time of this run (4/1/24) has ‘no_data’ in the rch_id_up and rch_id_dn fields when there should be values. To help out the SWORD database creators, we can report this discrepancy by clicking the Report Reach button at https://www.swordexplorer.com/. SWORD should be updated quarterly.

SWOT_HR_df[SWOT_HR_df.reach_id == '73120000531']
reach_id time time_tai time_str p_lat p_lon river_name wse wse_u wse_r_u wse_c wse_c_u slope slope_u slope_r_u slope2 slope2_u slope2_r_u width width_u width_c width_c_u area_total area_tot_u area_detct area_det_u area_wse d_x_area d_x_area_u layovr_val node_dist loc_offset xtrk_dist dschg_c dschg_c_u dschg_csf dschg_c_q dschg_gc dschg_gc_u dschg_gcsf dschg_gc_q dschg_m dschg_m_u dschg_msf dschg_m_q dschg_gm dschg_gm_u dschg_gmsf dschg_gm_q dschg_b dschg_b_u dschg_bsf dschg_b_q dschg_gb dschg_gb_u dschg_gbsf dschg_gb_q dschg_h dschg_h_u dschg_hsf dschg_h_q dschg_gh dschg_gh_u dschg_ghsf dschg_gh_q dschg_o dschg_o_u dschg_osf dschg_o_q dschg_go dschg_go_u dschg_gosf dschg_go_q dschg_s dschg_s_u dschg_ssf dschg_s_q dschg_gs dschg_gs_u dschg_gssf dschg_gs_q dschg_i dschg_i_u dschg_isf dschg_i_q dschg_gi dschg_gi_u dschg_gisf dschg_gi_q dschg_q_b dschg_gq_b reach_q reach_q_b dark_frac ice_clim_f ice_dyn_f partial_f n_good_nod obs_frac_n xovr_cal_q geoid_hght geoid_slop solid_tide load_tidef load_tideg pole_tide dry_trop_c wet_trop_c iono_c xovr_cal_c n_reach_up n_reach_dn rch_id_up rch_id_dn p_wse p_wse_var p_width p_wid_var p_n_nodes p_dist_out p_length p_maf p_dam_id p_n_ch_max p_n_ch_mod p_low_slp geometry
866 73120000531 7.605090e+08 7.605090e+08 2024-02-06T04:29:59Z 44.224658 -72.054978 Connecticut River 154.0388 1.46533 1.46257 -1.000000e+12 -1.000000e+12 -0.005891 0.000053 0.000053 -0.006434 -1.000000e+12 0.896640 1392.178327 35.649174 -1.000000e+12 -1.000000e+12 15211862.6 389526.4859 15095057.3 389526.5 15211862.6 -1.000000e+12 -1.000000e+12 7.8523 105.676909 10.84167 9765.19336 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 25428408 25428408 2 540686 0.007679 2 -999 0 33 0.589286 0 -28.335190 9.845300e-07 0.172423 0.010426 0.010006 0.005676 -2.282196 -0.045801 -0.003250 0.121413 0 0 no_data, no_data, no_data, no_data no_data, no_data, no_data, no_data 126.700005 3.094431 127.0 3164.993 56 479601.479 11140.899379 -1.000000e+12 0 2 1 0 LINESTRING (-72.05657 44.17983, -72.05663 44.1...
2477 73120000531 7.612328e+08 7.612329e+08 2024-02-14T13:34:08Z 44.224658 -72.054978 Connecticut River 128.0371 0.32207 0.30924 -1.000000e+12 -1.000000e+12 0.000855 0.000167 0.000167 0.000768 -1.000000e+12 0.006689 236.948849 1.282518 -1.000000e+12 -1.000000e+12 2640563.8 14292.4126 2161135.3 14292.4 2640563.8 -1.000000e+12 -1.000000e+12 8.2052 54.052922 0.21296 -21062.49316 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 8389049 8389049 1 14 0.181563 2 -999 0 44 0.785714 1 -28.335581 2.610410e-06 -0.117483 -0.005037 -0.004920 0.005339 -2.264607 -0.021861 -0.006972 0.192579 0 0 no_data, no_data, no_data, no_data no_data, no_data, no_data, no_data 126.700005 3.094431 127.0 3164.993 56 479601.479 11140.899379 -1.000000e+12 0 2 1 0 LINESTRING (-72.05657 44.17983, -72.05663 44.1...
1825 73120000531 7.623117e+08 7.623117e+08 2024-02-27T01:15:04Z 44.224658 -72.054978 Connecticut River 128.0144 1.19649 1.19310 -1.000000e+12 -1.000000e+12 0.001347 0.000243 0.000243 0.001149 -1.000000e+12 0.059092 140.618093 1.530273 -1.000000e+12 -1.000000e+12 1567051.5 17053.4007 929680.4 17053.4 1567051.5 -1.000000e+12 -1.000000e+12 9.2751 57.946006 0.51076 9967.06689 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 8651192 8651192 2 542734 0.406733 2 -999 0 28 0.500000 0 -28.334133 7.037000e-07 -0.090734 -0.008116 -0.007447 0.004975 -2.278251 -0.039789 -0.004193 -0.351682 0 0 no_data, no_data, no_data, no_data no_data, no_data, no_data, no_data 126.700005 3.094431 127.0 3164.993 56 479601.479 11140.899379 -1.000000e+12 0 2 1 0 LINESTRING (-72.05657 44.17983, -72.05663 44.1...
3083 73120000531 7.630356e+08 7.630356e+08 2024-03-06T10:19:13Z 44.224658 -72.054978 Connecticut River 132.4360 0.33872 0.32654 -1.000000e+12 -1.000000e+12 0.000345 0.000050 0.000050 0.000516 -1.000000e+12 0.004668 148.281475 0.719702 -1.000000e+12 -1.000000e+12 1652452.4 8020.3815 704909.5 8020.4 1652452.4 -1.000000e+12 -1.000000e+12 15.2661 97.873676 5.65395 -21404.77344 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 8651192 8651192 2 524302 0.573416 1 -999 0 39 0.696429 1 -28.334730 1.409300e-06 -0.122787 -0.012621 -0.013141 0.004544 -2.275936 -0.138596 -0.002577 0.981060 0 0 no_data, no_data, no_data, no_data no_data, no_data, no_data, no_data 126.700005 3.094431 127.0 3164.993 56 479601.479 11140.899379 -1.000000e+12 0 2 1 0 LINESTRING (-72.05657 44.17983, -72.05663 44.1...
3691 73120000531 7.648383e+08 7.648383e+08 2024-03-27T07:04:16Z 44.224658 -72.054978 Connecticut River 132.4095 0.19755 0.17586 -1.000000e+12 -1.000000e+12 0.001078 0.000065 0.000065 0.000907 -1.000000e+12 0.001526 167.129932 0.874109 -1.000000e+12 -1.000000e+12 1862500.1 9741.0965 987509.4 9741.1 1862500.1 -1.000000e+12 -1.000000e+12 8.0515 124.612257 -0.06486 -21380.69141 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 8651192 8651192 2 524302 0.469794 1 -999 0 44 0.785714 1 -28.335330 1.471800e-06 0.020488 0.006227 0.005686 0.003217 -2.283199 -0.149064 -0.003512 0.247772 0 0 no_data, no_data, no_data, no_data no_data, no_data, no_data, no_data 126.700005 3.094431 127.0 3164.993 56 479601.479 11140.899379 -1.000000e+12 0 2 1 0 LINESTRING (-72.05657 44.17983, -72.05663 44.1...

3. Watershed analysis: trace reaches upstream of starting reach using rch_id_up field

WARNING: This works as long as the data is exhaustive (no missing SWORD reaches)

First, let’s set up a dictionary relating all reaches in the dataset to their upstream neighbor

Note: rch_up_dict[rch_id] gives a list of all the reaches directly upstream from rch_id

# Format rch_id_up for dictionary. Rch_id_up allows for multiple upstream reaches to be stored
# Also removes spaces in attribute field
rch_id_up = [[x.strip() for x in SWOT_HR_df.rch_id_up[j].split(',')] for j in range(0,len(SWOT_HR_df.rch_id_up))]

# Filter upstream reach ids to remove 'no_data'
rch_id_up_fil = [[x for x in ups_id if x.isnumeric()] for ups_id in rch_id_up]

# Create lookup dictionary for river network topology: Upstream
rch_up_dict = {SWOT_HR_df.reach_id[i]: rch_id_up_fil[i] for i in range(len(SWOT_HR_df))}

Then, starting from a given reach, let’s trace all connected upstream reaches

This adds a bit of complexity, as we need to keep track of multiple branches upstream of the starting reach.

# Enter reach_id from which we will trace upstream    (e.g. outlet of the Connecticut River)
rch_up_st = {"Connecticut River": '73120000021',
             "Rhine": '23265000051'
            }

# Initialize list to store traced upstream reaches, including starting reach
rch_up_list = [rch_up_st[river]]
# Retrieve ids of reaches upstream of starting reach and add to list
rch_up_next = rch_up_dict[rch_up_st[river]]
# For upstream tracing, we need to set a list of next upstream ids to start while loop
rch_next_id = rch_up_next

# Loop until no more reaches to trace
while len(rch_next_id) != 0:
    # Initialize list to store next upstream ids
    rch_next_id = []
    # Loop through next upstream ids for given reach
    for rch_up_sel in rch_up_next:
        # Get values of existing upstream ids of rch_up_next reaches
        # If reach isn't in SWOT data (usually ghost reaches), continue to next reach
        try:
            rch_next_id = rch_next_id + rch_up_dict[rch_up_sel]
        except:
            continue
        # Append id to list
        rch_up_list.append(rch_up_sel)
    # If reaches exist, add to list for next cycle of tracing
    if len(rch_next_id) != 0:
        rch_up_next = rch_next_id

Finally, we filtered our downloaded data by the traced reaches to create a plot

# Filter downloaded data by upstream traced reaches
SWOT_up_trace = SWOT_HR_df[SWOT_HR_df.reach_id.isin(rch_up_list)]

# Remove reaches from rch_up_list that are not present in SWOT data
rch_up_list = [rch for rch in rch_up_list if rch in SWOT_HR_df.reach_id.values]

SWOT_up_trace[['reach_id','river_name','geometry']].explore('river_name', style_kwds=dict(weight=6))
Make this Notebook Trusted to load map: File -> Trust Notebook

It looks like the data was cut short!

Must be an error in the SWORD Database. Let’s check by singling out the reach it left off on.

It looks like reach ‘73120000131’ at the time of this run (4/1/24) has ‘no_data’ in the rch_id_up field when there should be values. To help out the SWORD database creators, we can report this discrepancy by clicking the Report Reach button at https://www.swordexplorer.com/. SWORD should be updated quarterly.

SWOT_HR_df[SWOT_HR_df.reach_id == '73120000131']
reach_id time time_tai time_str p_lat p_lon river_name wse wse_u wse_r_u wse_c wse_c_u slope slope_u slope_r_u slope2 slope2_u slope2_r_u width width_u width_c width_c_u area_total area_tot_u area_detct area_det_u area_wse d_x_area d_x_area_u layovr_val node_dist loc_offset xtrk_dist dschg_c dschg_c_u dschg_csf dschg_c_q dschg_gc dschg_gc_u dschg_gcsf dschg_gc_q dschg_m dschg_m_u dschg_msf dschg_m_q dschg_gm dschg_gm_u dschg_gmsf dschg_gm_q dschg_b dschg_b_u dschg_bsf dschg_b_q dschg_gb dschg_gb_u dschg_gbsf dschg_gb_q dschg_h dschg_h_u dschg_hsf dschg_h_q dschg_gh dschg_gh_u dschg_ghsf dschg_gh_q dschg_o dschg_o_u dschg_osf dschg_o_q dschg_go dschg_go_u dschg_gosf dschg_go_q dschg_s dschg_s_u dschg_ssf dschg_s_q dschg_gs dschg_gs_u dschg_gssf dschg_gs_q dschg_i dschg_i_u dschg_isf dschg_i_q dschg_gi dschg_gi_u dschg_gisf dschg_gi_q dschg_q_b dschg_gq_b reach_q reach_q_b dark_frac ice_clim_f ice_dyn_f partial_f n_good_nod obs_frac_n xovr_cal_q geoid_hght geoid_slop solid_tide load_tidef load_tideg pole_tide dry_trop_c wet_trop_c iono_c xovr_cal_c n_reach_up n_reach_dn rch_id_up rch_id_dn p_wse p_wse_var p_width p_wid_var p_n_nodes p_dist_out p_length p_maf p_dam_id p_n_ch_max p_n_ch_mod p_low_slp geometry
4289 73120000131 7.603747e+08 7.603748e+08 2024-02-04T15:12:22Z 42.150023 -72.611327 Connecticut River; Westfield River 17.8123 1.75473 1.75242 -1.000000e+12 -1.000000e+12 0.000037 0.000070 0.000069 -0.001077 -1.000000e+12 0.149820 269.926514 0.917276 -1.000000e+12 -1.000000e+12 4913349.6 16696.7556 4020726.7 16696.8 4913349.6 -1.000000e+12 -1.000000e+12 7.4382 77.889768 3.07849 -17744.08203 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 8651194 8651194 2 524298 0.181673 1 -999 0 63 0.692308 1 -29.751362 0.000009 -0.086159 -0.000891 -0.001675 0.005661 -2.308405 -0.038409 -0.007717 -0.119022 0 1 no_data, no_data, no_data, no_data 73120000121, no_data, no_data, no_data 11.400001 17.519935 283.0 3330.789 91 151626.309 18201.09844 -1.000000e+12 0 2 1 0 LINESTRING (-72.58355 42.08302, -72.58318 42.0...
826 73120000131 7.605090e+08 7.605090e+08 2024-02-06T04:29:28Z 42.150023 -72.611327 Connecticut River; Westfield River 12.6637 0.19421 0.17210 -1.000000e+12 -1.000000e+12 0.000114 0.000017 0.000017 0.000086 -1.000000e+12 0.001538 287.245279 0.797441 -1.000000e+12 -1.000000e+12 5228595.3 14515.4526 4606508.3 14515.5 5228595.3 -1.000000e+12 -1.000000e+12 9.1697 44.128698 1.25673 22611.02344 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 8651192 8651192 2 524302 0.118978 1 -999 0 79 0.868132 0 -29.758129 0.000009 0.174483 0.010891 0.010403 0.005627 -2.314298 -0.038225 -0.003412 0.275083 0 1 no_data, no_data, no_data, no_data 73120000121, no_data, no_data, no_data 11.400001 17.519935 283.0 3330.789 91 151626.309 18201.09844 -1.000000e+12 0 2 1 0 LINESTRING (-72.58355 42.08302, -72.58318 42.0...
5005 73120000131 7.621774e+08 7.621775e+08 2024-02-25T11:57:28Z 42.150023 -72.611327 Connecticut River; Westfield River 18.6698 0.71056 0.70483 -1.000000e+12 -1.000000e+12 -0.000197 0.000013 0.000013 -0.000449 -1.000000e+12 0.016066 176.825294 0.749504 -1.000000e+12 -1.000000e+12 3180801.8 13482.3639 2471691.4 13482.4 3180801.8 -1.000000e+12 -1.000000e+12 14.1412 61.492919 25.47558 -18295.04688 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 25428408 25428408 2 524298 0.222934 1 -999 0 57 0.626374 1 -29.754559 0.000009 -0.107900 -0.010993 -0.011123 0.004992 -2.318859 -0.020506 -0.004491 0.533674 0 1 no_data, no_data, no_data, no_data 73120000121, no_data, no_data, no_data 11.400001 17.519935 283.0 3330.789 91 151626.309 18201.09844 -1.000000e+12 0 2 1 0 LINESTRING (-72.58355 42.08302, -72.58318 42.0...
1785 73120000131 7.623117e+08 7.623117e+08 2024-02-27T01:14:33Z 42.150023 -72.611327 Connecticut River; Westfield River 14.2290 56.55282 56.55275 -1.000000e+12 -1.000000e+12 0.000227 0.000755 0.000755 0.000221 -1.000000e+12 105.629895 174.128982 0.481409 -1.000000e+12 -1.000000e+12 3020238.5 8349.9574 1643032.9 8350.0 3020238.5 -1.000000e+12 -1.000000e+12 3.7414 59.205995 -254.38090 22761.77734 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 8651194 8651194 2 559118 0.455992 1 -999 1 40 0.439560 0 -29.787819 0.000010 -0.097246 -0.010257 -0.009368 0.004914 -2.311219 -0.055498 -0.004463 -0.923738 0 1 no_data, no_data, no_data, no_data 73120000121, no_data, no_data, no_data 11.400001 17.519935 283.0 3330.789 91 151626.309 18201.09844 -1.000000e+12 0 2 1 0 LINESTRING (-72.58355 42.08302, -72.58318 42.0...
5721 73120000131 7.639802e+08 7.639802e+08 2024-03-17T08:42:30Z 42.150023 -72.611327 Connecticut River; Westfield River 16.4579 1.45118 1.44838 -1.000000e+12 -1.000000e+12 -0.000051 0.000020 0.000020 -0.000040 -1.000000e+12 0.101899 253.869874 0.921815 -1.000000e+12 -1.000000e+12 4365151.0 15850.0907 3943427.8 15850.1 4365151.0 -1.000000e+12 -1.000000e+12 8.2200 61.505402 34.55020 -17854.23730 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 -1.000000e+12 -1.000000e+12 -1.000000e+12 -999 25428408 25428408 2 524298 0.096611 1 -999 0 56 0.615385 1 -29.751930 0.000009 -0.081659 -0.008595 -0.009871 0.003843 -2.277789 -0.089168 -0.003424 0.688992 0 1 no_data, no_data, no_data, no_data 73120000121, no_data, no_data, no_data 11.400001 17.519935 283.0 3330.789 91 151626.309 18201.09844 -1.000000e+12 0 2 1 0 LINESTRING (-72.58355 42.08302, -72.58318 42.0...

4. Visualize and plot a time series of WSE/width/slope longitudinal profiles

Let’s create a time series dataframe from the downstream filtered database

# Retrieve all possible acquisition dates (keeping only YYYY-MM-DD)
dates = np.unique([i[:10] for i in [x for x in SWOT_HR_df['time_str'] if x!='no_data']])

# Create a new database for time series analysis with unique reach_ids
SWOT_dn_trace_time = SWOT_dn_trace.set_index('reach_id').groupby(level=0) \
                                  .apply(lambda df: df.reset_index(drop=True)) \
                                  .unstack().sort_index(axis=1, level=1)

SWOT_dn_trace_time.columns = ['{}_{}'.format(x[0],dates[x[1]]) for x in SWOT_dn_trace_time.columns]

Plot a longitudinal profile for selected SWOT variable

# Explore variables you could choose to plot
for var in ["wse","slope","width","len"]:
    print(SWOT_dn_trace.columns[SWOT_dn_trace.columns.str.contains(var)])
Index(['wse', 'wse_u', 'wse_r_u', 'wse_c', 'wse_c_u', 'area_wse', 'p_wse',
       'p_wse_var'],
      dtype='object')
Index(['slope', 'slope_u', 'slope_r_u', 'slope2', 'slope2_u', 'slope2_r_u'], dtype='object')
Index(['width', 'width_u', 'width_c', 'width_c_u', 'p_width'], dtype='object')
Index(['p_length'], dtype='object')
# Enter variable of interest for plotting
varstr = "wse"

The error that outputs the following cell is because of the SWORD database discrepancy noted above. When this is corrected, only the graph should appear without the error.

# Find cumulative length on the longitudinal profile
length_list    = np.nan_to_num([SWOT_dn_trace.p_length[SWOT_dn_trace.reach_id == rch].mean()/1000 for rch in rch_dn_list])
cumlength_list = np.cumsum(length_list)

## Plot a longitudinal profile from the downstream tracing database

## Plot a longitudinal profile from the downstream tracing database
plt.figure(figsize=(12,8))
for t in dates:
    
    # Store the quantity of interest (wse, width etc.) at time t
    value = SWOT_dn_trace_time.loc[rch_dn_list,varstr+'_'+t]
    
    # Remove set negative values (bad observations) to NaN and forward fill NaNs
    value[value < 0] = np.nan
    value = value.ffill()
    
    # Plot the data
    plt.plot(cumlength_list, value, label = varstr+'_'+t)
    
plt.xlabel('Downstream Distance (km)')
plt.ylabel(varstr)
plt.legend()
KeyError: 'wse_2024-03-06'

Map the longitudinal profile of selected SWOT variable

# Choose a date
date = dates[1]
#Set one column as the active geometry in the new database
SWOT_dn_trace_time = SWOT_dn_trace_time.set_geometry("geometry_"+date)

#Set cleaner colorbar bounds for better visualization
vmin = np.percentile([i for i in SWOT_dn_trace_time[varstr+'_'+date] if i>0],5)
vmax = np.percentile([i for i in SWOT_dn_trace_time[varstr+'_'+date] if i>0],95)

# Interactive map
SWOT_dn_trace_time.explore(varstr+'_'+date,
                           vmin = vmin,
                           vmax = vmax,
                           cmap = "Blues", #"Blues",
                           control_scale = True,
                           tooltip = varstr+'_'+dates[0],  # show "varstr+'_'+dates[0]" value in tooltip (on hover)
                           popup = True,  # show all values in popup (on click)
                           #tiles = "CartoDB positron",  # use "CartoDB positron" tiles
                           style_kwds=dict(weight=10)
                          )
Make this Notebook Trusted to load map: File -> Trust Notebook

Supplemental

We can also map the upstream traced database

SWOT_up_trace_time = SWOT_up_trace.set_index('reach_id').groupby(level=0) \
                                  .apply(lambda df: df.reset_index(drop=True)) \
                                  .unstack().sort_index(axis=1, level=1)

SWOT_up_trace_time.columns = ['{}_{}'.format(x[0],dates[x[1]]) for x in SWOT_up_trace_time.columns]

SWOT_up_trace_time = SWOT_up_trace_time.set_geometry("geometry_"+date)

#Set cleaner colorbar bounds for better visualization
vmin = np.percentile([i for i in SWOT_up_trace_time[varstr+'_'+date] if i>0],5)
vmax = np.percentile([i for i in SWOT_up_trace_time[varstr+'_'+date] if i>0],95)

# Interactive map
SWOT_up_trace_time.explore(varstr+'_'+date,
                           vmin = vmin,
                           vmax = vmax,
                           cmap = "Blues", #"Blues",
                           control_scale = True,
                           tooltip = varstr+'_'+dates[0],  # show "varstr+'_'+dates[0]" value in tooltip (on hover)
                           popup = True,  # show all values in popup (on click)
                           tiles = "CartoDB positron",  # use "CartoDB positron" tiles
                           style_kwds=dict(weight=5)
                          )
Make this Notebook Trusted to load map: File -> Trust Notebook

How to filter out raster data to reveal water bodies?

We can also search by spatial bounding box. Raster tiles make it easy to do this since their footprints in the metadata are smaller. If you want the tile number, you can find it in the kmz file.

# Retrieve granules from all days to find the cycle corresponding to the desired date
raster_results = earthaccess.search_data(short_name = 'SWOT_L2_HR_Raster_100m_2.0', 
                                         temporal = ('2024-01-25 00:00:00', '2024-03-29 23:59:59'), 
                                         bounding_box = (-72.44, 42.27, -72.15, 42.54)) # Quabbin Reservoir in Massachusetts
Granules found: 11

Display details of accessed files

print([i for i in raster_results])
[Collection: {'Version': '2.0', 'ShortName': 'SWOT_L2_HR_Raster_100m_2.0'}
Spatial coverage: {'HorizontalSpatialDomain': {'Geometry': {'GPolygons': [{'Boundary': {'Points': [{'Latitude': 41.952112658860564, 'Longitude': -72.42544746840993}, {'Latitude': 41.952112658860564, 'Longitude': -70.53315398295408}, {'Latitude': 43.348708275316724, 'Longitude': -70.53315398295408}, {'Latitude': 43.348708275316724, 'Longitude': -72.42544746840993}, {'Latitude': 41.952112658860564, 'Longitude': -72.42544746840993}]}}], 'BoundingRectangles': [{'WestBoundingCoordinate': -72.42544746840993, 'SouthBoundingCoordinate': 41.952112658860564, 'EastBoundingCoordinate': -70.53315398295408, 'NorthBoundingCoordinate': 43.348708275316724}]}, 'Track': {'Cycle': 10, 'Passes': [{'Pass': 35, 'Tiles': ['228L', '229L', '230L', '231L', '228R', '229R', '230R', '231R']}]}}}
Temporal coverage: {'RangeDateTime': {'EndingDateTime': '2024-01-26T06:07:09.985Z', 'BeginningDateTime': '2024-01-26T06:06:48.882Z'}}
Size(MB): 92.35498809814453
Data: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_2.0/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_010_035_115F_20240126T060648_20240126T060709_PIC0_01.nc'], Collection: {'Version': '2.0', 'ShortName': 'SWOT_L2_HR_Raster_100m_2.0'}
Spatial coverage: {'HorizontalSpatialDomain': {'Geometry': {'GPolygons': [{'Boundary': {'Points': [{'Latitude': 41.95211265886055, 'Longitude': -73.96975463204575}, {'Latitude': 41.95211265886055, 'Longitude': -72.07746114659037}, {'Latitude': 43.348708275316724, 'Longitude': -72.07746114659037}, {'Latitude': 43.348708275316724, 'Longitude': -73.96975463204575}, {'Latitude': 41.95211265886055, 'Longitude': -73.96975463204575}]}}], 'BoundingRectangles': [{'WestBoundingCoordinate': -73.96975463204575, 'SouthBoundingCoordinate': 41.95211265886055, 'EastBoundingCoordinate': -72.07746114659037, 'NorthBoundingCoordinate': 43.348708275316724}]}, 'Track': {'Cycle': 10, 'Passes': [{'Pass': 298, 'Tiles': ['078L', '079L', '080L', '081L', '078R', '079R', '080R', '081R']}]}}}
Temporal coverage: {'RangeDateTime': {'EndingDateTime': '2024-02-04T15:12:41.048Z', 'BeginningDateTime': '2024-02-04T15:12:19.946Z'}}
Size(MB): 71.12618827819824
Data: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_2.0/SWOT_L2_HR_Raster_100m_UTM18T_N_x_x_x_010_298_040F_20240204T151219_20240204T151241_PIC0_01.nc'], Collection: {'Version': '2.0', 'ShortName': 'SWOT_L2_HR_Raster_100m_2.0'}
Spatial coverage: {'HorizontalSpatialDomain': {'Geometry': {'GPolygons': [{'Boundary': {'Points': [{'Latitude': 41.95211265886055, 'Longitude': -73.65832419541033}, {'Latitude': 41.95211265886055, 'Longitude': -71.76603070995414}, {'Latitude': 43.34870827531672, 'Longitude': -71.76603070995414}, {'Latitude': 43.34870827531672, 'Longitude': -73.65832419541033}, {'Latitude': 41.95211265886055, 'Longitude': -73.65832419541033}]}}], 'BoundingRectangles': [{'WestBoundingCoordinate': -73.65832419541033, 'SouthBoundingCoordinate': 41.95211265886055, 'EastBoundingCoordinate': -71.76603070995414, 'NorthBoundingCoordinate': 43.34870827531672}]}, 'Track': {'Cycle': 10, 'Passes': [{'Pass': 341, 'Tiles': ['228L', '229L', '230L', '231L', '228R', '229R', '230R', '231R']}]}}}
Temporal coverage: {'RangeDateTime': {'EndingDateTime': '2024-02-06T04:29:57.503Z', 'BeginningDateTime': '2024-02-06T04:29:36.398Z'}}
Size(MB): 71.9098253250122
Data: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_2.0/SWOT_L2_HR_Raster_100m_UTM18T_N_x_x_x_010_341_115F_20240206T042936_20240206T042957_PIC0_01.nc'], Collection: {'Version': '2.0', 'ShortName': 'SWOT_L2_HR_Raster_100m_2.0'}
Spatial coverage: {'HorizontalSpatialDomain': {'Geometry': {'GPolygons': [{'Boundary': {'Points': [{'Latitude': 41.95211265886055, 'Longitude': -72.7368779330462}, {'Latitude': 41.95211265886055, 'Longitude': -70.84458444759079}, {'Latitude': 43.34870827531672, 'Longitude': -70.84458444759079}, {'Latitude': 43.34870827531672, 'Longitude': -72.7368779330462}, {'Latitude': 41.95211265886055, 'Longitude': -72.7368779330462}]}}], 'BoundingRectangles': [{'WestBoundingCoordinate': -72.7368779330462, 'SouthBoundingCoordinate': 41.95211265886055, 'EastBoundingCoordinate': -70.84458444759079, 'NorthBoundingCoordinate': 43.34870827531672}]}, 'Track': {'Cycle': 10, 'Passes': [{'Pass': 576, 'Tiles': ['078L', '079L', '080L', '081L', '078R', '079R', '080R', '081R']}]}}}
Temporal coverage: {'RangeDateTime': {'EndingDateTime': '2024-02-14T13:34:58.030Z', 'BeginningDateTime': '2024-02-14T13:34:36.929Z'}}
Size(MB): 83.17313957214355
Data: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_2.0/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_010_576_040F_20240214T133436_20240214T133458_PIC0_01.nc'], Collection: {'Version': '2.0', 'ShortName': 'SWOT_L2_HR_Raster_100m_2.0'}
Spatial coverage: {'HorizontalSpatialDomain': {'Geometry': {'GPolygons': [{'Boundary': {'Points': [{'Latitude': 41.952112658860564, 'Longitude': -72.42544746840993}, {'Latitude': 41.952112658860564, 'Longitude': -70.53315398295408}, {'Latitude': 43.348708275316724, 'Longitude': -70.53315398295408}, {'Latitude': 43.348708275316724, 'Longitude': -72.42544746840993}, {'Latitude': 41.952112658860564, 'Longitude': -72.42544746840993}]}}], 'BoundingRectangles': [{'WestBoundingCoordinate': -72.42544746840993, 'SouthBoundingCoordinate': 41.952112658860564, 'EastBoundingCoordinate': -70.53315398295408, 'NorthBoundingCoordinate': 43.348708275316724}]}, 'Track': {'Cycle': 11, 'Passes': [{'Pass': 35, 'Tiles': ['228L', '229L', '230L', '231L', '228R', '229R', '230R', '231R']}]}}}
Temporal coverage: {'RangeDateTime': {'EndingDateTime': '2024-02-16T02:52:14.795Z', 'BeginningDateTime': '2024-02-16T02:51:53.691Z'}}
Size(MB): 88.53574657440186
Data: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_2.0/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_011_035_115F_20240216T025153_20240216T025214_PIC0_01.nc'], Collection: {'Version': '2.0', 'ShortName': 'SWOT_L2_HR_Raster_100m_2.0'}
Spatial coverage: {'HorizontalSpatialDomain': {'Geometry': {'GPolygons': [{'Boundary': {'Points': [{'Latitude': 41.95211265886055, 'Longitude': -73.96975463204575}, {'Latitude': 41.95211265886055, 'Longitude': -72.07746114659037}, {'Latitude': 43.348708275316724, 'Longitude': -72.07746114659037}, {'Latitude': 43.348708275316724, 'Longitude': -73.96975463204575}, {'Latitude': 41.95211265886055, 'Longitude': -73.96975463204575}]}}], 'BoundingRectangles': [{'WestBoundingCoordinate': -73.96975463204575, 'SouthBoundingCoordinate': 41.95211265886055, 'EastBoundingCoordinate': -72.07746114659037, 'NorthBoundingCoordinate': 43.348708275316724}]}, 'Track': {'Cycle': 11, 'Passes': [{'Pass': 298, 'Tiles': ['078L', '079L', '080L', '081L', '078R', '079R', '080R', '081R']}]}}}
Temporal coverage: {'RangeDateTime': {'EndingDateTime': '2024-02-25T11:57:46.348Z', 'BeginningDateTime': '2024-02-25T11:57:25.248Z'}}
Size(MB): 65.02922439575195
Data: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_2.0/SWOT_L2_HR_Raster_100m_UTM18T_N_x_x_x_011_298_040F_20240225T115725_20240225T115746_PIC0_01.nc'], Collection: {'Version': '2.0', 'ShortName': 'SWOT_L2_HR_Raster_100m_2.0'}
Spatial coverage: {'HorizontalSpatialDomain': {'Geometry': {'GPolygons': [{'Boundary': {'Points': [{'Latitude': 41.95211265886055, 'Longitude': -73.65832419541033}, {'Latitude': 41.95211265886055, 'Longitude': -71.76603070995414}, {'Latitude': 43.34870827531672, 'Longitude': -71.76603070995414}, {'Latitude': 43.34870827531672, 'Longitude': -73.65832419541033}, {'Latitude': 41.95211265886055, 'Longitude': -73.65832419541033}]}}], 'BoundingRectangles': [{'WestBoundingCoordinate': -73.65832419541033, 'SouthBoundingCoordinate': 41.95211265886055, 'EastBoundingCoordinate': -71.76603070995414, 'NorthBoundingCoordinate': 43.34870827531672}]}, 'Track': {'Cycle': 11, 'Passes': [{'Pass': 341, 'Tiles': ['228L', '229L', '230L', '231L', '228R', '229R', '230R', '231R']}]}}}
Temporal coverage: {'RangeDateTime': {'EndingDateTime': '2024-02-27T01:15:02.918Z', 'BeginningDateTime': '2024-02-27T01:14:41.812Z'}}
Size(MB): 60.877685546875
Data: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_2.0/SWOT_L2_HR_Raster_100m_UTM18T_N_x_x_x_011_341_115F_20240227T011441_20240227T011502_PIC0_01.nc'], Collection: {'Version': '2.0', 'ShortName': 'SWOT_L2_HR_Raster_100m_2.0'}
Spatial coverage: {'HorizontalSpatialDomain': {'Geometry': {'GPolygons': [{'Boundary': {'Points': [{'Latitude': 41.95211265886055, 'Longitude': -72.7368779330462}, {'Latitude': 41.95211265886055, 'Longitude': -70.84458444759079}, {'Latitude': 43.34870827531672, 'Longitude': -70.84458444759079}, {'Latitude': 43.34870827531672, 'Longitude': -72.7368779330462}, {'Latitude': 41.95211265886055, 'Longitude': -72.7368779330462}]}}], 'BoundingRectangles': [{'WestBoundingCoordinate': -72.7368779330462, 'SouthBoundingCoordinate': 41.95211265886055, 'EastBoundingCoordinate': -70.84458444759079, 'NorthBoundingCoordinate': 43.34870827531672}]}, 'Track': {'Cycle': 11, 'Passes': [{'Pass': 576, 'Tiles': ['078L', '079L', '080L', '081L', '078R', '079R', '080R', '081R']}]}}}
Temporal coverage: {'RangeDateTime': {'EndingDateTime': '2024-03-06T10:20:02.252Z', 'BeginningDateTime': '2024-03-06T10:19:41.156Z'}}
Size(MB): 89.60176181793213
Data: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_2.0/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_011_576_040F_20240306T101941_20240306T102002_PIC0_01.nc'], Collection: {'Version': '2.0', 'ShortName': 'SWOT_L2_HR_Raster_100m_2.0'}
Spatial coverage: {'HorizontalSpatialDomain': {'Geometry': {'GPolygons': [{'Boundary': {'Points': [{'Latitude': 41.952112658860564, 'Longitude': -72.42544746840993}, {'Latitude': 41.952112658860564, 'Longitude': -70.53315398295408}, {'Latitude': 43.348708275316724, 'Longitude': -70.53315398295408}, {'Latitude': 43.348708275316724, 'Longitude': -72.42544746840993}, {'Latitude': 41.952112658860564, 'Longitude': -72.42544746840993}]}}], 'BoundingRectangles': [{'WestBoundingCoordinate': -72.42544746840993, 'SouthBoundingCoordinate': 41.952112658860564, 'EastBoundingCoordinate': -70.53315398295408, 'NorthBoundingCoordinate': 43.348708275316724}]}, 'Track': {'Cycle': 12, 'Passes': [{'Pass': 35, 'Tiles': ['228L', '229L', '230L', '231L', '228R', '229R', '230R', '231R']}]}}}
Temporal coverage: {'RangeDateTime': {'EndingDateTime': '2024-03-07T23:37:18.702Z', 'BeginningDateTime': '2024-03-07T23:36:57.601Z'}}
Size(MB): 99.20879173278809
Data: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_2.0/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_012_035_115F_20240307T233657_20240307T233718_PIC0_01.nc'], Collection: {'Version': '2.0', 'ShortName': 'SWOT_L2_HR_Raster_100m_2.0'}
Spatial coverage: {'HorizontalSpatialDomain': {'Geometry': {'GPolygons': [{'Boundary': {'Points': [{'Latitude': 41.95211265886055, 'Longitude': -73.96975463204575}, {'Latitude': 41.95211265886055, 'Longitude': -72.07746114659037}, {'Latitude': 43.348708275316724, 'Longitude': -72.07746114659037}, {'Latitude': 43.348708275316724, 'Longitude': -73.96975463204575}, {'Latitude': 41.95211265886055, 'Longitude': -73.96975463204575}]}}], 'BoundingRectangles': [{'WestBoundingCoordinate': -73.96975463204575, 'SouthBoundingCoordinate': 41.95211265886055, 'EastBoundingCoordinate': -72.07746114659037, 'NorthBoundingCoordinate': 43.348708275316724}]}, 'Track': {'Cycle': 12, 'Passes': [{'Pass': 298, 'Tiles': ['078L', '079L', '080L', '081L', '078R', '079R', '080R', '081R']}]}}}
Temporal coverage: {'RangeDateTime': {'EndingDateTime': '2024-03-17T08:42:48.423Z', 'BeginningDateTime': '2024-03-17T08:42:27.323Z'}}
Size(MB): 72.32065773010254
Data: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_2.0/SWOT_L2_HR_Raster_100m_UTM18T_N_x_x_x_012_298_040F_20240317T084227_20240317T084248_PIC0_01.nc'], Collection: {'Version': '2.0', 'ShortName': 'SWOT_L2_HR_Raster_100m_2.0'}
Spatial coverage: {'HorizontalSpatialDomain': {'Geometry': {'GPolygons': [{'Boundary': {'Points': [{'Latitude': 41.95211265886055, 'Longitude': -72.7368779330462}, {'Latitude': 41.95211265886055, 'Longitude': -70.84458444759079}, {'Latitude': 43.34870827531672, 'Longitude': -70.84458444759079}, {'Latitude': 43.34870827531672, 'Longitude': -72.7368779330462}, {'Latitude': 41.95211265886055, 'Longitude': -72.7368779330462}]}}], 'BoundingRectangles': [{'WestBoundingCoordinate': -72.7368779330462, 'SouthBoundingCoordinate': 41.95211265886055, 'EastBoundingCoordinate': -70.84458444759079, 'NorthBoundingCoordinate': 43.34870827531672}]}, 'Track': {'Cycle': 12, 'Passes': [{'Pass': 576, 'Tiles': ['078L', '079L', '080L', '081L', '078R', '079R', '080R', '081R']}]}}}
Temporal coverage: {'RangeDateTime': {'EndingDateTime': '2024-03-27T07:05:05.812Z', 'BeginningDateTime': '2024-03-27T07:04:44.714Z'}}
Size(MB): 89.06233215332031
Data: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_2.0/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_012_576_040F_20240327T070444_20240327T070505_PIC0_01.nc']]

Select a single file for visualization

Open file using xarray

ds_raster = xr.open_mfdataset(earthaccess.open([raster_results[1]]), engine='h5netcdf')
ds_raster
Opening 1 granules, approx size: 0.07 GB
using endpoint: https://archive.swot.podaac.earthdata.nasa.gov/s3credentials
<xarray.Dataset>
Dimensions:                  (x: 1574, y: 1574)
Coordinates:
  * x                        (x) float64 5.839e+05 5.84e+05 ... 7.412e+05
  * y                        (y) float64 4.645e+06 4.646e+06 ... 4.803e+06
Data variables: (12/39)
    crs                      object ...
    longitude                (y, x) float64 dask.array<chunksize=(525, 525), meta=np.ndarray>
    latitude                 (y, x) float64 dask.array<chunksize=(525, 525), meta=np.ndarray>
    wse                      (y, x) float32 dask.array<chunksize=(787, 787), meta=np.ndarray>
    wse_qual                 (y, x) float32 dask.array<chunksize=(1574, 1574), meta=np.ndarray>
    wse_qual_bitwise         (y, x) float64 dask.array<chunksize=(787, 787), meta=np.ndarray>
    ...                       ...
    load_tide_fes            (y, x) float32 dask.array<chunksize=(787, 787), meta=np.ndarray>
    load_tide_got            (y, x) float32 dask.array<chunksize=(787, 787), meta=np.ndarray>
    pole_tide                (y, x) float32 dask.array<chunksize=(787, 787), meta=np.ndarray>
    model_dry_tropo_cor      (y, x) float32 dask.array<chunksize=(787, 787), meta=np.ndarray>
    model_wet_tropo_cor      (y, x) float32 dask.array<chunksize=(787, 787), meta=np.ndarray>
    iono_cor_gim_ka          (y, x) float32 dask.array<chunksize=(787, 787), meta=np.ndarray>
Attributes: (12/49)
    Conventions:                   CF-1.7
    title:                         Level 2 KaRIn High Rate Raster Data Product
    source:                        Ka-band radar interferometer
    history:                       2024-02-08T18:43:05Z : Creation
    platform:                      SWOT
    references:                    V1.2.1
    ...                            ...
    x_min:                         583900.0
    x_max:                         741200.0
    y_min:                         4645400.0
    y_max:                         4802700.0
    institution:                   CNES
    product_version:               01
    • x
      PandasIndex
      PandasIndex(Float64Index([583900.0, 584000.0, 584100.0, 584200.0, 584300.0, 584400.0,
                    584500.0, 584600.0, 584700.0, 584800.0,
                    ...
                    740300.0, 740400.0, 740500.0, 740600.0, 740700.0, 740800.0,
                    740900.0, 741000.0, 741100.0, 741200.0],
                   dtype='float64', name='x', length=1574))
    • y
      PandasIndex
      PandasIndex(Float64Index([4645400.0, 4645500.0, 4645600.0, 4645700.0, 4645800.0, 4645900.0,
                    4646000.0, 4646100.0, 4646200.0, 4646300.0,
                    ...
                    4801800.0, 4801900.0, 4802000.0, 4802100.0, 4802200.0, 4802300.0,
                    4802400.0, 4802500.0, 4802600.0, 4802700.0],
                   dtype='float64', name='y', length=1574))
  • Conventions :
    CF-1.7
    title :
    Level 2 KaRIn High Rate Raster Data Product
    source :
    Ka-band radar interferometer
    history :
    2024-02-08T18:43:05Z : Creation
    platform :
    SWOT
    references :
    V1.2.1
    reference_document :
    JPL D-56416 - Revision C - December 8, 2023
    contact :
    podaac@podaac.jpl.nasa.gov
    cycle_number :
    10
    pass_number :
    298
    scene_number :
    40
    tile_numbers :
    [78 79 80 81 78 79 80 81]
    tile_names :
    298_078L, 298_079L, 298_080L, 298_081L, 298_078R, 298_079R, 298_080R, 298_081R
    tile_polarizations :
    H, H, H, H, V, V, V, V
    coordinate_reference_system :
    Universal Transverse Mercator
    resolution :
    100.0
    short_name :
    L2_HR_Raster
    descriptor_string :
    100m_UTM18T_N_x_x_x
    crid :
    PIC0
    pge_name :
    PGE_L2_HR_RASTER
    pge_version :
    5.1.1
    time_granule_start :
    2024-02-04T15:12:19.946118Z
    time_granule_end :
    2024-02-04T15:12:41.048879Z
    time_coverage_start :
    2024-02-04T15:12:20.482977Z
    time_coverage_end :
    2024-02-04T15:12:40.507776Z
    geospatial_lon_min :
    -73.96975463204575
    geospatial_lon_max :
    -72.07746114659037
    geospatial_lat_min :
    41.95211265886055
    geospatial_lat_max :
    43.348708275316724
    left_first_longitude :
    -72.44263832068619
    left_first_latitude :
    43.348708275316724
    left_last_longitude :
    -72.07746114659037
    left_last_latitude :
    42.22719163055777
    right_first_longitude :
    -73.96975463204575
    right_first_latitude :
    43.066480708621924
    right_last_longitude :
    -73.57988117405536
    right_last_latitude :
    41.95211265886055
    xref_l2_hr_pixc_files :
    SWOT_L2_HR_PIXC_010_298_078L_20240204T151209_20240204T151221_PIC0_01.nc, SWOT_L2_HR_PIXC_010_298_079L_20240204T151219_20240204T151231_PIC0_01.nc, SWOT_L2_HR_PIXC_010_298_080L_20240204T151229_20240204T151241_PIC0_01.nc, SWOT_L2_HR_PIXC_010_298_081L_20240204T151239_20240204T151251_PIC0_01.nc, SWOT_L2_HR_PIXC_010_298_078R_20240204T151209_20240204T151221_PIC0_01.nc, SWOT_L2_HR_PIXC_010_298_079R_20240204T151219_20240204T151231_PIC0_01.nc, SWOT_L2_HR_PIXC_010_298_080R_20240204T151229_20240204T151241_PIC0_01.nc, SWOT_L2_HR_PIXC_010_298_081R_20240204T151239_20240204T151251_PIC0_01.nc
    xref_l2_hr_pixcvec_files :
    SWOT_L2_HR_PIXCVec_010_298_078L_20240204T151209_20240204T151221_PIC0_01.nc, SWOT_L2_HR_PIXCVec_010_298_079L_20240204T151219_20240204T151231_PIC0_01.nc, SWOT_L2_HR_PIXCVec_010_298_080L_20240204T151229_20240204T151241_PIC0_01.nc, SWOT_L2_HR_PIXCVec_010_298_081L_20240204T151239_20240204T151251_PIC0_01.nc, SWOT_L2_HR_PIXCVec_010_298_078R_20240204T151209_20240204T151221_PIC0_01.nc, SWOT_L2_HR_PIXCVec_010_298_079R_20240204T151219_20240204T151231_PIC0_01.nc, SWOT_L2_HR_PIXCVec_010_298_080R_20240204T151229_20240204T151241_PIC0_01.nc, SWOT_L2_HR_PIXCVec_010_298_081R_20240204T151239_20240204T151251_PIC0_01.nc
    xref_param_l2_hr_raster_file :
    SWOT_Param_L2_HR_Raster_20000101T000000_21000101T000000_20230817T100000_v302.rdf
    xref_reforbittrack_files :
    SWOT_RefOrbitTrackTileBoundary_Nom_20000101T000000_21000101T000000_20200617T193054_v101.txt, SWOT_RefOrbitTrack125mPass1_Nom_20000101T000000_21000101T000000_20200617T193054_v101.txt, SWOT_RefOrbitTrack125mPass2_Nom_20000101T000000_21000101T000000_20200617T193054_v101.txt
    utm_zone_num :
    18
    mgrs_latitude_band :
    T
    x_min :
    583900.0
    x_max :
    741200.0
    y_min :
    4645400.0
    y_max :
    4802700.0
    institution :
    CNES
    product_version :
    01
  • Plot raster data using custom filters to improve image quality

    # Plot the data with a filter on water_frac > x, or sig0>50
    ds_raster.wse.where(ds_raster.water_frac > 0.5).hvplot.image(y='y', x='x').opts(cmap='Blues', clim=(vmin,vmax), width=1000, height=750)

    To continue this analysis and mask data with quality flags, see the end of this notebook.