Created
February 8, 2025 23:30
-
-
Save giswqs/06860357b1bc63db0bd92391ddf19094 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Access OPERA DSWx-HLS Data" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import os\n", | |
"import requests\n", | |
"import boto3\n", | |
"import rasterio as rio\n", | |
"from rasterio.session import AWSSession\n", | |
"import xarray as xr\n", | |
"\n", | |
"# Generates the temporary\n", | |
"s3_cred_endpoint = \"https://archive.podaac.earthdata.nasa.gov/s3credentials\"\n", | |
"\n", | |
"def get_temp_creds():\n", | |
" temp_creds_url = s3_cred_endpoint\n", | |
" return requests.get(temp_creds_url).json()\n", | |
"\n", | |
"temp_creds_req = get_temp_creds()\n", | |
"\n", | |
"session = boto3.Session(\n", | |
" aws_access_key_id=temp_creds_req[\"accessKeyId\"],\n", | |
" aws_secret_access_key=temp_creds_req[\"secretAccessKey\"],\n", | |
" aws_session_token=temp_creds_req[\"sessionToken\"],\n", | |
" region_name=\"us-west-2\",\n", | |
")\n", | |
"\n", | |
"rio_env = rio.Env(\n", | |
" AWSSession(session),\n", | |
" GDAL_DISABLE_READDIR_ON_OPEN=\"EMPTY_DIR\",\n", | |
" CPL_VSIL_CURL_ALLOWED_EXTENSIONS=\"TIF, TIFF\",\n", | |
" GDAL_HTTP_COOKIEFILE=os.path.expanduser(\"~/cookies.txt\"),\n", | |
" GDAL_HTTP_COOKIEJAR=os.path.expanduser(\"~/cookies.txt\"),\n", | |
")\n", | |
"rio_env.__enter__()\n", | |
"\n", | |
"url = 'https://archive.podaac.earthdata.nasa.gov/podaac-ops-cumulus-protected/OPERA_L3_DSWX-HLS_PROVISIONAL_V1/OPERA_L3_DSWx-HLS_T11SPA_20230409T181446Z_20230411T155818Z_L8_30_v1.0_B01_WTR.tif'\n", | |
"\n", | |
"ds = xr.open_dataset(url, engine=\"rasterio\")\n", | |
"ds" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Access OPERA RTC Data" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import os\n", | |
"import requests\n", | |
"import boto3\n", | |
"import rasterio as rio\n", | |
"from rasterio.session import AWSSession\n", | |
"import xarray as xr\n", | |
"\n", | |
"# Generates the temporary\n", | |
"s3_cred_endpoint = \"https://cumulus.asf.alaska.edu/s3credentials\"\n", | |
"\n", | |
"def get_temp_creds():\n", | |
" temp_creds_url = s3_cred_endpoint\n", | |
" return requests.get(temp_creds_url).json()\n", | |
"\n", | |
"temp_creds_req = get_temp_creds()\n", | |
"\n", | |
"session = boto3.Session(\n", | |
" aws_access_key_id=temp_creds_req[\"accessKeyId\"],\n", | |
" aws_secret_access_key=temp_creds_req[\"secretAccessKey\"],\n", | |
" aws_session_token=temp_creds_req[\"sessionToken\"],\n", | |
" region_name=\"us-west-2\",\n", | |
")\n", | |
"\n", | |
"rio_env = rio.Env(\n", | |
" AWSSession(session),\n", | |
" GDAL_DISABLE_READDIR_ON_OPEN=\"EMPTY_DIR\",\n", | |
" CPL_VSIL_CURL_ALLOWED_EXTENSIONS=\"TIF, TIFF\",\n", | |
" GDAL_HTTP_COOKIEFILE=os.path.expanduser(\"~/cookies.txt\"),\n", | |
" GDAL_HTTP_COOKIEJAR=os.path.expanduser(\"~/cookies.txt\"),\n", | |
")\n", | |
"rio_env.__enter__()\n", | |
"\n", | |
"url = 'https://datapool.asf.alaska.edu/RTC/OPERA-S1/OPERA_L2_RTC-S1_T100-213489-IW1_20220103T133500Z_20241217T081326Z_S1A_30_v1.0_VH.tif'\n", | |
"\n", | |
"ds = xr.open_dataset(url, engine=\"rasterio\")\n", | |
"ds" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "geo", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.12.2" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To leverage your temporary S3 credentials, you'll want to use
s3://
URIs, rather thanhttps://
URLs. For the ASF RTC example, I expect you'll have success by settingurl = 's3://asf-cumulus-prod-opera-products/OPERA_L2_RTC-S1/OPERA_L2_RTC-S1_T100-213489-IW1_20220103T133500Z_20241217T081326Z_S1A_30_v1.0/OPERA_L2_RTC-S1_T100-213489-IW1_20220103T133500Z_20241217T081326Z_S1A_30_v1.0_VH.tif'
For the PO.DAAC DSWX example, you'll likely see better performance if you set:
url = 's3://podaac-ops-cumulus-protected/OPERA_L3_DSWX-HLS_PROVISIONAL_V1/OPERA_L3_DSWx-HLS_T11SPA_20230409T181446Z_20230411T155818Z_L8_30_v1.0_B01_WTR.tif'
When using an
https://
url, I expectxr.open_dataset
is using Basic Authentication via your.netrc
file, rather than leveraging the s3 credentials you've set up. https://datapool.asf.alaska.edu has a known issue with Basic Authentication and would require some extra code to succeed, while https://archive.podaac.earthdata.nasa.gov works out-of-the-box.