diff --git a/docs/source/landsat/landsat_gee_2025.ipynb b/docs/source/landsat/landsat_gee_2025.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..87206afe6ecbd8d431cf053bd18604305426ae0a --- /dev/null +++ b/docs/source/landsat/landsat_gee_2025.ipynb @@ -0,0 +1,288 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "646198a0-e6d2-4145-bddc-69e97623fdfc", + "metadata": {}, + "source": [ + "# Load Landsat Collection\n", + "\n", + "Landsat, a joint program of the USGS and NASA, has been observing the Earth continuously from 1972 through the present day. Today the Landsat satellites image the entire Earth's surface at a 30-meter resolution about once every two weeks, including multispectral and thermal data.\n", + "\n", + "Landsat data is available in Earth Engine in its raw form, as Surface Reflectance, TOA-corrected reflectance, and in various ready-to-use computed products such as NDVI and EVI vegetation indices.\n", + "\n", + "> **📠Note:** \n", + ">In this course we will only work with *Landsat Collection 2* that marks the second major reprocessing effort on the Landsat archive by the USGS that results in several data product improvements over Collection 1 that harness recent advancements in data processing and algorithm development.\n", + "\n", + "\n", + "|Satellite | Landsat 5 | Landsat 7 | Landsat 8 | Landsat 9 |\n", + "|----------|:----------: |:----------:|:---------: | :--------:|\n", + "|**Instrument** | <font size=\"2\"> Multispectral Scanner (MSS), <br/>Thematic Mapper (TM) </font>| <font size=\"2\"> Enhanced Thematic Mapper <br/> (ETM+) </font>| <font size=\"2\"> Operational Land Imager (OLI),<br/> Thermal Infrared <br/>Sensor (TIRS)</font>| <font size=\"2\"> OLI-2, TIRS-2 </font>|\n", + "|**Number of bands**| 10 | 10 | 10 | 10 |\n", + "|**Spatial resolution**| 30m x 30m | 30m x 30m| 30m x 30m | 30m x 30m\n", + "|**Temporal resolution**| 16 days | 16 days | 16 days | 16 days \n", + "|**Temporal range**| 1984 - 2012 |1999 - Present| 2013 - Present | 2021 - Present\n", + "|**Google Earth Engine collection** | [Dataset](https://developers.google.com/earth-engine/datasets/catalog/LANDSAT_LT05_C02_T1_L2) | [Dataset](https://developers.google.com/earth-engine/datasets/catalog/LANDSAT_LE07_C02_T1_L2) | [Dataset](https://developers.google.com/earth-engine/datasets/catalog/LANDSAT_LC08_C02_T1_L2)| [Dataset](https://developers.google.com/earth-engine/datasets/catalog/LANDSAT_LC09_C02_T1_L2?hl=en) |\n", + "\n", + "\n", + "Let's define which datasets we will work with.\n", + "\n", + "```js\n", + "// Load USGS Landsat 5 Level 2, Collection 2, Tier 1\n", + "var landsat_5 = ee.ImageCollection(\"LANDSAT/LT05/C02/T1_L2\")\n", + "\n", + "// Load USGS Landsat 7 Level 2, Collection 2, Tier 1\n", + "var landsat_7 = ee.ImageCollection(\"LANDSAT/LE07/C02/T1_L2\")\n", + "\n", + "// Load USGS Landsat 8 Level 2, Collection 2, Tier 1\n", + "var landsat_8 = ee.ImageCollection('LANDSAT/LC08/C02/T1_L2')\n", + "\n", + "// Load USGS Landsat 9 Level 2, Collection 2, Tier 1\n", + "var landsat_9 = ee.ImageCollection('LANDSAT/LC09/C02/T1_L2')\n", + "\n", + "```\n", + "\n", + "## Filter Landsat data\n", + "\n", + "\n", + "```js\n", + "// Define time period\n", + "var startDate = '2024-01-01'\n", + "var endDate = '2024-12-31'\n", + "```\n", + "\n", + "```js\n", + "var fao_level1 = ee.FeatureCollection(\"FAO/GAUL/2015/level1\")\n", + "var roi = fao_level1.filter(\"ADM1_CODE == 602\")\n", + "```\n", + "\n", + "```js\n", + "// Select Landsat 8 images in area of interest and time period\n", + "var l8_filter = landsat_8\n", + " .filterDate(startDate, endDate)\n", + " .filterBounds(roi)\n", + "\n", + "var l9_filter = landsat_9\n", + " .filterDate(startDate, endDate)\n", + " .filterBounds(roi) \n", + "```\n", + "\n", + "## Apply scaling factors\n", + "\n", + "A scale factor must be applied to both Collection 1 and Collection 2 Landsat Level-2 surface reflectance and surface temperature products before using the data. \n", + "**Landsat Collection 2** have the following scale factors, fill values, data type, and valid range.\n", + "\n", + "\n", + "<figure class=\"responsive-figure-table\"><table>\n", + "<thead>\n", + "<tr>\n", + "<th>Science Product</th>\n", + "<th>Scale Factor</th>\n", + "<th>Fill Value</th>\n", + "<th>Data Type</th>\n", + "<th>Valid Range</th>\n", + "</tr>\n", + "</thead>\n", + "<tbody>\n", + "<tr>\n", + "<td><a href=\"https://www.usgs.gov/core-science-systems/nli/landsat/landsat-collection-2-surface-reflectance\">Surface Reflectance</a></td>\n", + "<td>0.0000275 + -0.2</td>\n", + "<td>0</td>\n", + "<td>Unsigned 16-bit integer</td>\n", + "<td>1-65455</td>\n", + "</tr>\n", + "<tr>\n", + "<td><a href=\"https://www.usgs.gov/core-science-systems/nli/landsat/landsat-collection-2-surface-temperature\">Surface Temperature</a></td>\n", + "<td>0.00341802 + 149.0</td>\n", + "<td>0</td>\n", + "<td>Unsigned 16-bit integer</td>\n", + "<td>1-65455</td>\n", + "</tr>\n", + "</tbody>\n", + "</table></figure>\n", + "\n", + "> **📠Note:** \n", + "> **Examples for scaling Landsat Collection 2 Level-2 science products** \n", + "> <font size=\"2\">Landsat Collection 2 surface reflectance has a scale factor of 0.0000275 and an additional offset of -0.2 per pixel. <br/> For example, a pixel value of 18,639 is multiplied by 0.0000275 for the scale factor and then -0.2 is added for the additional offset to get a reflectance value of 0.313 after the scale factor is applied. </font>\n", + "\n", + "\n", + "\n", + "```js\n", + "// Applies scaling factors.\n", + "function applyScaleFactors(image) {\n", + " var opticalBands = image.select('SR_B.').multiply(0.0000275).add(-0.2)\n", + " var thermalBands = image.select('ST_B.*').multiply(0.00341802).add(149.0)\n", + " return image.addBands(opticalBands, null, true)\n", + " .addBands(thermalBands, null, true)\n", + "}\n", + "\n", + "var l8_filter = l8_filter.map(applyScaleFactors)\n", + "var l9_filter = l9_filter.map(applyScaleFactors)\n", + "```\n" + ] + }, + { + "cell_type": "markdown", + "id": "a46e022f-ca87-42e0-a88c-b5ba0fd5c686", + "metadata": {}, + "source": [ + "# Cloud Mask\n", + "\n", + "Most optical satellite imagery products come with one or more QA-bands that allows the user to assess quality of each pixel and extract pixels that meet their requirements. The most common application for QA-bands is to extract information about cloudy pixels and mask them. But the QA bands contain a wealth of other information that can help you remove low quality data from your analysis. Typically the information contained in QA bands is stored as Bitwise Flags. [More info about bitmasks](https://spatialthoughts.com/2021/08/19/qa-bands-bitmasks-gee/)\n", + "\n", + "In Landsat imagery, pixel quality assessment (QA_PIXEL) bands are generated by the CFMask algorithm. Different bit definitions are used because the cirrus band is only available on Landsat 8 and 9. This band is relevant to both Surface Reflectance and Surface Temperature products.\n", + "\n", + "\n", + "|Bit | Landat 5 & 7 |Landsat 8 & 9 | \n", + "|---------|:----------: |:----------:|\n", + "|0 | Fill | Fill |\n", + "|1 | Dilated Cloud|Dilated Cloud|\n", + "|2|Unused|Cirrus|\n", + "|3|Cloud|Cloud|\n", + "|4|Cloud Shadow|Cloud Shadow|\n", + "|5|Snow|Snow|\n", + "|6|Clear|Clear|\n", + "|7|Water|Water|\n", + "|8-9|Cloud Confidence|Cloud Confidence|\n", + "|10-11|Cloud Shadow Confidence|Cloud Shadow Confidence|\n", + "|12-13|Snow/Ice Confidence|Snow/Ice Confidence|\n", + "|14-15|Unused|Cirrus Confidence| \n", + "\n", + "The two following functions will be used to mask clouds, cloud shadows, ... on every images of an `ImageCollection`.\n", + "\n", + "```js\n", + "/**\n", + " * Utility to extract bitmask values. \n", + " * Look up the bit-ranges in the catalog.\n", + " * \n", + " * value - ee.Number or ee.Image to extract from.\n", + " * fromBit - int or ee.Number with the first bit.\n", + " * toBit - int or ee.Number with the last bit (inclusive). \n", + " * Defaults to fromBit.\n", + " */\n", + "function bitwiseExtract(value, fromBit, toBit) {\n", + " if (toBit === undefined) toBit = fromBit\n", + " var maskSize = ee.Number(1).add(toBit).subtract(fromBit)\n", + " var mask = ee.Number(1).leftShift(maskSize).subtract(1)\n", + " return value.rightShift(fromBit).bitwiseAnd(mask)\n", + "}\n", + "```\n", + "\n", + "\n", + "```js\n", + "var maskClouds = function(image) {\n", + " var QA = image.select('QA_PIXEL');\n", + " var clouds = bitwiseExtract(QA, 3).eq(0)\n", + " var cloud_shadows = bitwiseExtract(QA, 4).eq(0)\n", + " var mask = clouds\n", + " .and(cloud_shadows)\n", + " var maskedImage = image.updateMask(mask)\n", + " return maskedImage\n", + "}" + ] + }, + { + "cell_type": "markdown", + "id": "7b4b6830-5c8f-40aa-bbe3-6df939b0e508", + "metadata": {}, + "source": [ + "# Composite" + ] + }, + { + "cell_type": "markdown", + "id": "1277af19-5c90-4097-bc5d-9f26a373d767", + "metadata": {}, + "source": [ + "\n", + "```js\n", + "var l8_composite = l8_filter\n", + " .filterDate(startPeriod, endPeriod)\n", + " .map(maskClouds)\n", + " .median()\n", + " .clip(roi)\n", + "var l9_composite = l9_filter\n", + " .filterDate(startPeriod, endPeriod)\n", + " .map(maskClouds)\n", + " .median()\n", + " .clip(roi)" + ] + }, + { + "cell_type": "markdown", + "id": "54832050-d981-46b3-be07-b0e8ac8e6695", + "metadata": {}, + "source": [ + "# Visualization" + ] + }, + { + "cell_type": "markdown", + "id": "9af7754e-1a0d-4146-9946-f17ba1d382ef", + "metadata": {}, + "source": [ + "```js\n", + "var visParams = {\n", + " bands: ['SR_B4', 'SR_B3', 'SR_B2'],\n", + " min: 0.0,\n", + " max: 0.3,\n", + "}\n", + " \n", + " \n", + "Map.centerObject(roi, 8)\n", + "Map.addLayer(l8_composite, visParams, 'True Color (432) - Mask - Median - Landsat 8')\n", + "Map.addLayer(l9_composite, visParams, 'True Color (432) - Mask - Median - Landsat 9')" + ] + }, + { + "cell_type": "markdown", + "id": "a2daac93-fe02-4fb1-8781-3397bf403d52", + "metadata": {}, + "source": [ + "```js\n", + "// Get projection of the original image\n", + "var projection = l8_filter.first().projection().getInfo()\n", + "\n", + "// Export the image, specifying the CRS, transform, and region.\n", + "Export.image.toDrive({\n", + " image: l8_composite,\n", + " description: 'L8_2019_median_composite',\n", + " folder: 'LBRAT2104',\n", + " crs: projection.crs, // The base coordinate reference system of this projection (e.g. 'EPSG:4326')\n", + " crsTransform: projection.transform, // The transform between projected coordinates and the base coordinate system\n", + " region: roi\n", + "});\n", + "```\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "35281a8f-932f-48af-8b0c-db62a4639b0c", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "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.10.14" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/docs/source/sentinel_2_gee/s2_gee_2025.ipynb b/docs/source/sentinel_2_gee/s2_gee_2025.ipynb index 943322e80a8b7571faf36f6c87dd2ca0995e8826..93ee84fc4f2fb34f3c8284c90f8987ad95d13180 100644 --- a/docs/source/sentinel_2_gee/s2_gee_2025.ipynb +++ b/docs/source/sentinel_2_gee/s2_gee_2025.ipynb @@ -17,9 +17,9 @@ "var s2_sr = ee.ImageCollection(\"COPERNICUS/S2_SR_HARMONIZED\")\n", "```\n", "\n", - "```{note}\n", - "The Sentinel Level-1C and Level-2A data products have a harmonized time series. The \"harmonized\" designation means that the band-dependent offset added to reflectance bands in the 04.00 processing baseline has been removed. The offset affects data after January 24th 2022; removing the offset puts these data in spectral alignment with pre-04.00 baseline data. If you are using COPERNICUS/S2 or COPERNICUS/S2_SR, it is recommended that you switch to COPERNICUS/S2_HARMONIZED and COPERNICUS/S2_SR_HARMONIZED.\n", - "```\n", + "> **📠Note:** \n", + ">The Sentinel Level-1C and Level-2A data products have a harmonized time series. The \"harmonized\" designation means that the band-dependent offset added to reflectance bands in the 04.00 processing baseline has been removed. The offset affects data after January 24th 2022; removing the offset puts these data in spectral alignment with pre-04.00 baseline data. If you are using COPERNICUS/S2 or COPERNICUS/S2_SR, it is recommended that you switch to COPERNICUS/S2_HARMONIZED and COPERNICUS/S2_SR_HARMONIZED.\n", + "\n", "\n", "## Filter Sentinel-2 data\n", "\n",