-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add simple satellite imagery notebook
- Loading branch information
Showing
1 changed file
with
125 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "e6a0105b-46d5-4514-ab80-f1be4d930106", | ||
"metadata": {}, | ||
"source": [ | ||
"# Satellite Image Processing" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "f2f207b1-e454-4cbf-b846-b7e0d815c784", | ||
"metadata": {}, | ||
"source": [ | ||
"## List file paths in the cloud" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "f3221ff3-24bd-4e38-a974-efde525e88b1", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import s3fs\n", | ||
"\n", | ||
"s3 = s3fs.S3FileSystem()\n", | ||
"\n", | ||
"urls = s3.glob(\"sentinel-cogs/sentinel-s2-l2a-cogs/1/C/CV/20*/*/*/*.tif\")\n", | ||
"urls[:5]" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "f2cd4092-358a-4a69-8013-e0b688b9583a", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"len(urls)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "91f84137-28c0-4aea-9698-760cf6d93665", | ||
"metadata": {}, | ||
"source": [ | ||
"## Process each file sequentially" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "6be2be6b-c673-4caf-aa9d-aa01c0262316", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import rasterio, rioxarray\n", | ||
"\n", | ||
"def process(url):\n", | ||
" data = rioxarray.open_rasterio(\"s3://\" + url)\n", | ||
" \n", | ||
" # TODO: do real work with data\n", | ||
"\n", | ||
" return ...\n", | ||
"\n", | ||
"for url in urls:\n", | ||
" process(url)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "7d46d6ac-7b83-44a6-9b18-9e10f8b34e0a", | ||
"metadata": {}, | ||
"source": [ | ||
"## Process each file in parallel on the cloud" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "7cb4013d-f2f9-497b-a5f1-9fb14bc50627", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import coiled # New!\n", | ||
"import rasterio, rioxarray\n", | ||
"\n", | ||
"@coiled.function( # New!\n", | ||
" region=\"us-west-2\",\n", | ||
")\n", | ||
"def process(url):\n", | ||
" data = rioxarray.open_rasterio(\"s3://\" + url)\n", | ||
" \n", | ||
" # TODO: do real work with data\n", | ||
"\n", | ||
" return ...\n", | ||
"\n", | ||
"results = process.map(urls)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python [conda env:coiled-examples]", | ||
"language": "python", | ||
"name": "conda-env-coiled-examples-py" | ||
}, | ||
"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.10.15" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |