Skip to content

Add script to convert cell coordinates from plane to sphere#675

Open
matthewhoffman wants to merge 5 commits intoMPAS-Dev:masterfrom
matthewhoffman:landice/convert-cellcoords-to-sphere
Open

Add script to convert cell coordinates from plane to sphere#675
matthewhoffman wants to merge 5 commits intoMPAS-Dev:masterfrom
matthewhoffman:landice/convert-cellcoords-to-sphere

Conversation

@matthewhoffman
Copy link
Member

Script to allow plotting MALI output on a sphere in Paraview. This works by replacing x/y/zCell fields and modifying global attributes so Paraview will plot as a spherical mesh. Paraview only uses those 3 fields for plotting. Plotting MALI output on a sphere allows it to be visualized with output from other E3SM components (e.g. MPAS-Ocean).

I placed it in landice/mesh_tools_li because it modifies a mesh, even though we are likely to primarily use it on output files.

@matthewhoffman
Copy link
Member Author

Example of plotting ice speed from the MALI 4km AIS mesh on a sphere overlaid on bottom depth from MPAS-Ocean:
image

@matthewhoffman matthewhoffman force-pushed the landice/convert-cellcoords-to-sphere branch 4 times, most recently from 1d6c296 to 8ae8405 Compare September 5, 2025 23:33
@matthewhoffman
Copy link
Member Author

Using optional surface warping:

image

Copy link
Collaborator

@trhille trhille left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this very useful script, @matthewhoffman. I think we want to avoid editing files in-place because we can imagine a nightmare scenario in which someone inadvertently overwrites one of the mesh files in our database, so almost all of my comments have to do with that.

from another file and set on_a_sphere back to NO.
Note that the modified coordinates will make the file no longer compatible
with MALI or many postprocessing tools, so this is meant as a modification
for visuatlization in Paraview only.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for visuatlization in Paraview only.
for visualization in Paraview only.

This works by replacing x/y/zCell fields and modifying global attributes so
Paraview will plot as a spherical mesh. Paraview only uses those 3 fields for
plotting.
The script modifies the file in place, so be sure to make a copy first!
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's get rid of this in favor of writing to a new output file. Otherwise we run the risk of someone inadvertently overwriting the mesh files in our database.

bedTopography = ds.variables['bedTopography'][0,:]
sfc = np.maximum(bedTopography + thickness,
(1.0 - 910.0 / 1028.0) * thickness)
#sfc = thickness + np.minimum(bedTopography, 0.0) * 1028.0 / 910.0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

@matthewhoffman
Copy link
Member Author

@trhille , thanks for the review - those are all good suggestions. Copilot implemented the requested changes and I tweaked them slightly.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new landice utility script to rewrite MPAS/MALI cell-center coordinates into spherical XYZ (optionally with surface warping) so NetCDF output can be rendered on a sphere in ParaView, and documents the workflow in the landice visualization docs.

Changes:

  • Add convert_cell_coordinates_to_sphere.py to copy an input NetCDF file and replace xCell/yCell/zCell, setting sphere-related global attributes.
  • Support optional surface warping based on upperSurface or thickness + bedTopography.
  • Document usage in conda_package/docs/landice/visualization.rst.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
landice/mesh_tools_li/convert_cell_coordinates_to_sphere.py New script to convert xCell/yCell/zCell to spherical coordinates (with optional warped radius) and set sphere attributes for ParaView rendering.
conda_package/docs/landice/visualization.rst Adds a new section describing how to use the conversion script for spherical ParaView rendering.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

matthewhoffman and others added 5 commits March 12, 2026 21:03
Script to allow plotting MALI output on a sphere in Paraview.
This works by replacing x/y/zCell fields and modifying global attributes so
Paraview will plot as a spherical mesh.  Paraview only uses those 3 fields for
plotting.
Enhance spherical coordinate conversion script:
* don't overwrite input file
* clean up to comments and docstring
* addition of documentation section
* error message when required fields are missing
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@matthewhoffman matthewhoffman force-pushed the landice/convert-cellcoords-to-sphere branch from 423b123 to a24eeea Compare March 13, 2026 03:04
@matthewhoffman
Copy link
Member Author

Rebased because CI was stuck and I thought that might help.

@trhille , I think this is ready to merge unless you see anything else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants