PIPE2D-1835: Add computeImageQuality() and fix bugs in showImageQuality#389
Open
PIPE2D-1835: Add computeImageQuality() and fix bugs in showImageQuality#389
Conversation
- 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>
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>
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
Refactors
showImageQualityinutils/quality.pyin preparation for the newImageQualityQaTaskindrp_qa(PIPE2D-1835).Changes
New function:
computeImageQuality(als)Extracts the pure data-processing logic from
showImageQualityinto a butler-free helper that accepts an enrichedArcLineSet(afteraddTraceLambdaToArclines) and returns apandas.DataFramewith:fwhm: Gaussian-equivalent FWHM in pixels (trace width when full second moments are unavailable)theta: PSF major-axis position angle in radians (NaNwhen traceOnly)traceOnly:Truewhen only trace widths (xx) were availableBug fixes in
showImageQualityarms[0:0] = a(line 122): inserts individual characters into the list instead of the arm string — fixed toarms[0:0] = [a].a, theta = als.xx, np.nan(traceOnly branch): used wrong variable name, shadowing the loop variablea(arm string) and leavingfwhmundefined for subsequent lines — fixed tofwhm, theta = als.xx, np.nan.fromTraceparameter: was accepted in the signature but never referenced in the body — removed.__all__updateAdded
computeImageQualityto__all__.