Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Multi model columns #76

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ History
X.Y.Z (YYYY-MM-DD)
------------------

* Add multi model column expression (:pr:`76`)
* Removed .travis and .travis.yml (:pr:`71`) and (:pr:`73`)
* Github CI Actions (:pr:`71`)

Expand Down
45 changes: 12 additions & 33 deletions tricolour/apps/tricolour/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,10 @@ def create_parser():
help="Number of channels to dilate as int "
"or string with units")
p.add_argument("-dc", "--data-column", type=str, default="DATA",
help="Name of visibility data column to flag")
help="Name of visibility data column to flag."
"Now supports multi model columns expressions"
"e.g 'DATA / (DIR1_DATA + DIR2_DATA + DIR3_DATA)'"
"In future will replace subtract-model-column")
smasoka marked this conversation as resolved.
Show resolved Hide resolved
p.add_argument("-fn", "--field-names", type=str, action='append',
default=[],
help="Name(s) of fields to flag. Defaults to flagging all")
Expand Down Expand Up @@ -212,8 +215,8 @@ def create_parser():
p.add_argument("-smc", "--subtract-model-column", default=None, type=str,
help="Subtracts specified column from data column "
"specified. "
"Flagging will proceed on residual "
"data.")
"Flagging will proceed on residual data."
"Depreciating argurment. See --data-column")
smasoka marked this conversation as resolved.
Show resolved Hide resolved
return p


Expand Down Expand Up @@ -269,14 +272,10 @@ def _main(args):
"Interactive Python Debugger, as per user request")
post_mortem_handler.disable_pdb_on_error()

log.info("Flagging on the {0:s} column".format(args.data_column))
if "/" in args.data_column:
data_string = args.data_column.split("/")
data_column = data_string[0]
string_columns = data_string[1]
else:
data_column = args.data_column
string_columns = None
# extract the name of the visibility column
# to support subtract_model_column
data_column = re.split(r'\+|-|/|\*|\(|\)', args.data_column)[0]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a regex designed to detect the kind of expressions that https://github.com/ska-sa/dask-ms/blob/master/daskms/expressions.py#L103 supports. I think it's probably better to just split on the equals as follows as its easer to separate into the two cases

parts = args.data_column.split("=")
log.info("Flagging on the {0:s} {0:s}".format(parts[0], "column" if len(parts) == 1 else "expression))

Additionally, I don't think the regex contained an equals sign so I think it would have failed on an assignment statement.

Could you please correct and test the two cases?

  1. The simple case where data_column just references a column name
  2. The complicated case where data_column contains an assignment.

log.info("Flagging on the {0:s} column".format(data_column))

masked_channels = [load_mask(fn, dilate=args.dilate_masks)
for fn in collect_masks()]
Expand All @@ -289,29 +288,7 @@ def _main(args):
# Index datasets by these columns
index_cols = ['TIME']

# Reopen the datasets using the aggregated row ordering
columns = [data_column,
"FLAG",
"TIME",
"ANTENNA1",
"ANTENNA2"]

# Get the columns to read
if string_columns is not None and "(" in string_columns:
match = re.search(r'\(([A-Za-z0-9+-_]+)\)', string_columns)
multi_columns = re.split(r'\+|-', match.group(1))
multi_columns = list(filter(None, multi_columns))
columns.extend(multi_columns)
else:
if string_columns is not None:
columns.append(string_columns)

if args.subtract_model_column is not None:
warnings.warn("Use -dc arg")
columns.append(args.subtract_model_column)

xds = list(xds_from_ms(args.ms,
columns=tuple(columns),
group_cols=group_cols,
index_cols=index_cols,
chunks={"row": args.row_chunks}))
Expand Down Expand Up @@ -398,6 +375,8 @@ def _main(args):
# Visibilities from the dataset
vis = getattr(ds, data_column).data
if args.subtract_model_column is not None:
warnings.warn("-smc arg is depreciating."
"See -dc arg for expressions")
smasoka marked this conversation as resolved.
Show resolved Hide resolved
log.info("Forming residual data between '{0:s}' and "
"'{1:s}' for flagging.".format(
data_column, args.subtract_model_column))
Expand Down