Skip to content

Enable auto levels by default in SkyFit2#921

Open
dvida wants to merge 2 commits into
prereleasefrom
skyfit-auto-levels-default
Open

Enable auto levels by default in SkyFit2#921
dvida wants to merge 2 commits into
prereleasefrom
skyfit-auto-levels-default

Conversation

@dvida

@dvida dvida commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Auto levels are now enabled by default when SkyFit2 starts, so images appear properly stretched immediately instead of spanning the full bit range (which often shows a nearly black image).
  • The histogram region is no longer locked while auto levels are active. Dragging the region (whole region or either edge line), or Ctrl+clicking the histogram to set a black/white level, seamlessly switches to manual mode — starting from the levels auto mode had determined.
  • Ctrl + A still toggles auto levels on/off as before; toggling off restores the previous manual levels.
  • The full-range setLevels calls on station change and on loading a state into a running instance now only apply in manual mode, so they don't override the auto stretch.
  • Updated Guides/SkyFit.md accordingly.

Implementation notes

User drags are distinguished from programmatic level updates via pyqtgraph's moving flags (region.moving for whole-region drags, line.moving for edge drags), which are never set by setRegion(). This means the periodic auto-level updates on image change never kick the user out of auto mode, but any manual interaction does.

Saved .state files are unaffected — the histogram widget is never pickled and is rebuilt in setupUI(), so auto levels are on after loading old states too.

Testing

  • Verified off-screen (QT_QPA_PLATFORM=offscreen) that: toggling on applies percentile-based levels and keeps the region draggable; programmatic image changes keep auto mode; a simulated user drag exits auto mode keeping the auto levels as the manual starting point; Ctrl+A round-trip restores manual levels.

🤖 Generated with Claude Code

Auto levels are now turned on when SkyFit2 starts, so images appear
properly stretched immediately instead of using the full bit range.

The histogram region is no longer locked while auto levels are active:
dragging the region (or Ctrl+clicking to set a level) switches to manual
mode, keeping the auto-determined levels as the starting point. Ctrl+A
still toggles auto levels on and off.

Full-range setLevels calls on station change and state load now only
apply in manual mode so they don't override the auto stretch.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b8022cf747

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread Utils/SkyFit2.py
Comment on lines +3643 to +3644
if not self.tab.hist.auto_levels:
self.tab.hist.setLevels(0, 2**(8*self.img.data.itemsize) - 1)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep the zoom image synced after auto-level reloads

When auto levels are enabled and a station is changed, self.img.changeHandle() recalculates the histogram levels and emits them to img_zoom before self.img_zoom.changeHandle() reloads the zoom image. That reload calls setImage() without levels, so pyqtgraph assigns independent min/max levels to the zoom item; because this guard skips the following hist.setLevels(...), nothing resynchronizes the zoom window. The same ordering exists in the running-state load path, so after switching stations/loading state in default auto mode the zoom view can be stretched differently from the main image.

Useful? React with 👍 / 👎.

img_zoom.changeHandle() reloads the zoom image via setImage() without
levels, so pyqtgraph assigns it independent min/max levels. With auto
levels on, the histogram was updated before the zoom reload and never
re-emitted, leaving the zoom window stretched differently from the main
image. The manual path had the same latent issue: setLevels() with an
unchanged full range early-returns in setRegion() without emitting.

Explicitly reapply the histogram levels to both image items after the
reload, matching the existing pattern in updateImage handling.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

1 participant