Skip to content

Commit

Permalink
BUG: Lazy load colormap through _manager.acquire() in merge
Browse files Browse the repository at this point in the history
  • Loading branch information
snowman2 committed Feb 28, 2022
1 parent 033668f commit 1ac7417
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions docs/history.rst
Expand Up @@ -3,6 +3,7 @@ History

Latest
-------
- BUG: Lazy load colormap through _manager.acquire() in merge (issue #479)

0.10.1
-------
Expand Down
19 changes: 13 additions & 6 deletions rioxarray/merge.py
Expand Up @@ -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
Expand Down

0 comments on commit 1ac7417

Please sign in to comment.