Series#

Basic examples of series, displaying NBR of all images.

Initialization of the notebook#

  • Imports

  • Loggers

  • Paths

from cloudpathlib import AnyPath
from eosets.series import Series
from eoreader.bands import NBR
from matplotlib import pyplot as plt
import cartopy.crs as ccrs
# Create logger
import logging
from sertit import logs

logs.init_logger(logging.getLogger("eoreader"), log_lvl=logging.INFO)
logs.init_logger(logging.getLogger("eosets"))
# Get the base paths
data_path = AnyPath(r"/home/ds2_db3/CI/eosets/DATA")
# Get a list of list (for potential mosaics) of Sentinel-2 images
s2_paths = [
    [data_path / "S2A_MSIL1C_20200824T110631_N0209_R137_T29TQE_20200824T150432.zip"],
    [data_path / "S2B_MSIL1C_20200908T110619_N0209_R137_T29TQE_20200908T132324.zip"]
]
aoi_path = data_path / "Fire_Spain.geojson"

Creation of the Series and loading of NBR#

To create a series, you just have to give the paths of your products.

The goal here will be to extract the NBR band for each product composing the series and display the most recent one.

\[ NBR = \frac{NIR - SWIR}{NIR + SWIR} \]
series = Series(paths=s2_paths)

# Load NBR
nbr_ds = series.load(
    bands=NBR,
    window=aoi_path,
    pixel_size=60
)

# Plot the pairs
crs = ccrs.UTM(str(nbr_ds.rio.crs.to_epsg())[-2:])
nbr_ds["NBR"].isel(time=-1).plot(
    robust=True,
    transform=crs,
    x="x",
    y="y",
    cmap="gist_heat",
    subplot_kws={'projection':crs}
)
plt.show()
2024-04-25 09:00:02,728 - [DEBUG] - *** Loading ['NBR'] for 20200824T110631_S2_T29TQE_L1C_150432 ***
2024-04-25 09:00:09,438 - [DEBUG] - Merging bands NBR
2024-04-25 09:00:09,554 - [DEBUG] - Collocating bands
2024-04-25 09:00:09,561 - [DEBUG] - *** Loading ['NBR'] for 20200908T110619_S2_T29TQE_L1C_132324 ***
0...10...20...30...40...50...60...70...80...90...100 - done.
2024-04-25 09:00:21,986 - [DEBUG] - Merging bands NBR
2024-04-25 09:00:22,081 - [DEBUG] - Collocating bands
0...10...20...30...40...50...60...70...80...90...100 - done.
../_images/2d54c7940a789153eb2dce0eac6fa8e682dabe808c0e437852612c0d8982c4bf.png
nbr_ds
<xarray.Dataset> Size: 594kB
Dimensions:      (x: 272, y: 271, band: 1, time: 2)
Coordinates:
  * x            (x) float64 2kB 7.705e+05 7.706e+05 ... 7.867e+05 7.868e+05
  * y            (y) float64 2kB 4.458e+06 4.458e+06 ... 4.442e+06 4.442e+06
  * band         (band) int64 8B 1
  * time         (time) datetime64[ns] 16B 2020-08-24T11:06:31 2020-09-08T11:...
    spatial_ref  int64 8B 0
Data variables:
    NBR          (band, y, x, time) float32 590kB 0.2922 0.2713 ... 0.4244
Attributes:
    long_name:       NBR
    condensed_name:  20200824T110631_S2_T29TQE_L1C_150432_20200908T110619_S2_...

Stacking Series#

A series can also be stacked.

stack = series.stack(NBR,
    window=aoi_path,
    pixel_size=60
    )
stack
2024-04-25 09:00:22,392 - [DEBUG] - Collocating bands
2024-04-25 09:00:22,423 - [DEBUG] - Collocating bands
<xarray.DataArray '2020-08-24T11:06:31_NBR_2020-09-08T11:06:19_NBR' (bands: 2,
                                                                     y: 271,
                                                                     x: 272)> Size: 590kB
array([[[ 0.29215732,  0.4141129 ,  0.41982567, ...,  0.0864888 ,
          0.03820598,  0.00598556],
        [ 0.27878785,  0.422693  ,  0.38966158, ...,  0.08063875,
          0.03872617, -0.00363637],
        [ 0.36653206,  0.43033397,  0.49138296, ...,  0.08462457,
          0.04146922,  0.09817036],
        ...,
        [ 0.04074569,  0.01427867,  0.01138141, ...,  0.28146973,
          0.35828874,  0.55584246],
        [ 0.01633488, -0.02060662, -0.04766013, ...,  0.53853804,
          0.51312035,  0.3917417 ],
        [-0.08005945, -0.09234507, -0.02785147, ...,  0.56374234,
          0.5784413 ,  0.45268297]],

       [[ 0.27130094,  0.3637257 ,  0.4012888 , ...,  0.06390254,
          0.00854352, -0.034127  ],
        [ 0.25713083,  0.4044636 ,  0.35099605, ...,  0.0451389 ,
         -0.01419647, -0.05843398],
        [ 0.33729634,  0.41639075,  0.43952683, ...,  0.04612509,
         -0.00711878,  0.0126822 ],
        ...,
        [ 0.02825456, -0.00621118, -0.00383959, ...,  0.25569504,
          0.36967078,  0.64235127],
        [ 0.00617283, -0.02171428, -0.05901639, ...,  0.5075718 ,
          0.47519293,  0.41946402],
        [-0.09205024, -0.11479785, -0.05879967, ...,  0.5896118 ,
          0.58982766,  0.42435047]]], dtype=float32)
Coordinates:
  * x            (x) float64 2kB 7.705e+05 7.706e+05 ... 7.867e+05 7.868e+05
  * y            (y) float64 2kB 4.458e+06 4.458e+06 ... 4.442e+06 4.442e+06
    spatial_ref  int64 8B 0
  * bands        (bands) object 16B MultiIndex
  * variable     (bands) object 16B 'NBR' 'NBR'
  * band         (bands) int64 16B 1 1
  * time         (bands) datetime64[ns] 16B 2020-08-24T11:06:31 2020-09-08T11...
Attributes:
    long_name:       2020-08-24T11:06:31_NBR 2020-09-08T11:06:19_NBR
    condensed_name:  20200824T110631_S2_T29TQE_L1C_150432_20200908T110619_S2_...
stack.isel(bands=1).plot(robust=True)
<matplotlib.collections.QuadMesh at 0x7f010cce0430>
../_images/1ff30e195c2bfea9d35171d03a61936efc6db0709bf00cc6f005c79ee75d2e6c.png