Skip to content

Commit

Permalink
Add image props and stats
Browse files Browse the repository at this point in the history
  • Loading branch information
giswqs committed Aug 6, 2020
1 parent 6f2d4e5 commit bd1d414
Show file tree
Hide file tree
Showing 6 changed files with 454 additions and 10 deletions.
14 changes: 14 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,20 @@ To add a local raster dataset to the map:
Map.add_raster(image, bands, colormap, layer_name)
To get image basic properties:

.. code:: python
geemap.image_props(image).getInfo()
To get image descriptive statistics:

.. code:: python
geemap.image_stats(image, region, scale)
Examples
--------

Expand Down
2 changes: 2 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ More video tutorials for geemap and Earth Engine are available on my [YouTube ch
26. How to create and deploy Earth Engine Apps using Python? ([video](https://youtu.be/nsIjfD83ggA) | [gif](https://i.imgur.com/Hpfzazk.gif) | [notebook](https://github.com/giswqs/geemap/blob/master/examples/notebooks/26_heroku.ipynb))
27. How to create an interactive Earth Engine App for creating Landsat timelapse? ([video](https://youtu.be/whIXudC6r_s) | [gif](https://i.imgur.com/doHfnKp.gif) | [notebook](https://github.com/giswqs/geemap/blob/master/examples/notebooks/27_timelapse_app.ipynb))
28. How to use your local computer as a web server for hosting Earth Engine Apps? ([video](https://youtu.be/eRDZBVJcNCk) | [gif](https://i.imgur.com/q0sJSyi.gif) | [notebook](https://github.com/giswqs/geemap/blob/master/examples/notebooks/28_voila.ipynb))
29. How to use pydeck for rendering Earth Engine data ([video](https://youtu.be/EIkEH4okFF4) | [gif](https://i.imgur.com/HjFB95l.gif) | [notebook](https://github.com/giswqs/geemap/blob/master/examples/notebooks/29_pydeck.ipynb))
30. How to get image basic properties and descriptive statistics (video | [gif](https://i.imgur.com/3B6YhkI.gif) | [notebook](https://github.com/giswqs/geemap/blob/master/examples/notebooks/30_image_props_stats.ipynb))

### 1. Introducing the geemap Python package for interactive mapping with Google Earth Engine

Expand Down
30 changes: 30 additions & 0 deletions examples/notebooks/00_geemap_key_features.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,7 @@
}
],
"metadata": {
"hide_input": false,
"kernelspec": {
"display_name": "Python 3",
"language": "python",
Expand Down Expand Up @@ -1010,6 +1011,35 @@
},
"toc_section_display": true,
"toc_window_display": true
},
"varInspector": {
"cols": {
"lenName": 16,
"lenType": 16,
"lenVar": 40
},
"kernels_config": {
"python": {
"delete_cmd_postfix": "",
"delete_cmd_prefix": "del ",
"library": "var_list.py",
"varRefreshCmd": "print(var_dic_list())"
},
"r": {
"delete_cmd_postfix": ") ",
"delete_cmd_prefix": "rm(",
"library": "var_list.r",
"varRefreshCmd": "cat(var_dic_list()) "
}
},
"types_to_exclude": [
"module",
"function",
"builtin_function_or_method",
"instance",
"_Feature"
],
"window_display": false
}
},
"nbformat": 4,
Expand Down
271 changes: 271 additions & 0 deletions examples/notebooks/30_image_props_stats.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,271 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# How to get image basic properties and descriptive statistics"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import ee\n",
"import geemap"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create an interactive map"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"Map = geemap.Map()\n",
"Map"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Add images to the map"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"centroid = ee.Geometry.Point([-122.4439, 37.7538])\n",
"\n",
"landsat = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR') \\\n",
" .filterBounds(centroid) \\\n",
" .first()\n",
"\n",
"landsat_vis = {\n",
" 'min': 0,\n",
" 'max': 3000,\n",
" 'bands': ['B5', 'B4', 'B3']\n",
"}\n",
"\n",
"Map.centerObject(centroid, 8)\n",
"Map.addLayer(landsat, landsat_vis, \"Landsat-8\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"naip = ee.ImageCollection('USDA/NAIP/DOQQ') \\\n",
" .filterBounds(centroid) \\\n",
" .first()\n",
"\n",
"naip_vis = {\n",
" 'bands': ['N', 'R', 'G']\n",
"}\n",
"\n",
"Map.addLayer(naip, naip_vis, 'NAIP')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Get image property names"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"landsat.propertyNames().getInfo()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"landsat.get('CLOUD_COVER').getInfo()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# The number of milliseconds since 1970-01-01T00:00:00Z.\n",
"landsat.get('system:time_start').getInfo()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ee.Date(landsat.get('system:time_start')).format('YYYY-MM-dd').getInfo()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Get image properties all at once"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"landsat_props = geemap.image_props(landsat)\n",
"landsat_props.getInfo()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"landsat_props.get('IMAGE_DATE').getInfo()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"naip_props = geemap.image_props(naip)\n",
"naip_props.getInfo()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"naip_props.get('NOMINAL_SCALE').getInfo()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Get image descriptive statistics\n",
"\n",
"Including minimum, maximum, mean, standard deviation, and sum."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"landsat_stats = geemap.image_stats(landsat, scale=90)\n",
"landsat_stats.getInfo()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"naip_stats = geemap.image_stats(naip, scale=10)\n",
"naip_stats.getInfo()"
]
}
],
"metadata": {
"hide_input": false,
"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.8.2"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": true,
"title_cell": "Table of Contents",
"title_sidebar": "Table of Contents",
"toc_cell": false,
"toc_position": {
"height": "calc(100% - 180px)",
"left": "10px",
"top": "150px",
"width": "384px"
},
"toc_section_display": true,
"toc_window_display": false
},
"varInspector": {
"cols": {
"lenName": 16,
"lenType": 16,
"lenVar": 40
},
"kernels_config": {
"python": {
"delete_cmd_postfix": "",
"delete_cmd_prefix": "del ",
"library": "var_list.py",
"varRefreshCmd": "print(var_dic_list())"
},
"r": {
"delete_cmd_postfix": ") ",
"delete_cmd_prefix": "rm(",
"library": "var_list.r",
"varRefreshCmd": "cat(var_dic_list()) "
}
},
"types_to_exclude": [
"module",
"function",
"builtin_function_or_method",
"instance",
"_Feature"
],
"window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Loading

0 comments on commit bd1d414

Please sign in to comment.