Skip to content

Commit

Permalink
BUG:merge: Add simple defaults for unused payload/colormap
Browse files Browse the repository at this point in the history
  • Loading branch information
snowman2 committed Apr 2, 2024
1 parent f0f4efc commit 4d55f71
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
3 changes: 2 additions & 1 deletion docs/history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ History

Latest
------

- BUG:merge: Use `rasterio.io.MemoryFile`` for reading (pull #765)
- BUG:merge: Add simple defaults for unused payload/colormap (pull #766)

0.15.2
------
Expand Down
28 changes: 8 additions & 20 deletions rioxarray/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,17 @@ def __init__(self, xds: DataArray):
res = xds.rio.resolution(recalc=True)
self.res = (abs(res[0]), abs(res[1]))
self.transform = xds.rio.transform(recalc=True)
try:
rio_file = xds.rio._manager.acquire()
self.profile = rio_file.profile
except AttributeError:
self.profile = {}
self.profile.update(
dtype=xds.dtype,
crs=xds.rio.crs,
nodata=xds.rio.nodata,
)
# profile is only used for writing to a file.
# This never happens with rioxarray merge.
self.profile = {}

def colormap(self, *args, **kwargs):
def colormap(self, *args, **kwargs) -> None:
"""
Lazy load colormap through _manager.acquire()
for the scenario many file handles are opened
See: https://github.com/corteva/rioxarray/issues/479
colormap is only used for writing to a file.
This never happens with rioxarray merge.
"""
try:
rio_file = self._xds.rio._manager.acquire()
return rio_file.colormap(*args, **kwargs)
except AttributeError:
return None
# pylint: disable=unused-argument
return None

def read(self, *args, **kwargs) -> numpy.ma.MaskedArray:
"""
Expand Down

0 comments on commit 4d55f71

Please sign in to comment.