Skip to content

Commit

Permalink
Merge pull request #555 from xylar/fix-xarray-sizes
Browse files Browse the repository at this point in the history
Change xarray `dims` --> `sizes`
  • Loading branch information
xylar authored Feb 15, 2024
2 parents 868b2b1 + 4c83a15 commit d9faf39
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
40 changes: 20 additions & 20 deletions conda_package/mpas_tools/mesh/creation/sort_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ def sort_mesh(mesh):
"""
Sort cells, edges and duals in the mesh
to improve cache-locality
Parameters
----------
mesh : xarray.Dataset
A dataset containing an MPAS mesh to sort
Returns
-------
mesh : xarray.Dataset
A dataset containing the sorted MPAS mesh
"""
# Authors: Darren Engwirda

ncells = mesh.dims["nCells"]
nedges = mesh.dims["nEdges"]
nduals = mesh.dims["nVertices"]
ncells = mesh.sizes["nCells"]
nedges = mesh.sizes["nEdges"]
nduals = mesh.sizes["nVertices"]

cell_fwd = np.arange(0, ncells) + 1
cell_rev = np.arange(0, ncells) + 1
Expand Down Expand Up @@ -110,8 +110,8 @@ def sort_mesh(mesh):
mesh["indexToEdgeID"][:] = np.arange(nedges) + 1

return mesh


def main():
parser = argparse.ArgumentParser(
description=__doc__,
Expand All @@ -135,7 +135,7 @@ def main():
args.sort_file), "graph.info"), "w") as fptr:
cellsOnCell = mesh["cellsOnCell"].values

ncells = mesh.dims["nCells"]
ncells = mesh.sizes["nCells"]
nedges = np.count_nonzero(cellsOnCell) // 2

fptr.write(f"{ncells} {nedges}\n")
Expand All @@ -152,15 +152,15 @@ def main():
def _sort_fwd(data, fwd):
"""
Apply a forward permutation to a mesh array
Parameters
----------
data : array-like
An MPAS mesh array to permute
fwd : numpy.ndarray
An array of integers defining the permutation
An array of integers defining the permutation
Returns
-------
data : numpy.ndarray
Expand All @@ -174,15 +174,15 @@ def _sort_fwd(data, fwd):
def _sort_rev(data, rev):
"""
Apply a reverse permutation to a mesh array
Parameters
----------
data : array-like
An MPAS mesh array to permute
rev : numpy.ndarray
An array of integers defining the permutation
An array of integers defining the permutation
Returns
-------
data : numpy.ndarray
Expand All @@ -197,17 +197,17 @@ def _sort_rev(data, rev):
def _cell_del2(mesh):
"""
Form cell-to-cell sparse adjacency graph
Parameters
----------
mesh : xarray.Dataset
A dataset containing an MPAS mesh to sort
Returns
-------
del2 : scipy.sparse.csr_matrix
The cell-to-cell adjacency graph as a sparse matrix
"""
"""
xvec = np.array([], dtype=np.int8)
ivec = np.array([], dtype=np.int32)
jvec = np.array([], dtype=np.int32)
Expand Down Expand Up @@ -236,6 +236,6 @@ def _cell_del2(mesh):

return csr_matrix((xvec, (ivec, jvec)))


if (__name__ == "__main__"):\
main()
12 changes: 6 additions & 6 deletions conda_package/mpas_tools/ocean/moc.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ def _extract_southern_boundary(mesh, mocMask, latBuffer, logger):
boundary.
"""

nCells = mesh.dims['nCells']
nEdges = mesh.dims['nEdges']
nCells = mesh.sizes['nCells']
nEdges = mesh.sizes['nEdges']

nRegions = mocMask.dims['nRegions']
assert(mocMask.dims['nCells'] == nCells)
nRegions = mocMask.sizes['nRegions']
assert(mocMask.sizes['nCells'] == nCells)

# convert to python zero-based indices
cellsOnEdge = mesh.variables['cellsOnEdge'].values-1
Expand Down Expand Up @@ -241,8 +241,8 @@ def _add_transects_to_moc(mesh, mocMask, southernBoundaryEdges,

nTransects = len(southernBoundaryEdges)

nEdges = mesh.dims['nEdges']
nVertices = mesh.dims['nVertices']
nEdges = mesh.sizes['nEdges']
nVertices = mesh.sizes['nVertices']

maxEdgesInTransect = numpy.amax([len(southernBoundaryEdges[iTransect])
for iTransect in range(nTransects)])
Expand Down

0 comments on commit d9faf39

Please sign in to comment.