-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflagdeadcorr.m
49 lines (39 loc) · 1.61 KB
/
flagdeadcorr.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
% Script to flag dead visibilities, based on average levels over all
% visibilities in a single timeslice.
% Arguments:
% acc : ACM for this time instant
% tobs: Time of obs
% freq: Freq. of obs.
%hithresh: Threshold of median cutoff as percent of median.
% All vis>hithresh*median are flagged.
%lothresh: Threshold of median cutoff as percent of median.
% All vis<lothresh*median are flagged.
% Returns:
% uvflag: flag matrix with 1s indicating visibilities to flag.
% flagant: indices of antennas reported to be bad.
% pep/30Jan13
function [uvflag, flagant] = flagdeadcorr (acc, tobs, freq, hithresh, lothresh)
ac = abs (acc - diag(diag(acc)));
uvflag = zeros (size (acc)); % 1 => bad visibility
flagant = [1:length(acc)];
if (isempty (hithresh)) hithresh =0.25; end; % default percent
if (isempty (lothresh)) lothresh =0.25; end; % default percent
% Find missing antennas. Row 20 is an arbit choice.
% missant = ac (20, :) == 0;
% missant(20) = 0; % Since missing autocorr will also be marked as bad.
% Find antennas with very low values.
mu = mean (ac); med = median (mu);
fl = mu < lothresh*med;
% missant = missant | fl;
flagant = flagant(fl);
uvflag (fl == 1, :) = 1; % Update uvflag with missing ants.
uvflag (:, fl == 1) = 1;
% For each antenna, find median absolute values of visibilities with all
% other antennas.
for ind = 1:size (acc, 1)
ant = ac (ind, :);
medant = median (ant); % NOTE: Median is unbiased wrt. outliers.
% plot (ant);
uvflag (ind, ant > medant + hithresh*medant) = 1; % Flag discrepant vis.
uvflag (ind, ant < medant - hithresh*medant) = 1;
end;