-
Notifications
You must be signed in to change notification settings - Fork 2
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
base: main
Are you sure you want to change the base?
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 |
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_collection
module pretty closely. The cartopy approach split the collections betweenpcolor
andpcolormesh
call for patches that cross projection boundaries, becausepcolormesh
does 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
MPASCollection
object, following catropy's approach, which has take special care to define aMPASCollection.set_array
method so that the collection array can be updated (i.e. for animating) while doing the bookkeeping need for periodic mirroring under the hood.