From 826529d3d18884e941e9971e398c71d639c3096b Mon Sep 17 00:00:00 2001 From: Jonathan Henshaw Date: Wed, 10 Jun 2026 12:28:42 +0000 Subject: [PATCH] fix: three crashes in suggest_extraction_scheme for cont extraction with 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 --- CHANGELOG.md | 1 + phangsPipeline/casaVisRoutines.py | 33 ++++++++++++++++++++++++------- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b5544b6a..d0ff706c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed TP crash when different atmospheric correction types are used (#343). - Calculation of additional number of channels in regrid mstransform call (#344). - Fix stokes passed as integer string to imsubimage in 4D mosaic path (#349). +- Fix crashes in suggest_extraction_scheme for cont extraction (#352). ### Dependencies - Bump actions/upload-artifact from 6 to 7 (#313). diff --git a/phangsPipeline/casaVisRoutines.py b/phangsPipeline/casaVisRoutines.py index 3e260eb7..b5c28961 100644 --- a/phangsPipeline/casaVisRoutines.py +++ b/phangsPipeline/casaVisRoutines.py @@ -1067,13 +1067,26 @@ def suggest_extraction_scheme( logger.warning("Channel too big for SPW "+str(this_spw)) continue - chan_width_list.append(chan_width_kms) + # Figure out the binfactor this_binfactor = int(np.floor(target_chan_kms/chan_width_kms)) - binfactor_list.append(this_binfactor) + # clamp to nchan if the binfactor exceeds the number of channels in the spw + nchan_spw = vm.spwInfo[this_spw]['numChannels'] + if this_binfactor > nchan_spw: + this_binfactor = nchan_spw # Figure out the total number of channels we should be expecting # for this spw total_nchan = int(np.floor(vwidth_kms / (chan_width_kms * this_binfactor))) + + # Inflate target slightly above the native chan width TOPO/LSRK + # only triggers for cases where desired target channel width is 1 channel and binfactor + # is greater than 1 + if total_nchan == 1 and this_binfactor > 1: + this_binfactor -= 1 + + # record the values for the scheme + chan_width_list.append(chan_width_kms) + binfactor_list.append(this_binfactor) total_nchans.append(total_nchan) # Record basic file information @@ -1098,11 +1111,17 @@ def suggest_extraction_scheme( scheme[this_infile][this_spw]['chan_width_kms'] = chan_width_kms scheme[this_infile][this_spw]['chan_width_ghz'] = chan_width_ghz - # Get the minimum total number of channels across all SPWs - total_nchan = np.nanmin(total_nchans) - for this_infile in scheme.keys(): - for this_spw in scheme[this_infile].keys(): - scheme[this_infile][this_spw]['total_nchan'] = total_nchan + # guard against total_nchans being empty + if total_nchans: + total_nchan = np.nanmin(total_nchans) + for this_infile in scheme.keys(): + for this_spw in scheme[this_infile].keys(): + scheme[this_infile][this_spw]['total_nchan'] = total_nchan + else: + logger.warning( + 'No SPW satisfies target_chan_kms for the requested range; ' + 'returning empty scheme.' + ) # ---------------------------------------------------------------- # Figure out the strategy