@@ -430,6 +430,7 @@ def find_spws_for_line(
430430 vsys_kms = None , vwidth_kms = None , vlow_kms = None , vhigh_kms = None ,
431431 max_chanwidth_kms = None ,
432432 require_data = False ,
433+ require_full_line_coverage = False ,
433434 exit_on_error = True ,
434435 as_list = False ,
435436 ):
@@ -495,6 +496,8 @@ def find_spws_for_line(
495496 # SPWs one at a time.
496497
497498 spw_list = []
499+ spw_lowest_ghz = None
500+ spw_highest_ghz = None
498501
499502 logger .debug ("... vm = au.ValueMapping(infile) ..." )
500503 vm = au .ValueMapping (infile )
@@ -522,12 +525,23 @@ def find_spws_for_line(
522525 continue
523526
524527 spw_list .append (this_spw )
528+
529+ if spw_lowest_ghz is None :
530+ spw_lowest_ghz = spw_low_ghz
531+ else :
532+ spw_lowest_ghz = min (spw_lowest_ghz , spw_low_ghz )
533+
534+ if spw_highest_ghz is None :
535+ spw_highest_ghz = spw_high_ghz
536+ else :
537+ spw_highest_ghz = max (spw_highest_ghz , spw_high_ghz )
525538
526539 # If we don't find the line in this data set, issue a warning and
527540 # return.
528541
529542 if len (spw_list ) == 0 :
530543 logger .warning ('No spectral windows contain the input line.' )
544+ spw_list = []
531545 spw_list_string = None # can't be '', that selects all
532546 else :
533547
@@ -536,7 +550,16 @@ def find_spws_for_line(
536550
537551 # make spw_list_string appropriate for use in selection
538552 spw_list_string = ',' .join (np .array (spw_list ).astype (str ))
539-
553+
554+ # check if the spws in this measurement set completely covers the given line frequency range
555+ if not (spw_lowest_ghz <= line_low_ghz and spw_highest_ghz >= line_high_ghz ):
556+ logger .warning ('The spectral windows in this measurement set "%s" (%.6f -- %.6f) does not cover the full "%s" line frequency range (%.6f -- %.6f).' % (\
557+ infile , spw_lowest_ghz , spw_highest_ghz , line , line_low_ghz , line_high_ghz ))
558+ if require_full_line_coverage :
559+ spw_list = []
560+ spw_list_string = None # can't be '', that selects all
561+
562+ # return
540563 if as_list :
541564 return (spw_list )
542565 else :
@@ -689,6 +712,7 @@ def compute_common_chanwidth(
689712 vwidth_kms = None ,
690713 vlow_kms = None ,
691714 vhigh_kms = None ,
715+ require_full_line_coverage = False ,
692716 ):
693717 """
694718 Calculates the coarsest channel width among all spectral windows
@@ -720,7 +744,8 @@ def compute_common_chanwidth(
720744 coarsest_channel = None
721745 for this_infile in infile_list :
722746 # Find spws for line
723- spw_list_string = find_spws_for_line (this_infile , line , vsys_kms = vsys_kms , vwidth_kms = vwidth_kms )
747+ spw_list_string = find_spws_for_line (this_infile , line , vsys_kms = vsys_kms , vwidth_kms = vwidth_kms ,
748+ require_full_line_coverage = require_full_line_coverage )
724749
725750 chan_widths_hz = au .getChanWidths (this_infile , spw_list_string )
726751
@@ -751,7 +776,8 @@ def batch_extract_line(
751776 method = 'regrid_then_rebin' ,
752777 exact = False ,
753778 freqtol = '' ,
754- clear_pointing = True ,
779+ clear_pointing = True ,
780+ require_full_line_coverage = False ,
755781 overwrite = False ,
756782 ):
757783 """
@@ -806,6 +832,7 @@ def batch_extract_line(
806832
807833 this_scheme ['outfile' ] = this_outfile
808834 this_scheme ['overwrite' ] = overwrite
835+ this_scheme ['require_full_line_coverage' ] = require_full_line_coverage
809836 split_file_list .append (this_outfile )
810837
811838 # Execute line extraction
@@ -1042,6 +1069,7 @@ def extract_line(
10421069 target_chan_kms = None ,
10431070 nchan = None ,
10441071 binfactor = None ,
1072+ require_full_line_coverage = False ,
10451073 overwrite = False ,
10461074 ):
10471075 """
@@ -1133,9 +1161,10 @@ def extract_line(
11331161 spw_list = find_spws_for_line (
11341162 infile = line , restfreq_ghz = restfreq_ghz ,
11351163 vsys_kms = vsys_kms , vwidth_kms = vwidth_kms , vlow_kms = vlow_kms , vhigh_kms = vhigh_kms ,
1136- require_data = True , exit_on_error = True , as_list = True ,
1164+ require_data = True , require_full_line_coverage = require_full_line_coverage ,
1165+ exit_on_error = True , as_list = True ,
11371166 )
1138- if spw_list is None :
1167+ if spw_list is None or len ( spw_list ) == 0 :
11391168 logging .error ("No SPWs for selected line and velocity range." )
11401169 return ()
11411170 spw = spw_list .join (',' )
@@ -1161,7 +1190,9 @@ def extract_line(
11611190 infile = infile , outfile = outfile , restfreq_ghz = restfreq_ghz , spw = spw ,
11621191 vstart_kms = vstart_kms , vwidth_kms = vwidth_kms ,
11631192 target_chan_kms = target_chan_kms , nchan = nchan ,
1164- method = 'regrid' )
1193+ method = 'regrid' ,
1194+ require_full_line_coverage = require_full_line_coverage ,
1195+ )
11651196
11661197 if method == 'just_rebin' or method == 'regrid_then_rebin' or \
11671198 method == 'rebin_then_regrid' :
@@ -1170,12 +1201,16 @@ def extract_line(
11701201
11711202 rebin_params , rebin_msg = build_mstransform_call (
11721203 infile = infile , outfile = outfile , restfreq_ghz = restfreq_ghz , spw = spw ,
1173- binfactor = binfactor , method = 'rebin' )
1204+ binfactor = binfactor , method = 'rebin' ,
1205+ require_full_line_coverage = require_full_line_coverage ,
1206+ )
11741207
11751208 if multiple_spws :
11761209 combine_params , combine_msg = build_mstransform_call (
11771210 infile = infile , outfile = outfile , restfreq_ghz = restfreq_ghz , spw = spw ,
1178- method = 'combine' )
1211+ method = 'combine' ,
1212+ require_full_line_coverage = require_full_line_coverage ,
1213+ )
11791214
11801215 # ............................................
11811216 # string the calls together in the desired order
@@ -1290,6 +1325,7 @@ def build_mstransform_call(
12901325 target_chan_kms = None ,
12911326 nchan = None ,
12921327 binfactor = None ,
1328+ require_full_line_coverage = False ,
12931329 overwrite = False ,
12941330 ):
12951331 """
@@ -1326,8 +1362,9 @@ def build_mstransform_call(
13261362 if spw is None :
13271363 if restfreq_ghz is not None :
13281364 spw = find_spws_for_line (
1329- infile = infile , restfreq_ghz = restfreq_ghz ,
1330- vlow_kms = vlow_kms , vhigh_kms = vhigh_kms )
1365+ infile = infile , restfreq_ghz = restfreq_ghz ,
1366+ vlow_kms = vlow_kms , vhigh_kms = vhigh_kms ,
1367+ require_full_line_coverage = require_full_line_coverage )
13311368
13321369 # Exit if no SPWs contain the line.
13331370 if spw is None :
0 commit comments