Skip to content

👌 Add scale_factors argument to plot_sas and 2 additional data color pairs#394

Merged
s-weigand merged 17 commits intoglotaran:mainfrom
s-weigand:new_options
Feb 15, 2026
Merged

👌 Add scale_factors argument to plot_sas and 2 additional data color pairs#394
s-weigand merged 17 commits intoglotaran:mainfrom
s-weigand:new_options

Conversation

@s-weigand
Copy link
Copy Markdown
Member

@s-weigand s-weigand commented Feb 14, 2026

This change adds the new functionality requested by @ism200 .

As discussed in the initial request, I removed the additional arguments, which can be easily achieved using data selection or changing the cycler.

The reasoning for the removal is that we should rather teach users to help themselves do basic operations than add more function arguments, which increases the cognitive load and causes option fatigue.

Thus, I added a new documentation section "Going beyond builtin" explaining the basics of data selection and how to work with cyclers.

Change summary

  • Add scale_factors argument to plot_sas for scaling control
  • Add 2 additional data color pairs
  • Add inspect_cycler utility function

Links to the changed docs sections

Checklist

  • ✔️ Passing the tests (mandatory for all PR's)
  • 📚 Adds documentation of the feature

Summary by CodeRabbit

  • New Features

    • Inspect and preview matplotlib color cycles with inline thumbnails
    • Per-species scaling option for spectral plots
    • Four new plot color choices added
  • Documentation

    • New "tips and tricks" notebook added to docs navigation with advanced plotting workflows
    • Dark-mode CSS improvements for notebook rendering
  • Chores

    • Updated project/config files and pre-commit tool versions

@s-weigand s-weigand requested a review from a team as a code owner February 14, 2026 10:46
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 14, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds documentation (dark-mode CSS, notebook), bumps dev/config files, exports a new cycler inspection utility with image previews, adds per-species SAS scaling and new plotting colors, and minor config/shell tweaks.

Changes

Cohort / File(s) Summary
Configuration & Hooks
\.pre-commit-config.yaml, pyproject.toml, justfile
Bumped pre-commit hook versions; added metadata URL and reorganized pyproject.toml (hatch, coverage, mypy overrides, docformatter); added -NoProfile to Windows PowerShell invocation in justfile.
Documentation CSS & Sphinx
docs/_static/css/mermaid_dark.css, docs/_static/css/xarray_dark.css, docs/conf.py
Fixed comment typos; added xarray dark-mode CSS overrides; registered the new dark stylesheet in Sphinx config.
Docs Navigation & Notebook
docs/index.md, docs/notebooks/tips_and_tricks.ipynb
Added notebooks/tips_and_tricks to the toctree and included a new notebook demonstrating xarray usage, plotting patterns, and cycler tips.
Cycler Inspection API
pyglotaran_extras/inspect/__init__.py, pyglotaran_extras/inspect/cycler.py
Introduced create_preview_cycler() and inspect_cycler() to render tiny Matplotlib previews, embed base64 images, and produce an HTML/Markdown preview table; exported inspect_cycler from the package namespace.
Plotting Changes
pyglotaran_extras/plotting/plot_concentrations.py, pyglotaran_extras/plotting/plot_spectra.py, pyglotaran_extras/plotting/style.py
Docstring update for default cycler; plot_sas signature adds optional `scale_factors: dict[str, float]

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant User
    participant Cycler as Cycler object
    participant Renderer as Matplotlib Renderer
    participant Encoder as Base64 Encoder
    participant Viewer as IPython/Markdown Viewer

    User->>Cycler: provide cycler styles
    Cycler->>Renderer: render tiny line plot per style (off-screen)
    Renderer->>Encoder: return image bytes (JPEG)
    Encoder->>Viewer: embed base64 image in HTML <img>
    Viewer-->>User: display markdown table with style previews
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐇 I sketch tiny lines in a burrowed byte,

base64 blooms tucked neat and light.
Dark sheets hush the table's gleam,
cyclers parade in miniature dream.
Hop, inspect, and stitch the scene.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title mentions 'scale_factors argument to plot_sas' and 'additional data color pairs' which are primary changes in the PR, but omits other significant additions like the new 'inspect_cycler' utility function and documentation notebook.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

No actionable comments were generated in the recent review. 🎉


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Feb 14, 2026

Greptile Overview

Greptile Summary

This PR adds per-species scaling functionality to plot_sas and expands color options for plotting, along with comprehensive documentation on advanced usage patterns.

Key Changes:

  • Added scale_factors parameter to plot_sas function enabling per-species scaling control
  • Added 4 new data color pairs (olive/olive4, turquoise/turquoise4) to support plotting more datasets
  • Introduced inspect_cycler utility function for visualizing matplotlib cycler properties with inline previews
  • Created comprehensive "tips and tricks" documentation notebook covering xarray data selection, cycler manipulation, and custom plot composition
  • Fixed .to_numpy() calls on species coordinates in plot_sas and plot_norm_sas for consistency
  • Fixed buffer management bug in create_preview_cycler by adding truncate() call
  • Updated pre-commit hook versions and reformatted pyproject.toml
  • Added dark mode CSS styling for xarray HTML output

Documentation Quality:
The new tutorial notebook is well-structured and pedagogical, teaching users fundamental skills (xarray operations, cycler manipulation) rather than adding more function parameters. This aligns well with the PR description's philosophy of reducing cognitive load.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • All changes are well-implemented with proper error handling, the buffer truncation bug was fixed during development, the new scale_factors parameter has sensible defaults (empty dict), and the .to_numpy() fix ensures consistent array handling. The documentation is comprehensive and adds significant value. Pre-commit hook updates are routine maintenance.
  • No files require special attention

Important Files Changed

Filename Overview
pyglotaran_extras/inspect/cycler.py New utility to inspect and preview matplotlib color cycles with inline thumbnails
pyglotaran_extras/plotting/plot_spectra.py Added scale_factors parameter to plot_sas, fixed .to_numpy() calls on species coords
pyglotaran_extras/plotting/style.py Added 4 new color choices (olive, olive4, turquoise, turquoise4) to DataColorCode enum
docs/notebooks/tips_and_tricks.ipynb Comprehensive new tutorial on data selection, cycler usage, and composing custom plots
pyglotaran_extras/inspect/init.py Exported new inspect_cycler function in public API

Flowchart

flowchart TD
    A[User calls plot_sas] --> B{scale_factors provided?}
    B -->|Yes| C[Iterate through species]
    B -->|No| C
    C --> D{species in scale_factors?}
    D -->|Yes| E[Apply scale_factor to data]
    D -->|No| F[Use original data]
    E --> G[Plot scaled species]
    F --> G
    
    H[User calls inspect_cycler] --> I[create_preview_cycler]
    I --> J[Create matplotlib figure]
    J --> K[Loop through cycler entries]
    K --> L[Plot line with style]
    L --> M[Save to BytesIO buffer]
    M --> N[Encode as base64]
    N --> O[Add to preview list]
    O --> P{More entries?}
    P -->|Yes| Q[Clear buffer with truncate]
    Q --> K
    P -->|No| R[Close figure]
    R --> S[Return cycler with previews]
    S --> T[Format as HTML table]
Loading

Last reviewed commit: 44ddd88

Copy link
Copy Markdown

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

12 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Feb 14, 2026

Additional Comments (1)

pyglotaran_extras/plotting/plot_spectra.py
Inconsistent with plot_sas - consider adding .to_numpy() for consistency

        for zorder, species in zip(range(100)[::-1], sas.coords["species"].to_numpy(), strict=False):

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 14, 2026

Codecov Report

❌ Patch coverage is 37.20930% with 27 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.19%. Comparing base (394e344) to head (6efb9bc).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
pyglotaran_extras/inspect/cycler.py 35.71% 18 Missing ⚠️
pyglotaran_extras/plotting/plot_spectra.py 0.00% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #394      +/-   ##
==========================================
- Coverage   60.70%   60.19%   -0.52%     
==========================================
  Files          29       30       +1     
  Lines        1532     1570      +38     
  Branches      212      215       +3     
==========================================
+ Hits          930      945      +15     
- Misses        582      605      +23     
  Partials       20       20              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🤖 Fix all issues with AI agents
In @.pre-commit-config.yaml:
- Line 42: The pre-commit configuration pins nbstripout to an unreleased commit
hash ("rev: 186d22f"); update the rev for the nbstripout entry in
.pre-commit-config.yaml to the latest tagged release (0.9.0) instead of the
commit hash so the hook uses the stable, reproducible tag; locate the nbstripout
entry by the package name "nbstripout" and replace the rev value accordingly.

In `@docs/notebooks/tips_and_tricks.ipynb`:
- Line 71: Fix the three minor typos in the notebook markdown cells by locating
and replacing the exact strings: change "From the fist look" to "From the first
look" (the cell containing "Result only contains a single dataset named
`dataset_1`"), change "Lucky for use" to "Lucky for us", and change "it's own
line" to "its own line"; update the corresponding markdown cells so the
corrected phrases replace the originals.
- Line 291: The variable name assigned from extract_irf_location is a typo
("if_location"); rename that variable to irf_location wherever it's assigned and
subsequently used (e.g., the statement currently "if_location =
extract_irf_location(ds)") so it matches the function and intended meaning;
update any downstream references in the same notebook cell or nearby cells to
use irf_location to avoid NameError and improve clarity.

In `@pyglotaran_extras/inspect/cycler.py`:
- Around line 38-55: The BytesIO buffer is reused in the loop and not truncated,
causing leftover bytes to corrupt subsequent JPEGs; in the loop around
fig.savefig(buffer, format="jpg") (inside the cycler iteration that builds
preview_images), ensure you reset and truncate the buffer between iterations by
seeking to 0 before savefig, then after savefig seek to 0, read the image bytes
into a local variable for the base64 encode, and then call buffer.truncate(0)
and buffer.seek(0) before the next iteration (references: buffer = io.BytesIO(),
fig.savefig(...), preview_images.append(...), ax.cla()).
🧹 Nitpick comments (1)
pyglotaran_extras/inspect/cycler.py (1)

40-41: Consider setting y to non-zero values for better line visibility in previews.

With y = [0] * 10, the line is drawn at the very bottom of the axes, which may make some line styles (especially dotted) hard to see. A midpoint value like [1] * 10 with a fixed y-range might produce clearer previews.

@s-weigand
Copy link
Copy Markdown
Member Author

@greptileai

@s-weigand
Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 14, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

12 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@docs/notebooks/tips_and_tricks.ipynb`:
- Around line 192-193: Update the markdown text to fix grammar: replace the
sentence fragment "Even so we now have a line plot this isn't what we wanted
because each point on the `spectral` \n" with "Even though we now have a line
plot this isn't what we wanted because each point on the `spectral` \n" (locate
the notebook cell containing the "Even so we now have" phrase) and change the
phrase "For data with up to two dimension" to "For data with up to two
dimensions" (locate the cell containing that exact phrase).

In `@pyproject.toml`:
- Around line 101-121: The TOML under [tool.coverage] replaces coverage.py
defaults by setting report.exclude_lines, so add "pragma: no cover" back into
report.exclude_lines or better switch to using the newer exclude_also option
(coverage >=7.13.2) which extends defaults instead of replacing them; update the
config to remove the dead comment strings (the former .coveragerc lines
currently in report.exclude_lines) and either add "pragma: no cover" to
report.exclude_lines or change to exclude_also to preserve defaults while
keeping any custom patterns you need (refer to report.exclude_lines and
exclude_also in the [tool.coverage] section and remove the TOML-embedded comment
entries).

jsnel
jsnel previously approved these changes Feb 15, 2026
Copy link
Copy Markdown
Member

@jsnel jsnel left a comment

Choose a reason for hiding this comment

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

I think the bots caught most of it, I don't see any more issues, just found a small issues about "plot_sas now mutates the input dataset when a scale factor is applied".

There's some overlap in the added documentation with the pyglotaran getting started guide so maybe at some point we can think of consolidating and/or putting in one place, or cross reference both, but better too much documentation than too little!

Copilot AI review requested due to automatic review settings February 15, 2026 09:25
Copy link
Copy Markdown

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

This PR adds enhanced plotting capabilities to pyglotaran-extras by introducing a scale_factors argument for per-species scaling in SAS plots, expanding the color palette with two new color pairs (olive/olive4 and turquoise/turquoise4), and adding a utility function to inspect plot cyclers. Additionally, it includes a comprehensive documentation notebook that teaches users how to work with the underlying libraries (xarray, matplotlib cyclers) to customize plots beyond the built-in options.

Changes:

  • Added scale_factors parameter to plot_sas for per-species amplitude scaling
  • Added 4 new color definitions (olive, olive4, turquoise, turquoise4) to DataColorCode enum
  • Added inspect_cycler utility function with preview generation for visualizing plot style cyclers

Reviewed changes

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

Show a summary per file
File Description
pyproject.toml Refactored configuration structure using nested syntax for hatch and tool settings; reorganized URL definitions alphabetically
pyglotaran_extras/plotting/style.py Added four new color codes (olive, olive4, turquoise, turquoise4) to DataColorCode enum
pyglotaran_extras/plotting/plot_spectra.py Added scale_factors parameter to plot_sas function for per-species scaling; converted coords to numpy arrays using .to_numpy()
pyglotaran_extras/plotting/plot_concentrations.py Fixed docstring to correctly state default cycler is PlotStyle().cycler
pyglotaran_extras/inspect/cycler.py New module with inspect_cycler and create_preview_cycler functions for visualizing plot style cyclers
pyglotaran_extras/inspect/init.py Exported inspect_cycler function
justfile Added -NoProfile flag to PowerShell invocation for Windows compatibility
docs/notebooks/tips_and_tricks.ipynb New comprehensive tutorial notebook covering xarray data selection, plotting, and cycler customization
docs/index.md Added tips_and_tricks notebook to documentation navigation
docs/conf.py Added tips_and_tricks to exclude lists and included xarray_dark.css
docs/_static/css/xarray_dark.css New CSS file for dark mode styling of xarray output and tables
docs/_static/css/mermaid_dark.css Fixed typos: 'dakr' → 'dark', 'arror' → 'arrow'
.pre-commit-config.yaml Updated dependency versions: pyproject-fmt (v2.11.1 → v2.16.0), nbstripout (0.9.0 → 186d22f), ruff (v0.14.14 → v0.15.1)

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

Copy link
Copy Markdown
Member

@jsnel jsnel left a comment

Choose a reason for hiding this comment

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

It's good to go from my end now!

@s-weigand s-weigand merged commit fa9f91d into glotaran:main Feb 15, 2026
47 checks 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.

4 participants