Skip to content

PIPE2D-1835: Add computeImageQuality() and fix bugs in showImageQuality#389

Open
wtgee wants to merge 8 commits intomasterfrom
tickets/PIPE2D-1835
Open

PIPE2D-1835: Add computeImageQuality() and fix bugs in showImageQuality#389
wtgee wants to merge 8 commits intomasterfrom
tickets/PIPE2D-1835

Conversation

@wtgee
Copy link
Copy Markdown
Member

@wtgee wtgee commented Apr 17, 2026

Summary

Refactors showImageQuality in utils/quality.py in preparation for the new ImageQualityQaTask in drp_qa (PIPE2D-1835).

Changes

New function: computeImageQuality(als)

Extracts the pure data-processing logic from showImageQuality into a butler-free helper that accepts an enriched ArcLineSet (after addTraceLambdaToArclines) and returns a pandas.DataFrame with:

  • All original arc-line columns
  • fwhm: Gaussian-equivalent FWHM in pixels (trace width when full second moments are unavailable)
  • theta: PSF major-axis position angle in radians (NaN when traceOnly)
  • traceOnly: True when only trace widths (xx) were available

Bug fixes in showImageQuality

  • arms[0:0] = a (line 122): inserts individual characters into the list instead of the arm string — fixed to arms[0:0] = [a].
  • a, theta = als.xx, np.nan (traceOnly branch): used wrong variable name, shadowing the loop variable a (arm string) and leaving fwhm undefined for subsequent lines — fixed to fwhm, theta = als.xx, np.nan.
  • fromTrace parameter: was accepted in the signature but never referenced in the body — removed.

__all__ update

Added computeImageQuality to __all__.

- Add computeImageQuality(als) which extracts arc-line shape data
  (FWHM, theta, traceOnly) into a pandas DataFrame.  This is the
  butler-free computation used by the new ImageQualityQaTask in drp_qa.
- Add computeImageQuality to __all__.
- Fix arms[0:0] = a (inserts characters) → arms[0:0] = [a].
- Fix traceOnly branch: a, theta = als.xx, np.nan →
  fwhm, theta = als.xx, np.nan (fwhm was referenced later but undefined).
- Remove unused fromTrace parameter from showImageQuality.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
wtgee and others added 7 commits April 17, 2026 08:44
Replace the duplicated traceOnly/fwhm/theta logic in showImageQuality
with a call to computeImageQuality(), which was added in the previous
commit but not actually wired in.

This also fixes the remaining bug where the traceOnly branch did:
  fwhm, theta = als.xx, np.nan
leaving theta as a scalar NaN (not a Series), and simplifies the ll
mask recomputation to just np.isfinite(als["fwhm"]).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Move the single-panel plotting logic into a new module-level
plotImageQuality(ax, data, ...) function that lives alongside
computeImageQuality().  showImageQuality() now calls plotImageQuality()
for each panel instead of duplicating the code.

This ensures notebook users and the automated ImageQualityQaTask in
drp_qa always produce identical output from the same code path, with no
risk of the two diverging.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…uality

Add a fourth public function loadImageQualityData(dataIds, butler,
alsCache=None) that owns all butler I/O: reads 'lines' and
'detectorMap' datasets, enriches them via addTraceLambdaToArclines, and
returns a populated alsCache dict.

showImageQuality() now requires either butler or alsCache to be non-None
and delegates all data loading to loadImageQualityData().  This means:
- Notebook users pass a butler as before (nothing changes for them).
- The pipeline task (ImageQualityQaTask) can pre-populate an alsCache
  via loadImageQualityData() and call showImageQuality() without ever
  touching a butler directly, getting identical output to the task.

The four public functions now form a clean layered API:
  loadImageQualityData  – butler I/O
  computeImageQuality   – data computation
  plotImageQuality      – single-panel rendering
  showImageQuality      – multi-panel figure (orchestrates the above)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Replace plt.sca(ax) + plt.* state-machine calls with ax.* methods
  throughout, making the function safe to call in any axes context.
- Fix plt.xlim(plt.ylim(-1, 4096)) side-effect trick with explicit
  ax.set_ylim(-1, 4096) / ax.set_xlim(-1, 4096) calls.
- Add maxFwhm parameter (default 8) replacing the hardcoded constant;
  used as both the line-selection cutoff and the FWHM histogram range.
- Replace 'data["flag"] == False' with '~data["flag"]'.
- Add flux > 0 guard in the mask when useSN=False to prevent log10(<=0);
  add fluxErr > 0 guard when useSN=True to prevent division by zero.
- Apply flag filter (ll_hist) to histogram plots so flagged lines are
  excluded from FWHM and flux histograms.
- Guard showFluxHistogram against all-NaN flux with a clear RuntimeError.
- Improve the 'no plot mode enabled' error message to list valid modes.
- Add maxFwhm parameter to showImageQuality, passed through to
  plotImageQuality.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.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