-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
retrained models, support for l2a, refactoring
- Loading branch information
Showing
14 changed files
with
367 additions
and
110 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
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 |
---|---|---|
@@ -1,5 +1,11 @@ | ||
include requirements.txt | ||
include README.md | ||
include LICENSE | ||
include ukis_csmask/model_4b.onnx | ||
include ukis_csmask/model_6b.onnx | ||
include ukis_csmask/model_4b_l1c.onnx | ||
include ukis_csmask/model_4b_l1c.json | ||
include ukis_csmask/model_4b_l2a.onnx | ||
include ukis_csmask/model_4b_l2a.json | ||
include ukis_csmask/model_6b_l1c.onnx | ||
include ukis_csmask/model_6b_l1c.json | ||
include ukis_csmask/model_6b_l2a.onnx | ||
include ukis_csmask/model_6b_l2a.json |
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
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,137 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Segment clouds and cloud shadows in Landsat images (L2A)\n", | ||
"This notebook shows an example on how to use [ukis-csmask]() to segment clouds and cloud shadows in Level-2A images from Landsat-9, Landsat-8, Landsat-7 and Landsat-5 satellites. Images are acquired from [Planetary Computer]() and are prepared according to [ukis-csmask]() requirements.\n", | ||
"\n", | ||
"> NOTE: to run this notebook, we first need to install some additional dependencies for work with Planetary Computer\n", | ||
"```shell\n", | ||
"pip install planetary_computer rasterio rioxarray pystac-client odc-stac tqdm\n", | ||
"```" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "703f3744-902d-470b-a80f-9a8d3ea08dfa", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import numpy as np\n", | ||
"import planetary_computer as pc\n", | ||
"\n", | ||
"from odc.stac import load\n", | ||
"from pystac_client import Client\n", | ||
"from tqdm import tqdm\n", | ||
"from ukis_csmask.mask import CSmask" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "8ca03c78-1e24-479c-9786-a1b43206a08b", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"stac_api_endpoint = \"https://planetarycomputer.microsoft.com/api/stac/v1\"\n", | ||
"collections = [\"landsat-c2-l2\"]\n", | ||
"# TODO: add ids for Landsat9, Landsat7, Landsat5\n", | ||
"ids = [\"LC08_L2SP_221081_20240508_02_T1\"]\n", | ||
"product_level = \"l2a\"\n", | ||
"band_order = [\"blue\", \"green\", \"red\", \"nir\", \"swir16\", \"swir22\"]" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "7b568942-84e6-4baf-b490-a213b3787f80", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# search catalog by scene id\n", | ||
"catalog = Client.open(stac_api_endpoint)\n", | ||
"search = catalog.search(collections=collections, ids=ids)\n", | ||
"items = [item for item in search.items()]\n", | ||
"items_cnt = len(items)\n", | ||
"print(f\"Search returned {items_cnt} item(s)\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "68eb9c30-06f7-409e-914d-21e00f45de99", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"for item in tqdm(items, total=items_cnt, desc=\"Predict images\"):\n", | ||
" # near infrared band has different alias in landsat collections\n", | ||
" bands = [b.replace(\"nir\", \"nir08\") for b in band_order]\n", | ||
"\n", | ||
" # load and preprocess image\n", | ||
" arr = (\n", | ||
" load(\n", | ||
" items=[item],\n", | ||
" bands=bands,\n", | ||
" resolution=30,\n", | ||
" dtype=\"float32\",\n", | ||
" patch_url=pc.sign,\n", | ||
" )\n", | ||
" .to_dataarray()\n", | ||
" .squeeze()\n", | ||
" .drop_vars(\"time\")\n", | ||
" )\n", | ||
" arr = arr.rename({\"variable\": \"band\"})\n", | ||
"\n", | ||
" # use band-specific rescale factors to convert DN to reflectance\n", | ||
" for idx, band_name in enumerate(bands):\n", | ||
" band_info = item.assets[band_name].extra_fields[\"raster:bands\"][0]\n", | ||
" arr[idx, :, :] = arr.sel(band=str(band_name)).astype(np.float32) * band_info[\"scale\"]\n", | ||
" arr[idx, :, :] += band_info[\"offset\"]\n", | ||
" arr[idx, :, :] = arr[idx, :, :].clip(min=0.0, max=1.0)\n", | ||
"\n", | ||
" # compute cloud and cloud shadow mask\n", | ||
" csmask = CSmask(\n", | ||
" img=np.moveaxis(arr, 0, -1),\n", | ||
" band_order=band_order,\n", | ||
" product_level=product_level,\n", | ||
" nodata_value=0,\n", | ||
" invalid_buffer=4,\n", | ||
" intra_op_num_threads=0,\n", | ||
" inter_op_num_threads=0,\n", | ||
" providers=None,\n", | ||
" batch_size=1,\n", | ||
" )\n", | ||
"\n", | ||
" # access cloud and cloud shadow mask\n", | ||
" csmask_csm = csmask.csm\n", | ||
"\n", | ||
" # access valid mask\n", | ||
" csmask_valid = csmask.valid" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"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.11.10" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
Submodule ukis-csmask
added at
bdf735
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
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "0.2.2" | ||
__version__ = "1.0.0" |
Oops, something went wrong.