Skip to content

Commit b5b16f6

Browse files
authored
Merge pull request #191 from 1054/20210320.vis.require.full.line.coverage
Check that cube frequency range is completely covered by all input Measurement Sets
2 parents a9a7967 + cae7824 commit b5b16f6

File tree

2 files changed

+64
-14
lines changed

2 files changed

+64
-14
lines changed

phangsPipeline/casaVisRoutines.py

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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:

phangsPipeline/handlerVis.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,22 @@ def loop_stage_uvdata(
101101
statwt_cont = True,
102102
collapse_cont = True,
103103
timebin = None,
104-
just_projects=None,
105-
strict_config=True,
104+
just_projects = None,
105+
strict_config = True,
106+
require_full_line_coverage = False,
106107
overwrite = False,
107108
):
108109
"""
109110
Loops over the full set of targets, products, and configurations
110111
to run the uv data processing. Toggle the parts of the loop
111112
using the do_XXX booleans. Other choices affect the algorithms
112113
used.
114+
115+
The strict_config option sets whether to require that a target has data
116+
from ALL arrays that make up the configuration (True) or not (False).
117+
118+
The require_full_line_coverage option sets whether to require a measurement set
119+
to completely cover a given line's frequency range (True) or not (False).
113120
"""
114121

115122
if make_directories:
@@ -153,7 +160,8 @@ def loop_stage_uvdata(
153160
obsnum = this_obsnum,
154161
product = this_product,
155162
timebin = timebin,
156-
overwrite = overwrite,
163+
require_full_line_coverage = require_full_line_coverage,
164+
overwrite = overwrite,
157165
)
158166

159167
# Run custom processing. Not currently used.
@@ -208,6 +216,7 @@ def loop_stage_uvdata(
208216
extra_ext_in = "",
209217
contsub = "prefer",
210218
# could add algorithm flags here
219+
require_full_line_coverage = require_full_line_coverage,
211220
overwrite = overwrite,
212221
)
213222

@@ -278,6 +287,7 @@ def task_split(
278287
do_statwt = False,
279288
timebin = None,
280289
use_symlink = True,
290+
require_full_line_coverage = False,
281291
overwrite = False,
282292
):
283293
"""
@@ -366,7 +376,8 @@ def task_split(
366376
spw = cvr.find_spws_for_line(
367377
infile = infile, line = this_line,
368378
max_chanwidth_kms = max_chanwidth_kms,
369-
vsys_kms = vsys, vwidth_kms = vwidth)
379+
vsys_kms = vsys, vwidth_kms = vwidth,
380+
require_full_line_coverage = require_full_line_coverage)
370381

371382
if spw is None or len(spw) == 0:
372383
logger.warning("... No SPWs meet the selection criteria. Skipping.")
@@ -647,6 +658,7 @@ def task_extract_line(
647658
do_statwt = True,
648659
edge_for_statwt = None,
649660
method = "regrid_then_rebin",
661+
require_full_line_coverage = False,
650662
overwrite = False,
651663
):
652664
"""
@@ -803,6 +815,7 @@ def task_extract_line(
803815
exact = exact,
804816
overwrite = overwrite,
805817
clear_pointing = False,
818+
require_full_line_coverage = require_full_line_coverage,
806819
)
807820

808821
if do_statwt:

0 commit comments

Comments
 (0)