In this tutorial we show how to quickly display single-band image tiles for a RasterFrame 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).
Import Libraries
We start by importing the Python libraries used in this example.
from earthai.init import * from IPython.display import display_html
Query the Earth OnDemand Catalog
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) product centered on a specific point with latitude/longitude coordinates.
cat = earth_ondemand.read_catalog( geo='POINT(-110.0 44.5)', start_datetime='2018-07-01', end_datetime='2018-07-05', collections='mcd43a4', )
Read the Query Results into a RasterFrame
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.
rf = spark.read.raster(cat, catalog_col_names=['B01','B02']) \ .withColumnRenamed('B01', 'red') \ .withColumnRenamed('B02', 'nir')
Visualize the Image Tiles
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.
rf.select('red', 'nir')
To view more than the top five rows, we can use the display_html
function from the IPython.display module, which we imported above.
display_html(rf.select('red','nir').showHTML(10), raw=True)
Comments
0 comments
Please sign in to leave a comment.