Skip to content

Commit

Permalink
Add support for xee (gee-community#1859)
Browse files Browse the repository at this point in the history
  • Loading branch information
giswqs authored Dec 22, 2023
1 parent efaf466 commit e7fed01
Show file tree
Hide file tree
Showing 7 changed files with 543 additions and 1 deletion.
179 changes: 179 additions & 0 deletions docs/notebooks/140_ee_to_xarray.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<a href=\"https://githubtocolab.com/gee-community/geemap/blob/master/examples/notebooks/140_ee_to_xarray.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open in Colab\"/></a>\n",
"\n",
"**Converting Earth Engine images to an Xarray Dataset**\n",
"\n",
"This notebook demonstrates how to convert Earth Engine images to an Xarray Dataset using [xee](https://github.com/google/Xee)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# !pip install -U geemap"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import ee\n",
"import geemap"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"geemap.ee_initialize()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Opening the [ERA5-Land hourly dataset](https://developers.google.com/earth-engine/datasets/catalog/ECMWF_ERA5_LAND_HOURLY) in Earth Engine and converting it to an Xarray Dataset. This is a huge dataset and it may take a minute or two to load. Please be patient."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ds = geemap.ee_to_xarray('ECMWF/ERA5_LAND/HOURLY', n_images=100)\n",
"ds"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Open all bands in a specific projection and spatial resolution. Similarly, it may take a minute or two to load."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ds = geemap.ee_to_xarray('ECMWF/ERA5_LAND/HOURLY', crs='EPSG:4326', scale=0.25, n_images=100)\n",
"ds"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Open an ImageCollection (maybe, with EE-side filtering or processing):"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"dataset = ee.ImageCollection('ECMWF/ERA5_LAND/HOURLY').filterDate('1992-10-05', '1993-03-31')\n",
"ds = geemap.ee_to_xarray(dataset, crs='EPSG:4326', scale=0.25)\n",
"ds"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Open an ImageCollection with a specific EE projection or geometry:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"dataset = ee.ImageCollection('ECMWF/ERA5_LAND/HOURLY').filterDate('1992-10-05', '1993-03-31')\n",
"geometry = ee.Geometry.Rectangle(113.33, -43.63, 153.56, -10.66)\n",
"ds = geemap.ee_to_xarray(\n",
" dataset,\n",
" projection=dataset.first().select(0).projection(),\n",
" geometry=geometry\n",
")\n",
"ds"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Opening a single image:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"image = ee.Image(\"LANDSAT/LC08/C02/T1_TOA/LC08_044034_20140318\")\n",
"ds = geemap.ee_to_xarray(image)\n",
"ds"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Open multiple ImageCollections into one xarray.Dataset, all with the same projection. This one may take a few minutes to load."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ds = geemap.ee_to_xarray(\n",
" dataset=['ECMWF/ERA5_LAND/HOURLY', 'NASA/GDDP-CMIP6'],\n",
" n_images=100,\n",
" crs='EPSG:4326',\n",
" scale=0.25\n",
" )\n",
"ds"
]
}
],
"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.11.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
1 change: 1 addition & 0 deletions docs/tutorials.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,4 @@ More video tutorials for geemap and Earth Engine are available on my [YouTube ch
137. Creating a rectangular grid covering a region of interest for computing zonal statistics ([notebook](https://geemap.org/notebooks/137_create_grid))
138. Clipping Earth Engine images interactively with the Draw Control ([notebook](https://geemap.org/notebooks/138_draw_control))
139. Converting an Earth Engine to an image ([notebook](https://geemap.org/notebooks/139_layer_to_image))
140. Converting Earth Engine images to an Xarray Dataset ([notebook](https://geemap.org/notebooks/140_ee_to_xarray))
1 change: 1 addition & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ More video tutorials for geemap and Earth Engine are available on my [YouTube ch
137. Creating a rectangular grid covering a region of interest for computing zonal statistics ([notebook](https://geemap.org/notebooks/137_create_grid))
138. Clipping Earth Engine images interactively with the Draw Control ([notebook](https://geemap.org/notebooks/138_draw_control))
139. Converting an Earth Engine to an image ([notebook](https://geemap.org/notebooks/139_layer_to_image))
140. Converting Earth Engine images to an Xarray Dataset ([notebook](https://geemap.org/notebooks/140_ee_to_xarray))

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

Expand Down
179 changes: 179 additions & 0 deletions examples/notebooks/140_ee_to_xarray.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<a href=\"https://githubtocolab.com/gee-community/geemap/blob/master/examples/notebooks/140_ee_to_xarray.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open in Colab\"/></a>\n",
"\n",
"**Converting Earth Engine images to an Xarray Dataset**\n",
"\n",
"This notebook demonstrates how to convert Earth Engine images to an Xarray Dataset using [xee](https://github.com/google/Xee)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# !pip install -U geemap"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import ee\n",
"import geemap"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"geemap.ee_initialize()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Opening the [ERA5-Land hourly dataset](https://developers.google.com/earth-engine/datasets/catalog/ECMWF_ERA5_LAND_HOURLY) in Earth Engine and converting it to an Xarray Dataset. This is a huge dataset and it may take a minute or two to load. Please be patient."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ds = geemap.ee_to_xarray('ECMWF/ERA5_LAND/HOURLY', n_images=100)\n",
"ds"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Open all bands in a specific projection and spatial resolution. Similarly, it may take a minute or two to load."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ds = geemap.ee_to_xarray('ECMWF/ERA5_LAND/HOURLY', crs='EPSG:4326', scale=0.25, n_images=100)\n",
"ds"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Open an ImageCollection (maybe, with EE-side filtering or processing):"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"dataset = ee.ImageCollection('ECMWF/ERA5_LAND/HOURLY').filterDate('1992-10-05', '1993-03-31')\n",
"ds = geemap.ee_to_xarray(dataset, crs='EPSG:4326', scale=0.25)\n",
"ds"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Open an ImageCollection with a specific EE projection or geometry:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"dataset = ee.ImageCollection('ECMWF/ERA5_LAND/HOURLY').filterDate('1992-10-05', '1993-03-31')\n",
"geometry = ee.Geometry.Rectangle(113.33, -43.63, 153.56, -10.66)\n",
"ds = geemap.ee_to_xarray(\n",
" dataset,\n",
" projection=dataset.first().select(0).projection(),\n",
" geometry=geometry\n",
")\n",
"ds"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Opening a single image:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"image = ee.Image(\"LANDSAT/LC08/C02/T1_TOA/LC08_044034_20140318\")\n",
"ds = geemap.ee_to_xarray(image)\n",
"ds"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Open multiple ImageCollections into one xarray.Dataset, all with the same projection. This one may take a few minutes to load."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ds = geemap.ee_to_xarray(\n",
" dataset=['ECMWF/ERA5_LAND/HOURLY', 'NASA/GDDP-CMIP6'],\n",
" n_images=100,\n",
" crs='EPSG:4326',\n",
" scale=0.25\n",
" )\n",
"ds"
]
}
],
"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.11.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading

0 comments on commit e7fed01

Please sign in to comment.