diff --git a/datasets/naip/naip-example.ipynb b/datasets/naip/naip-example.ipynb index 26d3ce15..e3cafb7b 100755 --- a/datasets/naip/naip-example.ipynb +++ b/datasets/naip/naip-example.ipynb @@ -179,88 +179,464 @@ "source": [ "### Render images\n", "\n", - "Each Item has an `href` field containing a URL to the underlying image." + "Each Item has a `rendered_preview` which uses the Planetary Computer's Data API to dynamically create a preview image from the raw data." ] }, { "cell_type": "code", "execution_count": 7, - "id": "0ab9b2d6", + "id": "8c46a5a4-bdbf-401d-bb4d-f89146a19fa5", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "import rioxarray\n", + "from IPython.display import Image\n", "\n", - "\n", - "def create_image(item):\n", - " print(item.datetime)\n", - "\n", - " ds = rioxarray.open_rasterio(item.assets[\"image\"].href).sel(band=[1, 2, 3])\n", - " img = ds.rio.clip([area_of_interest], crs=\"epsg:4326\").plot.imshow(\n", - " rgb=\"band\", aspect=1.5, size=12\n", - " )\n", - " img.axes.set_axis_off()\n", - " return img.axes" + "Image(url=item_old.assets[\"rendered_preview\"].href)" ] }, { "cell_type": "code", "execution_count": 8, - "id": "a5d7a9bb", + "id": "a8864522-0c93-42f8-bc22-2af72b29555b", "metadata": {}, "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "2011-07-20 00:00:00+00:00\n" - ] - }, { "data": { "text/html": [ - "" + "" ], "text/plain": [ - "
" + "" ] }, + "execution_count": 8, "metadata": {}, - "output_type": "display_data" + "output_type": "execute_result" } ], "source": [ - "create_image(item_old);" + "Image(url=item_new.assets[\"rendered_preview\"].href)" + ] + }, + { + "cell_type": "markdown", + "id": "22ec75f7-ec8c-4660-8421-d88ec14800c6", + "metadata": {}, + "source": [ + "To read the raw Cloud Optimized GeoTIFF, use a library like [rioxarray](https://corteva.github.io/rioxarray/html/rioxarray.html) or [rasterio](https://rasterio.readthedocs.io/) and the `image` asset." ] }, { "cell_type": "code", "execution_count": 9, - "id": "fdccdbdc", + "id": "0ab9b2d6", "metadata": {}, "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "2018-08-28 00:00:00+00:00\n" - ] - }, { "data": { "text/html": [ - "" + "
\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "
<xarray.DataArray (band: 3, y: 7630, x: 6000)>\n",
+       "[137340000 values with dtype=uint8]\n",
+       "Coordinates:\n",
+       "  * band         (band) int64 1 2 3\n",
+       "  * x            (x) float64 4.15e+05 4.15e+05 4.15e+05 ... 4.209e+05 4.209e+05\n",
+       "  * y            (y) float64 4.491e+06 4.491e+06 ... 4.483e+06 4.483e+06\n",
+       "    spatial_ref  int64 0\n",
+       "Attributes:\n",
+       "    AREA_OR_POINT:  Area\n",
+       "    scale_factor:   1.0\n",
+       "    add_offset:     0.0
" ], "text/plain": [ - "
" + "\n", + "[137340000 values with dtype=uint8]\n", + "Coordinates:\n", + " * band (band) int64 1 2 3\n", + " * x (x) float64 4.15e+05 4.15e+05 4.15e+05 ... 4.209e+05 4.209e+05\n", + " * y (y) float64 4.491e+06 4.491e+06 ... 4.483e+06 4.483e+06\n", + " spatial_ref int64 0\n", + "Attributes:\n", + " AREA_OR_POINT: Area\n", + " scale_factor: 1.0\n", + " add_offset: 0.0" ] }, + "execution_count": 9, "metadata": {}, - "output_type": "display_data" + "output_type": "execute_result" } ], "source": [ - "create_image(item_new);" + "import rioxarray\n", + "\n", + "ds = rioxarray.open_rasterio(item_old.assets[\"image\"].href).sel(band=[1, 2, 3])\n", + "ds" ] } ], @@ -280,7 +656,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.13" + "version": "3.10.6" }, "widgets": { "application/vnd.jupyter.widget-state+json": {