{ "cells": [ { "cell_type": "markdown", "id": "fcc18135-13cb-4fd8-b04b-c5cc9836ee74", "metadata": {}, "source": [ "# RioXarray raster index examples" ] }, { "cell_type": "code", "execution_count": 1, "id": "1b4ca507-2fa4-4809-a66e-28a907eda00e", "metadata": {}, "outputs": [], "source": [ "import xarray as xr\n", "import rioxarray as rio\n", "\n", "xr.set_options(display_expand_indexes=True);" ] }, { "cell_type": "markdown", "id": "9cbecd44-d3a7-4efa-8ac1-9840788bed81", "metadata": {}, "source": [ "## Example with rectilinear and no rotation affine transform\n", "\n", "Both x and y coordinates are 1-dimensional." ] }, { "cell_type": "code", "execution_count": 2, "id": "01685f92-546b-454a-908f-12e64c1a4631", "metadata": {}, "outputs": [], "source": [ "source = \"/vsicurl/https://noaadata.apps.nsidc.org/NOAA/G02135/south/daily/geotiff/2024/01_Jan/S_20240101_concentration_v3.0.tif\"" ] }, { "cell_type": "markdown", "id": "b12bfaff-fe20-43d1-b827-812a6299b87f", "metadata": {}, "source": [ "### Load and inspect the datasets, with and without `RasterIndex`." ] }, { "cell_type": "code", "execution_count": 3, "id": "628796f4-0cd8-405d-99de-ff7a1de976ef", "metadata": {}, "outputs": [], "source": [ "da_no_raster_index = xr.open_dataarray(source, engine=\"rasterio\")\n", "\n", "with rio.set_options(use_raster_index=True):\n", " # note: use open_dataarray() instead of load_dataarray()\n", " # for getting lazy spatial coordinates\n", " da_raster_index = xr.open_dataarray(source, engine=\"rasterio\")" ] }, { "cell_type": "code", "execution_count": 4, "id": "68328dfd-2885-4bd9-8346-44c2f01d5deb", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
<xarray.DataArray 'band_data' (band: 1, y: 332, x: 316)> Size: 420kB\n", "[104912 values with dtype=float32]\n", "Coordinates:\n", " * band (band) int64 8B 1\n", " * x (x) float64 3kB -3.938e+06 -3.912e+06 ... 3.912e+06 3.938e+06\n", " * y (y) float64 3kB 4.338e+06 4.312e+06 ... -3.912e+06 -3.938e+06\n", " spatial_ref int64 8B ...\n", "Attributes:\n", " AREA_OR_POINT: Area
<xarray.DataArray 'band_data' (band: 1, y: 332, x: 316)> Size: 420kB\n", "[104912 values with dtype=float32]\n", "Coordinates:\n", " * band (band) int64 8B 1\n", " * x (x) float64 3kB -3.938e+06 -3.912e+06 ... 3.912e+06 3.938e+06\n", " * y (y) float64 3kB 4.338e+06 4.312e+06 ... -3.912e+06 -3.938e+06\n", " spatial_ref int64 8B ...\n", "Indexes:\n", " ┌ x RasterIndex\n", " └ y\n", "Attributes:\n", " AREA_OR_POINT: Area
<xarray.DataArray 'band_data' (band: 1, y: 166, x: 3)> Size: 2kB\n", "array([[[0., 0., 0.],\n", " [0., 0., 0.],\n", " ...,\n", " [0., 0., 0.],\n", " [0., 0., 0.]]], shape=(1, 166, 3), dtype=float32)\n", "Coordinates:\n", " * band (band) int64 8B 1\n", " * x (x) float64 24B -3.912e+06 -3.888e+06 -3.862e+06\n", " * y (y) float64 1kB 4.338e+06 4.288e+06 ... -3.862e+06 -3.912e+06\n", " spatial_ref int64 8B 0\n", "Indexes:\n", " x RasterIndex\n", " y RasterIndex\n", "Attributes:\n", " AREA_OR_POINT: Area
<xarray.DataArray 'band_data' (band: 1, y: 3, x: 3)> Size: 36B\n", "array([[[0., 0., 0.],\n", " [0., 0., 0.],\n", " [0., 0., 0.]]], dtype=float32)\n", "Coordinates:\n", " * band (band) int64 8B 1\n", " * x (x) float64 24B -3.938e+06 -3.888e+06 -3.838e+06\n", " * y (y) float64 24B 4.338e+06 4.338e+06 4.312e+06\n", " spatial_ref int64 8B 0\n", "Indexes:\n", " x RasterIndex\n", " y RasterIndex\n", "Attributes:\n", " AREA_OR_POINT: Area
<xarray.DataArray 'band_data' (band: 1)> Size: 4B\n", "array([0.], dtype=float32)\n", "Coordinates:\n", " * band (band) int64 8B 1\n", " x float64 8B -3.938e+06\n", " y float64 8B 4.312e+06\n", " spatial_ref int64 8B 0\n", "Attributes:\n", " AREA_OR_POINT: Area
<xarray.DataArray 'band_data' (band: 1, y: 332)> Size: 1kB\n", "array([[0., 0., 0., ..., 0., 0., 0.]], shape=(1, 332), dtype=float32)\n", "Coordinates:\n", " * band (band) int64 8B 1\n", " x float64 8B -3.938e+06\n", " * y (y) float64 3kB 4.338e+06 4.312e+06 ... -3.912e+06 -3.938e+06\n", " spatial_ref int64 8B 0\n", "Indexes:\n", " y RasterIndex\n", "Attributes:\n", " AREA_OR_POINT: Area
<xarray.DataArray 'band_data' (band: 1, z: 2)> Size: 8B\n", "array([[0., 0.]], dtype=float32)\n", "Coordinates:\n", " * band (band) int64 8B 1\n", " * x (z) float64 16B -3.938e+06 -3.912e+06\n", " * y (z) float64 16B 4.312e+06 4.312e+06\n", " spatial_ref int64 8B 0\n", "Dimensions without coordinates: z\n", "Indexes:\n", " x RasterIndex\n", " y RasterIndex\n", "Attributes:\n", " AREA_OR_POINT: Area
<xarray.DataArray 'band_data' (band: 1, u: 2, v: 2)> Size: 16B\n", "array([[[0., 0.],\n", " [0., 0.]]], dtype=float32)\n", "Coordinates:\n", " * band (band) int64 8B 1\n", " x (u, v) float64 32B -3.938e+06 -3.912e+06 -3.888e+06 -3.862e+06\n", " y (u, v) float64 32B 4.312e+06 4.312e+06 4.288e+06 4.288e+06\n", " spatial_ref int64 8B 0\n", "Dimensions without coordinates: u, v\n", "Attributes:\n", " AREA_OR_POINT: Area