Topo & The Widgets!
This document explains the widget modules in mom6_bathy.
mom6_bathy comes with three UI modules/classes that wrap the three main
classes—VGrid, Grid, and Topo—to help with creating vertical grids
(VGridCreator), horizontal grids (GridCreator), and editing topography
(TopoEditor).
Creators
The creators act as visual wrappers around the constructors of their respective
classes, providing sliders and visualizations. They automatically generate
folders called VgridLibrary and GridLibrary to store created grids.
The currently selected grid is directly accessible as an object inside each
creator.
Topo & TopoEditor Edits
The Topo & TopoEditor workflow is a bit more nuanced.
Grids are simple: they are created once and rarely modified. Topo objects,
however, are built on top of the horizontal grid and are heavily edited during
the development cycle (filling bays, deepening ridges, etc.).
Because of this, Topo has many editing functions. TopoEditor provides a
visual, point-and-click interface on top of these functions.
Current editing functions (* = available in TopoEditor):
*Edit depth at a specific point*Edit the minimum depth*Erase a basin at a selected point*Erase every basin except the one containing the selected pointGenerate and apply an ocean mask from a land-fraction dataset
Apply a ridge to the bathymetry
You can also reapply an initializer (none supported in the TopoEditor):
Set flat bathy
Set spoon bathy
Set bowl bathy
Set from dataset
Set from previous topo object
Undo & Redo
To support the iterative editing process, we provide undo and redo
functionality across sessions. This requires maintaining a structured history,
stored inside a directory associated with your Topo object.
This folder contains:
The grid underlying the topo
The original blank topo
A permanent command history
Layout of a Topo folder.
Structure of the command history JSON file.
How It Works
You create your
Topoobject, which initializes the four files above.You make changes using
TopoorTopoEditor.Each change is added to history.
Each change is then committed via Git—this powers undo/redo.
Topo Git Functionality and How to Use It
We use Git to implement undo/redo functionality inside the topo directory.
You can view the history with:
git log
The command history is a JSON file mapping commit SHAs to change metadata. You can cross-reference the Git log with this JSON file to inspect details of each edit.
We also support simple version-control actions:
topo.tcm.create_branch("branchname")— create a branchtopo.tcm.checkout("branchname")— switch branchestopo.tcm.tag("tagname")— create a tag and save atagname_topog.ncfile
Tags cannot be checked out (this can cause unexpected states).
Undo and redo:
topo.tcm.undo()topo.tcm.redo()
These appear in the Git log as:
UNDO-<sha>REDO-<sha>
Be careful not to undo your initial set-function!
Warning
Do not run Git commands inside this folder except for harmless commands like git log.
We manage the folder internally. External Git commands (like git checkout)
may break state management.
Example git log for a topo editing session.
Nuances (Initialization, Naming, etc.)
Folders are named after the hash of the grid’s tlon variable.
This means that any topo using the same grid will share the same folder.
You can initialize Topo in three ways:
Topo()— creates an empty topo with the provided minimum depthTopo.from_version_control(path)— loads a folder, applies saved history, and returns the reconstructed topoTopo.from_topo_file(file)— loads a topo file and applies it on top of any existing changes in the folder
All of the git versioning (undo, redo, reset, checkout, tag, create branch) is handled by the TopoCommandManager, which can be accessed as the class variable “tcm”. The code for this manager resides in the command_manager class. We would use straight git functions, but the topo file itself is handled independently of the commits. (In the future, expect this to use icechunk)
See also the demonstration notebook: