Skip to content

Commit

Permalink
t
Browse files Browse the repository at this point in the history
  • Loading branch information
jurjen93 committed Nov 16, 2023
1 parent 45f4c50 commit 40a35ed
Showing 1 changed file with 37 additions and 6 deletions.
43 changes: 37 additions & 6 deletions subtract/subtract_with_wsclean.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,20 @@ def parse_history(ms, hist_item):
print('WARNING:' + hist_item + ' not found')
return None

def make_utf8(inp):
"""
Convert input to utf8 instead of bytes
:param inp: string input
:return: input in utf-8 format
"""

try:
inp = inp.decode('utf8')
return inp
except (UnicodeDecodeError, AttributeError):
return inp


def get_time_preavg_factor(ms: str = None):
"""
Expand Down Expand Up @@ -421,7 +435,7 @@ def isfulljones(h5: str = None):
"""
T = tables.open_file(h5)
soltab = list(T.root.sol000._v_groups.keys())[0]
if 'pol' in T.root.sol000._f_get_child(soltab).val.attrs["AXES"].decode('utf8'):
if 'pol' in make_utf8(T.root.sol000._f_get_child(soltab).val.attrs["AXES"]):
if T.root.sol000._f_get_child(soltab).pol[:].shape[0] == 4:
T.close()
return True
Expand Down Expand Up @@ -460,10 +474,20 @@ def run_DP3(self, phaseshift: str = None, freqavg: str = None,

# 2) APPLY BEAM
if applybeam:
steps.append('beam')
command += ['beam.type=applybeam',
'beam.direction=[]',
'beam.updateweights=True']
steps.append('beam1')
command += ['beam1.type=applybeam',
'beam1.updateweights=True']
if applycal_h5 is not None and phaseshift is not None and dirname is not None:
H = tables.open_file(applycal_h5)
sources = H.root.sol000.source[:]
H.close()
dirs = [make_utf8(dir) for dir in sources['name']]
dir_idx = dirs.index("Dir26")
ra, dec = sources['dir'][dir_idx]
dir = str(f"[{round(ra,5)},{round(dec,5)}]")
command += ['beam1.direction='+dir]
else:
command += ['beam1.direction=[]']

# 3) APPLYCAL
if applycal_h5 is not None:
Expand All @@ -490,7 +514,14 @@ def run_DP3(self, phaseshift: str = None, freqavg: str = None,
ac_count += 1
T.close()

# 4) AVERAGING
# 4) APPLY BEAM (OPTIONAL IF APPLY BEAM USED FOR APPLYCAL)
if applybeam and applycal_h5 is not None and phaseshift is not None and dirname is not None:
steps.append('beam2')
command += ['beam2.type=applybeam',
'beam2.updateweights=True',
'beam2.direction=[]']

# 5) AVERAGING
if freqavg is not None or timeres is not None:
steps.append('avg')
command += ['avg.type=averager']
Expand Down

0 comments on commit 40a35ed

Please sign in to comment.