import xarray as xr
import s3fs
import cartopy.crs as ccrs
import cartopy.feature as cfeature
from matplotlib import pyplot as plt
import earthaccess
from earthaccess import Auth, DataCollections, DataGranules, Store
%matplotlib inline
Access Sentinel 6 Data in the Cloud
Summary
This notebook will show direct access of PO.DAAC archived products in the Earthdata Cloud in AWS Simple Storage Service (S3).
In this demo, we will showcase the usage of the Sentinel 6 product:
Sentinel-6A MF Jason-CS L2 P4 Altimeter Low Resolution (LR) NTC Ocean Surface Topography F08 Data Product - shortname JASON_CS_S6A_L2_ALT_LR_STD_OST_NTC_F08
We will access the data from inside the AWS cloud (us-west-2 region, specifically) and plot the sea surface height anomaly.
Requirement
This tutorial can only be run in an AWS cloud instance running in us-west-2 region.
Learning Objectives:
Authenticate for earthaccess Python Library using your NASA Earthdata Login.
Access DAAC data directly from the in-region S3 bucket without moving or downloading any files to your local (cloud) workspace.
Note: no files are being downloaded off the cloud, rather, we are working with the data in the AWS cloud.
Libraries Needed:
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. We use earthaccess to authenticate your login credentials below.
= earthaccess.login() auth
1. Sentinel 6A Sea Surface Height Anomaly Data
Access Files without any Downloads to your running instance
Here, we use the earthaccess Python library to search for without downloading any files.
#contain links for each granules
= earthaccess.search_data(short_name = 'JASON_CS_S6A_L2_ALT_LR_STD_OST_NTC_F08',
ssh_data = ("2023-02-18 12:00:00", "2023-02-19 12:00:00"),
temporal )
Granules found: 22
Extract and grab first link
# extracting links (url)
= [granule.data_links(access="direct") for granule in ssh_data]
data_links
#picks first link
= data_links[0]
file_path file_path
['s3://podaac-ops-cumulus-protected/JASON_CS_S6A_L2_ALT_LR_STD_OST_NTC_F08/S6A_P4_2__LR_STD__NT_084_001_20230218T160856_20230218T170509_F08.nc']
Authenticate from AWS
#authenticate and get short term credientials to bucket (podaac-ops...)
= earthaccess.get_s3fs_session(results=ssh_data) fs_s3
Read file
#reading file into memory
open(file_path[0]) fs_s3.
<File-like object S3FileSystem, podaac-ops-cumulus-protected/JASON_CS_S6A_L2_ALT_LR_STD_OST_NTC_F08/S6A_P4_2__LR_STD__NT_084_001_20230218T160856_20230218T170509_F08.nc>
Load with xarray
The variable ‘ssha’ is located in the group ‘data_01’ and within the subgroup of ‘ku’. Here, we create variables that will access the group and the subgroups.
# Load the netCDF file using xarray
= xr.open_dataset(fs_s3.open(file_path[0]), group = 'data_01/ku')
ku_ds = xr.open_dataset(fs_s3.open(file_path[0]), group = 'data_01/c')
c_ds = xr.open_dataset(fs_s3.open(file_path[0]), group = 'data_01') data01_ds
Plot sea surface height anomaly (ssha)
# Access the 'ssha' variable under 'data_01' and 'ku'
= ku_ds['ssha']
ssha
# Plot the 'ssha'
=(10, 5))
plt.figure(figsize= ssha, cmap = 'coolwarm', vmin=-0.2, vmax=0.2)
plt.scatter(data01_ds.longitude, data01_ds.latitude, c ='Sea Surface Height Anomaly (ssha)')
plt.colorbar(label'Sea Surface Height Anomaly (ssha)')
plt.title('Longitude Index')
plt.xlabel('Latitude Index')
plt.ylabel( plt.show()
ssha.plot()
# Create a plot with a specific projection
= plt.figure(figsize=(10, 5))
fig = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())
ax -180, 180, -90, 90], crs=ccrs.PlateCarree()) # Set the extent to global
ax.set_extent([
# Add features to the map
ax.add_feature(cfeature.LAND)# Correct attribute for oceans
ax.add_feature(cfeature.OCEAN)
ax.add_feature(cfeature.COASTLINE)=':')
ax.add_feature(cfeature.BORDERS, linestyle
# Plot the 'ssha' with longitude and latitude from your dataset
= ax.scatter(data01_ds.longitude, data01_ds.latitude, c=ssha, cmap='coolwarm', transform=ccrs.PlateCarree())
scatter
# Add a colorbar
= plt.colorbar(scatter, ax=ax, orientation='vertical', fraction=0.046, pad=0.04)
cbar 'Sea Surface Height Anomaly (ssha)')
cbar.set_label(
# Set titles and labels
'Sea Surface Height Anomaly (ssha)')
plt.title('Longitude')
ax.set_xlabel('Latitude')
ax.set_ylabel(
# Show the plot
plt.show()