Repository navigation
Dual Mesh Construction - #859
Conversation
|
@philipc2 Thoughts on the API? Currently, I return a |
This type of implementation is what I was envisioning, since we don't want anything to be replaced in-place when creating the dual grid. Let's name it something like |
|
We should add functionality that can also convert a |
|
This was the block that we were able to get working in the Notebook. import uxarray as ux
from uxarray.constants import INT_DTYPE, INT_FILL_VALUE
import numpy as np
uxgrid = ux.open_grid("/Users/philipc/uxarray-gold/uxarray-gold/uxarray/test/meshfiles/geos-cs/c12/test-c12.native.nc4")
lonlat_t = [(lon, lat) for lon, lat in zip(uxgrid.node_lon.values, uxgrid.node_lat.values)]
# # Dictionary to track first occurrence and subsequent indices
occurrences = {}
# Iterate through the list and track occurrences
for index, tpl in enumerate(lonlat_t):
if tpl in occurrences:
occurrences[tpl].append((INT_DTYPE(index)))
else:
occurrences[tpl] = [INT_DTYPE(index)]
duplicate_dict = {}
for tpl, indices in occurrences.items():
if len(indices) > 1:
source_idx = indices[0]
for duplicate_idx in indices[1:]:
duplicate_dict[duplicate_idx] = source_idx
new_face_node_connectivity = uxgrid.face_node_connectivity.values.copy().ravel()
for idx, item in enumerate(new_face_node_connectivity):
# O(1)
if item in duplicate_dict:
new_face_node_connectivity[idx] = duplicate_dict[item]
new_face_node_connectivity = new_face_node_connectivity.reshape((uxgrid.n_face, uxgrid.n_max_face_nodes))
node_face_conn = {node_i: [] for node_i in range(uxgrid.n_node)}
for face_i, face_nodes in enumerate(new_face_node_connectivity):
for node_i in face_nodes:
if node_i != ux.INT_FILL_VALUE:
node_face_conn[node_i].append(face_i)
n_max_node_faces = -1
for face_indicies in node_face_conn.values():
if len(face_indicies) > n_max_node_faces:
n_max_node_faces = len(face_indicies)
node_face_connectivity = np.full((uxgrid.n_node, n_max_node_faces), INT_FILL_VALUE)
for node_idx, face_indices in enumerate(node_face_conn.values()):
n_faces = len(face_indices)
node_face_connectivity[node_idx, 0:n_faces] = face_indices
new_uxgrid = ux.Grid.from_topology(uxgrid.node_lon.values,
uxgrid.node_lat.values,
new_face_node_connectivity,
node_face_connectivity=node_face_connectivity)
|
|
Thanks @philipc2! I will see if I can help figure out what's going on. |
Right, it'd be better to compare the grid objects returned in each case, specifically the merged nodes part in both cases (notebook and installed versions) |
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
|
is this good to go? |
|
@philipc2 Could we get this merged? |
philipc2
left a comment
There was a problem hiding this comment.
Great work @aaronzedwick
Made some slight changes to the user guide notebook to use the updated plotting methods. Once it renders, I'll merge it.


Closes #825
Overview
Constructs the dual mesh of a grid using
face_centersandnode_face_connectivityExpected Usage
PR Checklist
General
Testing
Documentation
_) and have been added todocs/internal_api/index.rstdocs/user_api/index.rst