#!/usr/bin/perl -w
# Flexibly removes a confusing source from the latest visibilities in a
# directory, and adds an entry to logs/index.html.
use Getopt::Long;
use DRAORed;
my $cline = join(" ", @ARGV);
$use = q {
Use: remove_confsrc (--(casa|cyga|NP)|-l "RA, Dec") [-s size] [-(m|d)]
[-i minspac] [-a maxspac] [(-x pixxs -y pixys |--xy pixs)]
[-k stokes -b band] [confsrcname]
Remove a confusing source from the latest visibilities in the current directory.
It only removes one source at a time, but may be run repeatedly.
Appends progess information to index.html.
--casa: Remove Cassiopeia A.
--cyga: Remove Cygnus A.
--NP: Remove persistent site interference.
-l "RA, Dec": Remove the source at J2000 equatorial coordinates (RA, Dec).
They may be written in either hms, dms
(i.e. 10h23m39.78s, -78d56m23.78s) decimal degrees, or the format
of kvis' l output, but the pair must be enclosed in quotes to
keep them as a single argument.
-s size: Number of pixels on a side of the image of the confusing source.
Note that this is for the image that is actually removed, i.e.
the inner quarter of an intermediate image.
Defaults to 128.
-m: Produce a 1024^2 centered image from the resulting visibilities.
-d: Produce a 1024^2 dirty beam from the resulting visibilities.
Implies -m.
-n num Only use day number num of the observation for the image of the
confusing source. The maximum spacing is set to 24 for the image
only.
-i minspac: The minimum spacing to be used.
-a maxspac: The maximum spacing to be used.
-x pixxs: The x pixel size in arcminutes for the confusing source.
-y pixys: The y pixel size in arcminutes for the confusing source.
--xy pixs: The size for the confusing source in arcminutes for square pixels.
-k stokes: i, q, u, or v.
-b band: a, b, c, or d, or possibly some combination thereof.
If the path is of the form .../stokes/band it provides the
default for stokes and band. Otherwise they default to I and
ABCD.
confsrcname: Name to give the confusing source, used for its image filename
and in the log.
Overridably defaults to "Cas A" or "Cyg A" if --casa or --cyga
is used.
};
GetOptions("casa" => \$docasa,
"cyga" => \$docyga,
"NP" => \$donp,
"l=s" => \$posstr,
"s=i" => \$size,
"d" => \$dodb,
"m" => \$dom,
"n=i" => \$odnum,
"i=i" => \$minspacing,
"a=i" => \$maxspacing,
"x=f" => \$pixxs,
"y=f" => \$pixys,
"xy=f" => \$pixs,
"k=s" => \$stokes,
"b=s" => \$band) or die $use;
unless($stokes and $band){
($stokes, $band) = get_stokesandbandfromdir();
}
if($docasa){
$cnfsrcnm = "Cas A";
$cnfsrcfiln = "CASA.M\u${stokes}21";
$posstr = "23H 23M 25.80S, 58D 49\'";
}
elsif($docyga){
$cnfsrcnm = "Cyg A";
$cnfsrcfiln = "CYGA.M\u${stokes}21";
$posstr = "19h59m28.3s, 40d44\'02\"";
}
elsif($donp){
$cnfsrcnm = "NP";
$size ||= 256;
$maxspacing ||= 11;
$pixs ||= 2.5;
$cnfsrcfiln = "NP${maxspacing}.M\u${stokes}21";
my ($rac, $decc) = get_phase_center($stokes, $band);
$decc = "89d0m0s";
$posstr = "$rac, $decc";
}
# This must come after --casa and --cyga so that 2nd and 3rd removals of either
# can be given names like CASA2, etc.
if($ARGV[0]){
$cnfsrcnm = $ARGV[0];
$cnfsrcfiln = "\U${cnfsrcnm}.M${stokes}\E21";
}
unless($cnfsrcnm){
die "Need a name for the confusing source!\n$use";
}
if($posstr){
$posstr =~ s/Ra //i; # Remove kvisisms.
$posstr =~ s/s\s+Dec\s+/s, /i;
}
else{
die "Need a position!\n$use";
}
$size ||= 128;
if($size < 64 || $size > 1024){
die "Size must be 64, 128, 256, 512, or 1024.\n$use";
}
$minspacing ||= 3;
$maxspacing ||= 144;
if($minspacing > $maxspacing){
my $temp = $minspacing;
$minspacing = $maxspacing;
$maxspacing = $temp;
}
if($minspacing < 3){
$minspacing = 3;
warn "The minimum spacing must be within [3, 144]. Using 3.\n$use";
}
if($maxspacing > 144){ # It would be neat to use a specified maxspacing > 144
$maxspacing = 144; # as a specification for the 20% tapering spacing.
warn "The maximum spacing must be within [3, 144]. Using 144.\n$use";
}
$pixs ||= 0.3333333;
$pixxs ||= $pixs;
$pixys ||= $pixs;
my $survey = survey();
my ($visibs, $vnr) = latestviscode($stokes, $band);
# Make an image twice as large as requested of the confusing source.
if($odnum){
print "Day: $odnum\n";
($slog, $ofile) = makeimage(SURVEY => $survey,
STOKES => $stokes,
BAND => $band,
VISCODE => $visibs,
DAYNUM => $odnum,
MINSPAC => $minspacing,
MAXSPAC => 24,
XSIZE => 2 * $size,
YSIZE => 2 * $size,
PIXXS => $pixxs,
PIXYS => $pixys,
SHIFTPOS => $posstr);
}
else{
($slog, $ofile) = makeimage(SURVEY => $survey,
STOKES => $stokes,
BAND => $band,
VISCODE => $visibs,
MINSPAC => $minspacing,
MAXSPAC => $maxspacing,
XSIZE => 2 * $size,
YSIZE => 2 * $size,
PIXXS => $pixxs,
PIXYS => $pixys,
SHIFTPOS => $posstr);
}
$cline =~ s/([^ ]+), ([^ ]+)/\"$1, $2\"/; # Quote the position, if present.
my $logname = "${cnfsrcnm}.html";
$logname =~ s/ //;
my $dummy = checklogd($logname);
if($dummy > 0){
warn "Uh oh! $cnfsrcnm was already removed. You have some fixing to do!";
}
open(LOG, ">>logs/index.html") or warn "Could not add entry to index.html";
print LOG "remove_confsrc $cline
\n";
close(LOG) or warn "Could not close index.html! Continuing!";
open(LOG, ">logs/$logname") or warn "Could not open logs/$logname";
print LOG "