-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dual Mesh Construction #859
base: main
Are you sure you want to change the base?
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 |
@@ -0,0 +1,353 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using UXarray we can construct the dual mesh using grid.compute_dual()
, which returns a new grid object.
Reply via ReviewNB
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You want me to replace everything with just this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, meant only the final portion.
@@ -0,0 +1,353 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use the .relabel()
method with a legend for this instead?
Below is an example:
Reply via ReviewNB
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.relabel()
doesn't seem to work when combining plots of lines. It works in your notebook because everything you combined are points. Do you know how to make it work for actual grid plots? @philipc2
…into zedwick/dual_mesh
is this good to go? |
Closes #825
Overview
Constructs the dual mesh of a grid using
face_centers
andnode_face_connectivity
Expected Usage
PR Checklist
General
Testing
Documentation
_
) and have been added todocs/internal_api/index.rst
docs/user_api/index.rst