{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Explore the mosaic\n", "\n", "This section contains examples to work with the entire mosaic of Sentinel 2 [we have mirrored](GHS-composite-S2_mirror)." ] }, { "cell_type": "code", "execution_count": 104, "metadata": {}, "outputs": [], "source": [ "import rioxarray, xarray\n", "import geopandas, pandas\n", "import contextily\n", "from sklearn.preprocessing import MinMaxScaler\n", "from shapely.geometry import box\n", "from numpy import percentile" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Extract window\n", "\n", "In this example we will clip a section of the entire mosaic, transform it into true color, and plot it.\n", "\n", "First connect to the `.vrt`:" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
<xarray.DataArray (band: 4, y: 182437, x: 121865)>\n", "[88930740020 values with dtype=uint16]\n", "Coordinates:\n", " * band (band) int64 1 2 3 4\n", " * y (y) float64 1.612e+06 1.612e+06 ... -2.136e+05 -2.136e+05\n", " * x (x) float64 -2.228e+05 -2.228e+05 ... 9.968e+05 9.968e+05\n", " spatial_ref int64 0\n", "Attributes:\n", " _FillValue: 0.0\n", " scale_factor: 1.0\n", " add_offset: 0.0\n", " grid_mapping: spatial_ref
[88930740020 values with dtype=uint16]
array([1, 2, 3, 4])
array([1612232.376629, 1612222.368727, 1612212.360825, ..., -213549.231322,\n", " -213559.239224, -213569.247126])
array([-222818.73324 , -222808.725338, -222798.717436, ..., 996764.229958,\n", " 996774.23786 , 996784.245762])
array(0)
<xarray.DataArray (band: 3, y: 1072, x: 834)>\n", "[2682144 values with dtype=uint16]\n", "Coordinates:\n", " * band (band) int64 1 2 3\n", " * y (y) float64 3.958e+05 3.957e+05 3.957e+05 ... 3.85e+05 3.85e+05\n", " * x (x) float64 3.318e+05 3.318e+05 ... 3.402e+05 3.402e+05\n", " spatial_ref int64 0\n", "Attributes:\n", " scale_factor: 1.0\n", " add_offset: 0.0\n", " grid_mapping: spatial_ref\n", " _FillValue: 0
[2682144 values with dtype=uint16]
array([1, 2, 3])
array([395751.863075, 395741.855173, 395731.847271, ..., 385053.415753,\n", " 385043.40785 , 385033.399948])
array([331829.207902, 331839.215804, 331849.223706, ..., 340145.77453 ,\n", " 340155.782432, 340165.790334])
array(0)