diff --git a/.nojekyll b/.nojekyll index 6ff11b9..23708fe 100644 --- a/.nojekyll +++ b/.nojekyll @@ -1 +1 @@ -ddfcb7e0 \ No newline at end of file +d7dc2ec3 \ No newline at end of file diff --git a/Tutorials/SWOTHR_Science_Application.html b/Tutorials/SWOTHR_Science_Application.html new file mode 100644 index 0000000..eb5e541 --- /dev/null +++ b/Tutorials/SWOTHR_Science_Application.html @@ -0,0 +1,4166 @@ + + + + + + + + + +2024 SWOT Pre-Conference Workshop: AGU Chapman - SWOT Hydrology Science Application Tutorial on the Cloud + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+ +
+ + + + +
+ +
+
+

SWOT Hydrology Science Application Tutorial on the Cloud

+
+ + + +
+ + + + +
+ + + +
+ + +
+

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 1.1).

+

Notebook Authors: Arnaud Cerbelaud, Jeffrey Wade, NASA Jet Propulsion Laboratory - California Institute of Technology (Jan 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
    • +
    • Upstream tracing from reach id
      +
    • +
  2. +
  3. River longitudinal profile: filtering data to display all reaches located downstream of a given reach (e.g. headwater to outlet)
  4. +
  5. Watershed analysis: filtering data to display all reaches located upstream of a given reach (e.g. outlet to full river network)
  6. +
  7. Visualize and plot WSE, width, slope data on the filtered data
  8. +
+

Last updated: 31 Jan 2024

+
+
+

Import Packages

+
+
import glob
+import os
+import requests
+import s3fs
+import fiona
+import netCDF4 as nc
+import h5netcdf
+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
+from earthaccess import Auth, DataCollections, DataGranules, Store
+from pathlib import Path
+import zipfile
+
+ +
+
+ +
+
+ +
+
+
+
+

Authenticate

+

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

+
+
earthaccess.login() # Login with your EDL credentials if asked
+
+
Enter your Earthdata Login username:  jswade
+Enter your Earthdata password:  ········
+
+
+
<earthaccess.auth.Auth at 0x7fd9a7adbee0>
+
+
+
+
+

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 (Version 1.1) 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    = "009"   # e.g. 009 for Connecticut in NA, 003 for Rhine in EU
+# Enter continent code
+continent_code = "NA"     # e.g. "AF", "NA", "EU", "SI", "AS", "AU", "SA", "AR", "GR"
+
+# Retrieves granule from the day we want, in this case by passing to `earthdata.search_data` function the data collection shortname and temporal bounds
+river_results = earthaccess.search_data(short_name = 'SWOT_L2_HR_RIVERSP_1.1', 
+                                        temporal = ('2023-04-08 00:00:00', '2023-04-12 23:59:59'),
+                                        granule_name = "*Reach*_" + pass_number + "_" + continent_code + "*")
+
+# Create fiona session to read data
+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"]
+    )
+
+
Granules found: 5
+
+
+
+
+

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(river_results)):
+    
+    # Get the link for each zip file
+    river_link = earthaccess.results.DataGranule.data_links(river_results[j], access='direct')[0]
+    
+    # We use the zip+ prefix so fiona knows that we are operating on a zip file
+    river_shp_url = f"zip+{river_link}"
+    
+    # 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_idtimetime_taitime_strp_latp_lonriver_namewsewse_uwse_r_u...p_wid_varp_n_nodesp_dist_outp_lengthp_mafp_dam_idp_n_ch_maxp_n_ch_modp_low_slpgeometry
195872270400231-1.000000e+12-1.000000e+12no_data56.794630-66.461122no_data-1.000000e+12-1.000000e+12-1.000000e+12...1618.07953230079.47210630.774958-1.000000e+120110LINESTRING (-66.48682 56.83442, -66.48645 56.8...
264172270400231-1.000000e+12-1.000000e+12no_data56.794630-66.461122no_data-1.000000e+12-1.000000e+12-1.000000e+12...1618.07953230079.47210630.774958-1.000000e+120110LINESTRING (-66.48682 56.83442, -66.48645 56.8...
195972270400241-1.000000e+12-1.000000e+12no_data56.744361-66.341905no_data-1.000000e+12-1.000000e+12-1.000000e+12...4831.12853240728.43010648.958289-1.000000e+120210LINESTRING (-66.41602 56.75969, -66.41553 56.7...
264272270400241-1.000000e+12-1.000000e+12no_data56.744361-66.341905no_data-1.000000e+12-1.000000e+12-1.000000e+12...4831.12853240728.43010648.958289-1.000000e+120210LINESTRING (-66.41602 56.75969, -66.41553 56.7...
1960722704002517.344991e+087.344991e+082023-04-11T03:31:02Z56.676087-66.219811no_data2.855340e+021.008930e+001.004910e+00...412.97558252286.76911558.339052-1.000000e+120210LINESTRING (-66.27812 56.71437, -66.27775 56.7...
..................................................................
61573130000061-1.000000e+12-1.000000e+12no_data41.424945-73.230960Housatonic River-1.000000e+12-1.000000e+12-1.000000e+12...10469.7068247161.19116303.793847-1.000000e+120210LINESTRING (-73.17436 41.38295, -73.17465 41.3...
128373130000061-1.000000e+12-1.000000e+12no_data41.424945-73.230960Housatonic River-1.000000e+12-1.000000e+12-1.000000e+12...10469.7068247161.19116303.793847-1.000000e+120210LINESTRING (-73.17436 41.38295, -73.17465 41.3...
195773130000061-1.000000e+12-1.000000e+12no_data41.424945-73.230960Housatonic River-1.000000e+12-1.000000e+12-1.000000e+12...10469.7068247161.19116303.793847-1.000000e+120210LINESTRING (-73.17436 41.38295, -73.17465 41.3...
264073130000061-1.000000e+12-1.000000e+12no_data41.424945-73.230960Housatonic River-1.000000e+12-1.000000e+12-1.000000e+12...10469.7068247161.19116303.793847-1.000000e+120210LINESTRING (-73.17436 41.38295, -73.17465 41.3...
331273130000061-1.000000e+12-1.000000e+12no_data41.424945-73.230960Housatonic River-1.000000e+12-1.000000e+12-1.000000e+12...10469.7068247161.19116303.793847-1.000000e+120210LINESTRING (-73.17436 41.38295, -73.17465 41.3...
+ +

3313 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:
+['2023-04-08' '2023-04-09' '2023-04-10' '2023-04-11' '2023-04-12'
+ 'no_data']
+Available rivers are:
+['Allagash River' 'Androscoggin River' 'Big Black River' 'Canal de fuite'
+ 'Carrabassett River' 'Concord River' 'Concord River; Sudbury River'
+ 'Connecticut River' 'Connecticut River; Westfield River'
+ 'Connecticut River; White River' 'Dead River'
+ 'Dead River (Kennebec River)' 'Deerfield River' 'Farmington River'
+ 'Housatonic River' 'Ikarut River' 'Kennebec River' 'Komaktorvik River'
+ 'Magalloway River' 'Merrimack River' 'Moose River'
+ 'North Branch Penobscot River' 'Passumsic River' 'Pemigewasset River'
+ 'Penobscot River West Branch' 'Quinebaug River' 'Saco River'
+ 'Saguenay River' 'Saint Francis River' 'Saint John River'
+ 'Saint Lawrence River' 'Sandy River' 'Shetucket River' 'Sudbury River'
+ 'Thames River' 'West River' 'White River' '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.5,
+             "Rhine": 47.5
+            }
+lat_end   = {"Connecticut River": 45,
+             "Rhine": 51
+            }
+lon_start = {"Connecticut River": -74,
+             "Rhine": 7
+            }
+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
+
+
+
+
+
+

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": '73120000013',
+             "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
+
+
+
+
+
+

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"
+
+
+
# 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()
+
+
+
+

+
+
+
+
+
+
+

Map the longitudinal profile of selected SWOT variable

+
+
# Choose a date
+date = dates[0]
+
+
+
#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?

+

Now you will also need the tile number (in addition to the pass number). You can find it on the .kmz file

+
+
# Enter tile number
+tile_number = "116F"
+
+# 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_1.1', 
+                                         temporal = ('2023-04-01 00:00:00', '2023-04-22 23:59:59'), 
+                                         granule_name = "*100m*_" + pass_number + "_" + tile_number + "*")
+# here we filter by files with '100m' in the name, pass=009, scene = 116F (tile = 232L) for Connecticut
+                                                 # pass=003, scene = 120F (tile = 239R) for the Rhine
+
+
Granules found: 15
+
+
+
+

Display details of downloaded files

+
+
print([i for i in raster_results])
+
+
[Collection: {'Version': '1.1', 'ShortName': 'SWOT_L2_HR_Raster_1.1'}
+Spatial coverage: {'HorizontalSpatialDomain': {'Orbit': {'StartLatitude': -77.66, 'EndLatitude': 77.66, 'AscendingCrossing': -80.4, 'StartDirection': 'A', 'EndDirection': 'A'}, 'Track': {'Cycle': 484, 'Passes': [{'Pass': 9, 'Tiles': ['230L', '231L', '232L', '233L', '230R', '231R', '232R', '233R']}]}}}
+Temporal coverage: {'RangeDateTime': {'EndingDateTime': '2023-04-08T03:55:38.288Z', 'BeginningDateTime': '2023-04-08T03:55:18.398Z'}}
+Size(MB): 70.40732002258301
+Data: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_1.1/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_484_009_116F_20230408T035517_20230408T035538_PIB0_01.nc'], Collection: {'Version': '1.1', 'ShortName': 'SWOT_L2_HR_Raster_1.1'}
+Spatial coverage: {'HorizontalSpatialDomain': {'Orbit': {'StartLatitude': -77.66, 'EndLatitude': 77.66, 'AscendingCrossing': -80.4, 'StartDirection': 'A', 'EndDirection': 'A'}, 'Track': {'Cycle': 485, 'Passes': [{'Pass': 9, 'Tiles': ['230L', '231L', '232L', '233L', '230R', '231R', '232R', '233R']}]}}}
+Temporal coverage: {'RangeDateTime': {'EndingDateTime': '2023-04-09T03:46:16.448Z', 'BeginningDateTime': '2023-04-09T03:45:56.558Z'}}
+Size(MB): 68.41873073577881
+Data: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_1.1/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_485_009_116F_20230409T034556_20230409T034616_PIB0_01.nc'], Collection: {'Version': '1.1', 'ShortName': 'SWOT_L2_HR_Raster_1.1'}
+Spatial coverage: {'HorizontalSpatialDomain': {'Orbit': {'StartLatitude': -77.66, 'EndLatitude': 77.66, 'AscendingCrossing': -80.4, 'StartDirection': 'A', 'EndDirection': 'A'}, 'Track': {'Cycle': 486, 'Passes': [{'Pass': 9, 'Tiles': ['230L', '231L', '232L', '233L', '230R', '231R', '232R', '233R']}]}}}
+Temporal coverage: {'RangeDateTime': {'EndingDateTime': '2023-04-10T03:36:54.573Z', 'BeginningDateTime': '2023-04-10T03:36:34.684Z'}}
+Size(MB): 68.47044467926025
+Data: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_1.1/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_486_009_116F_20230410T033634_20230410T033655_PIB0_01.nc'], Collection: {'Version': '1.1', 'ShortName': 'SWOT_L2_HR_Raster_1.1'}
+Spatial coverage: {'HorizontalSpatialDomain': {'Orbit': {'StartLatitude': -77.66, 'EndLatitude': 77.66, 'AscendingCrossing': -80.4, 'StartDirection': 'A', 'EndDirection': 'A'}, 'Track': {'Cycle': 487, 'Passes': [{'Pass': 9, 'Tiles': ['230L', '231L', '232L', '233L', '230R', '231R', '232R', '233R']}]}}}
+Temporal coverage: {'RangeDateTime': {'EndingDateTime': '2023-04-11T03:27:32.662Z', 'BeginningDateTime': '2023-04-11T03:27:12.772Z'}}
+Size(MB): 69.02541446685791
+Data: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_1.1/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_487_009_116F_20230411T032712_20230411T032733_PIB0_01.nc'], Collection: {'Version': '1.1', 'ShortName': 'SWOT_L2_HR_Raster_1.1'}
+Spatial coverage: {'HorizontalSpatialDomain': {'Orbit': {'StartLatitude': -77.66, 'EndLatitude': 77.66, 'AscendingCrossing': -80.4, 'StartDirection': 'A', 'EndDirection': 'A'}, 'Track': {'Cycle': 488, 'Passes': [{'Pass': 9, 'Tiles': ['230L', '231L', '232L', '233L', '230R', '231R', '232R', '233R']}]}}}
+Temporal coverage: {'RangeDateTime': {'EndingDateTime': '2023-04-12T03:18:10.720Z', 'BeginningDateTime': '2023-04-12T03:17:50.831Z'}}
+Size(MB): 67.56003761291504
+Data: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_1.1/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_488_009_116F_20230412T031750_20230412T031811_PIB0_01.nc'], Collection: {'Version': '1.1', 'ShortName': 'SWOT_L2_HR_Raster_1.1'}
+Spatial coverage: {'HorizontalSpatialDomain': {'Orbit': {'StartLatitude': -77.66, 'EndLatitude': 77.66, 'AscendingCrossing': -80.4, 'StartDirection': 'A', 'EndDirection': 'A'}, 'Track': {'Cycle': 489, 'Passes': [{'Pass': 9, 'Tiles': ['230L', '231L', '232L', '233L', '230R', '231R', '232R', '233R']}]}}}
+Temporal coverage: {'RangeDateTime': {'EndingDateTime': '2023-04-13T03:08:48.751Z', 'BeginningDateTime': '2023-04-13T03:08:28.862Z'}}
+Size(MB): 68.72685241699219
+Data: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_1.1/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_489_009_116F_20230413T030828_20230413T030849_PIB0_01.nc'], Collection: {'Version': '1.1', 'ShortName': 'SWOT_L2_HR_Raster_1.1'}
+Spatial coverage: {'HorizontalSpatialDomain': {'Orbit': {'StartLatitude': -77.66, 'EndLatitude': 77.66, 'AscendingCrossing': -80.4, 'StartDirection': 'A', 'EndDirection': 'A'}, 'Track': {'Cycle': 490, 'Passes': [{'Pass': 9, 'Tiles': ['230L', '231L', '232L', '233L', '230R', '231R', '232R', '233R']}]}}}
+Temporal coverage: {'RangeDateTime': {'EndingDateTime': '2023-04-14T02:59:26.753Z', 'BeginningDateTime': '2023-04-14T02:59:06.866Z'}}
+Size(MB): 66.47898387908936
+Data: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_1.1/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_490_009_116F_20230414T025906_20230414T025927_PIB0_01.nc'], Collection: {'Version': '1.1', 'ShortName': 'SWOT_L2_HR_Raster_1.1'}
+Spatial coverage: {'HorizontalSpatialDomain': {'Orbit': {'StartLatitude': -77.66, 'EndLatitude': 77.66, 'AscendingCrossing': -80.41, 'StartDirection': 'A', 'EndDirection': 'A'}, 'Track': {'Cycle': 491, 'Passes': [{'Pass': 9, 'Tiles': ['230L', '231L', '232L', '233L', '230R', '231R', '232R', '233R']}]}}}
+Temporal coverage: {'RangeDateTime': {'EndingDateTime': '2023-04-15T02:50:04.726Z', 'BeginningDateTime': '2023-04-15T02:49:44.836Z'}}
+Size(MB): 67.29588985443115
+Data: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_1.1/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_491_009_116F_20230415T024944_20230415T025005_PIB0_01.nc'], Collection: {'Version': '1.1', 'ShortName': 'SWOT_L2_HR_Raster_1.1'}
+Spatial coverage: {'HorizontalSpatialDomain': {'Orbit': {'StartLatitude': -77.66, 'EndLatitude': 77.66, 'AscendingCrossing': -80.41, 'StartDirection': 'A', 'EndDirection': 'A'}, 'Track': {'Cycle': 492, 'Passes': [{'Pass': 9, 'Tiles': ['230L', '231L', '232L', '233L', '230R', '231R', '232R', '233R']}]}}}
+Temporal coverage: {'RangeDateTime': {'EndingDateTime': '2023-04-16T02:40:43.207Z', 'BeginningDateTime': '2023-04-16T02:40:22.244Z'}}
+Size(MB): 0.933258056640625
+Data: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_1.1/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_492_009_116F_20230416T024022_20230416T024043_PIB0_01.nc'], Collection: {'Version': '1.1', 'ShortName': 'SWOT_L2_HR_Raster_1.1'}
+Spatial coverage: {'HorizontalSpatialDomain': {'Orbit': {'StartLatitude': -77.66, 'EndLatitude': 77.66, 'AscendingCrossing': -80.41, 'StartDirection': 'A', 'EndDirection': 'A'}, 'Track': {'Cycle': 493, 'Passes': [{'Pass': 9, 'Tiles': ['230L', '231L', '232L', '233L', '230R', '231R', '232R', '233R']}]}}}
+Temporal coverage: {'RangeDateTime': {'EndingDateTime': '2023-04-17T02:31:21.112Z', 'BeginningDateTime': '2023-04-17T02:31:00.151Z'}}
+Size(MB): 0.9332094192504883
+Data: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_1.1/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_493_009_116F_20230417T023100_20230417T023121_PIB0_01.nc'], Collection: {'Version': '1.1', 'ShortName': 'SWOT_L2_HR_Raster_1.1'}
+Spatial coverage: {'HorizontalSpatialDomain': {'Orbit': {'StartLatitude': -77.66, 'EndLatitude': 77.66, 'AscendingCrossing': -80.41, 'StartDirection': 'A', 'EndDirection': 'A'}, 'Track': {'Cycle': 494, 'Passes': [{'Pass': 9, 'Tiles': ['230L', '231L', '232L', '233L', '230R', '231R', '232R', '233R']}]}}}
+Temporal coverage: {'RangeDateTime': {'EndingDateTime': '2023-04-18T02:21:58.990Z', 'BeginningDateTime': '2023-04-18T02:21:38.024Z'}}
+Size(MB): 0.9332304000854492
+Data: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_1.1/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_494_009_116F_20230418T022138_20230418T022158_PIB0_01.nc'], Collection: {'Version': '1.1', 'ShortName': 'SWOT_L2_HR_Raster_1.1'}
+Spatial coverage: {'HorizontalSpatialDomain': {'Orbit': {'StartLatitude': -77.66, 'EndLatitude': 77.66, 'AscendingCrossing': -80.41, 'StartDirection': 'A', 'EndDirection': 'A'}, 'Track': {'Cycle': 495, 'Passes': [{'Pass': 9, 'Tiles': ['230L', '231L', '232L', '233L', '230R', '231R', '232R', '233R']}]}}}
+Temporal coverage: {'RangeDateTime': {'EndingDateTime': '2023-04-19T02:12:36.279Z', 'BeginningDateTime': '2023-04-19T02:12:16.394Z'}}
+Size(MB): 63.773990631103516
+Data: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_1.1/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_495_009_116F_20230419T021215_20230419T021236_PIB0_01.nc'], Collection: {'Version': '1.1', 'ShortName': 'SWOT_L2_HR_Raster_1.1'}
+Spatial coverage: {'HorizontalSpatialDomain': {'Orbit': {'StartLatitude': -77.66, 'EndLatitude': 77.66, 'AscendingCrossing': -80.41, 'StartDirection': 'A', 'EndDirection': 'A'}, 'Track': {'Cycle': 496, 'Passes': [{'Pass': 9, 'Tiles': ['230L', '231L', '232L', '233L', '230R', '231R', '232R', '233R']}]}}}
+Temporal coverage: {'RangeDateTime': {'EndingDateTime': '2023-04-20T02:03:14.075Z', 'BeginningDateTime': '2023-04-20T02:02:54.187Z'}}
+Size(MB): 62.185853004455566
+Data: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_1.1/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_496_009_116F_20230420T020253_20230420T020314_PIB0_01.nc'], Collection: {'Version': '1.1', 'ShortName': 'SWOT_L2_HR_Raster_1.1'}
+Spatial coverage: {'HorizontalSpatialDomain': {'Orbit': {'StartLatitude': -77.66, 'EndLatitude': 77.66, 'AscendingCrossing': -80.41, 'StartDirection': 'A', 'EndDirection': 'A'}, 'Track': {'Cycle': 497, 'Passes': [{'Pass': 9, 'Tiles': ['230L', '231L', '232L', '233L', '230R', '231R', '232R', '233R']}]}}}
+Temporal coverage: {'RangeDateTime': {'EndingDateTime': '2023-04-21T01:53:51.831Z', 'BeginningDateTime': '2023-04-21T01:53:31.942Z'}}
+Size(MB): 61.36593437194824
+Data: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_1.1/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_497_009_116F_20230421T015331_20230421T015352_PIB0_01.nc'], Collection: {'Version': '1.1', 'ShortName': 'SWOT_L2_HR_Raster_1.1'}
+Spatial coverage: {'HorizontalSpatialDomain': {'Orbit': {'StartLatitude': -77.66, 'EndLatitude': 77.66, 'AscendingCrossing': -80.41, 'StartDirection': 'A', 'EndDirection': 'A'}, 'Track': {'Cycle': 498, 'Passes': [{'Pass': 9, 'Tiles': ['230L', '231L', '232L', '233L', '230R', '231R', '232R', '233R']}]}}}
+Temporal coverage: {'RangeDateTime': {'EndingDateTime': '2023-04-22T01:44:29.616Z', 'BeginningDateTime': '2023-04-22T01:44:09.731Z'}}
+Size(MB): 61.341376304626465
+Data: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_1.1/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_498_009_116F_20230422T014409_20230422T014430_PIB0_01.nc']]
+
+
+
+
+

Select a single file for visualization

+
+
# Let's look at cycle 485, on the second day of calval
+# Enter cycle
+cycle = "485"
+
+raster_results = earthaccess.search_data(short_name = 'SWOT_L2_HR_Raster_1.1', 
+                                         temporal = ('2023-04-01 00:00:00', '2023-04-22 23:59:59'), 
+                                         granule_name = "*100m*" + cycle + "_" + pass_number + "_" + tile_number + "*")
+
+# here we filter by files with '100m' in the name, cycle=484, pass=009, scene = 116F for Connecticut
+                                                 # cycle=485, pass=003, scene = 120F for the Rhine
+
+
Granules found: 1
+
+
+
+
+

Open file using fiona AWS session and read file using xarray

+
+
fs_s3 = earthaccess.get_s3fs_session(results=raster_results)
+
+# get link for file and open it
+raster_link = earthaccess.results.DataGranule.data_links(raster_results[0], access='direct')[0]
+s3_file_obj5 = fs_s3.open(raster_link, mode='rb')
+
+# Open data with xarray
+ds_raster = xr.open_dataset(s3_file_obj5, engine='h5netcdf')
+
+
+
+

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)
+
+ +
+
+
+
+
+ +
+
+ + +
+
+
+
+ +
+ +
+ + + + + + \ No newline at end of file diff --git a/Tutorials/SWOTHR_Science_Application_files/figure-html/cell-19-output-1.png b/Tutorials/SWOTHR_Science_Application_files/figure-html/cell-19-output-1.png new file mode 100644 index 0000000..4d1ce0b Binary files /dev/null and b/Tutorials/SWOTHR_Science_Application_files/figure-html/cell-19-output-1.png differ diff --git a/search.json b/search.json index 915ce5b..0e1921f 100644 --- a/search.json +++ b/search.json @@ -59,6 +59,83 @@ "Slides" ] }, + { + "objectID": "Tutorials/SWOTHR_Science_Application.html", + "href": "Tutorials/SWOTHR_Science_Application.html", + "title": "SWOT Hydrology Science Application Tutorial on the Cloud", + "section": "", + "text": "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.\n\n\n\nAn 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.\nThis code runs using SWOT Level 2 Data Products (Version 1.1).\nNotebook Authors: Arnaud Cerbelaud, Jeffrey Wade, NASA Jet Propulsion Laboratory - California Institute of Technology (Jan 2024)\n\n\n\n\n\nRetrieve SWOT hydrological attributes on river reaches within the AWS cloud (Cal/Val data). Query reaches by:\n\nRiver name\nSpatial bounding box\nDownstream tracing from reach id\nUpstream tracing from reach id\n\n\nRiver longitudinal profile: filtering data to display all reaches located downstream of a given reach (e.g. headwater to outlet)\nWatershed analysis: filtering data to display all reaches located upstream of a given reach (e.g. outlet to full river network)\nVisualize and plot WSE, width, slope data on the filtered data\n\nLast updated: 31 Jan 2024\n\n\n\n\nimport glob\nimport os\nimport requests\nimport s3fs\nimport fiona\nimport netCDF4 as nc\nimport h5netcdf\nimport xarray as xr\nimport pandas as pd\nimport geopandas as gpd\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport hvplot.xarray\nimport earthaccess\nfrom earthaccess import Auth, DataCollections, DataGranules, Store\nfrom pathlib import Path\nimport zipfile\n\n\n\n\n\n\n\n\n\n\n\n\n\nAuthenticate your Earthdata Login (EDL) information using the earthaccess python package as follows:\n\nearthaccess.login() # Login with your EDL credentials if asked\n\nEnter your Earthdata Login username: jswade\nEnter your Earthdata password: ········\n\n\n<earthaccess.auth.Auth at 0x7fd9a7adbee0>\n\n\n\n\n\n\n\n\nOptional step: Get the .kmz file of SWOT passes/swaths (Version 1.1) and import it into Google Earth for visualization\nDetermine which pass number corresponds to the river/basin you want to look at! #### Search for multiple days of data\n\n\n# Enter pass number\npass_number = \"009\" # e.g. 009 for Connecticut in NA, 003 for Rhine in EU\n# Enter continent code\ncontinent_code = \"NA\" # e.g. \"AF\", \"NA\", \"EU\", \"SI\", \"AS\", \"AU\", \"SA\", \"AR\", \"GR\"\n\n# Retrieves granule from the day we want, in this case by passing to `earthdata.search_data` function the data collection shortname and temporal bounds\nriver_results = earthaccess.search_data(short_name = 'SWOT_L2_HR_RIVERSP_1.1', \n temporal = ('2023-04-08 00:00:00', '2023-04-12 23:59:59'),\n granule_name = \"*Reach*_\" + pass_number + \"_\" + continent_code + \"*\")\n\n# Create fiona session to read data\nfs_s3 = earthaccess.get_s3fs_session(results=river_results)\nfiona_session=fiona.session.AWSSession(\n aws_access_key_id=fs_s3.storage_options[\"key\"],\n aws_secret_access_key=fs_s3.storage_options[\"secret\"],\n aws_session_token=fs_s3.storage_options[\"token\"]\n )\n\nGranules found: 5\n\n\n\n\n\n\n# Initialize list of shapefiles containing all dates\nSWOT_HR_shps = []\n\n# Loop through queried granules to stack all acquisition dates\nfor j in range(len(river_results)):\n \n # Get the link for each zip file\n river_link = earthaccess.results.DataGranule.data_links(river_results[j], access='direct')[0]\n \n # We use the zip+ prefix so fiona knows that we are operating on a zip file\n river_shp_url = f\"zip+{river_link}\"\n \n # Read shapefile\n with fiona.Env(session=fiona_session):\n SWOT_HR_shps.append(gpd.read_file(river_shp_url)) \n\n\n\n\n\n# Combine granules from all acquisition dates into one dataframe\nSWOT_HR_df = gpd.GeoDataFrame(pd.concat(SWOT_HR_shps, ignore_index=True))\n\n# Sort dataframe by reach_id and time\nSWOT_HR_df = SWOT_HR_df.sort_values(['reach_id', 'time'])\n\nSWOT_HR_df\n\n\n\n\n\n\n\n\nreach_id\ntime\ntime_tai\ntime_str\np_lat\np_lon\nriver_name\nwse\nwse_u\nwse_r_u\n...\np_wid_var\np_n_nodes\np_dist_out\np_length\np_maf\np_dam_id\np_n_ch_max\np_n_ch_mod\np_low_slp\ngeometry\n\n\n\n\n1958\n72270400231\n-1.000000e+12\n-1.000000e+12\nno_data\n56.794630\n-66.461122\nno_data\n-1.000000e+12\n-1.000000e+12\n-1.000000e+12\n...\n1618.079\n53\n230079.472\n10630.774958\n-1.000000e+12\n0\n1\n1\n0\nLINESTRING (-66.48682 56.83442, -66.48645 56.8...\n\n\n2641\n72270400231\n-1.000000e+12\n-1.000000e+12\nno_data\n56.794630\n-66.461122\nno_data\n-1.000000e+12\n-1.000000e+12\n-1.000000e+12\n...\n1618.079\n53\n230079.472\n10630.774958\n-1.000000e+12\n0\n1\n1\n0\nLINESTRING (-66.48682 56.83442, -66.48645 56.8...\n\n\n1959\n72270400241\n-1.000000e+12\n-1.000000e+12\nno_data\n56.744361\n-66.341905\nno_data\n-1.000000e+12\n-1.000000e+12\n-1.000000e+12\n...\n4831.128\n53\n240728.430\n10648.958289\n-1.000000e+12\n0\n2\n1\n0\nLINESTRING (-66.41602 56.75969, -66.41553 56.7...\n\n\n2642\n72270400241\n-1.000000e+12\n-1.000000e+12\nno_data\n56.744361\n-66.341905\nno_data\n-1.000000e+12\n-1.000000e+12\n-1.000000e+12\n...\n4831.128\n53\n240728.430\n10648.958289\n-1.000000e+12\n0\n2\n1\n0\nLINESTRING (-66.41602 56.75969, -66.41553 56.7...\n\n\n1960\n72270400251\n7.344991e+08\n7.344991e+08\n2023-04-11T03:31:02Z\n56.676087\n-66.219811\nno_data\n2.855340e+02\n1.008930e+00\n1.004910e+00\n...\n412.975\n58\n252286.769\n11558.339052\n-1.000000e+12\n0\n2\n1\n0\nLINESTRING (-66.27812 56.71437, -66.27775 56.7...\n\n\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n\n\n615\n73130000061\n-1.000000e+12\n-1.000000e+12\nno_data\n41.424945\n-73.230960\nHousatonic River\n-1.000000e+12\n-1.000000e+12\n-1.000000e+12\n...\n10469.706\n82\n47161.191\n16303.793847\n-1.000000e+12\n0\n2\n1\n0\nLINESTRING (-73.17436 41.38295, -73.17465 41.3...\n\n\n1283\n73130000061\n-1.000000e+12\n-1.000000e+12\nno_data\n41.424945\n-73.230960\nHousatonic River\n-1.000000e+12\n-1.000000e+12\n-1.000000e+12\n...\n10469.706\n82\n47161.191\n16303.793847\n-1.000000e+12\n0\n2\n1\n0\nLINESTRING (-73.17436 41.38295, -73.17465 41.3...\n\n\n1957\n73130000061\n-1.000000e+12\n-1.000000e+12\nno_data\n41.424945\n-73.230960\nHousatonic River\n-1.000000e+12\n-1.000000e+12\n-1.000000e+12\n...\n10469.706\n82\n47161.191\n16303.793847\n-1.000000e+12\n0\n2\n1\n0\nLINESTRING (-73.17436 41.38295, -73.17465 41.3...\n\n\n2640\n73130000061\n-1.000000e+12\n-1.000000e+12\nno_data\n41.424945\n-73.230960\nHousatonic River\n-1.000000e+12\n-1.000000e+12\n-1.000000e+12\n...\n10469.706\n82\n47161.191\n16303.793847\n-1.000000e+12\n0\n2\n1\n0\nLINESTRING (-73.17436 41.38295, -73.17465 41.3...\n\n\n3312\n73130000061\n-1.000000e+12\n-1.000000e+12\nno_data\n41.424945\n-73.230960\nHousatonic River\n-1.000000e+12\n-1.000000e+12\n-1.000000e+12\n...\n10469.706\n82\n47161.191\n16303.793847\n-1.000000e+12\n0\n2\n1\n0\nLINESTRING (-73.17436 41.38295, -73.17465 41.3...\n\n\n\n\n3313 rows × 127 columns\n\n\n\n\n\n\n\n\n\n\nprint('Available dates are:')\nprint(np.unique([i[:10] for i in SWOT_HR_df['time_str']]))\nprint('Available rivers are:')\nprint(np.unique([i for i in SWOT_HR_df['river_name']]))\n\nAvailable dates are:\n['2023-04-08' '2023-04-09' '2023-04-10' '2023-04-11' '2023-04-12'\n 'no_data']\nAvailable rivers are:\n['Allagash River' 'Androscoggin River' 'Big Black River' 'Canal de fuite'\n 'Carrabassett River' 'Concord River' 'Concord River; Sudbury River'\n 'Connecticut River' 'Connecticut River; Westfield River'\n 'Connecticut River; White River' 'Dead River'\n 'Dead River (Kennebec River)' 'Deerfield River' 'Farmington River'\n 'Housatonic River' 'Ikarut River' 'Kennebec River' 'Komaktorvik River'\n 'Magalloway River' 'Merrimack River' 'Moose River'\n 'North Branch Penobscot River' 'Passumsic River' 'Pemigewasset River'\n 'Penobscot River West Branch' 'Quinebaug River' 'Saco River'\n 'Saguenay River' 'Saint Francis River' 'Saint John River'\n 'Saint Lawrence River' 'Sandy River' 'Shetucket River' 'Sudbury River'\n 'Thames River' 'West River' 'White River' 'no_data']\n\n\n\n\n\nNote: Some rivers have multiple names, hence using the contains function\n\n# Enter river name\nriver = \"Connecticut River\" # e.g. \"Rhine\", \"Connecticut River\"\n\n## Filter dataframe\nSWOT_HR_df_river = SWOT_HR_df[(SWOT_HR_df.river_name.str.contains(river))]\n\n# Plot geopandas dataframe with 'explore' by reach id\nSWOT_HR_df_river[['reach_id','river_name','geometry']].explore('reach_id', style_kwds=dict(weight=6))\n\nMake this Notebook Trusted to load map: File -> Trust Notebook\n\n\n\n\n\n\nlat_start = {\"Connecticut River\": 41.5,\n \"Rhine\": 47.5\n }\nlat_end = {\"Connecticut River\": 45,\n \"Rhine\": 51\n }\nlon_start = {\"Connecticut River\": -74,\n \"Rhine\": 7\n }\nlon_end = {\"Connecticut River\": -71,\n \"Rhine\": 10\n }\n\n## Filter dataframe\nSWOT_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])]\n\n# Plot geopandas dataframe with 'explore' by river name\nSWOT_HR_df_box[['reach_id','river_name','geometry']].explore('river_name', style_kwds=dict(weight=6))\n\nMake this Notebook Trusted to load map: File -> Trust Notebook\n\n\n\n\n\n\nWARNING: This works as long as the data is exhaustive (no missing SWORD reaches)\n\n\nNote: rch_dn_dict[rch_id] gives a list of all the reaches directly downstream from rch_id\n\n# Format rch_id_dn for dictionary. Rch_id_dn allows for multiple downstream reaches to be stored\n# Also removes spaces in attribute field\nrch_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))]\n\n# Filter upstream reach ids to remove 'no_data'\nrch_id_dn_filter = [[x for x in dn_id if x.isnumeric()] for dn_id in rch_id_dn]\n\n# Create lookup dictionary for river network topology: Downstream\nrch_dn_dict = {SWOT_HR_df.reach_id[i]: rch_id_dn_filter[i] for i in range(len(SWOT_HR_df))}\n\n\n\n\n\n# Enter reach_id from which we will trace downstream (e.g. headwaters of the Connecticut River)\nrch_dn_st = {\"Connecticut River\": '73120000691',\n \"Rhine\": '23267000651'\n }\n\n# Initialize list to store downstream reaches, including starting reach\nrch_dn_list = [rch_dn_st[river]]\n# Retrieve first downstream id of starting reach and add to list\nrch_dn_next = rch_dn_dict[rch_dn_st[river]][0]\n\n# Trace next downstream reach until we hit the outlet (or here the last reach on file)\nwhile len(rch_dn_next) != 0:\n # Add reach to list if value exists\n if len(rch_dn_next) != 0:\n rch_dn_list.append(rch_dn_next)\n # Recursively retrieve first downstream id of next reach\n # Catch error if reach isn't in downloaded data\n try:\n rch_dn_next = rch_dn_dict[rch_dn_next][0]\n except:\n break\n\n\n\n\n\n# Filter downloaded data by downstream traced reaches\nSWOT_dn_trace = SWOT_HR_df[SWOT_HR_df.reach_id.isin(rch_dn_list)]\n\n# Remove reaches from rch_dn_list that are not present in SWOT data\nrch_dn_list = [rch for rch in rch_dn_list if rch in SWOT_HR_df.reach_id.values]\n\nSWOT_dn_trace[['reach_id','river_name','geometry']].explore('river_name', style_kwds=dict(weight=6))\n\nMake this Notebook Trusted to load map: File -> Trust Notebook\n\n\n\n\n\n\nWARNING: This works as long as the data is exhaustive (no missing SWORD reaches)\n\n\nNote: rch_up_dict[rch_id] gives a list of all the reaches directly upstream from rch_id\n\n# Format rch_id_up for dictionary. Rch_id_up allows for multiple upstream reaches to be stored\n# Also removes spaces in attribute field\nrch_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))]\n\n# Filter upstream reach ids to remove 'no_data'\nrch_id_up_fil = [[x for x in ups_id if x.isnumeric()] for ups_id in rch_id_up]\n\n# Create lookup dictionary for river network topology: Upstream\nrch_up_dict = {SWOT_HR_df.reach_id[i]: rch_id_up_fil[i] for i in range(len(SWOT_HR_df))}\n\n\n\n\nThis adds a bit of complexity, as we need to keep track of multiple branches upstream of the starting reach.\n\n# Enter reach_id from which we will trace upstream (e.g. outlet of the Connecticut River)\nrch_up_st = {\"Connecticut River\": '73120000013',\n \"Rhine\": '23265000051'\n }\n\n# Initialize list to store traced upstream reaches, including starting reach\nrch_up_list = [rch_up_st[river]]\n# Retrieve ids of reaches upstream of starting reach and add to list\nrch_up_next = rch_up_dict[rch_up_st[river]]\n# For upstream tracing, we need to set a list of next upstream ids to start while loop\nrch_next_id = rch_up_next\n\n# Loop until no more reaches to trace\nwhile len(rch_next_id) != 0:\n # Initialize list to store next upstream ids\n rch_next_id = []\n # Loop through next upstream ids for given reach\n for rch_up_sel in rch_up_next:\n # Get values of existing upstream ids of rch_up_next reaches\n # If reach isn't in SWOT data (usually ghost reaches), continue to next reach\n try:\n rch_next_id = rch_next_id + rch_up_dict[rch_up_sel]\n except:\n continue\n # Append id to list\n rch_up_list.append(rch_up_sel)\n # If reaches exist, add to list for next cycle of tracing\n if len(rch_next_id) != 0:\n rch_up_next = rch_next_id\n\n\n\n\n\n# Filter downloaded data by upstream traced reaches\nSWOT_up_trace = SWOT_HR_df[SWOT_HR_df.reach_id.isin(rch_up_list)]\n\n# Remove reaches from rch_up_list that are not present in SWOT data\nrch_up_list = [rch for rch in rch_up_list if rch in SWOT_HR_df.reach_id.values]\n\nSWOT_up_trace[['reach_id','river_name','geometry']].explore('river_name', style_kwds=dict(weight=6))\n\nMake this Notebook Trusted to load map: File -> Trust Notebook\n\n\n\n\n\n\n\n\n\n# Retrieve all possible acquisition dates (keeping only YYYY-MM-DD)\ndates = np.unique([i[:10] for i in [x for x in SWOT_HR_df['time_str'] if x!='no_data']])\n\n# Create a new database for time series analysis with unique reach_ids\nSWOT_dn_trace_time = SWOT_dn_trace.set_index('reach_id').groupby(level=0) \\\n .apply(lambda df: df.reset_index(drop=True)) \\\n .unstack().sort_index(axis=1, level=1)\n\nSWOT_dn_trace_time.columns = ['{}_{}'.format(x[0],dates[x[1]]) for x in SWOT_dn_trace_time.columns]\n\n\n\n\n\n# Explore variables you could choose to plot\nfor var in [\"wse\",\"slope\",\"width\",\"len\"]:\n print(SWOT_dn_trace.columns[SWOT_dn_trace.columns.str.contains(var)])\n\nIndex(['wse', 'wse_u', 'wse_r_u', 'wse_c', 'wse_c_u', 'area_wse', 'p_wse',\n 'p_wse_var'],\n dtype='object')\nIndex(['slope', 'slope_u', 'slope_r_u', 'slope2', 'slope2_u', 'slope2_r_u'], dtype='object')\nIndex(['width', 'width_u', 'width_c', 'width_c_u', 'p_width'], dtype='object')\nIndex(['p_length'], dtype='object')\n\n\n\n# Enter variable of interest for plotting\nvarstr = \"wse\"\n\n\n# Find cumulative length on the longitudinal profile\nlength_list = np.nan_to_num([SWOT_dn_trace.p_length[SWOT_dn_trace.reach_id == rch].mean()/1000 for rch in rch_dn_list])\ncumlength_list = np.cumsum(length_list)\n\n## Plot a longitudinal profile from the downstream tracing database\n\n## Plot a longitudinal profile from the downstream tracing database\nplt.figure(figsize=(12,8))\nfor t in dates:\n \n # Store the quantity of interest (wse, width etc.) at time t\n value = SWOT_dn_trace_time.loc[rch_dn_list,varstr+'_'+t]\n \n # Remove set negative values (bad observations) to NaN and forward fill NaNs\n value[value < 0] = np.nan\n value = value.ffill()\n \n # Plot the data\n plt.plot(cumlength_list, value, label = varstr+'_'+t)\n \nplt.xlabel('Downstream Distance (km)')\nplt.ylabel(varstr)\nplt.legend()\n\n\n\n\n\n\n\n\n\n\n\n\n# Choose a date\ndate = dates[0]\n\n\n#Set one column as the active geometry in the new database\nSWOT_dn_trace_time = SWOT_dn_trace_time.set_geometry(\"geometry_\"+date)\n\n#Set cleaner colorbar bounds for better visualization\nvmin = np.percentile([i for i in SWOT_dn_trace_time[varstr+'_'+date] if i>0],5)\nvmax = np.percentile([i for i in SWOT_dn_trace_time[varstr+'_'+date] if i>0],95)\n\n# Interactive map\nSWOT_dn_trace_time.explore(varstr+'_'+date,\n vmin = vmin,\n vmax = vmax,\n cmap = \"Blues\", #\"Blues\",\n control_scale = True,\n tooltip = varstr+'_'+dates[0], # show \"varstr+'_'+dates[0]\" value in tooltip (on hover)\n popup = True, # show all values in popup (on click)\n #tiles = \"CartoDB positron\", # use \"CartoDB positron\" tiles\n style_kwds=dict(weight=10)\n )\n\nMake this Notebook Trusted to load map: File -> Trust Notebook\n\n\n\n\n\n\n\n\n\nSWOT_up_trace_time = SWOT_up_trace.set_index('reach_id').groupby(level=0) \\\n .apply(lambda df: df.reset_index(drop=True)) \\\n .unstack().sort_index(axis=1, level=1)\n\nSWOT_up_trace_time.columns = ['{}_{}'.format(x[0],dates[x[1]]) for x in SWOT_up_trace_time.columns]\n\nSWOT_up_trace_time = SWOT_up_trace_time.set_geometry(\"geometry_\"+date)\n\n#Set cleaner colorbar bounds for better visualization\nvmin = np.percentile([i for i in SWOT_up_trace_time[varstr+'_'+date] if i>0],5)\nvmax = np.percentile([i for i in SWOT_up_trace_time[varstr+'_'+date] if i>0],95)\n\n# Interactive map\nSWOT_up_trace_time.explore(varstr+'_'+date,\n vmin = vmin,\n vmax = vmax,\n cmap = \"Blues\", #\"Blues\",\n control_scale = True,\n tooltip = varstr+'_'+dates[0], # show \"varstr+'_'+dates[0]\" value in tooltip (on hover)\n popup = True, # show all values in popup (on click)\n tiles = \"CartoDB positron\", # use \"CartoDB positron\" tiles\n style_kwds=dict(weight=5)\n )\n\nMake this Notebook Trusted to load map: File -> Trust Notebook\n\n\n\n\n\nNow you will also need the tile number (in addition to the pass number). You can find it on the .kmz file\n\n# Enter tile number\ntile_number = \"116F\"\n\n# Retrieve granules from all days to find the cycle corresponding to the desired date\nraster_results = earthaccess.search_data(short_name = 'SWOT_L2_HR_Raster_1.1', \n temporal = ('2023-04-01 00:00:00', '2023-04-22 23:59:59'), \n granule_name = \"*100m*_\" + pass_number + \"_\" + tile_number + \"*\")\n# here we filter by files with '100m' in the name, pass=009, scene = 116F (tile = 232L) for Connecticut\n # pass=003, scene = 120F (tile = 239R) for the Rhine\n\nGranules found: 15\n\n\n\n\n\nprint([i for i in raster_results])\n\n[Collection: {'Version': '1.1', 'ShortName': 'SWOT_L2_HR_Raster_1.1'}\nSpatial coverage: {'HorizontalSpatialDomain': {'Orbit': {'StartLatitude': -77.66, 'EndLatitude': 77.66, 'AscendingCrossing': -80.4, 'StartDirection': 'A', 'EndDirection': 'A'}, 'Track': {'Cycle': 484, 'Passes': [{'Pass': 9, 'Tiles': ['230L', '231L', '232L', '233L', '230R', '231R', '232R', '233R']}]}}}\nTemporal coverage: {'RangeDateTime': {'EndingDateTime': '2023-04-08T03:55:38.288Z', 'BeginningDateTime': '2023-04-08T03:55:18.398Z'}}\nSize(MB): 70.40732002258301\nData: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_1.1/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_484_009_116F_20230408T035517_20230408T035538_PIB0_01.nc'], Collection: {'Version': '1.1', 'ShortName': 'SWOT_L2_HR_Raster_1.1'}\nSpatial coverage: {'HorizontalSpatialDomain': {'Orbit': {'StartLatitude': -77.66, 'EndLatitude': 77.66, 'AscendingCrossing': -80.4, 'StartDirection': 'A', 'EndDirection': 'A'}, 'Track': {'Cycle': 485, 'Passes': [{'Pass': 9, 'Tiles': ['230L', '231L', '232L', '233L', '230R', '231R', '232R', '233R']}]}}}\nTemporal coverage: {'RangeDateTime': {'EndingDateTime': '2023-04-09T03:46:16.448Z', 'BeginningDateTime': '2023-04-09T03:45:56.558Z'}}\nSize(MB): 68.41873073577881\nData: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_1.1/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_485_009_116F_20230409T034556_20230409T034616_PIB0_01.nc'], Collection: {'Version': '1.1', 'ShortName': 'SWOT_L2_HR_Raster_1.1'}\nSpatial coverage: {'HorizontalSpatialDomain': {'Orbit': {'StartLatitude': -77.66, 'EndLatitude': 77.66, 'AscendingCrossing': -80.4, 'StartDirection': 'A', 'EndDirection': 'A'}, 'Track': {'Cycle': 486, 'Passes': [{'Pass': 9, 'Tiles': ['230L', '231L', '232L', '233L', '230R', '231R', '232R', '233R']}]}}}\nTemporal coverage: {'RangeDateTime': {'EndingDateTime': '2023-04-10T03:36:54.573Z', 'BeginningDateTime': '2023-04-10T03:36:34.684Z'}}\nSize(MB): 68.47044467926025\nData: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_1.1/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_486_009_116F_20230410T033634_20230410T033655_PIB0_01.nc'], Collection: {'Version': '1.1', 'ShortName': 'SWOT_L2_HR_Raster_1.1'}\nSpatial coverage: {'HorizontalSpatialDomain': {'Orbit': {'StartLatitude': -77.66, 'EndLatitude': 77.66, 'AscendingCrossing': -80.4, 'StartDirection': 'A', 'EndDirection': 'A'}, 'Track': {'Cycle': 487, 'Passes': [{'Pass': 9, 'Tiles': ['230L', '231L', '232L', '233L', '230R', '231R', '232R', '233R']}]}}}\nTemporal coverage: {'RangeDateTime': {'EndingDateTime': '2023-04-11T03:27:32.662Z', 'BeginningDateTime': '2023-04-11T03:27:12.772Z'}}\nSize(MB): 69.02541446685791\nData: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_1.1/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_487_009_116F_20230411T032712_20230411T032733_PIB0_01.nc'], Collection: {'Version': '1.1', 'ShortName': 'SWOT_L2_HR_Raster_1.1'}\nSpatial coverage: {'HorizontalSpatialDomain': {'Orbit': {'StartLatitude': -77.66, 'EndLatitude': 77.66, 'AscendingCrossing': -80.4, 'StartDirection': 'A', 'EndDirection': 'A'}, 'Track': {'Cycle': 488, 'Passes': [{'Pass': 9, 'Tiles': ['230L', '231L', '232L', '233L', '230R', '231R', '232R', '233R']}]}}}\nTemporal coverage: {'RangeDateTime': {'EndingDateTime': '2023-04-12T03:18:10.720Z', 'BeginningDateTime': '2023-04-12T03:17:50.831Z'}}\nSize(MB): 67.56003761291504\nData: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_1.1/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_488_009_116F_20230412T031750_20230412T031811_PIB0_01.nc'], Collection: {'Version': '1.1', 'ShortName': 'SWOT_L2_HR_Raster_1.1'}\nSpatial coverage: {'HorizontalSpatialDomain': {'Orbit': {'StartLatitude': -77.66, 'EndLatitude': 77.66, 'AscendingCrossing': -80.4, 'StartDirection': 'A', 'EndDirection': 'A'}, 'Track': {'Cycle': 489, 'Passes': [{'Pass': 9, 'Tiles': ['230L', '231L', '232L', '233L', '230R', '231R', '232R', '233R']}]}}}\nTemporal coverage: {'RangeDateTime': {'EndingDateTime': '2023-04-13T03:08:48.751Z', 'BeginningDateTime': '2023-04-13T03:08:28.862Z'}}\nSize(MB): 68.72685241699219\nData: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_1.1/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_489_009_116F_20230413T030828_20230413T030849_PIB0_01.nc'], Collection: {'Version': '1.1', 'ShortName': 'SWOT_L2_HR_Raster_1.1'}\nSpatial coverage: {'HorizontalSpatialDomain': {'Orbit': {'StartLatitude': -77.66, 'EndLatitude': 77.66, 'AscendingCrossing': -80.4, 'StartDirection': 'A', 'EndDirection': 'A'}, 'Track': {'Cycle': 490, 'Passes': [{'Pass': 9, 'Tiles': ['230L', '231L', '232L', '233L', '230R', '231R', '232R', '233R']}]}}}\nTemporal coverage: {'RangeDateTime': {'EndingDateTime': '2023-04-14T02:59:26.753Z', 'BeginningDateTime': '2023-04-14T02:59:06.866Z'}}\nSize(MB): 66.47898387908936\nData: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_1.1/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_490_009_116F_20230414T025906_20230414T025927_PIB0_01.nc'], Collection: {'Version': '1.1', 'ShortName': 'SWOT_L2_HR_Raster_1.1'}\nSpatial coverage: {'HorizontalSpatialDomain': {'Orbit': {'StartLatitude': -77.66, 'EndLatitude': 77.66, 'AscendingCrossing': -80.41, 'StartDirection': 'A', 'EndDirection': 'A'}, 'Track': {'Cycle': 491, 'Passes': [{'Pass': 9, 'Tiles': ['230L', '231L', '232L', '233L', '230R', '231R', '232R', '233R']}]}}}\nTemporal coverage: {'RangeDateTime': {'EndingDateTime': '2023-04-15T02:50:04.726Z', 'BeginningDateTime': '2023-04-15T02:49:44.836Z'}}\nSize(MB): 67.29588985443115\nData: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_1.1/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_491_009_116F_20230415T024944_20230415T025005_PIB0_01.nc'], Collection: {'Version': '1.1', 'ShortName': 'SWOT_L2_HR_Raster_1.1'}\nSpatial coverage: {'HorizontalSpatialDomain': {'Orbit': {'StartLatitude': -77.66, 'EndLatitude': 77.66, 'AscendingCrossing': -80.41, 'StartDirection': 'A', 'EndDirection': 'A'}, 'Track': {'Cycle': 492, 'Passes': [{'Pass': 9, 'Tiles': ['230L', '231L', '232L', '233L', '230R', '231R', '232R', '233R']}]}}}\nTemporal coverage: {'RangeDateTime': {'EndingDateTime': '2023-04-16T02:40:43.207Z', 'BeginningDateTime': '2023-04-16T02:40:22.244Z'}}\nSize(MB): 0.933258056640625\nData: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_1.1/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_492_009_116F_20230416T024022_20230416T024043_PIB0_01.nc'], Collection: {'Version': '1.1', 'ShortName': 'SWOT_L2_HR_Raster_1.1'}\nSpatial coverage: {'HorizontalSpatialDomain': {'Orbit': {'StartLatitude': -77.66, 'EndLatitude': 77.66, 'AscendingCrossing': -80.41, 'StartDirection': 'A', 'EndDirection': 'A'}, 'Track': {'Cycle': 493, 'Passes': [{'Pass': 9, 'Tiles': ['230L', '231L', '232L', '233L', '230R', '231R', '232R', '233R']}]}}}\nTemporal coverage: {'RangeDateTime': {'EndingDateTime': '2023-04-17T02:31:21.112Z', 'BeginningDateTime': '2023-04-17T02:31:00.151Z'}}\nSize(MB): 0.9332094192504883\nData: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_1.1/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_493_009_116F_20230417T023100_20230417T023121_PIB0_01.nc'], Collection: {'Version': '1.1', 'ShortName': 'SWOT_L2_HR_Raster_1.1'}\nSpatial coverage: {'HorizontalSpatialDomain': {'Orbit': {'StartLatitude': -77.66, 'EndLatitude': 77.66, 'AscendingCrossing': -80.41, 'StartDirection': 'A', 'EndDirection': 'A'}, 'Track': {'Cycle': 494, 'Passes': [{'Pass': 9, 'Tiles': ['230L', '231L', '232L', '233L', '230R', '231R', '232R', '233R']}]}}}\nTemporal coverage: {'RangeDateTime': {'EndingDateTime': '2023-04-18T02:21:58.990Z', 'BeginningDateTime': '2023-04-18T02:21:38.024Z'}}\nSize(MB): 0.9332304000854492\nData: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_1.1/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_494_009_116F_20230418T022138_20230418T022158_PIB0_01.nc'], Collection: {'Version': '1.1', 'ShortName': 'SWOT_L2_HR_Raster_1.1'}\nSpatial coverage: {'HorizontalSpatialDomain': {'Orbit': {'StartLatitude': -77.66, 'EndLatitude': 77.66, 'AscendingCrossing': -80.41, 'StartDirection': 'A', 'EndDirection': 'A'}, 'Track': {'Cycle': 495, 'Passes': [{'Pass': 9, 'Tiles': ['230L', '231L', '232L', '233L', '230R', '231R', '232R', '233R']}]}}}\nTemporal coverage: {'RangeDateTime': {'EndingDateTime': '2023-04-19T02:12:36.279Z', 'BeginningDateTime': '2023-04-19T02:12:16.394Z'}}\nSize(MB): 63.773990631103516\nData: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_1.1/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_495_009_116F_20230419T021215_20230419T021236_PIB0_01.nc'], Collection: {'Version': '1.1', 'ShortName': 'SWOT_L2_HR_Raster_1.1'}\nSpatial coverage: {'HorizontalSpatialDomain': {'Orbit': {'StartLatitude': -77.66, 'EndLatitude': 77.66, 'AscendingCrossing': -80.41, 'StartDirection': 'A', 'EndDirection': 'A'}, 'Track': {'Cycle': 496, 'Passes': [{'Pass': 9, 'Tiles': ['230L', '231L', '232L', '233L', '230R', '231R', '232R', '233R']}]}}}\nTemporal coverage: {'RangeDateTime': {'EndingDateTime': '2023-04-20T02:03:14.075Z', 'BeginningDateTime': '2023-04-20T02:02:54.187Z'}}\nSize(MB): 62.185853004455566\nData: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_1.1/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_496_009_116F_20230420T020253_20230420T020314_PIB0_01.nc'], Collection: {'Version': '1.1', 'ShortName': 'SWOT_L2_HR_Raster_1.1'}\nSpatial coverage: {'HorizontalSpatialDomain': {'Orbit': {'StartLatitude': -77.66, 'EndLatitude': 77.66, 'AscendingCrossing': -80.41, 'StartDirection': 'A', 'EndDirection': 'A'}, 'Track': {'Cycle': 497, 'Passes': [{'Pass': 9, 'Tiles': ['230L', '231L', '232L', '233L', '230R', '231R', '232R', '233R']}]}}}\nTemporal coverage: {'RangeDateTime': {'EndingDateTime': '2023-04-21T01:53:51.831Z', 'BeginningDateTime': '2023-04-21T01:53:31.942Z'}}\nSize(MB): 61.36593437194824\nData: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_1.1/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_497_009_116F_20230421T015331_20230421T015352_PIB0_01.nc'], Collection: {'Version': '1.1', 'ShortName': 'SWOT_L2_HR_Raster_1.1'}\nSpatial coverage: {'HorizontalSpatialDomain': {'Orbit': {'StartLatitude': -77.66, 'EndLatitude': 77.66, 'AscendingCrossing': -80.41, 'StartDirection': 'A', 'EndDirection': 'A'}, 'Track': {'Cycle': 498, 'Passes': [{'Pass': 9, 'Tiles': ['230L', '231L', '232L', '233L', '230R', '231R', '232R', '233R']}]}}}\nTemporal coverage: {'RangeDateTime': {'EndingDateTime': '2023-04-22T01:44:29.616Z', 'BeginningDateTime': '2023-04-22T01:44:09.731Z'}}\nSize(MB): 61.341376304626465\nData: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_1.1/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_498_009_116F_20230422T014409_20230422T014430_PIB0_01.nc']]\n\n\n\n\n\n\n# Let's look at cycle 485, on the second day of calval\n# Enter cycle\ncycle = \"485\"\n\nraster_results = earthaccess.search_data(short_name = 'SWOT_L2_HR_Raster_1.1', \n temporal = ('2023-04-01 00:00:00', '2023-04-22 23:59:59'), \n granule_name = \"*100m*\" + cycle + \"_\" + pass_number + \"_\" + tile_number + \"*\")\n\n# here we filter by files with '100m' in the name, cycle=484, pass=009, scene = 116F for Connecticut\n # cycle=485, pass=003, scene = 120F for the Rhine\n\nGranules found: 1\n\n\n\n\n\n\nfs_s3 = earthaccess.get_s3fs_session(results=raster_results)\n\n# get link for file and open it\nraster_link = earthaccess.results.DataGranule.data_links(raster_results[0], access='direct')[0]\ns3_file_obj5 = fs_s3.open(raster_link, mode='rb')\n\n# Open data with xarray\nds_raster = xr.open_dataset(s3_file_obj5, engine='h5netcdf')\n\n\n\n\n\n# Plot the data with a filter on water_frac > x, or sig0>50\nds_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)" + }, + { + "objectID": "Tutorials/SWOTHR_Science_Application.html#retrieving-swot-attributes-wse-width-slope-and-plotting-a-longitudinal-profile-along-a-river-or-over-a-basin", + "href": "Tutorials/SWOTHR_Science_Application.html#retrieving-swot-attributes-wse-width-slope-and-plotting-a-longitudinal-profile-along-a-river-or-over-a-basin", + "title": "SWOT Hydrology Science Application Tutorial on the Cloud", + "section": "", + "text": "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.\n\n\n\nAn 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.\nThis code runs using SWOT Level 2 Data Products (Version 1.1).\nNotebook Authors: Arnaud Cerbelaud, Jeffrey Wade, NASA Jet Propulsion Laboratory - California Institute of Technology (Jan 2024)" + }, + { + "objectID": "Tutorials/SWOTHR_Science_Application.html#learning-objectives", + "href": "Tutorials/SWOTHR_Science_Application.html#learning-objectives", + "title": "SWOT Hydrology Science Application Tutorial on the Cloud", + "section": "", + "text": "Retrieve SWOT hydrological attributes on river reaches within the AWS cloud (Cal/Val data). Query reaches by:\n\nRiver name\nSpatial bounding box\nDownstream tracing from reach id\nUpstream tracing from reach id\n\n\nRiver longitudinal profile: filtering data to display all reaches located downstream of a given reach (e.g. headwater to outlet)\nWatershed analysis: filtering data to display all reaches located upstream of a given reach (e.g. outlet to full river network)\nVisualize and plot WSE, width, slope data on the filtered data\n\nLast updated: 31 Jan 2024" + }, + { + "objectID": "Tutorials/SWOTHR_Science_Application.html#import-packages", + "href": "Tutorials/SWOTHR_Science_Application.html#import-packages", + "title": "SWOT Hydrology Science Application Tutorial on the Cloud", + "section": "", + "text": "import glob\nimport os\nimport requests\nimport s3fs\nimport fiona\nimport netCDF4 as nc\nimport h5netcdf\nimport xarray as xr\nimport pandas as pd\nimport geopandas as gpd\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport hvplot.xarray\nimport earthaccess\nfrom earthaccess import Auth, DataCollections, DataGranules, Store\nfrom pathlib import Path\nimport zipfile" + }, + { + "objectID": "Tutorials/SWOTHR_Science_Application.html#authenticate", + "href": "Tutorials/SWOTHR_Science_Application.html#authenticate", + "title": "SWOT Hydrology Science Application Tutorial on the Cloud", + "section": "", + "text": "Authenticate your Earthdata Login (EDL) information using the earthaccess python package as follows:\n\nearthaccess.login() # Login with your EDL credentials if asked\n\nEnter your Earthdata Login username: jswade\nEnter your Earthdata password: ········\n\n\n<earthaccess.auth.Auth at 0x7fd9a7adbee0>" + }, + { + "objectID": "Tutorials/SWOTHR_Science_Application.html#retrieve-swot-hydrological-attributes-on-river-reaches-within-the-aws-cloud-calval-data", + "href": "Tutorials/SWOTHR_Science_Application.html#retrieve-swot-hydrological-attributes-on-river-reaches-within-the-aws-cloud-calval-data", + "title": "SWOT Hydrology Science Application Tutorial on the Cloud", + "section": "", + "text": "Optional step: Get the .kmz file of SWOT passes/swaths (Version 1.1) and import it into Google Earth for visualization\nDetermine which pass number corresponds to the river/basin you want to look at! #### Search for multiple days of data\n\n\n# Enter pass number\npass_number = \"009\" # e.g. 009 for Connecticut in NA, 003 for Rhine in EU\n# Enter continent code\ncontinent_code = \"NA\" # e.g. \"AF\", \"NA\", \"EU\", \"SI\", \"AS\", \"AU\", \"SA\", \"AR\", \"GR\"\n\n# Retrieves granule from the day we want, in this case by passing to `earthdata.search_data` function the data collection shortname and temporal bounds\nriver_results = earthaccess.search_data(short_name = 'SWOT_L2_HR_RIVERSP_1.1', \n temporal = ('2023-04-08 00:00:00', '2023-04-12 23:59:59'),\n granule_name = \"*Reach*_\" + pass_number + \"_\" + continent_code + \"*\")\n\n# Create fiona session to read data\nfs_s3 = earthaccess.get_s3fs_session(results=river_results)\nfiona_session=fiona.session.AWSSession(\n aws_access_key_id=fs_s3.storage_options[\"key\"],\n aws_secret_access_key=fs_s3.storage_options[\"secret\"],\n aws_session_token=fs_s3.storage_options[\"token\"]\n )\n\nGranules found: 5\n\n\n\n\n\n\n# Initialize list of shapefiles containing all dates\nSWOT_HR_shps = []\n\n# Loop through queried granules to stack all acquisition dates\nfor j in range(len(river_results)):\n \n # Get the link for each zip file\n river_link = earthaccess.results.DataGranule.data_links(river_results[j], access='direct')[0]\n \n # We use the zip+ prefix so fiona knows that we are operating on a zip file\n river_shp_url = f\"zip+{river_link}\"\n \n # Read shapefile\n with fiona.Env(session=fiona_session):\n SWOT_HR_shps.append(gpd.read_file(river_shp_url)) \n\n\n\n\n\n# Combine granules from all acquisition dates into one dataframe\nSWOT_HR_df = gpd.GeoDataFrame(pd.concat(SWOT_HR_shps, ignore_index=True))\n\n# Sort dataframe by reach_id and time\nSWOT_HR_df = SWOT_HR_df.sort_values(['reach_id', 'time'])\n\nSWOT_HR_df\n\n\n\n\n\n\n\n\nreach_id\ntime\ntime_tai\ntime_str\np_lat\np_lon\nriver_name\nwse\nwse_u\nwse_r_u\n...\np_wid_var\np_n_nodes\np_dist_out\np_length\np_maf\np_dam_id\np_n_ch_max\np_n_ch_mod\np_low_slp\ngeometry\n\n\n\n\n1958\n72270400231\n-1.000000e+12\n-1.000000e+12\nno_data\n56.794630\n-66.461122\nno_data\n-1.000000e+12\n-1.000000e+12\n-1.000000e+12\n...\n1618.079\n53\n230079.472\n10630.774958\n-1.000000e+12\n0\n1\n1\n0\nLINESTRING (-66.48682 56.83442, -66.48645 56.8...\n\n\n2641\n72270400231\n-1.000000e+12\n-1.000000e+12\nno_data\n56.794630\n-66.461122\nno_data\n-1.000000e+12\n-1.000000e+12\n-1.000000e+12\n...\n1618.079\n53\n230079.472\n10630.774958\n-1.000000e+12\n0\n1\n1\n0\nLINESTRING (-66.48682 56.83442, -66.48645 56.8...\n\n\n1959\n72270400241\n-1.000000e+12\n-1.000000e+12\nno_data\n56.744361\n-66.341905\nno_data\n-1.000000e+12\n-1.000000e+12\n-1.000000e+12\n...\n4831.128\n53\n240728.430\n10648.958289\n-1.000000e+12\n0\n2\n1\n0\nLINESTRING (-66.41602 56.75969, -66.41553 56.7...\n\n\n2642\n72270400241\n-1.000000e+12\n-1.000000e+12\nno_data\n56.744361\n-66.341905\nno_data\n-1.000000e+12\n-1.000000e+12\n-1.000000e+12\n...\n4831.128\n53\n240728.430\n10648.958289\n-1.000000e+12\n0\n2\n1\n0\nLINESTRING (-66.41602 56.75969, -66.41553 56.7...\n\n\n1960\n72270400251\n7.344991e+08\n7.344991e+08\n2023-04-11T03:31:02Z\n56.676087\n-66.219811\nno_data\n2.855340e+02\n1.008930e+00\n1.004910e+00\n...\n412.975\n58\n252286.769\n11558.339052\n-1.000000e+12\n0\n2\n1\n0\nLINESTRING (-66.27812 56.71437, -66.27775 56.7...\n\n\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n\n\n615\n73130000061\n-1.000000e+12\n-1.000000e+12\nno_data\n41.424945\n-73.230960\nHousatonic River\n-1.000000e+12\n-1.000000e+12\n-1.000000e+12\n...\n10469.706\n82\n47161.191\n16303.793847\n-1.000000e+12\n0\n2\n1\n0\nLINESTRING (-73.17436 41.38295, -73.17465 41.3...\n\n\n1283\n73130000061\n-1.000000e+12\n-1.000000e+12\nno_data\n41.424945\n-73.230960\nHousatonic River\n-1.000000e+12\n-1.000000e+12\n-1.000000e+12\n...\n10469.706\n82\n47161.191\n16303.793847\n-1.000000e+12\n0\n2\n1\n0\nLINESTRING (-73.17436 41.38295, -73.17465 41.3...\n\n\n1957\n73130000061\n-1.000000e+12\n-1.000000e+12\nno_data\n41.424945\n-73.230960\nHousatonic River\n-1.000000e+12\n-1.000000e+12\n-1.000000e+12\n...\n10469.706\n82\n47161.191\n16303.793847\n-1.000000e+12\n0\n2\n1\n0\nLINESTRING (-73.17436 41.38295, -73.17465 41.3...\n\n\n2640\n73130000061\n-1.000000e+12\n-1.000000e+12\nno_data\n41.424945\n-73.230960\nHousatonic River\n-1.000000e+12\n-1.000000e+12\n-1.000000e+12\n...\n10469.706\n82\n47161.191\n16303.793847\n-1.000000e+12\n0\n2\n1\n0\nLINESTRING (-73.17436 41.38295, -73.17465 41.3...\n\n\n3312\n73130000061\n-1.000000e+12\n-1.000000e+12\nno_data\n41.424945\n-73.230960\nHousatonic River\n-1.000000e+12\n-1.000000e+12\n-1.000000e+12\n...\n10469.706\n82\n47161.191\n16303.793847\n-1.000000e+12\n0\n2\n1\n0\nLINESTRING (-73.17436 41.38295, -73.17465 41.3...\n\n\n\n\n3313 rows × 127 columns" + }, + { + "objectID": "Tutorials/SWOTHR_Science_Application.html#exploring-the-dataset", + "href": "Tutorials/SWOTHR_Science_Application.html#exploring-the-dataset", + "title": "SWOT Hydrology Science Application Tutorial on the Cloud", + "section": "", + "text": "print('Available dates are:')\nprint(np.unique([i[:10] for i in SWOT_HR_df['time_str']]))\nprint('Available rivers are:')\nprint(np.unique([i for i in SWOT_HR_df['river_name']]))\n\nAvailable dates are:\n['2023-04-08' '2023-04-09' '2023-04-10' '2023-04-11' '2023-04-12'\n 'no_data']\nAvailable rivers are:\n['Allagash River' 'Androscoggin River' 'Big Black River' 'Canal de fuite'\n 'Carrabassett River' 'Concord River' 'Concord River; Sudbury River'\n 'Connecticut River' 'Connecticut River; Westfield River'\n 'Connecticut River; White River' 'Dead River'\n 'Dead River (Kennebec River)' 'Deerfield River' 'Farmington River'\n 'Housatonic River' 'Ikarut River' 'Kennebec River' 'Komaktorvik River'\n 'Magalloway River' 'Merrimack River' 'Moose River'\n 'North Branch Penobscot River' 'Passumsic River' 'Pemigewasset River'\n 'Penobscot River West Branch' 'Quinebaug River' 'Saco River'\n 'Saguenay River' 'Saint Francis River' 'Saint John River'\n 'Saint Lawrence River' 'Sandy River' 'Shetucket River' 'Sudbury River'\n 'Thames River' 'West River' 'White River' 'no_data']\n\n\n\n\n\nNote: Some rivers have multiple names, hence using the contains function\n\n# Enter river name\nriver = \"Connecticut River\" # e.g. \"Rhine\", \"Connecticut River\"\n\n## Filter dataframe\nSWOT_HR_df_river = SWOT_HR_df[(SWOT_HR_df.river_name.str.contains(river))]\n\n# Plot geopandas dataframe with 'explore' by reach id\nSWOT_HR_df_river[['reach_id','river_name','geometry']].explore('reach_id', style_kwds=dict(weight=6))\n\nMake this Notebook Trusted to load map: File -> Trust Notebook\n\n\n\n\n\n\nlat_start = {\"Connecticut River\": 41.5,\n \"Rhine\": 47.5\n }\nlat_end = {\"Connecticut River\": 45,\n \"Rhine\": 51\n }\nlon_start = {\"Connecticut River\": -74,\n \"Rhine\": 7\n }\nlon_end = {\"Connecticut River\": -71,\n \"Rhine\": 10\n }\n\n## Filter dataframe\nSWOT_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])]\n\n# Plot geopandas dataframe with 'explore' by river name\nSWOT_HR_df_box[['reach_id','river_name','geometry']].explore('river_name', style_kwds=dict(weight=6))\n\nMake this Notebook Trusted to load map: File -> Trust Notebook" + }, + { + "objectID": "Tutorials/SWOTHR_Science_Application.html#river-longitudinal-profile-trace-reaches-downstream-of-given-starting-reach-using-rch_id_dn-field", + "href": "Tutorials/SWOTHR_Science_Application.html#river-longitudinal-profile-trace-reaches-downstream-of-given-starting-reach-using-rch_id_dn-field", + "title": "SWOT Hydrology Science Application Tutorial on the Cloud", + "section": "", + "text": "WARNING: This works as long as the data is exhaustive (no missing SWORD reaches)\n\n\nNote: rch_dn_dict[rch_id] gives a list of all the reaches directly downstream from rch_id\n\n# Format rch_id_dn for dictionary. Rch_id_dn allows for multiple downstream reaches to be stored\n# Also removes spaces in attribute field\nrch_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))]\n\n# Filter upstream reach ids to remove 'no_data'\nrch_id_dn_filter = [[x for x in dn_id if x.isnumeric()] for dn_id in rch_id_dn]\n\n# Create lookup dictionary for river network topology: Downstream\nrch_dn_dict = {SWOT_HR_df.reach_id[i]: rch_id_dn_filter[i] for i in range(len(SWOT_HR_df))}\n\n\n\n\n\n# Enter reach_id from which we will trace downstream (e.g. headwaters of the Connecticut River)\nrch_dn_st = {\"Connecticut River\": '73120000691',\n \"Rhine\": '23267000651'\n }\n\n# Initialize list to store downstream reaches, including starting reach\nrch_dn_list = [rch_dn_st[river]]\n# Retrieve first downstream id of starting reach and add to list\nrch_dn_next = rch_dn_dict[rch_dn_st[river]][0]\n\n# Trace next downstream reach until we hit the outlet (or here the last reach on file)\nwhile len(rch_dn_next) != 0:\n # Add reach to list if value exists\n if len(rch_dn_next) != 0:\n rch_dn_list.append(rch_dn_next)\n # Recursively retrieve first downstream id of next reach\n # Catch error if reach isn't in downloaded data\n try:\n rch_dn_next = rch_dn_dict[rch_dn_next][0]\n except:\n break\n\n\n\n\n\n# Filter downloaded data by downstream traced reaches\nSWOT_dn_trace = SWOT_HR_df[SWOT_HR_df.reach_id.isin(rch_dn_list)]\n\n# Remove reaches from rch_dn_list that are not present in SWOT data\nrch_dn_list = [rch for rch in rch_dn_list if rch in SWOT_HR_df.reach_id.values]\n\nSWOT_dn_trace[['reach_id','river_name','geometry']].explore('river_name', style_kwds=dict(weight=6))\n\nMake this Notebook Trusted to load map: File -> Trust Notebook" + }, + { + "objectID": "Tutorials/SWOTHR_Science_Application.html#watershed-analysis-trace-reaches-upstream-of-starting-reach-using-rch_id_up-field", + "href": "Tutorials/SWOTHR_Science_Application.html#watershed-analysis-trace-reaches-upstream-of-starting-reach-using-rch_id_up-field", + "title": "SWOT Hydrology Science Application Tutorial on the Cloud", + "section": "", + "text": "WARNING: This works as long as the data is exhaustive (no missing SWORD reaches)\n\n\nNote: rch_up_dict[rch_id] gives a list of all the reaches directly upstream from rch_id\n\n# Format rch_id_up for dictionary. Rch_id_up allows for multiple upstream reaches to be stored\n# Also removes spaces in attribute field\nrch_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))]\n\n# Filter upstream reach ids to remove 'no_data'\nrch_id_up_fil = [[x for x in ups_id if x.isnumeric()] for ups_id in rch_id_up]\n\n# Create lookup dictionary for river network topology: Upstream\nrch_up_dict = {SWOT_HR_df.reach_id[i]: rch_id_up_fil[i] for i in range(len(SWOT_HR_df))}\n\n\n\n\nThis adds a bit of complexity, as we need to keep track of multiple branches upstream of the starting reach.\n\n# Enter reach_id from which we will trace upstream (e.g. outlet of the Connecticut River)\nrch_up_st = {\"Connecticut River\": '73120000013',\n \"Rhine\": '23265000051'\n }\n\n# Initialize list to store traced upstream reaches, including starting reach\nrch_up_list = [rch_up_st[river]]\n# Retrieve ids of reaches upstream of starting reach and add to list\nrch_up_next = rch_up_dict[rch_up_st[river]]\n# For upstream tracing, we need to set a list of next upstream ids to start while loop\nrch_next_id = rch_up_next\n\n# Loop until no more reaches to trace\nwhile len(rch_next_id) != 0:\n # Initialize list to store next upstream ids\n rch_next_id = []\n # Loop through next upstream ids for given reach\n for rch_up_sel in rch_up_next:\n # Get values of existing upstream ids of rch_up_next reaches\n # If reach isn't in SWOT data (usually ghost reaches), continue to next reach\n try:\n rch_next_id = rch_next_id + rch_up_dict[rch_up_sel]\n except:\n continue\n # Append id to list\n rch_up_list.append(rch_up_sel)\n # If reaches exist, add to list for next cycle of tracing\n if len(rch_next_id) != 0:\n rch_up_next = rch_next_id\n\n\n\n\n\n# Filter downloaded data by upstream traced reaches\nSWOT_up_trace = SWOT_HR_df[SWOT_HR_df.reach_id.isin(rch_up_list)]\n\n# Remove reaches from rch_up_list that are not present in SWOT data\nrch_up_list = [rch for rch in rch_up_list if rch in SWOT_HR_df.reach_id.values]\n\nSWOT_up_trace[['reach_id','river_name','geometry']].explore('river_name', style_kwds=dict(weight=6))\n\nMake this Notebook Trusted to load map: File -> Trust Notebook" + }, + { + "objectID": "Tutorials/SWOTHR_Science_Application.html#visualize-and-plot-a-time-series-of-wsewidthslope-longitudinal-profiles", + "href": "Tutorials/SWOTHR_Science_Application.html#visualize-and-plot-a-time-series-of-wsewidthslope-longitudinal-profiles", + "title": "SWOT Hydrology Science Application Tutorial on the Cloud", + "section": "", + "text": "# Retrieve all possible acquisition dates (keeping only YYYY-MM-DD)\ndates = np.unique([i[:10] for i in [x for x in SWOT_HR_df['time_str'] if x!='no_data']])\n\n# Create a new database for time series analysis with unique reach_ids\nSWOT_dn_trace_time = SWOT_dn_trace.set_index('reach_id').groupby(level=0) \\\n .apply(lambda df: df.reset_index(drop=True)) \\\n .unstack().sort_index(axis=1, level=1)\n\nSWOT_dn_trace_time.columns = ['{}_{}'.format(x[0],dates[x[1]]) for x in SWOT_dn_trace_time.columns]\n\n\n\n\n\n# Explore variables you could choose to plot\nfor var in [\"wse\",\"slope\",\"width\",\"len\"]:\n print(SWOT_dn_trace.columns[SWOT_dn_trace.columns.str.contains(var)])\n\nIndex(['wse', 'wse_u', 'wse_r_u', 'wse_c', 'wse_c_u', 'area_wse', 'p_wse',\n 'p_wse_var'],\n dtype='object')\nIndex(['slope', 'slope_u', 'slope_r_u', 'slope2', 'slope2_u', 'slope2_r_u'], dtype='object')\nIndex(['width', 'width_u', 'width_c', 'width_c_u', 'p_width'], dtype='object')\nIndex(['p_length'], dtype='object')\n\n\n\n# Enter variable of interest for plotting\nvarstr = \"wse\"\n\n\n# Find cumulative length on the longitudinal profile\nlength_list = np.nan_to_num([SWOT_dn_trace.p_length[SWOT_dn_trace.reach_id == rch].mean()/1000 for rch in rch_dn_list])\ncumlength_list = np.cumsum(length_list)\n\n## Plot a longitudinal profile from the downstream tracing database\n\n## Plot a longitudinal profile from the downstream tracing database\nplt.figure(figsize=(12,8))\nfor t in dates:\n \n # Store the quantity of interest (wse, width etc.) at time t\n value = SWOT_dn_trace_time.loc[rch_dn_list,varstr+'_'+t]\n \n # Remove set negative values (bad observations) to NaN and forward fill NaNs\n value[value < 0] = np.nan\n value = value.ffill()\n \n # Plot the data\n plt.plot(cumlength_list, value, label = varstr+'_'+t)\n \nplt.xlabel('Downstream Distance (km)')\nplt.ylabel(varstr)\nplt.legend()\n\n\n\n\n\n\n\n\n\n\n\n\n# Choose a date\ndate = dates[0]\n\n\n#Set one column as the active geometry in the new database\nSWOT_dn_trace_time = SWOT_dn_trace_time.set_geometry(\"geometry_\"+date)\n\n#Set cleaner colorbar bounds for better visualization\nvmin = np.percentile([i for i in SWOT_dn_trace_time[varstr+'_'+date] if i>0],5)\nvmax = np.percentile([i for i in SWOT_dn_trace_time[varstr+'_'+date] if i>0],95)\n\n# Interactive map\nSWOT_dn_trace_time.explore(varstr+'_'+date,\n vmin = vmin,\n vmax = vmax,\n cmap = \"Blues\", #\"Blues\",\n control_scale = True,\n tooltip = varstr+'_'+dates[0], # show \"varstr+'_'+dates[0]\" value in tooltip (on hover)\n popup = True, # show all values in popup (on click)\n #tiles = \"CartoDB positron\", # use \"CartoDB positron\" tiles\n style_kwds=dict(weight=10)\n )\n\nMake this Notebook Trusted to load map: File -> Trust Notebook" + }, + { + "objectID": "Tutorials/SWOTHR_Science_Application.html#supplemental", + "href": "Tutorials/SWOTHR_Science_Application.html#supplemental", + "title": "SWOT Hydrology Science Application Tutorial on the Cloud", + "section": "", + "text": "SWOT_up_trace_time = SWOT_up_trace.set_index('reach_id').groupby(level=0) \\\n .apply(lambda df: df.reset_index(drop=True)) \\\n .unstack().sort_index(axis=1, level=1)\n\nSWOT_up_trace_time.columns = ['{}_{}'.format(x[0],dates[x[1]]) for x in SWOT_up_trace_time.columns]\n\nSWOT_up_trace_time = SWOT_up_trace_time.set_geometry(\"geometry_\"+date)\n\n#Set cleaner colorbar bounds for better visualization\nvmin = np.percentile([i for i in SWOT_up_trace_time[varstr+'_'+date] if i>0],5)\nvmax = np.percentile([i for i in SWOT_up_trace_time[varstr+'_'+date] if i>0],95)\n\n# Interactive map\nSWOT_up_trace_time.explore(varstr+'_'+date,\n vmin = vmin,\n vmax = vmax,\n cmap = \"Blues\", #\"Blues\",\n control_scale = True,\n tooltip = varstr+'_'+dates[0], # show \"varstr+'_'+dates[0]\" value in tooltip (on hover)\n popup = True, # show all values in popup (on click)\n tiles = \"CartoDB positron\", # use \"CartoDB positron\" tiles\n style_kwds=dict(weight=5)\n )\n\nMake this Notebook Trusted to load map: File -> Trust Notebook\n\n\n\n\n\nNow you will also need the tile number (in addition to the pass number). You can find it on the .kmz file\n\n# Enter tile number\ntile_number = \"116F\"\n\n# Retrieve granules from all days to find the cycle corresponding to the desired date\nraster_results = earthaccess.search_data(short_name = 'SWOT_L2_HR_Raster_1.1', \n temporal = ('2023-04-01 00:00:00', '2023-04-22 23:59:59'), \n granule_name = \"*100m*_\" + pass_number + \"_\" + tile_number + \"*\")\n# here we filter by files with '100m' in the name, pass=009, scene = 116F (tile = 232L) for Connecticut\n # pass=003, scene = 120F (tile = 239R) for the Rhine\n\nGranules found: 15\n\n\n\n\n\nprint([i for i in raster_results])\n\n[Collection: {'Version': '1.1', 'ShortName': 'SWOT_L2_HR_Raster_1.1'}\nSpatial coverage: {'HorizontalSpatialDomain': {'Orbit': {'StartLatitude': -77.66, 'EndLatitude': 77.66, 'AscendingCrossing': -80.4, 'StartDirection': 'A', 'EndDirection': 'A'}, 'Track': {'Cycle': 484, 'Passes': [{'Pass': 9, 'Tiles': ['230L', '231L', '232L', '233L', '230R', '231R', '232R', '233R']}]}}}\nTemporal coverage: {'RangeDateTime': {'EndingDateTime': '2023-04-08T03:55:38.288Z', 'BeginningDateTime': '2023-04-08T03:55:18.398Z'}}\nSize(MB): 70.40732002258301\nData: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_1.1/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_484_009_116F_20230408T035517_20230408T035538_PIB0_01.nc'], Collection: {'Version': '1.1', 'ShortName': 'SWOT_L2_HR_Raster_1.1'}\nSpatial coverage: {'HorizontalSpatialDomain': {'Orbit': {'StartLatitude': -77.66, 'EndLatitude': 77.66, 'AscendingCrossing': -80.4, 'StartDirection': 'A', 'EndDirection': 'A'}, 'Track': {'Cycle': 485, 'Passes': [{'Pass': 9, 'Tiles': ['230L', '231L', '232L', '233L', '230R', '231R', '232R', '233R']}]}}}\nTemporal coverage: {'RangeDateTime': {'EndingDateTime': '2023-04-09T03:46:16.448Z', 'BeginningDateTime': '2023-04-09T03:45:56.558Z'}}\nSize(MB): 68.41873073577881\nData: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_1.1/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_485_009_116F_20230409T034556_20230409T034616_PIB0_01.nc'], Collection: {'Version': '1.1', 'ShortName': 'SWOT_L2_HR_Raster_1.1'}\nSpatial coverage: {'HorizontalSpatialDomain': {'Orbit': {'StartLatitude': -77.66, 'EndLatitude': 77.66, 'AscendingCrossing': -80.4, 'StartDirection': 'A', 'EndDirection': 'A'}, 'Track': {'Cycle': 486, 'Passes': [{'Pass': 9, 'Tiles': ['230L', '231L', '232L', '233L', '230R', '231R', '232R', '233R']}]}}}\nTemporal coverage: {'RangeDateTime': {'EndingDateTime': '2023-04-10T03:36:54.573Z', 'BeginningDateTime': '2023-04-10T03:36:34.684Z'}}\nSize(MB): 68.47044467926025\nData: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_1.1/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_486_009_116F_20230410T033634_20230410T033655_PIB0_01.nc'], Collection: {'Version': '1.1', 'ShortName': 'SWOT_L2_HR_Raster_1.1'}\nSpatial coverage: {'HorizontalSpatialDomain': {'Orbit': {'StartLatitude': -77.66, 'EndLatitude': 77.66, 'AscendingCrossing': -80.4, 'StartDirection': 'A', 'EndDirection': 'A'}, 'Track': {'Cycle': 487, 'Passes': [{'Pass': 9, 'Tiles': ['230L', '231L', '232L', '233L', '230R', '231R', '232R', '233R']}]}}}\nTemporal coverage: {'RangeDateTime': {'EndingDateTime': '2023-04-11T03:27:32.662Z', 'BeginningDateTime': '2023-04-11T03:27:12.772Z'}}\nSize(MB): 69.02541446685791\nData: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_1.1/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_487_009_116F_20230411T032712_20230411T032733_PIB0_01.nc'], Collection: {'Version': '1.1', 'ShortName': 'SWOT_L2_HR_Raster_1.1'}\nSpatial coverage: {'HorizontalSpatialDomain': {'Orbit': {'StartLatitude': -77.66, 'EndLatitude': 77.66, 'AscendingCrossing': -80.4, 'StartDirection': 'A', 'EndDirection': 'A'}, 'Track': {'Cycle': 488, 'Passes': [{'Pass': 9, 'Tiles': ['230L', '231L', '232L', '233L', '230R', '231R', '232R', '233R']}]}}}\nTemporal coverage: {'RangeDateTime': {'EndingDateTime': '2023-04-12T03:18:10.720Z', 'BeginningDateTime': '2023-04-12T03:17:50.831Z'}}\nSize(MB): 67.56003761291504\nData: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_1.1/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_488_009_116F_20230412T031750_20230412T031811_PIB0_01.nc'], Collection: {'Version': '1.1', 'ShortName': 'SWOT_L2_HR_Raster_1.1'}\nSpatial coverage: {'HorizontalSpatialDomain': {'Orbit': {'StartLatitude': -77.66, 'EndLatitude': 77.66, 'AscendingCrossing': -80.4, 'StartDirection': 'A', 'EndDirection': 'A'}, 'Track': {'Cycle': 489, 'Passes': [{'Pass': 9, 'Tiles': ['230L', '231L', '232L', '233L', '230R', '231R', '232R', '233R']}]}}}\nTemporal coverage: {'RangeDateTime': {'EndingDateTime': '2023-04-13T03:08:48.751Z', 'BeginningDateTime': '2023-04-13T03:08:28.862Z'}}\nSize(MB): 68.72685241699219\nData: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_1.1/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_489_009_116F_20230413T030828_20230413T030849_PIB0_01.nc'], Collection: {'Version': '1.1', 'ShortName': 'SWOT_L2_HR_Raster_1.1'}\nSpatial coverage: {'HorizontalSpatialDomain': {'Orbit': {'StartLatitude': -77.66, 'EndLatitude': 77.66, 'AscendingCrossing': -80.4, 'StartDirection': 'A', 'EndDirection': 'A'}, 'Track': {'Cycle': 490, 'Passes': [{'Pass': 9, 'Tiles': ['230L', '231L', '232L', '233L', '230R', '231R', '232R', '233R']}]}}}\nTemporal coverage: {'RangeDateTime': {'EndingDateTime': '2023-04-14T02:59:26.753Z', 'BeginningDateTime': '2023-04-14T02:59:06.866Z'}}\nSize(MB): 66.47898387908936\nData: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_1.1/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_490_009_116F_20230414T025906_20230414T025927_PIB0_01.nc'], Collection: {'Version': '1.1', 'ShortName': 'SWOT_L2_HR_Raster_1.1'}\nSpatial coverage: {'HorizontalSpatialDomain': {'Orbit': {'StartLatitude': -77.66, 'EndLatitude': 77.66, 'AscendingCrossing': -80.41, 'StartDirection': 'A', 'EndDirection': 'A'}, 'Track': {'Cycle': 491, 'Passes': [{'Pass': 9, 'Tiles': ['230L', '231L', '232L', '233L', '230R', '231R', '232R', '233R']}]}}}\nTemporal coverage: {'RangeDateTime': {'EndingDateTime': '2023-04-15T02:50:04.726Z', 'BeginningDateTime': '2023-04-15T02:49:44.836Z'}}\nSize(MB): 67.29588985443115\nData: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_1.1/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_491_009_116F_20230415T024944_20230415T025005_PIB0_01.nc'], Collection: {'Version': '1.1', 'ShortName': 'SWOT_L2_HR_Raster_1.1'}\nSpatial coverage: {'HorizontalSpatialDomain': {'Orbit': {'StartLatitude': -77.66, 'EndLatitude': 77.66, 'AscendingCrossing': -80.41, 'StartDirection': 'A', 'EndDirection': 'A'}, 'Track': {'Cycle': 492, 'Passes': [{'Pass': 9, 'Tiles': ['230L', '231L', '232L', '233L', '230R', '231R', '232R', '233R']}]}}}\nTemporal coverage: {'RangeDateTime': {'EndingDateTime': '2023-04-16T02:40:43.207Z', 'BeginningDateTime': '2023-04-16T02:40:22.244Z'}}\nSize(MB): 0.933258056640625\nData: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_1.1/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_492_009_116F_20230416T024022_20230416T024043_PIB0_01.nc'], Collection: {'Version': '1.1', 'ShortName': 'SWOT_L2_HR_Raster_1.1'}\nSpatial coverage: {'HorizontalSpatialDomain': {'Orbit': {'StartLatitude': -77.66, 'EndLatitude': 77.66, 'AscendingCrossing': -80.41, 'StartDirection': 'A', 'EndDirection': 'A'}, 'Track': {'Cycle': 493, 'Passes': [{'Pass': 9, 'Tiles': ['230L', '231L', '232L', '233L', '230R', '231R', '232R', '233R']}]}}}\nTemporal coverage: {'RangeDateTime': {'EndingDateTime': '2023-04-17T02:31:21.112Z', 'BeginningDateTime': '2023-04-17T02:31:00.151Z'}}\nSize(MB): 0.9332094192504883\nData: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_1.1/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_493_009_116F_20230417T023100_20230417T023121_PIB0_01.nc'], Collection: {'Version': '1.1', 'ShortName': 'SWOT_L2_HR_Raster_1.1'}\nSpatial coverage: {'HorizontalSpatialDomain': {'Orbit': {'StartLatitude': -77.66, 'EndLatitude': 77.66, 'AscendingCrossing': -80.41, 'StartDirection': 'A', 'EndDirection': 'A'}, 'Track': {'Cycle': 494, 'Passes': [{'Pass': 9, 'Tiles': ['230L', '231L', '232L', '233L', '230R', '231R', '232R', '233R']}]}}}\nTemporal coverage: {'RangeDateTime': {'EndingDateTime': '2023-04-18T02:21:58.990Z', 'BeginningDateTime': '2023-04-18T02:21:38.024Z'}}\nSize(MB): 0.9332304000854492\nData: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_1.1/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_494_009_116F_20230418T022138_20230418T022158_PIB0_01.nc'], Collection: {'Version': '1.1', 'ShortName': 'SWOT_L2_HR_Raster_1.1'}\nSpatial coverage: {'HorizontalSpatialDomain': {'Orbit': {'StartLatitude': -77.66, 'EndLatitude': 77.66, 'AscendingCrossing': -80.41, 'StartDirection': 'A', 'EndDirection': 'A'}, 'Track': {'Cycle': 495, 'Passes': [{'Pass': 9, 'Tiles': ['230L', '231L', '232L', '233L', '230R', '231R', '232R', '233R']}]}}}\nTemporal coverage: {'RangeDateTime': {'EndingDateTime': '2023-04-19T02:12:36.279Z', 'BeginningDateTime': '2023-04-19T02:12:16.394Z'}}\nSize(MB): 63.773990631103516\nData: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_1.1/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_495_009_116F_20230419T021215_20230419T021236_PIB0_01.nc'], Collection: {'Version': '1.1', 'ShortName': 'SWOT_L2_HR_Raster_1.1'}\nSpatial coverage: {'HorizontalSpatialDomain': {'Orbit': {'StartLatitude': -77.66, 'EndLatitude': 77.66, 'AscendingCrossing': -80.41, 'StartDirection': 'A', 'EndDirection': 'A'}, 'Track': {'Cycle': 496, 'Passes': [{'Pass': 9, 'Tiles': ['230L', '231L', '232L', '233L', '230R', '231R', '232R', '233R']}]}}}\nTemporal coverage: {'RangeDateTime': {'EndingDateTime': '2023-04-20T02:03:14.075Z', 'BeginningDateTime': '2023-04-20T02:02:54.187Z'}}\nSize(MB): 62.185853004455566\nData: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_1.1/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_496_009_116F_20230420T020253_20230420T020314_PIB0_01.nc'], Collection: {'Version': '1.1', 'ShortName': 'SWOT_L2_HR_Raster_1.1'}\nSpatial coverage: {'HorizontalSpatialDomain': {'Orbit': {'StartLatitude': -77.66, 'EndLatitude': 77.66, 'AscendingCrossing': -80.41, 'StartDirection': 'A', 'EndDirection': 'A'}, 'Track': {'Cycle': 497, 'Passes': [{'Pass': 9, 'Tiles': ['230L', '231L', '232L', '233L', '230R', '231R', '232R', '233R']}]}}}\nTemporal coverage: {'RangeDateTime': {'EndingDateTime': '2023-04-21T01:53:51.831Z', 'BeginningDateTime': '2023-04-21T01:53:31.942Z'}}\nSize(MB): 61.36593437194824\nData: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_1.1/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_497_009_116F_20230421T015331_20230421T015352_PIB0_01.nc'], Collection: {'Version': '1.1', 'ShortName': 'SWOT_L2_HR_Raster_1.1'}\nSpatial coverage: {'HorizontalSpatialDomain': {'Orbit': {'StartLatitude': -77.66, 'EndLatitude': 77.66, 'AscendingCrossing': -80.41, 'StartDirection': 'A', 'EndDirection': 'A'}, 'Track': {'Cycle': 498, 'Passes': [{'Pass': 9, 'Tiles': ['230L', '231L', '232L', '233L', '230R', '231R', '232R', '233R']}]}}}\nTemporal coverage: {'RangeDateTime': {'EndingDateTime': '2023-04-22T01:44:29.616Z', 'BeginningDateTime': '2023-04-22T01:44:09.731Z'}}\nSize(MB): 61.341376304626465\nData: ['https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_Raster_1.1/SWOT_L2_HR_Raster_100m_UTM19T_N_x_x_x_498_009_116F_20230422T014409_20230422T014430_PIB0_01.nc']]\n\n\n\n\n\n\n# Let's look at cycle 485, on the second day of calval\n# Enter cycle\ncycle = \"485\"\n\nraster_results = earthaccess.search_data(short_name = 'SWOT_L2_HR_Raster_1.1', \n temporal = ('2023-04-01 00:00:00', '2023-04-22 23:59:59'), \n granule_name = \"*100m*\" + cycle + \"_\" + pass_number + \"_\" + tile_number + \"*\")\n\n# here we filter by files with '100m' in the name, cycle=484, pass=009, scene = 116F for Connecticut\n # cycle=485, pass=003, scene = 120F for the Rhine\n\nGranules found: 1\n\n\n\n\n\n\nfs_s3 = earthaccess.get_s3fs_session(results=raster_results)\n\n# get link for file and open it\nraster_link = earthaccess.results.DataGranule.data_links(raster_results[0], access='direct')[0]\ns3_file_obj5 = fs_s3.open(raster_link, mode='rb')\n\n# Open data with xarray\nds_raster = xr.open_dataset(s3_file_obj5, engine='h5netcdf')\n\n\n\n\n\n# Plot the data with a filter on water_frac > x, or sig0>50\nds_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)" + }, { "objectID": "Tutorials/SWOTHR_s3Access_real_data_v11.html", "href": "Tutorials/SWOTHR_s3Access_real_data_v11.html", diff --git a/sitemap.xml b/sitemap.xml index ba68ade..52e1e96 100644 --- a/sitemap.xml +++ b/sitemap.xml @@ -2,22 +2,26 @@ https://podaac.github.io/2024-SWOT-Hydro-Workshop/index.html - 2024-01-31T00:28:11.478Z + 2024-01-31T18:05:31.941Z https://podaac.github.io/2024-SWOT-Hydro-Workshop/slides.html - 2024-01-31T00:28:11.478Z + 2024-01-31T18:05:31.941Z + + + https://podaac.github.io/2024-SWOT-Hydro-Workshop/Tutorials/SWOTHR_Science_Application.html + 2024-01-31T18:05:31.901Z https://podaac.github.io/2024-SWOT-Hydro-Workshop/Tutorials/SWOTHR_s3Access_real_data_v11.html - 2024-01-31T00:28:11.478Z + 2024-01-31T18:05:31.941Z https://podaac.github.io/2024-SWOT-Hydro-Workshop/schedule.html - 2024-01-31T00:28:11.478Z + 2024-01-31T18:05:31.941Z https://podaac.github.io/2024-SWOT-Hydro-Workshop/prerequisites.html - 2024-01-31T00:28:11.478Z + 2024-01-31T18:05:31.941Z