Skip to content

Commit

Permalink
added transform attribute lookup to support passing bounds as data sl…
Browse files Browse the repository at this point in the history
…ice objects
  • Loading branch information
Jordan committed May 11, 2021
1 parent 5698572 commit 5d79796
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions geowombat/core/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,10 @@ def read(filename,

with rio.open(filename) as src:

src_transform = src.gw.transform if hasattr(src, 'gw') else src.transform

if bounds and ('window' not in kwargs):
kwargs['window'] = from_bounds(*bounds, transform=src.gw.transform)
kwargs['window'] = from_bounds(*bounds, transform=src_transform)

ycoords, xcoords, attrs = get_attrs(src, **kwargs)

Expand All @@ -190,16 +192,18 @@ def read(filename,
data = xr.DataArray(data,
dims=('band', 'y', 'x'),
coords={'band': band_names,
'y': ycoords,
'x': xcoords},
'y': ycoords[:data.shape[-2]],
'x': xcoords[:data.shape[-1]]},
attrs=attrs)

else:

with rio.open(filename[0]) as src:

src_transform = src.gw.transform if hasattr(src, 'gw') else src.transform

if bounds and ('window' not in kwargs):
kwargs['window'] = from_bounds(*bounds, transform=src.gw.transform)
kwargs['window'] = from_bounds(*bounds, transform=src_transform)

ycoords, xcoords, attrs = get_attrs(src, **kwargs)

Expand Down Expand Up @@ -227,8 +231,8 @@ def read(filename,
dims=('time', 'band', 'y', 'x'),
coords={'time': time_names,
'band': band_names,
'y': ycoords,
'x': xcoords},
'y': ycoords[:data.shape[-2]],
'x': xcoords[:data.shape[-1]]},
attrs=attrs)

return data
Expand All @@ -240,7 +244,7 @@ def read(filename,
class open(object):

"""
Opens a raster file
Opens one or more raster files
Args:
filename (str or list): The file name, search string, or a list of files to open.
Expand Down

0 comments on commit 5d79796

Please sign in to comment.