From b6bc46977b23b2112cd1d44fbd02f909a1b5dc0f Mon Sep 17 00:00:00 2001 From: AdrienWehrle Date: Thu, 12 Dec 2024 22:00:24 +0100 Subject: [PATCH] modify compression methods --- earthspy/earthspy.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/earthspy/earthspy.py b/earthspy/earthspy.py index cab0fd9..d0b4bc5 100644 --- a/earthspy/earthspy.py +++ b/earthspy/earthspy.py @@ -203,21 +203,18 @@ def get_raster_compression(self, raster_compression: Union[None, str]) -> str: :rtype: Union[None, str] """ - if raster_compression in [ - "DEFLATE", - "LZW", - "PACKBITS", - "JPEG", - "WEBP", - "LZMA", - "ZSTD", - ]: + # list rasterio compression algorithm and exclude dunders + rasterio_compression_algorithms = [ + m for m in dir(rasterio.enums.Compression) if not m.startswith("__") + ] + # use rasterio compression method as is + if raster_compression.lower() in rasterio_compression_algorithms: self.raster_compression = raster_compression elif raster_compression is None: self.raster_compression = None else: - raise KeyError("Compression mode not found") + raise KeyError("Compression algorithm not found") return self.raster_compression