From 1ac74175557eb172ebd8ea1c9a8154ce562db27d Mon Sep 17 00:00:00 2001 From: snowman2 Date: Mon, 28 Feb 2022 10:47:19 -0600 Subject: [PATCH] BUG: Lazy load colormap through _manager.acquire() in merge --- docs/history.rst | 1 + rioxarray/merge.py | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/docs/history.rst b/docs/history.rst index 207e5685..1945ae80 100644 --- a/docs/history.rst +++ b/docs/history.rst @@ -3,6 +3,7 @@ History Latest ------- +- BUG: Lazy load colormap through _manager.acquire() in merge (issue #479) 0.10.1 ------- diff --git a/rioxarray/merge.py b/rioxarray/merge.py index 45b88b75..928954d3 100644 --- a/rioxarray/merge.py +++ b/rioxarray/merge.py @@ -35,19 +35,26 @@ def __init__(self, xds: DataArray): try: rio_file = xds.rio._manager.acquire() self.profile = rio_file.profile - self.colormap = rio_file.colormap except AttributeError: self.profile = {} - - def colormap(_): - return None - - self.colormap = colormap self.profile.update( dtype=xds.dtype, crs=xds.rio.crs, nodata=xds.rio.nodata, ) + + def colormap(self, *args, **kwargs): + """ + Lazy load colormap through _manager.acquire() + for the scenario many file handles are opened + + See: https://github.com/corteva/rioxarray/issues/479 + """ + try: + rio_file = self.xds.rio._manager.acquire() + return rio_file.colormap(*args, **kwargs) + except AttributeError: + return None def read(self, window, out_shape, *args, **kwargs) -> numpy.ma.array: # pylint: disable=unused-argument