Skip to content

Commit

Permalink
effecient subtract
Browse files Browse the repository at this point in the history
  • Loading branch information
jurjen93 committed Oct 18, 2024
1 parent 7390f39 commit ef7e52c
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions subtract/subtract_with_wsclean.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,40 +424,35 @@ def subtract_col(self, out_column: str = None):
"""

for ms in self.mslist:
print('Subtract ' + ms)
with table(ms, readonly=False, ack=False) as ts:
colnames = ts.colnames()

if "MODEL_DATA" not in colnames:
sys.exit(
f"ERROR: MODEL_DATA does not exist in {ms}.\nThis is most likely due to a failed predict step.")

if out_column not in colnames:
# get column description from DATA
desc = ts.getcoldesc('DATA')
# create output column
print('Create ' + out_column)
desc['name'] = out_column
# create template for output column
ts.addcols(desc)

else:
print(out_column, ' already exists')


if self.inverse:
sign = '+'
if out_column not in colnames:
# Creating the column with DP3 ensures we can directly compress the data
os.system(f"DP3 msin={ms} msout=. msout.datacolumn={out_column} steps=[] msout.storagemanager=dysco")
else:
sign = '-'
print(out_column, ' already exists')

if 'SUBTRACT_DATA' in colnames:
colmn = 'SUBTRACT_DATA'
else:
colmn = 'DATA'

print(f'Output --> {colmn} {sign} MODEL_DATA')
if self.inverse:
sign = '+'
else:
sign = '-'

print(f'Subtracting --> {colmn} {sign} MODEL_DATA for {ms}')

# subtraction or addition
taql(f"UPDATE {ms} SET {out_column}={colmn}{sign}MODEL_DATA")

# remove MODEL_DATA to save memory
taql(f"ALTER TABLE {ms} DROP COLUMN MODEL_DATA")

return self
Expand Down

0 comments on commit ef7e52c

Please sign in to comment.