-
Notifications
You must be signed in to change notification settings - Fork 2
Mirror patches across periodic boundaries #29
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
Mirror patches across periodic boundaries #29
Conversation
Not really the "origin" but the lower left corner of the figure.
Testing:import mosaic
import matplotlib.pyplot as plt
def test_periodic(descriptor, ds, loc):
fig, ax = plt.subplots()
lc = mosaic.polypcolor(ax, descriptor, ds.indexToCellID * 0.0, ec='k', cmap='binary', zorder=0)
pc = mosaic.polypcolor(ax, descriptor, ds[f"indexTo{loc}ID"], alpha=0.5, ec='tab:orange')
ax.scatter(ds[f"x{loc}"], ds[f"y{loc}"], color="tab:blue")
ax.set_title(f"{loc} Patches")
ax.set_aspect("equal")
fig.savefig(f”mirror/{loc}.png", dpi=300, bbox_inches='tight’)
return ax, pc, lc
ds = mosaic.datasets.open_dataset("doubly_periodic_4x4")
descriptor = mosaic.Descriptor(ds)
for loc in ["Cell", "Edge", "Vertex"]:
ax, pc, lc = test_periodic(descriptor, ds, loc)
plt.show()Cell:Edge:Vertex: |
Testing (cont).Here's an example of using the import mosaic
import matplotlib.animation as animation
import matplotlib.pyplot as plt
ds = mosaic.datasets.open_dataset("doubly_periodic_4x4")
descriptor = mosaic.Descriptor(ds)
fig, ax = plt.subplots(constrained_layout=True)
pc = mosaic.polypcolor(ax, descriptor, ds.indexToCellID, alpha=0.5, ec='k')
def update(frame):
pc.set_array(ds.indexToCellID - frame)
return(pc, )
ani = animation.FuncAnimation(fig=fig, func=update, frames=10, interval=500) |
|
Once |
|
I've come back to this PR, in hopes to get it merged in time to be included in the I had continued the testing this PR by running the "baroclinic channel" test case from I was able to confirm the It turns out that the |
| vmin = kwargs.pop('vmin', None) | ||
| vmax = kwargs.pop('vmax', None) | ||
| norm = kwargs.pop('norm', None) | ||
|
|
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.
By using the pop method, we were removing the entry from the kwargs dictionary. Which means we this was forwarded along to the _mirror_polycollection call below the entries here were all none.
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.
But, PolyCollection does not accept these arguments, which is why there were originally poped.
So we still need to pop but then repack before the _mirror_polycollection so that all the kwargs are consistent.
|
This now works successfully for the "baroclinic channel" testcase. As for the examples shown above. I've added unit test which should catch the inconsistent color limits I was dealing with earlier. @xylar If you have other ideas about how to further test this PR, they be appreciated. Otherwise a look over would be appreciated! |
xylar
left a comment
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.
@andrewdnolan, this looks great to me. I looked through the code and I think your testing is sufficient. Please merge when ready.





This PR add the ability to mirror patch across periodic boundaries for planar periodic meshes. With this feature added we have the "full" periodic effect when plotting.
Much of the implementation of this PR follows the
cartopy.mpl.geo_collectionmodule pretty closely. The cartopy approach split the collections betweenpcolorandpcolormeshcall for patches that cross projection boundaries, becausepcolormeshdoes not support nan's in the coordinate array. Our need to keeping two collections is a little different thancartopy.We instead keep track of a second collection, which is the mirrored patches, and the associated indices to enable plotting. We have created our own
MPASCollectionobject, following catropy's approach, which has take special care to define aMPASCollection.set_arraymethod so that the collection array can be updated (i.e. for animating) while doing the bookkeeping need for periodic mirroring under the hood.