diff --git a/6. COG.ipynb b/6. COG.ipynb new file mode 100644 index 0000000..8664f16 --- /dev/null +++ b/6. COG.ipynb @@ -0,0 +1,256 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "A Cloud Optimized GeoTIFF (COG) is a specific type of GeoTIFF file that is optimized for use over the internet. It allows for efficient, partial reading of a large raster image file over the network, without needing to download the entire file first." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "pip install leafmap" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Conda install is recommended (pip install had missing dependencies)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "conda install -n geo -c conda-forge localtileserver" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import leafmap\n", + "import os" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Resolves CRS invalid error by downloading the latest version of leafmap" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# leafmap.update_package()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Create an interactive map" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "Map = leafmap.Map()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Input file's url should point to a cloud url that is not password protected" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# url = \"https://fcx-downloader.s3.amazonaws.com/HLS.L30.T59VLL.2024150T235328.v2.0.B10.tiff\"\n", + "# url = \"https://fcx-downloader.s3.amazonaws.com/TIF/HLS.L30.T59VLL.2024149T235855.v2.0.B10.tiff\"\n", + "# url = \"https://fcx-downloader.s3.amazonaws.com/TIF/HLS_TIF/HLS.L30.T59VLL.2024156T001136.v2.0.B02.tiff\"\n", + "url = \"https://fcx-downloader.s3.amazonaws.com/h1qr42lq/HLS.L30.T16XER.2024156T000315.v2.0.B02.tif\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Validate COG file" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "leafmap.cog_validate(url, verbose = True)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Titiler is a modern dynamic tile server built on top of FastAPI and Rasterio/GDAL. Leafmap uses Titiler to decode the structure of COG file as a JSON." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "os.environ[\"TITILER_ENDPOINT\"] = \"https://titiler.xyz\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Retrieve the bounding box coordinates, band names, centroid coordinates, and tile layer URL of the COG file." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "leafmap.cog_bounds(url)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "leafmap.cog_bands(url)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "leafmap.cog_center(url)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "leafmap.cog_tile(url)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Add a COG layer to the map. The layer can be given a name or bands as parameters." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "Map.add_cog_layer(url)\n", + "Map" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "To create timelapse of multiple COG files, images should be a local path consisting of file names ending with \".tif\"\n", + "This expects TIF images in a specific format. For e.g, HLS(Harmonized Landsat and Sentinel-2) L30 TIF images could not be visualized but [Landsat7](https://search.earthdata.nasa.gov/search/granules?p=C1979944011-GHRC_DAAC&pg[0][v]=f&pg[0][qt]=2002-10-02T00%3A00%3A00.000Z%2C2002-10-02T23%3A59%3A59.999Z&pg[0][id]=L71021039*TIF&pg[0][gsk]=-start_date&g=G1979944367-GHRC_DAAC&q=landsat&fdc=Global%2BHydrology%2BResource%2BCenter%2B%2528GHRC%2529&tl=1717122715!3!!&lat=-33.75&long=-75.375&zoom=0) images works fine as seen below." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "images = \"/Users/Indhuja/Downloads/L7/\"\n", + "\n", + "import os\n", + "os.listdir(images)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "leafmap.create_timelapse(\n", + " images,\n", + " out_gif=\"l7.gif\",\n", + " # bands = [1,2],\n", + " fps=1,\n", + " mp4=False,\n", + " quiet=False,\n", + " reduce_size=True,\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "leafmap.show_image(\"l7.gif\")" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/7. STAC.ipynb b/7. STAC.ipynb new file mode 100644 index 0000000..dc529e0 --- /dev/null +++ b/7. STAC.ipynb @@ -0,0 +1,157 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The SpatioTemporal Asset Catalog (STAC) specification provides a common language to describe a range of geospatial information, so it can more easily be indexed and discovered. A 'spatiotemporal asset' is any file that represents information about the earth captured in a certain space and time." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "!pip install leafmap\n", + "# leafmap.update_package()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import leafmap\n", + "import os" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "os.environ[\"TITILER_ENDPOINT\"] = \"https://titiler.xyz\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "To create STAC file, follow the format similar to [this example](https://canada-spot-ortho.s3.amazonaws.com/canada_spot_orthoimages/canada_spot5_orthoimages/S5_2007/S5_11055_6057_20070622/S5_11055_6057_20070622.json) and also [stac-spec](https://stacspec.org/en/about/stac-spec/).\n", + "\n", + "A list of STAC APIs and catalogs are available [here](https://stacindex.org/catalogs/)." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "url = \"https://fcx-downloader.s3.amazonaws.com/TIF/stacHLS1.json\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Retrieve the bounding box coordinates, band names, centroid coordinates, and tile layer URL of the STAC file." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "leafmap.stac_bounds(url)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "leafmap.stac_center(url)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "leafmap.stac_bands(url)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "leafmap.stac_tile(url, bands=[\"B01\"])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "Map = leafmap.Map()\n", + "Map.add_stac_layer(url, bands=[\"B01\"])\n", + "Map" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "A STAC file can be opened after loading an interactive map and giving the STAC endpoint as url. Below is an example of the same." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "!pip install markdown\n", + "![](Open_STAC.mp4)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/Open_STAC.mp4 b/Open_STAC.mp4 new file mode 100644 index 0000000..bd53152 Binary files /dev/null and b/Open_STAC.mp4 differ diff --git a/l7.gif b/l7.gif new file mode 100644 index 0000000..c73f847 Binary files /dev/null and b/l7.gif differ