def target_start(self, beam_info, output_dir): # Send target information to apsuse pipeline # and trigger file writing # First build message containing beam information # in JSON form: # # { # "command":"start", # "beam_parameters": [ # {id: "cfbf00000", name: "PSRJ1823+3410", "ra": "00:00:00.00", "dec": "00:00:00.00"}, # {id: "cfbf00002", name: "SBGS0000", "ra": "00:00:00.00", "dec": "00:00:00.00"}, # {id: "cfbf00006", name: "SBGS0000", "ra": "00:00:00.00", "dec": "00:00:00.00"}, # {id: "cfbf00008", name: "SBGS0000", "ra": "00:00:00.00", "dec": "00:00:00.00"}, # {id: "cfbf00010", name: "SBGS0000", "ra": "00:00:00.00", "dec": "00:00:00.00"} # ] # } # # Here the "idx" parameter refers to the internal index of the beam, e.g. if the # apsuse executable is handling 6 beams these are numbered 0-5 regardless of their # global index. It is thus necessary to track the mapping between internal and # external indices for these beams. # log.info("Target start on capture instance") beam_params = [] message_dict = { "command": "start", "directory": output_dir, "beam_parameters": beam_params } log.info("Parsing beam information") for beam, target_str in beam_info.items(): if beam in self._internal_beam_mapping: idx = self._internal_beam_mapping[beam] target = Target(target_str) ra, dec = map(str, target.radec()) log.info( "IDX: {}, name: {}, ra: {}, dec: {}, source: {}".format( idx, beam, ra, dec, target.name)) beam_params.append({ "idx": idx, "name": beam, "source": target.name, "ra": ra, "dec": dec }) log.debug("Connecting to apsuse instance via socket") client = UDSClient(self._control_socket) log.debug("Sending message: {}".format(json.dumps(message_dict))) client.send(json.dumps(message_dict)) response_str = client.recv(timeout=3) try: response = json.loads(response_str)["response"] except Exception: log.exception( "Unable to parse JSON returned from apsuse application") else: log.debug("Response: {}".format(response_str)) if response != "success": raise Exception("Failed to start APSUSE recording") finally: client.close() log.debug("Closed socket connection")
class TestVirtualSensors: def setup(self): self.target = Target('PKS1934-638, radec, 19:39, -63:42') self.antennas = [ Antenna('m000, -30:42:39.8, 21:26:38.0, 1086.6, 13.5, ' '-8.264 -207.29 8.5965'), Antenna('m063, -30:42:39.8, 21:26:38.0, 1086.6, 13.5, ' '-3419.5845 -1840.48 16.3825') ] corrprods = [('m000h', 'm000h'), ('m000v', 'm000v'), ('m063h', 'm063h'), ('m063v', 'm063v'), ('m000h', 'm063h'), ('m000v', 'm063v')] subarray = Subarray(self.antennas, corrprods) spw = SpectralWindow(centre_freq=1284e6, channel_width=0, num_chans=16, sideband=1, bandwidth=856e6) # Pick a time when the source is up as that seems more realistic self.timestamps = 1234667890.0 + 1.0 * np.arange(10) self.dataset = MinimalDataSet(self.target, subarray, spw, self.timestamps) self.array_ant = self.dataset.sensor.get('Antennas/array/antenna')[0] def test_timestamps(self): mjd = Timestamp(self.timestamps[0]).to_mjd() assert_equal(self.dataset.mjd[0], mjd) lst = self.array_ant.local_sidereal_time(self.timestamps) # Convert LST from radians (katpoint) to hours (katdal) assert_array_equal(self.dataset.lst, lst * (12 / np.pi)) def test_pointing(self): az, el = self.target.azel(self.timestamps, self.antennas[1]) assert_array_equal(self.dataset.az[:, 1], rad2deg(az)) assert_array_equal(self.dataset.el[:, 1], rad2deg(el)) ra, dec = self.target.radec(self.timestamps, self.antennas[0]) assert_array_almost_equal(self.dataset.ra[:, 0], rad2deg(ra), decimal=5) assert_array_almost_equal(self.dataset.dec[:, 0], rad2deg(dec), decimal=5) angle = self.target.parallactic_angle(self.timestamps, self.antennas[0]) # TODO: Check why this is so poor... see SR-1882 for progress on this assert_array_almost_equal(self.dataset.parangle[:, 0], rad2deg(angle), decimal=0) x, y = self.target.sphere_to_plane(az, el, self.timestamps, self.antennas[1]) assert_array_equal(self.dataset.target_x[:, 1], rad2deg(x)) assert_array_equal(self.dataset.target_y[:, 1], rad2deg(y)) def test_uvw(self): u0, v0, w0 = self.target.uvw(self.antennas[0], self.timestamps, self.array_ant) u1, v1, w1 = self.target.uvw(self.antennas[1], self.timestamps, self.array_ant) u = u0 - u1 v = v0 - v1 w = w0 - w1 assert_array_equal(self.dataset.u[:, 4], u) assert_array_equal(self.dataset.v[:, 4], v) assert_array_equal(self.dataset.w[:, 4], w) # Check that both H and V polarisations have the same (u, v, w) assert_array_equal(self.dataset.u[:, 5], u) assert_array_equal(self.dataset.v[:, 5], v) assert_array_equal(self.dataset.w[:, 5], w)