Source
174
174
if os.path.exists(outvis) and overwrite:
175
175
print("REMOVING EXISTING COPY")
176
176
shutil.rmtree(outvis)
177
177
elif os.path.exists(outvis) and not overwrite:
178
178
print("File ", outvis, " already exists, set overwrite=True or change outvis name")
179
179
return
180
180
# run the antab parsing and table filling
181
181
shutil.copytree(vis, outvis)
182
182
antab_interp(vis, outvis, antab, ant_names, n_band, spws,
183
183
gc_interval, gc_time, first_time, last_time,
184
-
append_tsys, append_gc)
184
+
append_tsys, append_gc, overwrite)
185
185
186
186
187
187
188
188
#################################################################################################
189
189
# scanner regex from casavlbitools
190
190
def s_err(scanner, error):
191
191
raise RuntimeError("line: %d" % scanner.line_no)
192
192
193
193
def s_keyword(scanner, token):
194
194
if len(token) > 9 or '.' in token:
615
615
data.freqid.append(1)
616
616
data.y_typ.append(y_typ)
617
617
data.nterm.append(len(poly))
618
618
data.gain.append(poly)
619
619
data.sens_1.append(dpfu['R'])
620
620
data.sens_2.append(dpfu['L'])
621
621
return
622
622
623
623
def antab_interp(vis, outvis, antab, ant_names, n_band, spws,
624
624
gc_interval, gc_time, first_time, last_time,
625
-
append_tsys, append_gc):
625
+
append_tsys, append_gc, overwrite):
626
626
pols = []
627
627
data = TSysTable()
628
628
data_gc = GainCurveTable()
629
629
keys = StringIO()
630
630
fp = open(antab, 'r')
631
631
632
632
for line in fp:
633
633
if line.startswith('!'):
634
634
continue
635
635
keys.write(line)
644
644
process_tsys(fp, tsys, pols, data, n_band, spws, first_time, last_time, ant_names)
645
645
pass
646
646
elif tsys and tsys[0] and tsys[0][0][0] == 'GAIN':
647
647
process_gc(fp, tsys, pols, data_gc, ant_names)
648
648
keys = StringIO()
649
649
continue
650
650
continue
651
651
652
652
# Create the subtable for syscal if selected in params
653
653
if append_tsys:
654
-
create_syscal_subtable(data, outvis, spws)
654
+
create_syscal_subtable(data, outvis, spws, overwrite)
655
655
if append_gc:
656
-
create_gaincurve_subtable(data_gc, outvis, spws, gc_interval, gc_time)
656
+
create_gaincurve_subtable(data_gc, outvis, spws, gc_interval, gc_time, overwrite)
657
657
658
-
def create_gaincurve_subtable(data, outvis, spws, gc_interval, gc_time):
658
+
def create_gaincurve_subtable(data, outvis, spws, gc_interval, gc_time, overwrite):
659
659
# If overwriting and subtable exists
660
660
if overwrite and os.path.exists(f'{outvis}/GAIN_CURVE'):
661
661
print("Overwriting existint GAIN_CURVE subtable")
662
662
shutil.rmtree(f'{outvis}/GAIN_CURVE')
663
663
if not os.path.exits(f'{outvis}/GAIN_CURVE'):
664
664
# Create the subtable for gain curve
665
665
tb.create(f'{outvis}/GAIN_CURVE', desc_gc, dminfo=dminfo_gc)
666
666
tb.putkeyword('GAIN_CURVE', f'Table: {outvis}/GAIN_CURVE')
667
667
668
668
# assemble columns
717
717
if len(np.shape(GAIN[i])):
718
718
tb.putcell('GAIN', i, [GAIN[i],GAIN[i]])
719
719
else:
720
720
tb.putcell('GAIN', i, GAIN[i])
721
721
tb.putcol('SPECTRAL_WINDOW_ID', SPECTRAL_WINDOW_ID)
722
722
tb.putcol('SENSITIVITY', SENSITIVITY)
723
723
#tb.flush()
724
724
tb.close()
725
725
726
726
727
-
def create_syscal_subtable(data, outvis, spws):
727
+
def create_syscal_subtable(data, outvis, spws, overwrite):
728
728
### What to do if in append regime? ###
729
729
# If not overwriting then check if sys cal exists
730
730
# If overwriting then get rid of the existing subtable and create a new one
731
731
# If appending get the new indexs of added rows and apply to them?
732
732
# just use getcol, append to that, then putcol
733
733
734
734
# If overwriting and subtable exists
735
735
if overwrite and os.path.exists(f'{outvis}/SYSCAL'):
736
736
print("Overwriting existint SYSCAL subtable")
737
737
shutil.rmtree(f'{outvis}/SYSCAL')