|
36 | 36 |
|
37 | 37 | import numpy as np |
38 | 38 | from .spyfile import SpyFile, MemmapFile |
39 | | -from spectral.utilities.python23 import typecode |
| 39 | +from spectral.utilities.python23 import typecode, tobytes, frombytes |
40 | 40 |
|
41 | 41 | byte_typecode = typecode('b') |
42 | 42 |
|
@@ -112,7 +112,7 @@ def read_band(self, band, use_memmap=True): |
112 | 112 | self.ncols, 0) |
113 | 113 | vals.fromfile(f, self.ncols * self.sample_size) |
114 | 114 |
|
115 | | - arr = numpy.fromstring(vals.tostring(), dtype=self.dtype) |
| 115 | + arr = numpy.fromstring(tobytes(vals), dtype=self.dtype) |
116 | 116 | arr = arr.reshape((self.nrows, self.ncols)) |
117 | 117 |
|
118 | 118 | if self.scale_factor != 1: |
@@ -166,7 +166,7 @@ def read_bands(self, bands, use_memmap=True): |
166 | 166 | f.seek(row_offset + bands[j] * self.sample_size * self.ncols, 0) |
167 | 167 | vals.fromfile(f, self.ncols * self.sample_size) |
168 | 168 |
|
169 | | - frame = numpy.fromstring(vals.tostring(), dtype=self.dtype) |
| 169 | + frame = numpy.fromstring(tobytes(vals), dtype=self.dtype) |
170 | 170 | arr[i, :, :] = frame.reshape((len(bands), self.ncols)).transpose() |
171 | 171 |
|
172 | 172 | if self.scale_factor != 1: |
@@ -218,7 +218,7 @@ def read_pixel(self, row, col, use_memmap=True): |
218 | 218 | f.seek(offset + i * sample_size * ncols, 0) |
219 | 219 | vals.fromfile(f, sample_size) |
220 | 220 |
|
221 | | - pixel = numpy.fromstring(vals.tostring(), dtype=self.dtype) |
| 221 | + pixel = numpy.fromstring(tobytes(vals), dtype=self.dtype) |
222 | 222 |
|
223 | 223 | if self.scale_factor != 1: |
224 | 224 | return pixel / float(self.scale_factor) |
@@ -301,7 +301,7 @@ def read_subregion(self, row_bounds, col_bounds, bands=None, |
301 | 301 | for j in bands: |
302 | 302 | f.seek(rowPos + j * ncols * sampleSize, 0) |
303 | 303 | vals.fromfile(f, nSubCols * sampleSize) |
304 | | - subArray = numpy.fromstring(vals.tostring(), dtype=self.dtype) |
| 304 | + subArray = numpy.fromstring(tobytes(vals), dtype=self.dtype) |
305 | 305 | subArray = subArray.reshape((nSubBands, nSubCols)) |
306 | 306 | arr[i - row_bounds[0], :, :] = numpy.transpose(subArray) |
307 | 307 |
|
@@ -386,7 +386,7 @@ def read_subimage(self, rows, cols, bands=None, use_memmap=False): |
386 | 386 | j * d_col + |
387 | 387 | k * d_band, 0) |
388 | 388 | vals.fromfile(f, sample_size) |
389 | | - subArray = numpy.fromstring(vals.tostring(), dtype=self.dtype) |
| 389 | + subArray = numpy.fromstring(tobytes(vals), dtype=self.dtype) |
390 | 390 | subArray = subArray.reshape((nSubRows, nSubCols, nSubBands)) |
391 | 391 |
|
392 | 392 | if self.scale_factor != 1: |
@@ -426,5 +426,5 @@ def read_datum(self, i, j, k, use_memmap=True): |
426 | 426 | self.fid.seek(self.offset + i * d_row + j * d_col + k * d_band, 0) |
427 | 427 | vals = array.array(byte_typecode) |
428 | 428 | vals.fromfile(self.fid, self.sample_size) |
429 | | - arr = np.fromstring(vals.tostring(), dtype=self.dtype) |
| 429 | + arr = np.fromstring(tobytes(vals), dtype=self.dtype) |
430 | 430 | return arr.tolist()[0] / float(self.scale_factor) |
0 commit comments