Skip to content

Instantly share code, notes, and snippets.

@giswqs
Created October 26, 2020 14:26
Show Gist options
  • Save giswqs/4353a2d61fc05e5a9b0762d9a5d8a8f8 to your computer and use it in GitHub Desktop.
Save giswqs/4353a2d61fc05e5a9b0762d9a5d8a8f8 to your computer and use it in GitHub Desktop.
zonal stats
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "import os\nimport ee\nimport geemap",
"execution_count": 1,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "Map = geemap.Map()\nMap",
"execution_count": 2,
"outputs": [
{
"output_type": "display_data",
"data": {
"text/plain": "Map(center=[40, -100], controls=(WidgetControl(options=['position'], widget=HBox(children=(ToggleButton(value=…",
"application/vnd.jupyter.widget-view+json": {
"version_major": 2,
"version_minor": 0,
"model_id": "d5fdcc77c2c84aedacb588a2159c8ba3"
}
},
"metadata": {}
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "start_date = '2013-01-01'\nend_date = '2013-12-31'\n\n# Add Earth Engine dataset\ndataset = ee.ImageCollection('NASA/GIMMS/3GV0') \\\n .filterDate(start_date, end_date) \n\nndvi = dataset.select('ndvi')\n\n# turn collection to bands\nndvi_bands = ndvi.toBands()\n\n# get Nonimal Scale\nprint(ndvi_bands.projection().nominalScale().getInfo())\n\nbuffers = Map.user_rois # replace buffers with your FeatureCollection. Alternatively, you can draw shapes on the map.\n\n# From Dr. Wu's tutorial:\nout_dir = os.path.join(os.path.expanduser('~'), 'Downloads')\nout_ndvi_stats = os.path.join(out_dir, 'ndvi_05to11_mean.csv') \ngeemap.zonal_statistics(ndvi_bands, buffers, out_ndvi_stats, statistics_type = 'MEAN', scale = 9276)",
"execution_count": 3,
"outputs": [
{
"output_type": "stream",
"text": "9276.624232772796\nComputing statistics ...\nGenerating URL ...\nDownloading data from https://earthengine.googleapis.com/v1alpha/projects/earthengine-legacy/tables/ca8c2d396ec8a5ebcc65b396f1b090b8-0a736b69a9e402064744c376f30c5b5b:getFeatures\nPlease wait ...\nData downloaded to /home/qiusheng/Downloads/ndvi_05to11_mean.csv\n",
"name": "stdout"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "",
"execution_count": null,
"outputs": []
}
],
"metadata": {
"kernelspec": {
"name": "python3",
"display_name": "Python 3",
"language": "python"
},
"varInspector": {
"window_display": false,
"cols": {
"lenName": 16,
"lenType": 16,
"lenVar": 40
},
"kernels_config": {
"python": {
"library": "var_list.py",
"delete_cmd_prefix": "del ",
"delete_cmd_postfix": "",
"varRefreshCmd": "print(var_dic_list())"
},
"r": {
"library": "var_list.r",
"delete_cmd_prefix": "rm(",
"delete_cmd_postfix": ") ",
"varRefreshCmd": "cat(var_dic_list()) "
}
},
"types_to_exclude": [
"module",
"function",
"builtin_function_or_method",
"instance",
"_Feature"
]
},
"hide_input": false,
"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": {},
"toc_section_display": true,
"toc_window_display": true
},
"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"
},
"gist": {
"id": "",
"data": {
"description": "zonal stats",
"public": true
}
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment