Skip to content

Commit

Permalink
fix some numpy datatypes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Mather committed Apr 5, 2024
1 parent bddb582 commit acb9eb8
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion quagmire/mesh/commonmesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def get_label(self, label):
pt_range = np.logical_and(labelIS.indices >= pStart, labelIS.indices < pEnd)
indices = labelIS.indices[pt_range] - pStart
else:
indices = np.zeros((0,), dtype=np.int)
indices = np.zeros((0,), dtype=PETSc.IntType)

return indices

Expand Down
14 changes: 7 additions & 7 deletions quagmire/mesh/pixmesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,10 @@ def interpolate(self, xi, yi, zdata, order=1):
"""
grid = np.array(zdata).reshape(self.ny, self.nx)

icoords = np.array(np.c_[xi,yi], dtype=np.float)
icoords = np.array(np.c_[xi,yi], dtype=np.float32)

# check if inside bounds
inside_bounds = np.zeros(icoords.shape[0], dtype=np.bool)
inside_bounds = np.zeros(icoords.shape[0], dtype=bool)
inside_bounds += icoords[:,0] < self.minX
inside_bounds += icoords[:,0] > self.maxX
inside_bounds += icoords[:,1] < self.minY
Expand All @@ -282,7 +282,7 @@ def interpolate(self, xi, yi, zdata, order=1):
# now interpolate
ival = _map_coordinates(grid.T, icoords.T, order=order, mode='nearest')

return ival, inside_bounds.astype(np.int)
return ival, inside_bounds.astype(PETSc.IntType)

def derivatives(self, PHI, **kwargs):
return self.derivative_grad(PHI, **kwargs)
Expand Down Expand Up @@ -384,8 +384,8 @@ def construct_natural_neighbour_cloud(self):
numpy array for efficient lookup.
"""

natural_neighbours = np.empty((self.npoints, 9), dtype=np.int)
nodes = np.arange(0, self.npoints, dtype=np.int).reshape(self.ny,self.nx)
natural_neighbours = np.empty((self.npoints, 9), dtype=PETSc.IntType)
nodes = np.arange(0, self.npoints, dtype=PETSc.IntType).reshape(self.ny,self.nx)
index = np.pad(nodes, (1,1), mode='constant', constant_values=-1)


Expand Down Expand Up @@ -441,14 +441,14 @@ def construct_neighbour_cloud(self, size=25):
corners = [0, self.nx-1, -self.nx, -1]

# interior nodes have 3*3 neighbours (including self)
neighbours = np.full(self.npoints, 9, dtype=np.int)
neighbours = np.full(self.npoints, 9, dtype=PETSc.IntType)
neighbours[~self.bmask] = 6 # walls have 3*2 neighbours
neighbours[corners] = 4 # corners have 4 neighbours

self.near_neighbours = neighbours + 2
self.extended_neighbours = np.full_like(neighbours, size)

# self.near_neighbour_mask = np.zeros_like(self.neighbour_cloud, dtype=np.bool)
# self.near_neighbour_mask = np.zeros_like(self.neighbour_cloud, dtype=bool)

# for node in range(0,self.npoints):
# self.near_neighbour_mask[node, 0:self.near_neighbours[node]] = True
Expand Down
4 changes: 2 additions & 2 deletions quagmire/mesh/strimesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ def construct_natural_neighbour_cloud(self):
lend = self.tri.lend
lptr = self.tri.lptr

segments_array = np.empty((len(lptr),2),dtype=np.int)
segments_array = np.empty((len(lptr),2),dtype=PETSc.IntType)
segments_array[:,0] = np.abs(lst[:]) - 1
segments_array[:,1] = np.abs(lst[lptr[:]-1]) - 1

Expand All @@ -511,7 +511,7 @@ def construct_natural_neighbour_cloud(self):
istart = np.zeros_like(iend)
istart[1:] = iend[:-1]

natural_neighbours = np.full((self.npoints, natural_neighbours_count.max()+1), -1, dtype=np.int)
natural_neighbours = np.full((self.npoints, natural_neighbours_count.max()+1), -1, dtype=PETSc.IntType)

for j in range(0,self.npoints):
natural_neighbours[j, 0] = j
Expand Down
4 changes: 2 additions & 2 deletions quagmire/mesh/trimesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def construct_natural_neighbour_cloud(self):
lend = self.tri.lend
lptr = self.tri.lptr

segments_array = np.empty((len(lptr),2),dtype=np.int)
segments_array = np.empty((len(lptr),2),dtype=PETSc.IntType)
segments_array[:,0] = np.abs(lst[:]) - 1
segments_array[:,1] = np.abs(lst[lptr[:]-1]) - 1

Expand All @@ -375,7 +375,7 @@ def construct_natural_neighbour_cloud(self):
istart = np.zeros_like(iend)
istart[1:] = iend[:-1]

natural_neighbours = np.full((self.npoints, natural_neighbours_count.max()+1), -1, dtype=np.int)
natural_neighbours = np.full((self.npoints, natural_neighbours_count.max()+1), -1, dtype=PETSc.IntType)

for j in range(0,self.npoints):
natural_neighbours[j, 0] = j
Expand Down
6 changes: 3 additions & 3 deletions quagmire/tools/meshtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,10 +581,10 @@ def _create_DMPlex(points, simplices, boundary_vertices=None, refinement_levels=
mesh_type = {2: "TriMesh", 3: "sTriMesh"}

if PETSc.COMM_WORLD.rank == 0:
coords = _np.array(points, dtype=_np.float)
coords = _np.array(points, dtype=_np.float32)
cells = simplices.astype(PETSc.IntType)
else:
coords = _np.zeros((0,ndim), dtype=_np.float)
coords = _np.zeros((0,ndim), dtype=_np.float32)
cells = _np.zeros((0,3), dtype=PETSc.IntType)

dim = 2
Expand Down Expand Up @@ -1011,6 +1011,6 @@ def map_global_raster_to_strimesh(mesh, latlongrid, order=3, origin="lower", uni

icoords = np.array((ilons, ilats))

mvals = ndimage.map_coordinates(raster, icoords , order=order, mode='nearest').astype(np.float)
mvals = ndimage.map_coordinates(raster, icoords , order=order, mode='nearest').astype(np.float32)

return mvals
10 changes: 5 additions & 5 deletions quagmire/topomesh/topomesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ def _node_walk_downhill(self, node):
"""

"""
chain = -np.ones(self.npoints, dtype=np.int32)
chain = -np.ones(self.npoints, dtype=PETSc.IntType32)
idx = 0
max_idx = self.npoints
Expand Down Expand Up @@ -717,7 +717,7 @@ def build_node_chains(self):
"""

"""
self.node_chain_lookup = -np.ones(self.npoints, dtype=np.int32)
self.node_chain_lookup = -np.ones(self.npoints, dtype=PETSc.IntType32)
self.node_chain_list = []
node_chain_idx = 1
Expand Down Expand Up @@ -852,7 +852,7 @@ def low_points_swamp_fill(self, its=1000, saddles=None, ref_height=0.0, ref_grad
my_glow_points = self.lgmap_row.apply(my_low_points.astype(PETSc.IntType))

t = perf_counter()
ctmt = self.uphill_propagation(my_low_points, my_glow_points, its=its, fill=-999999).astype(np.int)
ctmt = self.uphill_propagation(my_low_points, my_glow_points, its=its, fill=-999999).astype(PETSc.IntType)

height = self.topography.data.copy()

Expand Down Expand Up @@ -1077,7 +1077,7 @@ def identify_low_points(self, include_shadows=False, ref_height=0):

# from petsc4py import PETSc

nodes = np.arange(0, self.npoints, dtype=np.int)
nodes = np.arange(0, self.npoints, dtype=PETSc.IntType)
gnodes = self.lgmap_row.apply(nodes.astype(PETSc.IntType))

low_nodes = self.down_neighbour[1]
Expand Down Expand Up @@ -1142,7 +1142,7 @@ def identify_outflow_points(self):
Identify the (boundary) outflow points and return an array of (local) node indices
"""

# nodes = np.arange(0, self.npoints, dtype=np.int)
# nodes = np.arange(0, self.npoints, dtype=PETSc.IntType)
# low_nodes = self.down_neighbour[1]
# mask = np.logical_and(nodes == low_nodes, self.bmask == False)
#
Expand Down

0 comments on commit acb9eb8

Please sign in to comment.