tkp.stream – Streaming telescope data

tkp.stream

Code for parsing streaming telescope data. For now we only support AARTFAAC data version 1. We implemented an emulator for this stream in testutil.stream_emu.

tkp.stream.connection_handler(socket_, image_queue)[source]

Handles the connection, waits until a windows is returned and puts it in the queue.

Daemon thread, will loop forever.

Parameters:
tkp.stream.connector(host, port, image_queue)[source]

Tries to connect to a specific host and port, if succesfull will call connection_handler() with the connection.

Parameters:
  • host (str) – host to connect to
  • port (int) – port to connect to
  • image_queue (Queue.Queue) – Will be used for putting the images in
tkp.stream.extract_timestamp(hdulist)[source]
Parameters:hdulist (astropy.io.fits.HDUList) – fits header to extract timestamp from
Returns:extracted timestamp
Return type:datetime.datetime
tkp.stream.getbytes(socket_, bytes_)[source]

Read an amount of bytes from the socket

Parameters:
  • socket (socket.socket) – socket to use for reading
  • bytes (int) – amount of bytes to read
Returns:

raw bytes from socket

Return type:

str

tkp.stream.merger(image_queue, grouped_queue)[source]

Will monitor image_queue for images and group them by timestamp. When an image with an successive timestamp is received the group is put on the grouped queue.

Parameters:
  • image_queue (Queue) – the incoming image queue
  • grouped_queue (Queue) – the outgoing grouped image queue
tkp.stream.read_window(socket_)[source]

read raw aarfaac protocol window

Parameters:socket (socket.socket) – socket to read from
Returns:fits_bytes, image_bytes
tkp.stream.reconstruct_fits(fits_bytes, image_bytes)[source]

reconstruct a fits object from serialised fits header and data.

Parameters:
  • fits_bytes (str) – a string with serialized fits bytes
  • image_bytes (str) – a string with serialized image data
Returns:

the fits object

Return type:

astropy.io.fits.HDUList

tkp.stream.stream_generator(hosts, ports)[source]

Connects to all hosts on port in ports. Returns a generator yielding sets of images with the same timestamp.

Parameters:
  • hosts (tuple) – list of hosts to connect to
  • ports (tuple) – list of ports to connect to