Skip to content

Commit

Permalink
Merge pull request #233 from cbegeman/enhance-tracer-test-viz
Browse files Browse the repository at this point in the history
Enhance spherical tracer transport test viz

Add options for over/under colors for the colormap used in spherical mpas visualization. These were added to be able to more conveniently visualize over and undershoots in the tracer advection scheme tested in the sphere_transport tests.
  • Loading branch information
cbegeman authored Oct 1, 2024
2 parents 563b1f8 + accf5df commit 002293c
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 1 deletion.
6 changes: 6 additions & 0 deletions docs/developers_guide/framework/visualization.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,13 @@ colormap).

The `colorbar_limits` are the lower and upper bound of the colorbar range.

There are also two optional config options used to set the colors on either end of the colormap:

```cfg
# [optional] colormap set_under and set_over options
under_color = k
over_color = orange
```
### plotting from lat/lon grids

You can use {py:func}`polaris.viz.plot_global_lat_lon_field()` to plot a field
Expand Down
4 changes: 4 additions & 0 deletions docs/developers_guide/ocean/tasks/correlated_tracers_2d.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ each resolution. The colormap is controlled by these options:
# colormap
colormap_name = viridis
# [optional] colormap set_under and set_over options
under_color = k
over_color = orange
# the type of norm used in the colormap
norm_type = linear
Expand Down
4 changes: 4 additions & 0 deletions docs/developers_guide/ocean/tasks/divergent_2d.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ each resolution. The colormap is controlled by these options:
# colormap
colormap_name = viridis
# [optional] colormap set_under and set_over options
under_color = k
over_color = orange
# the type of norm used in the colormap
norm_type = linear
Expand Down
4 changes: 4 additions & 0 deletions docs/developers_guide/ocean/tasks/nondivergent_2d.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ each resolution. The colormap is controlled by these options:
# colormap
colormap_name = viridis
# [optional] colormap set_under and set_over options
under_color = k
over_color = orange
# the type of norm used in the colormap
norm_type = linear
Expand Down
4 changes: 4 additions & 0 deletions docs/developers_guide/ocean/tasks/rotation_2d.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ each resolution. The colormap is controlled by these options:
# colormap
colormap_name = viridis
# [optional] colormap set_under and set_over options
under_color = k
over_color = orange
# the type of norm used in the colormap
norm_type = linear
Expand Down
4 changes: 4 additions & 0 deletions polaris/ocean/tasks/sphere_transport/sphere_transport.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ slotted_cylinders_amplitude = 1.0
# colormap
colormap_name = viridis

# [optional] colormap set_under and set_over options
under_color = k
over_color = orange

# the type of norm used in the colormap
norm_type = linear

Expand Down
10 changes: 9 additions & 1 deletion polaris/viz/spherical.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import matplotlib.colors as cols
import matplotlib.pyplot as plt
import uxarray as ux
from matplotlib import cm
from mpl_toolkits.axes_grid1.inset_locator import inset_axes
from pyremap.descriptor.utility import interp_extrap_corner

Expand Down Expand Up @@ -81,6 +82,13 @@ def plot_global_mpas_field(mesh_filename, da, out_filename, config,
projection = cartopy.crs.PlateCarree(central_longitude=central_longitude)

colormap = config.get(colormap_section, 'colormap_name')
cmap = cm.get_cmap(colormap)
if config.has_option(colormap_section, 'under_color'):
under_color = config.get(colormap_section, 'under_color')
cmap.set_under(under_color)
if config.has_option(colormap_section, 'over_color'):
over_color = config.get(colormap_section, 'over_color')
cmap.set_over(over_color)

norm_type = config.get(colormap_section, 'norm_type')
if norm_type == 'linear':
Expand All @@ -94,7 +102,7 @@ def plot_global_mpas_field(mesh_filename, da, out_filename, config,
dtype=float)

plot = gdf_data.hvplot.polygons(
c=da.name, cmap=colormap, logz=logz,
c=da.name, cmap=cmap, logz=logz,
clim=tuple(colorbar_limits),
clabel=colorbar_label,
width=1600, height=800, title=title,
Expand Down

0 comments on commit 002293c

Please sign in to comment.