Skip to content

added a method to get discrete colour from dataset config#1286

Merged
JustinElms merged 21 commits intomasterfrom
Discrete_Colourmap_Range
Mar 23, 2026
Merged

added a method to get discrete colour from dataset config#1286
JustinElms merged 21 commits intomasterfrom
Discrete_Colourmap_Range

Conversation

@Shasan634
Copy link
Copy Markdown
Contributor

@Shasan634 Shasan634 commented Mar 10, 2026

Background: Discrete Colormap Range Support

Ocean Navigator had no proper support for discrete/categorical variables (like seabed lithology or potential sub-surface channels) that represent distinct named categories rather than a continuous numeric range.

Previously these variables were:

Rendered with continuous color interpolation, which visually blurred distinct category boundaries
Displayed with a generic numeric colorbar that gave no indication of what each color meant
Controlled by min/max range inputs and an "Auto Range" toggle, which are meaningless for discrete categories
The "Potential Sub Surface Channel" colormap had its labels hardcoded directly in tile.py

Fix

Added map_colors and legend_labels properties to VariableConfig in dataset_config.py, reading per-variable color lists and human-readable category names from the dataset config files
Moved colormap color definitions out of hardcoded Python into the dataset config (e.g. psubsurfacechannel, lithology), making it data-driven

Rendering (Map, Tile, Hovmöller plots):

When a variable has legend_labels, rendering now uses BoundaryNorm instead of linear normalization, this produces sharp, discrete color boundaries rather than smooth gradients
The colorbar now shows the category names as tick labels instead of raw numbers, across map plots, tile scale bars, and Hovmöller plots

Frontend (UI):
ScaleViewer: when a variable has both legend_labels and map_colors, the range slider is replaced with a proper color swatch legend showing each category's color and name
AreaWindow: the "Auto Range" checkbox and manual range inputs are hidden entirely for discrete variables
api_v2_0: map_colors and legend_labels are now exposed through the variables API endpoint so the frontend can consume them

Checks

  • I ran unit tests.
  • I've tested the relevant changes from a user POV.
  • I've formatted my Python code using black ..

Hint To run all python unit tests run the following command from the root repository directory:

bash run_python_tests.sh

@Shasan634 Shasan634 requested a review from JustinElms as a code owner March 10, 2026 16:10
@Shasan634 Shasan634 self-assigned this Mar 12, 2026
@Shasan634 Shasan634 added enhancement Javascript Python Code Quality Anything related to the quality of the code labels Mar 18, 2026
Comment thread plotting/tile.py Outdated
Comment thread plotting/colormap.py Outdated
@JustinElms
Copy link
Copy Markdown
Contributor

JustinElms commented Mar 19, 2026

Great start overall! A couple more thoughts in addition to the suggestions above:

  • The categorical colorbars on plots can be very crowded. Using a legend instead might be better for presentation.
  • the legend_labels key might not be very clear to users. I'd rename it to something like data_categories or something similar so it's obvious that the variable is categorical that anyone working on the codebase.
  • It doesn't make sense to compare continuous data variables to categorical ones so it might be a good idea to hide these options in dataset compare mode.
  • If the selected variable is categorical then we can just hide the expand button and colormap range panel in the scale viewer. It doesn't make sense to put a legend there too since that info is already provided by the colorbar.

JustinElms
JustinElms previously approved these changes Mar 23, 2026
@JustinElms JustinElms merged commit cf9e899 into master Mar 23, 2026
7 checks passed
@JustinElms JustinElms deleted the Discrete_Colourmap_Range branch March 23, 2026 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Code Quality Anything related to the quality of the code enhancement Javascript Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants