Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EE charting functions #1855

Merged
merged 40 commits into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
ae45627
Add image chart functions
giswqs Dec 19, 2023
325e8e5
Add LineChart class
giswqs Dec 22, 2023
483644a
Merge branch 'master' into chart
giswqs Dec 22, 2023
c7280d6
Merge branch 'master' into chart
giswqs Dec 25, 2023
e62576f
Merge branch 'master' into chart
giswqs Jan 3, 2024
03dfa55
Merge branch 'master' into chart
giswqs Feb 15, 2024
ca8377f
Merge branch 'master' into chart
giswqs May 25, 2024
a40c217
Add DataTable class
giswqs May 25, 2024
57fa6d8
Add BaseChart class
giswqs May 25, 2024
ce2f0bf
Add image_byClass function
giswqs May 26, 2024
2abc944
Add chart.image_histogram function
giswqs May 26, 2024
b51f17c
Add the Chart class
giswqs May 27, 2024
5f4f6b9
Add image_series function
giswqs May 27, 2024
2ff67b6
Add image_seriesByRegion function
giswqs May 27, 2024
c3e268d
Merge branch 'master' into chart
giswqs May 27, 2024
3220ee2
Merge branch 'master' into chart
giswqs Jun 3, 2024
ad42e8c
Add transpose_df function
giswqs Jun 13, 2024
850d9b2
Merge branch 'master' into chart
giswqs Jun 21, 2024
f6184bd
Merge branch 'master' into chart
giswqs Aug 5, 2024
307995d
Merge branch 'master' into chart
giswqs Aug 8, 2024
1d0d27d
Change function name to snake case
giswqs Aug 8, 2024
8537471
Add doy_series_by_year function
giswqs Aug 8, 2024
ade6b25
Add image_doy_series function
giswqs Aug 8, 2024
8617bfd
Add image_doy_series_by_region function
giswqs Aug 8, 2024
5e193be
Add image_by_class function
giswqs Aug 8, 2024
218dc5d
Add typehints and docstrings
giswqs Aug 8, 2024
df81be4
Add notebook template
giswqs Aug 9, 2024
bc5fc82
Merge branch 'master' into chart
giswqs Aug 9, 2024
0bdb0bd
Merge branch 'master' into chart
giswqs Aug 9, 2024
4bcca8c
Add chart_features.ipynb
giswqs Aug 10, 2024
74f6c44
Add chart_image.ipynb
giswqs Aug 10, 2024
39fb436
Add chart_image_collection.ipynb
giswqs Aug 10, 2024
0a77c67
Add chart.array_values function
giswqs Aug 10, 2024
77640ec
Add AreaChart type
giswqs Aug 10, 2024
dc55ef1
Add more chart array examples
giswqs Aug 10, 2024
e96e8c8
Add IntervalChart
giswqs Aug 10, 2024
cd080b5
Save save_png method
giswqs Aug 10, 2024
ad2e2ff
Add images to notebook
giswqs Aug 11, 2024
a888d9d
Merge branch 'master' into chart
giswqs Aug 14, 2024
27c5198
Update mkdocs.yml
giswqs Aug 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
352 changes: 352 additions & 0 deletions docs/notebooks/144_chart_features.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,352 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<a href=\"https://githubtocolab.com/gee-community/geemap/blob/master/examples/notebooks/144_chart_features.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open in Colab\"/></a>\n",
"\n",
"**Feature and FeatureCollection Charts**\n",
"\n",
"Uncomment the following line to install [geemap](https://geemap.org) if needed."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# %pip install -U geemap"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Import libraries"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import calendar\n",
"import ee\n",
"import geemap\n",
"from geemap import chart"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"geemap.ee_initialize()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## feature_by_feature\n",
"\n",
"Features are plotted along the x-axis, labeled by values of a selected property. Series are represented by adjacent columns defined by a list of property names whose values are plotted along the y-axis."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ecoregions = ee.FeatureCollection(\"projects/google/charts_feature_example\")\n",
"features = ecoregions.select(\"[0-9][0-9]_tmean|label\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"geemap.ee_to_df(features)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"x_property = \"label\"\n",
"y_properties = [str(x).zfill(2) + \"_tmean\" for x in range(1, 13)]\n",
"\n",
"labels = calendar.month_abbr[1:] # a list of month labels, e.g. ['Jan', 'Feb', ...]\n",
"\n",
"colors = [\n",
" \"#604791\",\n",
" \"#1d6b99\",\n",
" \"#39a8a7\",\n",
" \"#0f8755\",\n",
" \"#76b349\",\n",
" \"#f0af07\",\n",
" \"#e37d05\",\n",
" \"#cf513e\",\n",
" \"#96356f\",\n",
" \"#724173\",\n",
" \"#9c4f97\",\n",
" \"#696969\",\n",
"]\n",
"title = \"Average Monthly Temperature by Ecoregion\"\n",
"x_label = \"Ecoregion\"\n",
"y_label = \"Temperature\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig = chart.feature_by_feature(\n",
" features,\n",
" x_property,\n",
" y_properties,\n",
" colors=colors,\n",
" labels=labels,\n",
" title=title,\n",
" x_label=x_label,\n",
" y_label=y_label,\n",
")\n",
"fig"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"![](https://i.imgur.com/MZa99Vf.png)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## feature.by_property"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ecoregions = ee.FeatureCollection(\"projects/google/charts_feature_example\")\n",
"features = ecoregions.select(\"[0-9][0-9]_ppt|label\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"geemap.ee_to_df(features)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"keys = [str(x).zfill(2) + \"_ppt\" for x in range(1, 13)]\n",
"values = calendar.month_abbr[1:] # a list of month labels, e.g. ['Jan', 'Feb', ...]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"x_properties = dict(zip(keys, values))\n",
"series_property = \"label\"\n",
"title = \"Average Ecoregion Precipitation by Month\"\n",
"colors = [\"#f0af07\", \"#0f8755\", \"#76b349\"]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig = chart.feature_by_property(\n",
" features,\n",
" x_properties,\n",
" series_property,\n",
" title=title,\n",
" colors=colors,\n",
" x_label=\"Month\",\n",
" y_label=\"Precipitation (mm)\",\n",
" legend_location=\"top-left\",\n",
")\n",
"fig"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"![](https://i.imgur.com/6RhuUc7.png)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## feature_groups"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ecoregions = ee.FeatureCollection(\"projects/google/charts_feature_example\")\n",
"features = ecoregions.select(\"[0-9][0-9]_ppt|label\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"features = ee.FeatureCollection(\"projects/google/charts_feature_example\")\n",
"x_property = \"label\"\n",
"y_property = \"01_tmean\"\n",
"series_property = \"warm\"\n",
"title = \"Average January Temperature by Ecoregion\"\n",
"colors = [\"#cf513e\", \"#1d6b99\"]\n",
"labels = [\"Warm\", \"Cold\"]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"chart.feature_groups(\n",
" features,\n",
" x_property,\n",
" y_property,\n",
" series_property,\n",
" title=title,\n",
" colors=colors,\n",
" x_label=\"Ecoregion\",\n",
" y_label=\"January Temperature (°C)\",\n",
" legend_location=\"top-right\",\n",
" labels=labels,\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"![](https://i.imgur.com/YFZlJtc.png)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## feature_histogram"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"source = ee.ImageCollection(\"OREGONSTATE/PRISM/Norm91m\").toBands()\n",
"region = ee.Geometry.Rectangle(-123.41, 40.43, -116.38, 45.14)\n",
"features = source.sample(region, 5000)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"geemap.ee_to_df(features.limit(5).select([\"07_ppt\"]))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"property = \"07_ppt\"\n",
"title = \"July Precipitation Distribution for NW USA\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig = chart.feature_histogram(\n",
" features,\n",
" property,\n",
" max_buckets=None,\n",
" title=title,\n",
" x_label=\"Precipitation (mm)\",\n",
" y_label=\"Pixel Count\",\n",
" colors=[\"#1d6b99\"],\n",
")\n",
"fig"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"![](https://i.imgur.com/ErIp7Oy.png)"
]
}
],
"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.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading
Loading