From 0aec16ae6f0e977da77d4278d737d4d1adcb0c91 Mon Sep 17 00:00:00 2001 From: Dugal Harris Date: Sat, 10 Jun 2023 20:21:03 +0200 Subject: [PATCH] add logging level argument suppress_rio_logs --- geedim/tile.py | 2 +- geedim/utils.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/geedim/tile.py b/geedim/tile.py index b37e940..e80289b 100644 --- a/geedim/tile.py +++ b/geedim/tile.py @@ -123,7 +123,7 @@ def download(self, session=None, response=None, bar: tqdm = None): # read the geotiff with a rasterio memory file env = rio.Env(GDAL_NUM_THREADS='ALL_CPUs', GTIFF_FORCE_RGBA=False) - with utils.suppress_rio_warn_logs(), env, MemoryFile(ext_buffer) as mem_file: + with utils.suppress_rio_logs(), env, MemoryFile(ext_buffer) as mem_file: with mem_file.open() as ds: array = ds.read() if (array.dtype == np.dtype('float32')) or (array.dtype == np.dtype('float64')): diff --git a/geedim/utils.py b/geedim/utils.py index f8182fd..34149c1 100644 --- a/geedim/utils.py +++ b/geedim/utils.py @@ -109,13 +109,13 @@ def split_id(image_id: str) -> Tuple[str, str]: @contextmanager -def suppress_rio_warn_logs(): - """ A context manager that sets the `rasterio` logging level to ERROR, then returns it to its original value. """ +def suppress_rio_logs(level: int = logging.ERROR): + """ A context manager that sets the `rasterio` logging level, then returns it to its original value. """ try: # GEE sets GeoTIFF `colorinterp` tags incorrectly. This suppresses `rasterio` warning relating to this: # 'Sum of Photometric type-related color channels and ExtraSamples doesn't match SamplesPerPixel' rio_level = logging.getLogger('rasterio').getEffectiveLevel() - logging.getLogger('rasterio').setLevel(logging.ERROR) + logging.getLogger('rasterio').setLevel(level) yield finally: logging.getLogger('rasterio').setLevel(rio_level) @@ -137,7 +137,7 @@ def get_bounds(filename: pathlib.Path, expand: float = 5): dict Geojson polygon. """ - with suppress_rio_warn_logs(), rio.Env(GTIFF_FORCE_RGBA=False), rio.open(filename) as im: + with suppress_rio_logs(), rio.Env(GTIFF_FORCE_RGBA=False), rio.open(filename) as im: bbox = im.bounds if (im.crs.linear_units == "metre") and (expand > 0): # expand the bounding box expand_x = (bbox.right - bbox.left) * expand / 100.0