{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "In this tutorial we show how to quickly display single-band image tiles for a [RasterFrame](https://rasterframes.io) data structure. Tiles are subsets of scenes, where scenes are discrete instances of Earth observation data with specified spatial extent, datetime, and coordinate reference system (CRS).\n", "\n", "# Import Libraries\n", "\n", "We start by importing the Python libraries used in this example." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from earthai.init import *\n", "from IPython.display import display_html" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Query the Earth OnDemand Catalog\n", "\n", "Next we query the Earth OnDemand catalog to obtain imagery using the `earth_ondemand.read_catalog` function. This example queries the [MODIS/Terra and Aqua Nadir BRDF-Adjusted Reflectance (NBAR)](https://lpdaac.usgs.gov/products/mcd43a4v006/) product centered on a specific point with latitude/longitude coordinates." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cat = earth_ondemand.read_catalog(\n", " geo='POINT(-110.0 44.5)',\n", " start_datetime='2018-07-01',\n", " end_datetime='2018-07-05',\n", " collections='mcd43a4',\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Read the Query Results into a RasterFrame\n", "\n", "Now we read the results of the Earth OnDemand query into a RasterFrame using the `spark.read.raster` function. In this example we read in only the red and near-infrared (NIR) MODIS bands, B01 and B02. For clarity we also rename the columns **red** and **nir** using the `withColumnRenamed` method." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "rf = spark.read.raster(cat, \n", " catalog_col_names=['B01','B02']) \\\n", " .withColumnRenamed('B01', 'red') \\\n", " .withColumnRenamed('B02', 'nir')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Visualize the Image Tiles\n", "\n", "To visualize these tiles, we can use the `select` method on the RasterFrame. As shown below, `select` shows only the top five rows of **rf**, and displays separate, single-band renderings of the **red** and **nir** tiles using the Viridis color palette." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "rf.select('red', 'nir')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To view more than the top five rows, we can use the `display_html` function from the IPython.display module, which we imported above. " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "display_html(rf.select('red','nir').showHTML(10), \n", " raw=True)" ] } ], "metadata": { "kernelspec": { "display_name": "EarthAI Environment", "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.7.7" }, "zendesk": { "draft": true, "section_id": 360010176352, "title": "Display Single-band Image Tiles with RasterFrames" } }, "nbformat": 4, "nbformat_minor": 4 }