Skip to content

Sentinel-2 L2A COG assets missing CRS metadata for specific scenes #490

Description

@SashaNasonova

Hello,

I encountered several Sentinel-2 L2A assets hosted by the Planetary Computer where the GeoTIFF opens successfully with rasterio, but ds.crs is None. This leads to issues down the line for a median calculation leading to the following exception: AttributeError: 'NoneType' object has no attribute 'to_epsg'. Here's the code snippet and full traceback:

data_all = stackstac.stack(
good_items,
assets= params['bands'] + ["SCL"],
bounds_latlon=bbox,
chunksize=1024, #512
resolution=params['scale'],
epsg=params['proj'],
properties=False)

scl = data_all.sel(band="SCL")
is_clear = scl.isin([2, 4, 5, 6, 7, 11])
rgb = data_all.sel(band=params['bands']).where(lambda x: x > 0, other=np.nan).where(is_clear).median(dim="time").compute()

Traceback (most recent call last):
File "C:\Dev\Python\mpc\mpc_s2_mosaic_parallel_wkill.py", line 203, in process_single_tile
rgb = data_all.sel(band=params['bands']).where(lambda x: x > 0, other=np.nan).where(is_clear).median(dim="time").compute()
File "C:\Users\snasonova\AppData\Local\miniforge3\envs\mpc2\Lib\site-packages\xarray\core\dataarray.py", line 1247, in compute
return new.load(**kwargs)
~~~~~~~~^^^^^^^^^^
File "C:\Users\snasonova\AppData\Local\miniforge3\envs\mpc2\Lib\site-packages\xarray\core\dataarray.py", line 1173, in load
ds = self._to_temp_dataset().load(**kwargs)
File "C:\Users\snasonova\AppData\Local\miniforge3\envs\mpc2\Lib\site-packages\xarray\core\dataset.py", line 569, in load
evaluated_data: tuple[np.ndarray[Any, Any], ...] = chunkmanager.compute(
~~~~~~~~~~~~~~~~~~~~^
*chunked_data.values(), **kwargs
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "C:\Users\snasonova\AppData\Local\miniforge3\envs\mpc2\Lib\site-packages\xarray\namedarray\daskmanager.py", line 85, in compute
return compute(*data, **kwargs) # type: ignore[no-untyped-call, no-any-return]
File "C:\Users\snasonova\AppData\Local\miniforge3\envs\mpc2\Lib\site-packages\dask\base.py", line 685, in compute
results = schedule(expr, keys, **kwargs)
File "C:\Users\snasonov\AppData\Local\miniforge3\envs\mpc2\Lib\site-packages\stackstac\to_dask.py", line 189, in fetch_raster_window
data = reader.read(current_window)
File "C:\Users\snasonova\AppData\Local\miniforge3\envs\mpc2\Lib\site-packages\stackstac\rio_reader.py", line 383, in read
reader = self.dataset
^^^^^^^^^^^^
File "C:\Users\snasonova\AppData\Local\miniforge3\envs\mpc2\Lib\site-packages\stackstac\rio_reader.py", line 379, in dataset
self._dataset = self._open()
~~~~~~~~~~^^
File "C:\Users\snasonova\AppData\Local\miniforge3\envs\mpc2\Lib\site-packages\stackstac\rio_reader.py", line 346, in _open
"crs": ds.crs.to_epsg(),
^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'to_epsg'

The problem scenes are over British Columbia, Canada:

['S2C_MSIL2A_20260406T185911_R013_T10UEA_20260407T003455',
'S2B_MSIL2A_20260404T190909_R056_T11VLG_20260404T231005',
'S2B_MSIL2A_20260406T194859_R085_T09UUU_20260406T233341',
'S2B_MSIL2A_20260406T194859_R085_T09UVT_20260406T233341']

Interestingly they are from April 4th and 6th and from both S2B and S2C.

I've built a workaround to check per scene crs information and remove the scenes that are causing the issue if the median calculation fails using rasterio.

Cheers,
Sasha

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions