Skip to content

Foundation/phase3 global defaults#34

Merged
shaia merged 12 commits intomasterfrom
foundation/phase3-global-defaults
Mar 7, 2026
Merged

Foundation/phase3 global defaults#34
shaia merged 12 commits intomasterfrom
foundation/phase3-global-defaults

Conversation

@shaia
Copy link
Copy Markdown
Owner

@shaia shaia commented Mar 7, 2026

No description provided.

shaia added 7 commits March 7, 2026 13:57
…ot_context)

Centralized plotting defaults so researchers can set preferences once
instead of passing cmap/figsize/dpi to every function call. Supports
context manager for temporary overrides and optional TOML config files.
Replace hardcoded cmap/levels defaults with UNSET sentinel and
resolve() calls so they respect set_defaults() and plot_context().
…faults

Replace hardcoded cmap/levels/figsize/fontsize/colormap defaults with
UNSET sentinel and resolve() calls.
…ults

Replace hardcoded figsize/cmap/levels with UNSET+resolve() or
get_defaults() for inline values.
…ults

Replace hardcoded cmap/levels/figsize/dpi defaults with UNSET+resolve()
for parameters and get_defaults() for inline values.
Replace hardcoded Plotly colorscale defaults with UNSET+resolve() for
parameters and get_defaults() for inline colorscale values.
Tests that set_defaults(), plot_context(), and per-field cmap resolution
(cmap, diverging_cmap, sequential_cmap) are correctly picked up by
plotting functions.
@shaia shaia requested a review from Copilot March 7, 2026 14:06
@shaia shaia self-assigned this Mar 7, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Introduces a centralized global defaults system for plotting/visualization so callers can configure colormaps, sizing, DPI, etc. once (optionally via TOML) and have plotting/animation/interactive helpers pick those up consistently.

Changes:

  • Added cfd_viz.defaults with PlotDefaults, set_defaults/get_defaults/reset_defaults, plot_context, load_config_file, and UNSET/resolve sentinel-based parameter resolution.
  • Updated multiple Matplotlib/Plotly plotting and animation entry points to default to UNSET and resolve from global defaults.
  • Added a comprehensive test suite validating default behavior, config loading, and that selected plotting functions respect the global defaults.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
cfd_viz/defaults.py New global defaults implementation, including TOML config loading and a context manager for temporary overrides.
cfd_viz/__init__.py Re-exports defaults API (set_defaults, plot_context, etc.) at the package root.
cfd_viz/quick.py Uses UNSET + resolve() so figsize comes from global defaults when not explicitly provided.
cfd_viz/plotting/fields.py Resolves levels/cmap from global defaults rather than hard-coded values.
cfd_viz/plotting/line_plots.py Resolves colormap parameters from global defaults.
cfd_viz/plotting/time_series.py Resolves figsize and applies global defaults to some contour plots.
cfd_viz/plotting/analysis.py Resolves figsize/cmap/levels/fontsize from global defaults.
cfd_viz/interactive/plotly.py Resolves Plotly colorscale and uses global defaults in dashboard creation.
cfd_viz/animation/renderers.py Resolves figsize/cmap/levels and applies global defaults in multi-panel animations.
cfd_viz/animation/export.py Resolves figsize/dpi and applies global defaults for colormaps in exports.
tests/test_defaults.py New tests covering defaults API, TOML loading, context manager behavior, and integration with key plotting functions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

shaia added 3 commits March 7, 2026 16:22
Calling matplotlib.use("Agg") after importing pyplot can be
ineffective or raise warnings depending on the backend state.
plot_context() now uses a contextvars.ContextVar for context-local
overrides instead of mutating and restoring the global _defaults.
This prevents concurrent set_defaults() calls from being silently
overwritten when the context exits.
…port.py

The initial migration missed inline contourf levels in
export_frame_to_image and export_analysis_frame, so
set_defaults(levels=...) had no effect on exported frames.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

shaia added 2 commits March 7, 2026 17:09
load_config_file() needs a TOML parser but tomllib is only available
in Python 3.11+. Add tomli as a fallback for older Python versions.
@shaia shaia merged commit 79c4898 into master Mar 7, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants