Skip to content

Commit

Permalink
Merge pull request #245 from groutr/bool_
Browse files Browse the repository at this point in the history
Use bool_ instead of bool8 (deprecated).
  • Loading branch information
mdbartos authored Feb 19, 2024
2 parents 56e6aea + 3bafbdb commit d9ad47d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 31 deletions.
34 changes: 17 additions & 17 deletions pysheds/_sgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def _d8_catchment_recursion(ix, catch, fdir, offsets, r_dirmap):
@njit(boolean[:,:](int64[:,:], UniTuple(int64, 2), UniTuple(int64, 8)),
cache=True)
def _d8_catchment_recur_numba(fdir, pour_point, dirmap):
catch = np.zeros(fdir.shape, dtype=np.bool8)
catch = np.zeros(fdir.shape, dtype=np.bool_)
offset = fdir.shape[1]
i, j = pour_point
ix = (i * offset) + j
Expand All @@ -329,7 +329,7 @@ def _d8_catchment_recur_numba(fdir, pour_point, dirmap):

@njit(boolean[:,:](int64[:,:], UniTuple(int64, 2), UniTuple(int64, 8)))
def _d8_catchment_iter_numba(fdir, pour_point, dirmap):
catch = np.zeros(fdir.shape, dtype=np.bool8)
catch = np.zeros(fdir.shape, dtype=np.bool_)
offset = fdir.shape[1]
i, j = pour_point
ix = (i * offset) + j
Expand Down Expand Up @@ -372,7 +372,7 @@ def _dinf_catchment_recursion(ix, catch, fdir_0, fdir_1, offsets, r_dirmap):
@njit(boolean[:,:](int64[:,:], int64[:,:], UniTuple(int64, 2), UniTuple(int64, 8)),
cache=True)
def _dinf_catchment_recur_numba(fdir_0, fdir_1, pour_point, dirmap):
catch = np.zeros(fdir_0.shape, dtype=np.bool8)
catch = np.zeros(fdir_0.shape, dtype=np.bool_)
dirmap = np.array(dirmap)
offset = fdir_0.shape[1]
i, j = pour_point
Expand All @@ -389,7 +389,7 @@ def _dinf_catchment_recur_numba(fdir_0, fdir_1, pour_point, dirmap):
@njit(boolean[:,:](int64[:,:], int64[:,:], UniTuple(int64, 2), UniTuple(int64, 8)),
cache=True)
def _dinf_catchment_iter_numba(fdir_0, fdir_1, pour_point, dirmap):
catch = np.zeros(fdir_0.shape, dtype=np.bool8)
catch = np.zeros(fdir_0.shape, dtype=np.bool_)
dirmap = np.array(dirmap)
offset = fdir_0.shape[1]
i, j = pour_point
Expand Down Expand Up @@ -423,7 +423,7 @@ def _dinf_catchment_iter_numba(fdir_0, fdir_1, pour_point, dirmap):
def _mfd_catchment_iter_numba(fdir, pour_point):
_, m, n = fdir.shape
mn = m * n
catch = np.zeros((m, n), dtype=np.bool8)
catch = np.zeros((m, n), dtype=np.bool_)
i, j = pour_point
ix = (i * n) + j
offsets = np.array([-n, 1 - n, 1,
Expand Down Expand Up @@ -544,7 +544,7 @@ def _dinf_accumulation_recursion(startnode, endnode, acc, fdir_0, fdir_1,
def _dinf_accumulation_recur_numba(acc, fdir_0, fdir_1, indegree, startnodes,
props_0, props_1):
n = startnodes.size
visited = np.zeros(acc.shape, dtype=np.bool8)
visited = np.zeros(acc.shape, dtype=np.bool_)
for k in range(n):
startnode = startnodes.flat[k]
endnode_0 = fdir_0.flat[startnode]
Expand Down Expand Up @@ -613,7 +613,7 @@ def _dinf_accumulation_eff_recursion(startnode, endnode, acc, fdir_0, fdir_1,
def _dinf_accumulation_eff_numba(acc, fdir_0, fdir_1, indegree, startnodes,
props_0, props_1, eff):
n = startnodes.size
visited = np.zeros(acc.shape, dtype=np.bool8)
visited = np.zeros(acc.shape, dtype=np.bool_)
for k in range(n):
startnode = startnodes.flat[k]
endnode_0 = fdir_0.flat[startnode]
Expand Down Expand Up @@ -744,7 +744,7 @@ def _d8_flow_distance_recursion(ix, fdir, visits, dist, weights, r_dirmap,
@njit(float64[:,:](int64[:,:], float64[:,:], UniTuple(int64, 2), UniTuple(int64, 8)),
cache=True)
def _d8_flow_distance_recur_numba(fdir, weights, pour_point, dirmap):
visits = np.zeros(fdir.shape, dtype=np.bool8)
visits = np.zeros(fdir.shape, dtype=np.bool_)
dist = np.full(fdir.shape, np.inf, dtype=np.float64)
r_dirmap = np.array([dirmap[4], dirmap[5], dirmap[6],
dirmap[7], dirmap[0], dirmap[1],
Expand All @@ -762,7 +762,7 @@ def _d8_flow_distance_recur_numba(fdir, weights, pour_point, dirmap):
@njit(float64[:,:](int64[:,:], float64[:,:], UniTuple(int64, 2), UniTuple(int64, 8)),
cache=True)
def _d8_flow_distance_iter_numba(fdir, weights, pour_point, dirmap):
visits = np.zeros(fdir.shape, dtype=np.bool8)
visits = np.zeros(fdir.shape, dtype=np.bool_)
dist = np.full(fdir.shape, np.inf, dtype=np.float64)
r_dirmap = np.array([dirmap[4], dirmap[5], dirmap[6],
dirmap[7], dirmap[0], dirmap[1],
Expand Down Expand Up @@ -820,7 +820,7 @@ def _dinf_flow_distance_recursion(ix, fdir_0, fdir_1, visits, dist,
cache=True)
def _dinf_flow_distance_recur_numba(fdir_0, fdir_1, weights_0, weights_1,
pour_point, dirmap):
visits = np.zeros(fdir_0.shape, dtype=np.bool8)
visits = np.zeros(fdir_0.shape, dtype=np.bool_)
dist = np.full(fdir_0.shape, np.inf, dtype=np.float64)
r_dirmap = np.array([dirmap[4], dirmap[5], dirmap[6],
dirmap[7], dirmap[0], dirmap[1],
Expand All @@ -841,7 +841,7 @@ def _dinf_flow_distance_recur_numba(fdir_0, fdir_1, weights_0, weights_1,
def _dinf_flow_distance_iter_numba(fdir_0, fdir_1, weights_0, weights_1,
pour_point, dirmap):
dist = np.full(fdir_0.shape, np.inf, dtype=np.float64)
visited = np.zeros(fdir_0.shape, dtype=np.bool8)
visited = np.zeros(fdir_0.shape, dtype=np.bool_)
r_dirmap = np.array([dirmap[4], dirmap[5], dirmap[6],
dirmap[7], dirmap[0], dirmap[1],
dirmap[2], dirmap[3]])
Expand Down Expand Up @@ -885,7 +885,7 @@ def _mfd_flow_distance_iter_numba(fdir, pour_point, weights):
_, m, n = fdir.shape
mn = m * n
dist = np.full((m, n), np.inf, dtype=np.float64)
visited = np.zeros((m, n), dtype=np.bool8)
visited = np.zeros((m, n), dtype=np.bool_)
i, j = pour_point
ix = (i * n) + j
offsets = np.array([-n, 1 - n, 1,
Expand Down Expand Up @@ -1022,9 +1022,9 @@ def _mfd_reverse_distance_iter_numba(rdist, fdir, indegree, startnodes, weights)
def _par_get_candidates_numba(dem, inside):
n = inside.size
offset = dem.shape[1]
fdirs_defined = np.zeros(dem.shape, dtype=np.bool8)
flats = np.zeros(dem.shape, dtype=np.bool8)
higher_cells = np.zeros(dem.shape, dtype=np.bool8)
fdirs_defined = np.zeros(dem.shape, dtype=np.bool_)
flats = np.zeros(dem.shape, dtype=np.bool_)
higher_cells = np.zeros(dem.shape, dtype=np.bool_)
offsets = np.array([-offset, 1 - offset, 1,
1 + offset, offset, - 1 + offset,
- 1, - 1 - offset])
Expand Down Expand Up @@ -1658,7 +1658,7 @@ def _dinf_fix_cycles_recursion(node, fdir_0, fdir_1, ancestor,
cache=True)
def _dinf_fix_cycles_numba(fdir_0, fdir_1, max_cycle_size):
n = fdir_0.size
visited = np.zeros(fdir_0.shape, dtype=np.bool8)
visited = np.zeros(fdir_0.shape, dtype=np.bool_)
depth = 0
for node in range(n):
_dinf_fix_cycles_recursion(node, fdir_0, fdir_1, node,
Expand Down Expand Up @@ -1822,7 +1822,7 @@ def _construct_matching(fdir, dirmap):
def _find_pits_numba(dem, inside):
n = inside.size
offset = dem.shape[1]
pits = np.zeros(dem.shape, dtype=np.bool8)
pits = np.zeros(dem.shape, dtype=np.bool_)
offsets = np.array([-offset, 1 - offset, 1,
1 + offset, offset, - 1 + offset,
- 1, - 1 - offset])
Expand Down
18 changes: 9 additions & 9 deletions pysheds/sgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ def catchment(self, x, y, fdir, pour_value=None, dirmap=(64, 128, 1, 2, 4, 8, 16
-------
catch : Raster
Raster indicating cells that lie in the catchment. The dtype will be
np.bool8, unless `pour_value` is specified, in which case the dtype will
np.bool_, unless `pour_value` is specified, in which case the dtype will
be the smallest dtype capable of representing the pour value.
"""
if routing.lower() == 'd8':
Expand Down Expand Up @@ -1284,7 +1284,7 @@ def compute_hand(self, fdir, dem, mask, dirmap=(64, 128, 1, 2, 4, 8, 16, 32),
else:
raise ValueError('Routing method must be one of: `d8`, `dinf`, `mfd`')
dem_overrides = {'dtype' : np.float64, 'nodata' : dem.nodata}
mask_overrides = {'dtype' : np.bool8, 'nodata' : False}
mask_overrides = {'dtype' : np.bool_, 'nodata' : False}
kwargs.update(fdir_overrides)
fdir = self._input_handler(fdir, **kwargs)
kwargs.update(dem_overrides)
Expand Down Expand Up @@ -1414,7 +1414,7 @@ def extract_river_network(self, fdir, mask, dirmap=(64, 128, 1, 2, 4, 8, 16, 32)
fdir_overrides = {'dtype' : np.int64, 'nodata' : fdir.nodata}
else:
raise NotImplementedError('Only implemented for `d8` routing.')
mask_overrides = {'dtype' : np.bool8, 'nodata' : False}
mask_overrides = {'dtype' : np.bool_, 'nodata' : False}
kwargs.update(fdir_overrides)
fdir = self._input_handler(fdir, **kwargs)
kwargs.update(mask_overrides)
Expand Down Expand Up @@ -1497,7 +1497,7 @@ def extract_profiles(self, fdir, mask, dirmap=(64, 128, 1, 2, 4, 8, 16, 32),
fdir_overrides = {'dtype' : np.int64, 'nodata' : fdir.nodata}
else:
raise NotImplementedError('Only implemented for `d8` routing.')
mask_overrides = {'dtype' : np.bool8, 'nodata' : False}
mask_overrides = {'dtype' : np.bool_, 'nodata' : False}
kwargs.update(fdir_overrides)
fdir = self._input_handler(fdir, **kwargs)
kwargs.update(mask_overrides)
Expand Down Expand Up @@ -1561,7 +1561,7 @@ def stream_order(self, fdir, mask, dirmap=(64, 128, 1, 2, 4, 8, 16, 32),
fdir_overrides = {'dtype' : np.int64, 'nodata' : fdir.nodata}
else:
raise NotImplementedError('Only implemented for `d8` routing.')
mask_overrides = {'dtype' : np.bool8, 'nodata' : False}
mask_overrides = {'dtype' : np.bool_, 'nodata' : False}
kwargs.update(fdir_overrides)
fdir = self._input_handler(fdir, **kwargs)
kwargs.update(mask_overrides)
Expand Down Expand Up @@ -2119,7 +2119,7 @@ def detect_depressions(self, dem, **kwargs):
kwargs.update(input_overrides)
dem = self._input_handler(dem, **kwargs)
filled_dem = self.fill_depressions(dem, **kwargs)
depressions = np.zeros(filled_dem.shape, dtype=np.bool8)
depressions = np.zeros(filled_dem.shape, dtype=np.bool_)
depressions[dem != filled_dem] = True
depressions[np.isnan(dem) | np.isnan(filled_dem)] = False
depressions = self._output_handler(data=depressions,
Expand Down Expand Up @@ -2372,7 +2372,7 @@ def snap_to_mask(self, mask, xy, return_dist=False, **kwargs):
assert isinstance(mask, Raster)
except:
raise TypeError('`mask` must be a Raster instance.')
mask_overrides = {'dtype' : np.bool8, 'nodata' : False}
mask_overrides = {'dtype' : np.bool_, 'nodata' : False}
kwargs.update(mask_overrides)
mask = self._input_handler(mask, **kwargs)
affine = mask.affine
Expand Down Expand Up @@ -2406,9 +2406,9 @@ def _get_nodata_cells(self, data):
raise TypeError('Data must be a Raster.')
nodata = data.nodata
if np.isnan(nodata):
nodata_cells = np.isnan(data).astype(np.bool8)
nodata_cells = np.isnan(data).astype(np.bool_)
else:
nodata_cells = (data == nodata).astype(np.bool8)
nodata_cells = (data == nodata).astype(np.bool_)
return nodata_cells

def _pop_rim(self, data, nodata=0):
Expand Down
9 changes: 4 additions & 5 deletions pysheds/sview.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def __init__(self, affine=Affine(1., 0., 0., 0., 1., 0.), shape=(1,1),
self.crs = crs
self.nodata = nodata
if mask is None:
self.mask = np.ones(shape, dtype=np.bool8)
self.mask = np.ones(shape, dtype=np.bool_)
else:
self.mask = mask

Expand Down Expand Up @@ -385,10 +385,10 @@ def mask(self):
@mask.setter
def mask(self, new_mask):
try:
assert (np.min_scalar_type(new_mask) <= np.dtype(np.bool8))
assert (np.min_scalar_type(new_mask) <= np.dtype(np.bool_))
except:
raise TypeError('`mask` must be of boolean type')
new_mask = np.asarray(new_mask).astype(np.bool8)
new_mask = np.asarray(new_mask).astype(np.bool_)
self._mask = new_mask

@property
Expand Down Expand Up @@ -621,7 +621,7 @@ def _view_multiraster(cls, data, target_view, data_view=None, interpolation='nea
k, m, n = data.shape
if out is None:
out = np.empty((k, *target_view.shape), dtype=dtype)
out_mask = np.ones((k, *target_view.shape), dtype=np.bool8)
out_mask = np.ones((k, *target_view.shape), dtype=np.bool_)
for i in range(k):
slice_viewfinder = ViewFinder(affine=data_view.affine, mask=data_view.mask[i],
nodata=data_view.nodata, crs=data_view.crs)
Expand Down Expand Up @@ -971,4 +971,3 @@ def _view_different_crs(cls, view, data, data_view, target_view, interpolation='
else:
raise ValueError('Interpolation method must be one of: `nearest`, `linear`')
return view

0 comments on commit d9ad47d

Please sign in to comment.