Skip to content
This repository has been archived by the owner on Jun 14, 2019. It is now read-only.

Commit

Permalink
Fix bug with dtype cast when reading from cache
Browse files Browse the repository at this point in the history
Fixes failure with np.copyto(data, scratch) that occurs
after data is read from cache (turns into non-float) and
scratch_data is copied into it (float -> int16 is unsafe)
  • Loading branch information
ceholden committed Aug 27, 2016
1 parent 7ec87bd commit ac657d7
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions tstools/src/ts_driver/series.py
Expand Up @@ -147,7 +147,7 @@ def fetch_data(self, mx, my, crs_wkt,
(pixel_fn, e.message))
else:
logger.debug('Read pixel from cache')
self.data = dat
self.data = dat.astype(np.float)
got_cache = True
i += self.data.shape[1]
yield float(i)
Expand All @@ -162,21 +162,22 @@ def fetch_data(self, mx, my, crs_wkt,
(line_fn, e.message))
else:
logger.debug('Read line from cache')
self.data = dat[..., self.px]
self.data = dat[..., self.px].astype(np.float)
got_cache = True
i += self.data.shape[1]
yield float(i)

# Last resort -- read from images
if not got_cache:
for i_img in range(self.n):
self._scratch_data[:, i_img] = read_pixel_GDAL(
self._scratch_data[:, i_img] = (read_pixel_GDAL(
self.images['path'][i_img], self.px, self.py)
.astype(np.float))
i += 1
yield float(i)

# Copy from scratch variable if it completes
np.copyto(self.data, self._scratch_data)
np.copyto(self.data, self._scratch_data, 'unsafe')

if write_cache and not got_cache:
try:
Expand Down

0 comments on commit ac657d7

Please sign in to comment.