From 6b524e7158a0ddeed89cdb3641a1fabd6300b172 Mon Sep 17 00:00:00 2001 From: BRAUN REMI Date: Thu, 19 Dec 2024 12:39:50 +0100 Subject: [PATCH] Fix Landsats' cloudpathlib error in case of dask + s3 + extracted file --- eoreader/products/optical/landsat_product.py | 22 +++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/eoreader/products/optical/landsat_product.py b/eoreader/products/optical/landsat_product.py index 0f2510f0..6875156e 100644 --- a/eoreader/products/optical/landsat_product.py +++ b/eoreader/products/optical/landsat_product.py @@ -29,7 +29,7 @@ from lxml import etree from lxml.builder import E from rasterio.enums import Resampling -from sertit import AnyPath, path, rasters, types +from sertit import AnyPath, dask, path, rasters, types from sertit.misc import ListEnum from sertit.types import AnyPathStrType, AnyPathType @@ -311,8 +311,17 @@ def footprint(self) -> gpd.GeoDataFrame: footprint_dezoom = 1 # Read the file with a very low resolution + qa_path = self._get_path(self._pixel_quality_id) + if ( + not self.is_archived + and path.is_cloud_path(qa_path) + and dask.get_client() is not None + ): + # Workaround... + qa_path = qa_path.download_to(self.output) + nodata_band = utils.read( - self._get_path(self._pixel_quality_id), + qa_path, pixel_size=self.pixel_size * footprint_dezoom, masked=False, ) @@ -1220,7 +1229,6 @@ def _to_tb( k2_str = "K2_CONSTANT_BAND_" + band_name k1 = float(mtd.findtext(f".//{k1_str}")) k2 = float(mtd.findtext(f".//{k2_str}")) - band_arr = k2 / np.log(k1 / band_arr + 1) elif self.product_type == LandsatProductType.L2: c_mul_str = "TEMPERATURE_MULT_BAND_ST_B" + band_name @@ -1313,7 +1321,7 @@ def _manage_invalid_pixels( landsat_qa_path = self._get_path(self._radsat_id) qa_arr = self._read_band( landsat_qa_path, size=(band_arr.rio.width, band_arr.rio.height), **kwargs - ).data + ) if self._collection == LandsatCollection.COL_1: # https://www.usgs.gov/core-science-systems/nli/landsat/landsat-collection-1-level-1-quality-assessment-band @@ -1364,8 +1372,8 @@ def _manage_invalid_pixels( landsat_stat_path, size=(band_arr.rio.width, band_arr.rio.height), **kwargs, - ).data - nodata = np.where(pixel_arr == 1, 1, 0) + ) + nodata = xr.where(pixel_arr == 1, 1, 0) mask = sat | other | nodata @@ -1408,7 +1416,7 @@ def _manage_nodata( size=(band_arr.rio.width, band_arr.rio.height), **kwargs, ) - nodata = np.where(pixel_arr == 1, 1, 0).astype(np.uint8) + nodata = xr.where(pixel_arr == 1, 1, 0).astype(np.uint8) return self._set_nodata_mask(band_arr, nodata)