1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 """
19
20 This module provides the ObitTask class. It adapts the Task class from
21 the Task module to be able to run Obit tasks:
22
23 >>> imean = ObitTask('Template')
24
25 The resulting class instance has all associated adverbs as attributes:
26
27 >>> print imean.ind
28 0.0
29 >>> imean.ind = 1
30 >>> print imean.indisk
31 1.0
32 >>> imean.indi = 2.0
33 >>> print imean.ind
34 2.0
35
36 It also knows the range for these attributes:
37
38 >>> imean.ind = -1
39 Traceback (most recent call last):
40 ...
41 ValueError: value '-1.0' is out of range for attribute 'indisk'
42 >>> imean.ind = 10.0
43 Traceback (most recent call last):
44 ...
45 ValueError: value '10.0' is out of range for attribute 'indisk'
46
47 >>> imean.inc = 'UVDATA'
48
49 >>> print imean.inclass
50 UVDATA
51
52 """
53
54
55 import AIPS
56
57
58 from AIPSTask import AIPSTask
59 from FITS import FITS
60
61
62 from Task import Task, List
63
64
65 import glob, os, pickle, sys
66
68
69 """This class implements running Obit tasks."""
70
71
72 _package = 'Obit'
73
74
75 _disk_adverbs = ['inDisk', 'in2Disk', 'outDisk', 'out2Disk']
76
77
78 version = 'OBIT'
79
80
81 userno = -1
82
83
84 debug = False
85
89
91 """Spawn the task."""
92
93 if self.userno == 0:
94 raise RuntimeError, "AIPS user number is not set"
95
96 input_dict = {}
97 for adverb in self._input_list:
98 input_dict[adverb] = self._retype(self.__dict__[adverb])
99
100
101 input_dict["DEBUG"] = self.debug
102
103
104
105 url = None
106 proxy = None
107 for adverb in self._disk_adverbs:
108 if adverb in input_dict:
109 disk = int(input_dict[adverb])
110 if disk == 0:
111 continue
112 if not url and not proxy:
113 if self.__dict__['DataType'] == 'AIPS':
114 url = AIPS.disks[disk].url
115 proxy = AIPS.disks[disk].proxy()
116 if AIPS.disks[disk].url != url:
117 raise RuntimeError, \
118 "AIPS disks are not on the same machine"
119 input_dict[adverb] = int(AIPS.disks[disk].disk)
120 elif self.__dict__['DataType'] == 'FITS':
121 url = FITS.disks[disk].url
122 proxy = FITS.disks[disk].proxy()
123 if FITS.disks[disk].url != url:
124 raise RuntimeError, \
125 "FITS disks are not on the same machine"
126 input_dict[adverb] = int(FITS.disks[disk].disk)
127 if not proxy:
128 raise RuntimeError, \
129 "Unable to determine where to execute task"
130
131 inst = getattr(proxy, self.__class__.__name__)
132 tid = inst.spawn(self._name, self.version, self.userno,
133 self.msgkill, self.isbatch, input_dict)
134
135 self._message_list = []
136 return (proxy, tid)
137
138 - def messages(self, proxy=None, tid=None):
139 """Return messages for the task specified by PROXY and TID."""
140
141 if not proxy and not tid:
142 return self._message_list
143
144 inst = getattr(proxy, self.__class__.__name__)
145 messages = inst.messages(tid)
146 if not messages:
147 return None
148 self._message_list.extend(messages)
149 return messages
150
170
171
172
173 if __name__ == '__main__':
174 import doctest, sys
175 doctest.testmod(sys.modules[__name__])
176