Skip to content

Instantly share code, notes, and snippets.

@giswqs
Created September 19, 2024 23:53
Show Gist options
  • Save giswqs/eb262b8efb79fd2f91af2c4321f53bcd to your computer and use it in GitHub Desktop.
Save giswqs/eb262b8efb79fd2f91af2c4321f53bcd to your computer and use it in GitHub Desktop.
Download Landsat imagery from Earth Engine
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import ee\n",
"import geemap"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"geemap.ee_initialize()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"m = geemap.Map()\n",
"m"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"dataset = ee.ImageCollection('LANDSAT/LC09/C02/T1_L2') \\\n",
" .filterDate('2024-01-01', '2024-09-01') \\\n",
" .filterBounds(ee.Geometry.Point(-115.0033, 36.0990)) \\\n",
" .sort('CLOUD_COVER') \\\n",
" .select(\"SR_B[1-7]\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"first_image = dataset.first()\n",
"\n",
"# Applies scaling factors.\n",
"def apply_scale_factors(image):\n",
" optical_bands = image.select('SR_B.').multiply(0.0000275).add(-0.2)\n",
" return image.addBands(optical_bands, None, True)\n",
"\n",
"first_image = apply_scale_factors(first_image)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"m.addLayer(first_image, {'bands': ['SR_B4', 'SR_B3', 'SR_B2'], 'min': 0, 'max': 0.3}, 'First image')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"first_image"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"geemap.download_ee_image(first_image, \"LC09_039035_20240708_90m.tif\", dtype=\"float32\", scale=90)"
]
}
],
"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.11.9"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment