25
25
class RasterioArrayWrapper (BackendArray ):
26
26
"""A wrapper around rasterio dataset objects"""
27
27
28
- def __init__ (self , rasterio_ds ):
29
- self .rasterio_ds = rasterio_ds
30
- self ._shape = (rasterio_ds . count , rasterio_ds .height ,
31
- rasterio_ds .width )
28
+ def __init__ (self , riods ):
29
+ self .riods = riods
30
+ self ._shape = (riods . value . count , riods . value .height ,
31
+ riods . value .width )
32
32
self ._ndims = len (self .shape )
33
33
34
34
@property
35
35
def dtype (self ):
36
- dtypes = self .rasterio_ds .dtypes
36
+ dtypes = self .riods . value .dtypes
37
37
if not np .all (np .asarray (dtypes ) == dtypes [0 ]):
38
38
raise ValueError ('All bands should have the same dtype' )
39
39
return np .dtype (dtypes [0 ])
@@ -105,7 +105,7 @@ def _get_indexer(self, key):
105
105
def __getitem__ (self , key ):
106
106
band_key , window , squeeze_axis , np_inds = self ._get_indexer (key )
107
107
108
- out = self .rasterio_ds .read (band_key , window = tuple (window ))
108
+ out = self .riods . value .read (band_key , window = tuple (window ))
109
109
if squeeze_axis :
110
110
out = np .squeeze (out , axis = squeeze_axis )
111
111
return indexing .NumpyIndexingAdapter (out )[np_inds ]
@@ -203,20 +203,20 @@ def open_rasterio(filename, parse_coordinates=None, chunks=None, cache=None,
203
203
coords = OrderedDict ()
204
204
205
205
# Get bands
206
- if riods .count < 1 :
206
+ if riods .value . count < 1 :
207
207
raise ValueError ('Unknown dims' )
208
- coords ['band' ] = np .asarray (riods .indexes )
208
+ coords ['band' ] = np .asarray (riods .value . indexes )
209
209
210
210
# Get coordinates
211
211
if LooseVersion (rasterio .__version__ ) < '1.0' :
212
- transform = riods .affine
212
+ transform = riods .value . affine
213
213
else :
214
- transform = riods .transform
214
+ transform = riods .value . transform
215
215
if transform .is_rectilinear :
216
216
# 1d coordinates
217
217
parse = True if parse_coordinates is None else parse_coordinates
218
218
if parse :
219
- nx , ny = riods .width , riods .height
219
+ nx , ny = riods .value . width , riods . value .height
220
220
# xarray coordinates are pixel centered
221
221
x , _ = (np .arange (nx ) + 0.5 , np .zeros (nx ) + 0.5 ) * transform
222
222
_ , y = (np .zeros (ny ) + 0.5 , np .arange (ny ) + 0.5 ) * transform
@@ -239,41 +239,42 @@ def open_rasterio(filename, parse_coordinates=None, chunks=None, cache=None,
239
239
# For serialization store as tuple of 6 floats, the last row being
240
240
# always (0, 0, 1) per definition (see https://github.com/sgillies/affine)
241
241
attrs ['transform' ] = tuple (transform )[:6 ]
242
- if hasattr (riods , 'crs' ) and riods .crs :
242
+ if hasattr (riods . value , 'crs' ) and riods . value .crs :
243
243
# CRS is a dict-like object specific to rasterio
244
244
# If CRS is not None, we convert it back to a PROJ4 string using
245
245
# rasterio itself
246
- attrs ['crs' ] = riods .crs .to_string ()
247
- if hasattr (riods , 'res' ):
246
+ attrs ['crs' ] = riods .value . crs .to_string ()
247
+ if hasattr (riods . value , 'res' ):
248
248
# (width, height) tuple of pixels in units of CRS
249
- attrs ['res' ] = riods .res
250
- if hasattr (riods , 'is_tiled' ):
249
+ attrs ['res' ] = riods .value . res
250
+ if hasattr (riods . value , 'is_tiled' ):
251
251
# Is the TIF tiled? (bool)
252
252
# We cast it to an int for netCDF compatibility
253
- attrs ['is_tiled' ] = np .uint8 (riods .is_tiled )
253
+ attrs ['is_tiled' ] = np .uint8 (riods .value . is_tiled )
254
254
with warnings .catch_warnings ():
255
- # casting riods.transform to a tuple makes this future proof
255
+ # casting riods.value. transform to a tuple makes this future proof
256
256
warnings .simplefilter ('ignore' , FutureWarning )
257
- if hasattr (riods , 'transform' ):
257
+ if hasattr (riods . value , 'transform' ):
258
258
# Affine transformation matrix (tuple of floats)
259
259
# Describes coefficients mapping pixel coordinates to CRS
260
- attrs ['transform' ] = tuple (riods .transform )
261
- if hasattr (riods , 'nodatavals' ):
260
+ attrs ['transform' ] = tuple (riods .value . transform )
261
+ if hasattr (riods . value , 'nodatavals' ):
262
262
# The nodata values for the raster bands
263
263
attrs ['nodatavals' ] = tuple ([np .nan if nodataval is None else nodataval
264
- for nodataval in riods .nodatavals ])
264
+ for nodataval in riods .value . nodatavals ])
265
265
266
266
# Parse extra metadata from tags, if supported
267
267
parsers = {'ENVI' : _parse_envi }
268
268
269
- driver = riods .driver
269
+ driver = riods .value . driver
270
270
if driver in parsers :
271
- meta = parsers [driver ](riods .tags (ns = driver ))
271
+ meta = parsers [driver ](riods .value . tags (ns = driver ))
272
272
273
273
for k , v in meta .items ():
274
274
# Add values as coordinates if they match the band count,
275
275
# as attributes otherwise
276
- if isinstance (v , (list , np .ndarray )) and len (v ) == riods .count :
276
+ if (isinstance (v , (list , np .ndarray )) and
277
+ len (v ) == riods .value .count ):
277
278
coords [k ] = ('band' , np .asarray (v ))
278
279
else :
279
280
attrs [k ] = v
0 commit comments