Source
536
536
keys = StringIO()
537
537
continue
538
538
continue
539
539
540
540
# Create the subtable for syscal if selected in params
541
541
if self.append_tsys:
542
542
self.create_syscal_subtable()
543
543
if self.append_gc:
544
544
self.create_gaincurve_subtable()
545
545
546
+
def get_spw_ranges(self):
547
+
# Get ranges for each spectral window
548
+
try:
549
+
tb.open(f'{self.vis}/SPECTRAL_WINDOW')
550
+
#print(self.spws)
551
+
for spw in self.spws:
552
+
chan_freq = tb.getcol('CHAN_FREQ')[:,spw]
553
+
min_freq = min(chan_freq) / (1e6)
554
+
max_freq = max(chan_freq) / (1e6)
555
+
self.spw_ranges[spw] = (min_freq, max_freq)
556
+
tb.close()
557
+
except Exception as e:
558
+
print("ERROR FAILED TO GET SPW FREQ RANGES")
559
+
560
+
def check_which_spw(self, freq):
561
+
in_spw = []
562
+
for spw, ranges in self.spw_ranges.items():
563
+
if ranges[0] >= freq[0] and ranges[1] <= freq[1]:
564
+
in_spw.append(spw)
565
+
# If there is no spw that this belongs to default to what we were setting this value to before
566
+
if not in_spw:
567
+
print("WARNING: NO CORRESPONDING SPW FOUND FOR FREQ {}".format(freq))
568
+
return [-1]
569
+
else:
570
+
return in_spw
571
+
546
572
def process_tsys(self, infp, keys):
547
573
# Get the antenna name
548
574
antenna_name = find_antenna(keys[0], ['SRC/SYS'])
549
575
# Skip if no antenna name found
550
576
if not antenna_name:
551
577
print('ANTENNA missing from TSYS group')
552
578
skip_values(infp)
553
579
return
554
580
try:
555
581
antenna = get_antenna_index(antenna_name, self.ant_names)
556
582
except:
557
583
print('Antenna %s not present in the Measurement Set. %s values will be ignored.' % antenna_name)
558
584
skip_values(infp)
559
585
return
586
+
587
+
try:
588
+
self.get_spw_ranges()
589
+
spw_ids = self.check_which_spw(keys['FREQ'])
590
+
except Exception as e:
591
+
spw_ids = [-1]
592
+
print('ANTAB HAS NO FREQ INFORMATION DEFAULTING TO FREQ ID -1')
560
593
561
594
keys = dict(keys[0])
562
595
spws = []
563
596
spwmap = {}
564
597
565
598
if 'INDEX' in keys:
566
599
update_map(self.pols, spws, spwmap, keys['INDEX'])
567
600
if 'INDEX2' in keys:
568
601
update_map(self.pols, spws, spwmap, keys['INDEX2'])
569
602
pass
623
656
tsys[pol].append(value)
624
657
continue
625
658
continue
626
659
if source != -1:
627
660
time_val = mjd_sec + (days * 86400)
628
661
self.data.time.append(time_val)
629
662
self.data.time_interval.append(0.0)
630
663
self.data.antenna_no.append(antenna)
631
664
self.data.tsys_1.append(tsys['R'])
632
665
self.data.tsys_2.append(tsys['L'])
666
+
self.data.freqid(spw_ids)
633
667
634
668
pass
635
669
pass
636
670
637
671
if line.strip().endswith('/'):
638
672
break
639
673
continue
640
674
return
641
675
642
-
def get_spw_ranges(self):
643
-
# Get ranges for each spectral window
644
-
try:
645
-
tb.open(f'{self.vis}/SPECTRAL_WINDOW')
646
-
#print(self.spws)
647
-
for spw in self.spws:
648
-
chan_freq = tb.getcol('CHAN_FREQ')[:,spw]
649
-
min_freq = min(chan_freq) / (1e6)
650
-
max_freq = max(chan_freq) / (1e6)
651
-
self.spw_ranges[spw] = (min_freq, max_freq)
652
-
tb.close()
653
-
except Exception as e:
654
-
print("ERROR FAILED TO GET SPW FREQ RANGES")
655
-
656
-
def check_which_spw(self, freq):
657
-
in_spw = []
658
-
for spw, ranges in self.spw_ranges.items():
659
-
if ranges[0] >= freq[0] and ranges[1] <= freq[1]:
660
-
in_spw.append(spw)
661
-
# If there is no spw that this belongs to default to what we were setting this value to before
662
-
if not in_spw:
663
-
print("WARNING: NO CORRESPONDING SPW FOUND FOR FREQ {}".format(freq))
664
-
return [-1]
665
-
else:
666
-
#print('SELECTED SPWS: ', in_spw)
667
-
return in_spw
668
-
669
676
def process_gc(self, infp, keys):
670
677
antenna_name = find_antenna(keys[0], self.gain_keys)
671
678
if not antenna_name:
672
679
print('Antenna missing from GAIN group')
673
680
skip_values(infp)
674
681
return
675
682
try:
676
683
antenna = get_antenna_index(antenna_name, self.ant_names)
677
684
except:
678
685
print('Antenna %s not present in FITS-IDI file' % antenna_name)
942
949
# if the antenna has been visited already with the same time stamp then ignore
943
950
if self.data.antenna_no[i] in existing_data and self.data.time[i] in existing_data[self.data.antenna_no[i]]['times'] and not self.overwrite:
944
951
# This data is already in the subtable so ignore
945
952
#print("antenna: {} has data present for the time {}. The antab data for this value will be ignored".format(data.antenna_no[i], data.time[i]))
946
953
to_skip.append(True)
947
954
continue
948
955
else:
949
956
to_skip.append(False)
950
957
951
958
for j in self.spws:
959
+
# Check that this antenna is in this spectral window
960
+
if j not in self.data.freqid[i] and self.data.freqid[i] != [-1]:
961
+
continue
952
962
if self.data.antenna_no[i] in existing_data and self.data.time[i] in existing_data[self.data.antenna_no[i]]['times'] and self.overwrite:
953
963
# Get the row and information to overwrite the row from the ms
954
964
row = existing_data[self.data.antenna_no[i]]['row']
955
965
to_skip.append(True)
956
966
957
967
self.replacements[row] = {'ANTENNA':self.data.antenna_no[i], 'FEED_ID':0, 'INTERVAL':self.data.time_interval[i],
958
968
'SPW_ID':int(j), 'TIME':self.data.time[i], 'TSYS':[[],[]]}
959
969
960
970
continue
961
971