Last active
July 1, 2020 18:16
-
-
Save giswqs/60cba5e22c0b850ee039f4faec795334 to your computer and use it in GitHub Desktop.
xarray-leaflet-geotiff
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": [ | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "import requests\nimport os\nfrom tqdm import tqdm\nimport numpy as np\nimport zipfile\nimport rioxarray\nimport xarray as xr\nimport xarray_leaflet\nfrom ipyleaflet import Map, basemaps\nfrom matplotlib import pyplot as plt", | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"metadata": {}, | |
"cell_type": "markdown", | |
"source": "The example SRTM (10 MB) can be downloaded at the link below. Place the downloaded DEM under the same directory of this notebook.\n\nhttps://drive.google.com/file/d/1Cpcpe5XW5Kjfw43vE3aOe5sGSzKYaQRl/view?usp=sharing" | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "# tif_file = os.path.join(os.getcwd(), 'srtm90.tif')\ntif_file = '/media/hdd/Google-Drive/export/landsat.tif'", | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "da = xr.open_rasterio(tif_file)\nda", | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "crs = da.rio.crs\nnan = da.attrs['nodatavals'][0]\nda = da.sel(band=[5, 4, 3])\nda = xr.where(da==nan, np.nan, da)\nda = da.rio.write_crs(crs)", | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "da", | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true, | |
"scrolled": false | |
}, | |
"cell_type": "code", | |
"source": "# import geemap\n# Map = geemap.Map()\n# Map", | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"scrolled": false, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "m = Map(center=[40, -100], zoom=4, scroll_wheel_zoom = True)\nm", | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "l = da.leaflet.plot(m, x_dim='x', y_dim='y', rgb_dim='band')\nl.interact(opacity=(0.0,1.0,0.1))", | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "# l = da.leaflet.plot(Map, x_dim='x', y_dim='y', colormap=plt.cm.gray)\n# l.interact(opacity=(0.0,1.0,0.1))", | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "# import ee", | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "# image = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20140318').select(['B5', 'B4', 'B3'])", | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "# geemap.ee_export_image_to_drive(image, 'landsat', scale=90)", | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "", | |
"execution_count": null, | |
"outputs": [] | |
} | |
], | |
"metadata": { | |
"_draft": { | |
"nbviewer_url": "https://gist.github.com/60cba5e22c0b850ee039f4faec795334" | |
}, | |
"gist": { | |
"id": "60cba5e22c0b850ee039f4faec795334", | |
"data": { | |
"description": "xarray-leaflet-geotiff", | |
"public": true | |
} | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3", | |
"language": "python" | |
}, | |
"language_info": { | |
"name": "python", | |
"version": "3.8.2", | |
"mimetype": "text/x-python", | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"pygments_lexer": "ipython3", | |
"nbconvert_exporter": "python", | |
"file_extension": ".py" | |
}, | |
"toc": { | |
"nav_menu": {}, | |
"number_sections": true, | |
"sideBar": true, | |
"skip_h1_title": true, | |
"base_numbering": 1, | |
"title_cell": "Table of Contents", | |
"title_sidebar": "Table of Contents", | |
"toc_cell": false, | |
"toc_position": { | |
"height": "calc(100% - 180px)", | |
"left": "10px", | |
"top": "150px", | |
"width": "270px" | |
}, | |
"toc_section_display": true, | |
"toc_window_display": true | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment