Skip to content

Commit

Permalink
get_dtype function bug correction
Browse files Browse the repository at this point in the history
  • Loading branch information
iamtekson committed Oct 9, 2023
1 parent 7931164 commit b138b0e
Showing 1 changed file with 5 additions and 24 deletions.
29 changes: 5 additions & 24 deletions geotile/GeoTile.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,33 +198,14 @@ def get_dtype(self, data_array: np.ndarray):
>>> from geotile import GeoTile
>>> gt = GeoTile('/path/to/raster/file.tif')
>>> data_array = np.array([1, 2, 3, 4])
>>> gt.get_appropriate_dtype(data_array)
>>> gt.get_dtype(data_array)
'uint8'
"""

# min and max value of the data array, ignore nan values
min_value = np.nanmin(data_array)
max_value = np.nanmax(data_array)

# check if the data array is positive or negative
if min_value >= 0:
if max_value <= 255:
return "uint8"
elif max_value <= 65535:
return "uint16"
elif max_value <= 4294967295:
return "uint32"
else:
return "float64"
if isinstance(data_array, np.ndarray):
return str(data_array.dtype)

else:
if min_value >= -128 and max_value <= 127:
return "int8"
elif min_value >= -32768 and max_value <= 32767:
return "int16"
elif min_value >= -2147483648 and max_value <= 2147483647:
return "int32"
else:
return "float64"
return 'Input is not a NumPy array.'

def generate_tiles(
self,
Expand Down

0 comments on commit b138b0e

Please sign in to comment.