Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions src/climatebenchpress/compressor/plotting/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
_COMPRESSOR2LINEINFO = [
("jpeg2000", ("#EE7733", "-", "o")),
("sperr", ("#117733", ":", "s")),
("zfp-round", ("#DDAA33", "--", "D")),
("zfp", ("#EE3377", "--", "^")),
("sz3-abs", ("#CC3311", "-.", "p")),
("sz3", ("#CC3311", "-.", "v")),
("bitround-pco", ("#0077BB", ":", "P")),
("bitround", ("#33BBEE", "-", "X")),
("stochround-pco", ("#BBBBBB", "--", "d")),
("stochround", ("#009988", "--", "h")),
("tthresh", ("#882255", "-.", "<")),
("ebcc-abs", ("#AA4444", "-.", ">")),
("ebcc", ("#AA4444", "-.", "8")),
]


def _get_lineinfo(compressor: str) -> tuple[str, str, str]:
"""Get the line color, style, and marker for a given compressor."""
for comp, (color, linestyle, marker) in _COMPRESSOR2LINEINFO:
if compressor.startswith(comp):
return color, linestyle, marker
raise ValueError(f"Unknown compressor: {compressor}")


_COMPRESSOR2LEGEND_NAME = [
("jpeg2000", "JPEG2000"),
("sperr", "SPERR"),
("zfp-round", "ZFP-ROUND"),
("zfp", "ZFP"),
("sz3-abs", "SZ3-Abs"),
("sz3", "SZ3"),
("bitround-pco", "BitRound + PCO"),
("bitround", "BitRound + Zstd"),
("stochround-pco", "StochRound + PCO"),
("stochround", "StochRound + Zstd"),
("tthresh", "TTHRESH"),
("ebcc-abs", "EBCC-Abs"),
("ebcc", "EBCC"),
]

DISTORTION2LEGEND_NAME = {
"Relative MAE": "Mean Absolute Error",
"Relative DSSIM": "DSSIM",
"Relative MaxAbsError": "Max Absolute Error",
"Relative SpectralError": "Spectral Error",
}


def _get_compressor_legend_name(compressor: str) -> str:
"""Get the legend name for a given compressor."""
for comp, name in _COMPRESSOR2LEGEND_NAME:
if compressor.startswith(comp):
return name

return compressor # Fallback to the compressor name if not found in the mapping.
12 changes: 10 additions & 2 deletions src/climatebenchpress/compressor/plotting/error_dist_plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ def compute_errors(self, compressor, ds, ds_new, var, err_bound_type):
if "-pco" in compressor:
return

if "-abs" in compressor and err_bound_type == "abs_error":
# The compressors with a "-abs" suffix are versions of compressors
# that have their relative error bound option removed. For absolute
# error bounds, the errors are the same as their non "-abs" counterparts.
return

error = robust_error(ds[var], ds_new[var])
if err_bound_type == "abs_error":
error = error.compute().values
Expand Down Expand Up @@ -60,10 +66,12 @@ def plot_error_bound_histograms(
# We only plot bitround and stochround once because the lossless compressor
# does not change the error plot distribution. Hence, we ignore the PCO
# compressors here.
compressors = [comp for comp in compressors if "-pco" not in comp]
compressors = [
comp for comp in compressors if "-pco" not in comp and "-abs" not in comp
]
for var in variables:
for comp in compressors:
color, linestyle = get_line_info(comp)
color, linestyle, _ = get_line_info(comp)
label = get_legend_name(comp)
# Don't state the lossless compressor in the legend.
if label.startswith("BitRound"):
Expand Down
Loading
Loading