-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathimage_cenA.py
executable file
·118 lines (106 loc) · 5.95 KB
/
image_cenA.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/python
# Track target(s) for a specified time.
# The *with* keyword is standard in Python 2.6, but has to be explicitly imported in Python 2.5
from __future__ import with_statement
import optparse
import sys
import uuid
import katuilib
import katpoint
import numpy as np
# Parse command-line options that allow the defaults to be overridden
parser = optparse.OptionParser(usage="%prog [options] <'target'> <'calsource'> [<'calsource'>*]",
description="Perform an imaging run of a specified target. A target and one or more cal sources are specified. The mosaic option provides for a three north south scans offset by the HPBW.")
# Generic options
parser.add_option('-i', '--ini_file', dest='ini_file', type="string", metavar='INI', help='Telescope configuration ' +
'file to use in conf directory (default reuses existing connection, or falls back to cfg-local.ini)')
parser.add_option('-s', '--selected_config', dest='selected_config', type="string", metavar='SELECTED',
help='Selected configuration to use (default reuses existing connection, or falls back to local_ff)')
parser.add_option('-u', '--experiment_id', dest='experiment_id', type="string",
help='Experiment ID used to link various parts of experiment together (UUID generated by default)')
parser.add_option('-o', '--observer', dest='observer', type="string",
help='Name of person doing the observation (**required**)')
parser.add_option('-d', '--description', dest='description', type="string", default="Target track",
help='Description of observation (default="%default")')
parser.add_option('-a', '--ants', dest='ants', type="string", metavar='ANTS',
help="Comma-separated list of antennas to include (e.g. 'ant1,ant2')," +
" or 'all' for all antennas (**required** - safety reasons)")
parser.add_option('-f', '--centre_freq', dest='centre_freq', type="float", default=1822.0,
help='Centre frequency, in MHz (default="%default")')
parser.add_option('-w', '--discard_slews', dest='record_slews', action="store_false", default=True,
help='Do not record all the time, i.e. pause while antennas are slewing to the next target')
# Experiment-specific options
parser.add_option('-t', '--track_duration', dest='track_duration', type="int", default=60*15,
help='Length of time to track each segment of the mosaic, in integer secs (default="%default")')
parser.add_option('-c', '--cal_duration', dest='cal_duration', type='int', default=60*3, help='Length of time to spend on the cal source (default="%default")')
parser.add_option('-m', '--mosaic', dest='mosaic', action="store_true", default=False, help='Do a 3 pixel N/S mosaic. Only really useful for CenA')
(opts, args) = parser.parse_args()
if len(args) < 2:
print "Please specify at least a target and a cal source"
sys.exit(1)
# Various non-optional options...
if opts.ants is None:
print 'Please specify the antennas to use via -a option (yes, this is a non-optional option...)'
sys.exit(1)
if opts.observer is None:
print 'Please specify the observer name via -o option (yes, this is a non-optional option...)'
sys.exit(1)
if opts.experiment_id is None:
# Generate unique string via RFC 4122 version 1
opts.experiment_id = str(uuid.uuid1())
# Try to build the given KAT configuration (which might be None, in which case try to reuse latest active connection)
# This connects to all the proxies and devices and queries their commands and sensors
try:
kat = katuilib.tbuild(opts.ini_file, opts.selected_config)
# Fall back to *local* configuration to prevent inadvertent use of the real hardware
except ValueError:
kat = katuilib.tbuild('cfg-local.ini', 'local_ff')
print "\nUsing KAT connection with configuration: %s\n" % (kat.get_config(),)
targets = []
for arg in args:
# With no comma in the target string, assume it's the name of a target to be looked up in the standard catalogue
if arg.find(',') < 0:
target = kat.sources[arg]
if target is None:
print "Unknown source '%s', skipping it" % (arg,)
else:
targets.append(target)
else:
# Assume the argument is a target description string
targets.append(katpoint.Target(arg, antenna=kat.sources.antenna))
if len(targets) != len(args):
print "Failed to find all targets specified."
sys.exit(1)
tgt = targets[0]
calibrators = targets[1:]
print "Target is",tgt.description
print "Calibrator(s) are",calibrators
hpbw_r = tgt.antenna.beamwidth * katpoint.lightspeed / (opts.centre_freq * 1e6) / 12 / 2
# half power beam width in radians
tgts = []
if opts.mosaic:
(ra, dec) = tgt.radec()
print "Mosaic declinations are:",dec-hpbw_r,",",float(dec),",",dec+hpbw_r
tgts.append(katpoint.construct_radec_target(ra, dec-hpbw_r))
tgts.append(katpoint.construct_radec_target(ra, dec))
tgts.append(katpoint.construct_radec_target(ra, dec+hpbw_r))
else:
tgts.append(tgt)
# Create a data capturing session with the selected sub-array of antennas
with katuilib.start_session(kat, **vars(opts)) as session:
session.standard_setup(**vars(opts))
session.capture_start()
while tgt.azel()[1] > 0.57/2.0:
# observe the calibrator(s)
for cal in [x for x in calibrators if x.azel()[1] > 0.57/2.0]:
print "Observing calibrator"
session.track(cal, duration=opts.cal_duration, drive_strategy='longest-track', label='cal_source')
session.fire_noise_diode('coupler')
# observe the target(s)
print "Doing track(s)"
for target in tgts:
# Track target
session.track(target, duration=opts.track_duration, drive_strategy='longest-track', label='track')
# Fire noise diode, to allow gain calibration
session.fire_noise_diode('coupler')
print "Session ended with tgt el",tgt.azel()[1],"and cal el",[x.azel()[1] for x in calibrators]