fix: crashes in suggest_extraction_scheme for cont extraction #352
Draft
jdhenshaw wants to merge 1 commit into
Draft
fix: crashes in suggest_extraction_scheme for cont extraction #352jdhenshaw wants to merge 1 commit into
jdhenshaw wants to merge 1 commit into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #352 +/- ##
=========================================
- Coverage 6.28% 6.27% -0.01%
=========================================
Files 38 38
Lines 15232 15239 +7
Branches 3660 3663 +3
=========================================
Hits 957 957
- Misses 14261 14268 +7
Partials 14 14 ☔ View full report in Codecov by Harness. |
…ith freq_ranges_ghz - guard np.nanmin against empty total_nchans - clamp binfactor to nchan_spw when freq_range overshoots SPW - decrement binfactor when total_nchan == 1 to clear the TOPO/LSRK frame gap
d0cf928 to
826529d
Compare
Collaborator
|
This seems reasonable to me. Tagging @astrojysun who has done a bunch of continuum work for another look |
Collaborator
|
The fixes look good to me too! Just wanted to mention that in practice we usually choose |
Collaborator
|
@jdhenshaw, you wanna flip this off draft if you're happy and we can merge this in? |
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
Three minimal fixes in
suggest_extraction_schemethat resolve crashes inbatch_extract_continuumwhenfreq_ranges_ghzis specified with eitherchannel_ghz: Noneorchannel_ghzvalues thatare lower than the native res of the only covering SPW.
Bug 1 —
np.nanminon emptytotal_nchansWhen the per-SPW loop excludes every covering SPW (because
chan_width_kms > target_chan_kmsfor all of them ifchannel_ghzis set low),total_nchansends up empty andnp.nanmin([])raisesValueError.Example:
channel_ghz: 0.001on ALMA Band 6 centres 232–234 GHz window. Target = 1.287 km/s, native chan width = 40 km/s -> SPW excluded -> empty lists -> crash.Fix: guard
np.nanminwithif total_nchans:; emit a warning and return the empty scheme (whichbatch_extract_continuum's outer loop silently skips). May not be perfect solution, but it emits a warning.Bug 2 —
binfactorexceeds the SPW's channel countint(np.floor(target_chan_kms/chan_width_kms))can exceedvm.spwInfo[this_spw]['numChannels']when the user'sfreq_ranges_ghzovershoots the SPW's actual bandwidth. The resulting per-spw target resolution ends up beingfiner than the SPW's native width and mstransform crashes with
calcChanFreqs failed. Discovered because i didn't set the windows correctly.Example: range
[215.97, 217.85]= 1.88 GHz on an SPW that actually covers only 1.875 GHz (1920 channels × 976.5 kHz).binfactor = 1925, per-spw target = 1.34980 km/s = 976,623 Hz, < native 976,672Hz → crash.
Fix: clamp
this_binfactortonchan_spw. The clamp enforces that binfactor can never exceed available channels.Bug 3 — TOPO/LSRK frame mismatch - not 100% sure on the cause
PHANGS reads
chan_width_kmsfromvm.spwInfo[this_spw]['chanWidth']from the MS (TOPO?). mstransform, withoutframe='lsrk', internally converts input channels to LSRK before validating the requested output width. The LSRK-converted native is larger than TOPO by a small factor.When
target = refvwidth / binfactorlands above TOPO native but below LSRK native the downstream safety net passes the request through, but mstransform's internal check rejects it.Example: range
[219.06, 219.52]withchannel_ghz: null.refvwidth = 628.87 km/s,chan_width_kms = 0.667532 km/s,binfactor = floor(942.080) = 942, per-spw target = 0.667588 km/s = 488323 Hz.LSRK native = 488336 Hz -> target is below native -> crash.
2026-06-10 08:31:25 WARN MSTransformRegridder::calcChanFreqs *** Requested new channel width (488323 Hz) is smaller than smallest original channel width
2026-06-10 08:31:25 WARN MSTransformRegridder::calcChanFreqs+ which is 488336 Hz
2026-06-10 08:31:25 WARN MSTransformRegridder::calcChanFreqs+ or 667.607 m/s
2026-06-10 08:31:25 SEVERE MSTransformRegridder::calcChanFreqs calcChanFreqs failed, check input start and width parameters
Fix: when
total_nchan == 1(the signature of "one channel per range" intent), decreasebinfactorby 1. This inflates per-spw target by1/(N-1), which then exceeds (slightly) the requirement for the check.The fix is targeted only to the
total_nchan == 1case (line cubes havetotal_nchanin the hundreds). Final output dimensionality is preserved: the rebin step'schanbin = N-1still collapses to 1 channel; only the intermediate per-channel width is affected.Verification
Tested with the PHANGS-CMZs NGC 1087 anchor data (project
2023.1.01182.S). All four ranges extract cleanly into a 4-SPW cont MS, including continuum window (previously silently dropped by the np.nanmin guard's empty-schemebehaviour under probelm 1 above).
Final
ngc1087_12mext_cont.ms:Changes
All in
phangsPipeline/casaVisRoutines.py, functionsuggest_extraction_scheme:np.nanmin(total_nchans)against empty list; log warning and return empty scheme in that case.this_binfactortovm.spwInfo[this_spw]['numChannels'].this_binfactorby 1 whentotal_nchan == 1 and this_binfactor > 1.No changes to
build_mstransform_call,extract_continuum, or downstream code. No new dependencies.