Last active
November 11, 2020 14:34
-
-
Save jdbcode/6136506f8c2d12787a4b604b17354074 to your computer and use it in GitHub Desktop.
Earth Engine visualization with pydeck / deck.gl
This file contains hidden or 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
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"from pydeck_earthengine_layers import EarthEngineTerrainLayer\n", | |
"import pydeck as pdk\n", | |
"import ee\n", | |
"ee.Initialize()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 44, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"aoi = ee.Geometry.Rectangle(-124.887, 47.027, -122.470, 48.478)\n", | |
"usa = (ee.FeatureCollection(\"USDOS/LSIB_SIMPLE/2017\")\n", | |
" .filter(ee.Filter.eq('country_na', 'United States')))\n", | |
"\n", | |
"def fmask(img):\n", | |
" cloudShadowBitMask = 1 << 3\n", | |
" cloudsBitMask = 1 << 5\n", | |
" qa = img.select('pixel_qa')\n", | |
" mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0) \\\n", | |
" .And(qa.bitwiseAnd(cloudsBitMask).eq(0))\n", | |
" return(img.updateMask(mask))\n", | |
"\n", | |
"imgComp = (ee.ImageCollection('LANDSAT/LT05/C01/T1_SR')\n", | |
" .filterBounds(aoi)\n", | |
" .filterDate('1985-06-15', '1985-09-15')\n", | |
" .map(fmask)\n", | |
" .median()\n", | |
" .select(['B5', 'B4', 'B2'])\n", | |
" .clipToCollection(usa))\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"print(imgComp.getInfo())" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"scrolled": true | |
}, | |
"outputs": [], | |
"source": [ | |
"from IPython.display import Image\n", | |
"\n", | |
"Image(url = imgComp.getThumbURL({'min': 0, 'max': 4500, 'gamma': 0.8, 'dimensions': 512, 'region': aoi}))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"scrolled": true | |
}, | |
"outputs": [], | |
"source": [ | |
"visParams={\n", | |
" 'min': 0, \n", | |
" 'max': 4500,\n", | |
" 'gamma': 0.8\n", | |
"}\n", | |
"\n", | |
"terrain = ee.Image('USGS/SRTMGL1_003')\n", | |
"\n", | |
"ee_layer = EarthEngineTerrainLayer(\n", | |
" imgComp,\n", | |
" terrain,\n", | |
" visParams,\n", | |
" id='EETerrainLayer'\n", | |
")\n", | |
"\n", | |
"view_state = pdk.ViewState(\n", | |
" latitude=47.674,\n", | |
" longitude=-123.605,\n", | |
" zoom=10.5, \n", | |
" bearing=-66.16,\n", | |
" pitch=60)\n", | |
"\n", | |
"r = pdk.Deck(\n", | |
" layers=[ee_layer], \n", | |
" initial_view_state=view_state\n", | |
")\n", | |
"r.show()" | |
] | |
} | |
], | |
"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.9.0" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment