Skip to content

Commit

Permalink
use 'corrected_data' column by default.
Browse files Browse the repository at this point in the history
  • Loading branch information
iancze committed Dec 1, 2023
1 parent fc2a1d0 commit d710b20
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/visread/scatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
msmd = casatools.msmetadata()
ms = casatools.ms()

def get_scatter_datadescid(filename, datadescid, sigma_rescale=1.0, apply_flags=True, residual=True):
def get_scatter_datadescid(filename, datadescid, sigma_rescale=1.0, apply_flags=True, residual=True, datacolumn="corrected_data"):
r"""
Calculate the residuals for each polarization (XX, YY) in units of :math:`\sigma`, where
Expand All @@ -28,6 +28,7 @@ def get_scatter_datadescid(filename, datadescid, sigma_rescale=1.0, apply_flags=
sigma_rescale (int): multiply the uncertainties by this factor
apply_flags (bool): calculate the scatter *after* the flags have been applied
residual (bool): if True, subtract MODEL_DATA column (from a tclean model, most likely) to plot scatter of residual visibilities.
datacolumn (string): which datacolumn to use (i.e., 'corrected_data' or 'data').
Returns:
scatter_XX, scatter_YY: a 2-tuple of numpy arrays containing the scatter in each polarization.
Expand All @@ -39,7 +40,7 @@ def get_scatter_datadescid(filename, datadescid, sigma_rescale=1.0, apply_flags=

ms.open(filename)
ms.selectinit(datadescid=datadescid)
keys = ["data", "weight", "flag"]
keys = ["weight", "flag", datacolumn]
if residual:
keys += ["model_data"]
q = ms.getdata(keys)
Expand All @@ -52,11 +53,11 @@ def get_scatter_datadescid(filename, datadescid, sigma_rescale=1.0, apply_flags=
), "MODEL_DATA column empty, retry tclean with savemodel='modelcolumn'"

# subtract model from data
residuals = q["data"] - q["model_data"]
residuals = q[datacolumn] - q["model_data"]

else:
# assume the S/N of each individual visibility is negligible.
residuals = q["data"]
residuals = q[datacolumn]

# calculate sigma from weight
sigma = process.weight_to_sigma(q["weight"])
Expand Down
6 changes: 4 additions & 2 deletions src/visread/visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def plot_scatter_datadescid(
chan_slice=None,
apply_flags=True,
residual=True,
datacolumn="corrected_data"
):
r"""
Plot a set of histograms of the scatter of the residual visibilities for the real and
Expand All @@ -67,6 +68,7 @@ def plot_scatter_datadescid(
chan_slice (slice): if not None, a slice object specifying the channels to subselect
apply_flags (bool): calculate the scatter *after* the flags have been applied
residual (bool): if True, subtract MODEL_DATA column (from a tclean model, most likely) to plot scatter of residual visibilities.
datacolumn (string): which datacolumn to use (i.e., 'corrected_data' or 'data').
Returns:
matplotlib figure with scatter histograms
Expand All @@ -76,15 +78,15 @@ def plot_scatter_datadescid(
print("apply_flags setting is ignored when chan_slice is not None")

scatter_XX, scatter_YY = scatter.get_scatter_datadescid(
filename, datadescid, sigma_rescale, apply_flags=False, residual=residual
filename, datadescid, sigma_rescale, apply_flags=False, residual=residual, datacolumn=datacolumn
)

scatter_XX = scatter_XX[chan_slice]
scatter_YY = scatter_YY[chan_slice]

else:
scatter_XX, scatter_YY = scatter.get_scatter_datadescid(
filename, datadescid, sigma_rescale, apply_flags=apply_flags, residual=residual
filename, datadescid, sigma_rescale, apply_flags=apply_flags, residual=residual, datacolumn=datacolumn
)

scatter_XX = scatter_XX.flatten()
Expand Down

0 comments on commit d710b20

Please sign in to comment.