{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\"Open\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 }