[FIX] Report figures: consistent fonts via figsize↔slot, smaller files, paginated multipanels, clock ±30 / stage1 - #70
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Report figures had small, inconsistent fonts and large files because there was no mapping between a figure's rendered width and its display slot: figures were drawn at arbitrary 12–14 in widths, then CSS capped them to
max-width:50%/33%, so a half-slot figure downscaled ~0.43 (not the intended ~0.80) and a 12 pt label showed at ~8 px. This branch introduces a figsize↔slot convention so onefont.sizerenders at one on-screen size everywhere, cuts figure bytes with palette-quantized PNGs, paginates tall multipanel figures so they stop overflowing PDF pages, and fixes several specific figure bugs (clock-alignment window, start/end window data source). It also removes one piece of dead plotting code.Figure sizing and fonts
Added slot-width constants to
oceanarray/config/parameters.py—W_FULL=9.0,W_TWOTHIRDS=6.0,W_HALF=4.5,W_THIRD=3.0(inches; width only, height stays content-driven). Every figure now sets its width from the constant matching its CSS display slot, sodisplay_px / png_inis constant across the report and fonts are consistent at every slot.Swept ~24 hardcoded
figsize=values acrossplotters/current.py,ts.py,spectrum.py,primitives.py,hydrography.pyanddiagnostic.pyonto the slot constants, and removed scattered per-figurefontsize=overrides so the mplstyle governs type size.Updated
oceanarray/oceanarray.mplstyleto a single consistent type scale —axes.titlesize 12,axes.labelsize/xtick/ytick 10,font.size 10,legend.fontsize 9— plusaxes.linewidth 0.6and explicit grid/contour line settings.savefig.dpi: 150is retained in the mplstyle as the single source of truth for figure dpi, and the previousREPORT_FIG_DPI = 110override in_fig_to_base64(which silently shadowed it — figures were rendering at 110, not 150) is gone. dpi is a size/crispness knob only; displayed font size is set by the figsize↔slot ratio and is dpi-independent.Smaller figure files
_fig_to_base64now composites each figure onto white and quantizes it to a 256-colour palette PNG. Report figures are few-colour by construction (line art plus discrete colorbars, which the project already mandates), so indexed PNG is ~visually lossless here and cuts figure bytes roughly 3×, the dominant lever on report and PDF size. Adds an explicitpillow>=9.0entry torequirements.txt(matplotlib already pulls it in).Paginated multipanel figures (report-figures #3 / #10)
Tall instrument figures were overflowing PDF pages (a single
<img>cannot split across pages)._build_fig_from_dsnow accepts apanels=subset;_make_instrument_figreturns a list of base64 PNGs, chunking panels into images of at most_MAX_TS_PANELS(5) each, and the instrument template loops over them. Per-panel height dropped 3.0 → 2.0 so a 5-panel image fits one page without vertical squish.The same treatment was applied to the start/end windows figure:
draw_windowsgained apanels=subset arg and now renders atW_FULLwith per-panel height 2.0;_make_windows_figreturns a paginated list; the template loops. Each row is a half-width "First 6 h" panel beside a half-width "Last 6 h" panel.The
img.fig { max-height: 22cm }print cap remains as a backstop for any figure that still exceeds a page.Clock-alignment check (report-figures #4)
plot_clock_offset_checknow centres its zoom windows on the deployment and recovery times (±30 min, was 10), and normalises each plotted instrument trace over the plotted window as(x − mean) / stdso traces of different amplitude overlay comparably; the y-axis is labelled in standard deviations. The Tier-3 wrapper_make_clock_check_b64default was corrected from 10 to 30 (it had been shadowing the plotter default).Start/end windows use stage-1 data
MooringReport._clock_nc_pathsand the windows figure now prefer the untrimmed_stage1.ncover stage2/3, falling back only if stage1 is absent. stage2/3 are trimmed to the deployment window, which removes exactly the pre-deploy / post-recover data the ±window check needs to show the deployment/recovery transient; raw clocks also expose the real inter-instrument offsets before correction.Dead code removal
Removed
draw_isopycnal_fig(an unwired time × pressure iso-sigma contour figure with no call site) together with its Tier-3 wrapper_make_isopycnal_fig_b64, the now-orphanedfilter_sigma_tukeyandpressure_axisimports, its threeplotters/__init__.pyexport references, and stale migration notes inspectrum.py. The grid report's "Isopycnal height above seabed" section is unaffected — it is drawn by the separate, still-wireddraw_isopycnal_ts_fig.Testing
Full suite: 739 passed, 4 skipped. ruff check and ruff format clean.
test_plot_guard.pyupdated so_make_instrument_figand_make_windows_figassert a non-empty list (they now paginate). Rendered the dune2 fixture to HTML + combined PDF and visually verified pagination, half-width window columns, and figure crispness.Breaking changes
oceanarray.plotters.draw_isopycnal_figremoved. It was exported inplotters.__all__but was dead code with no call site. Migration: none required; nothing called it. The wired isopycnal figuredraw_isopycnal_ts_figis unchanged.Report HTML output changes shape: the instrument time-series and start/end-windows sections now emit one or more
<img>per section (paginated) rather than a single image. Anything that scraped a fixed single figure per section must handle a list.