Skip to content

Commit

Permalink
cleanup more code dealing with string nodata values
Browse files Browse the repository at this point in the history
  • Loading branch information
v0lat1le committed Jul 7, 2016
1 parent 71bf48b commit 713d680
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions datacube/storage/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ def no_fractional_translate(affine, eps=0.01):

def reproject(source, dest):
with source.open() as src:
# HACK: dtype shenanigans to make sure 'NaN' string gets translated to NaN value
src_nodata = numpy.dtype(src.dtype).type(source.nodata)
array_transform = ~source.transform * dst_transform
if (source.crs == dst_projection and no_scale(array_transform) and
(resampling == RESAMPLING.nearest or no_fractional_translate(array_transform))):
Expand All @@ -100,13 +98,13 @@ def reproject(source, dest):
window = ((read[0], read[0] + shape[0]), (read[1], read[1] + shape[1]))
tmp = src.ds.read(indexes=src.bidx, window=window)
numpy.copyto(dest[write[0]:write[0] + shape[0], write[1]:write[1] + shape[1]],
tmp, where=(tmp != src_nodata))
tmp, where=(tmp != source.nodata))
else:
rasterio.warp.reproject(src,
dest,
src_transform=source.transform,
src_crs=str(source.crs),
src_nodata=src_nodata,
src_nodata=source.nodata,
dst_transform=dst_transform,
dst_crs=str(dst_projection),
dst_nodata=dst_nodata,
Expand Down Expand Up @@ -145,6 +143,7 @@ def __init__(self, dataset, measurement_id):
self._descriptor = dataset.measurements[measurement_id]
self.transform = None
self.crs = None
self.dtype = None
self.nodata = None
self.format = dataset.format
self.time = dataset.center_time
Expand Down Expand Up @@ -180,7 +179,9 @@ def open(self):

self.transform = src.affine
self.crs = CRS(_rasterio_crs_wkt(src))
self.nodata = src.nodatavals[0] or self._bandinfo.get('nodata')
self.dtype = numpy.dtype(src.dtypes[0])
self.nodata = self.dtype.type(src.nodatavals[0] if src.nodatavals[0] is not None else
self._bandinfo.get('nodata'))
yield rasterio.band(src, bandnumber)
except Exception as e:
_LOG.error("Error opening source dataset: %s", filename)
Expand Down

0 comments on commit 713d680

Please sign in to comment.