In [1]:
import zmq
import numpy

In [2]:
%pylab inline


Populating the interactive namespace from numpy and matplotlib

In [3]:
pylab.rcParams['figure.figsize'] = 14,5

In [4]:
def recv_array(socket, flags=0, copy=False, track=False):
    """recv a numpy array"""
    md = socket.recv_json(flags=flags)
    msg = socket.recv(flags=flags, copy=copy, track=track)
    buf = buffer(msg)
    A = numpy.frombuffer(buf, dtype=md['dtype'])
    return A.reshape(md['shape'])

In [5]:
REQUEST_TIMEOUT = 2500
SERVER_ENDPOINT = "tcp://localhost:5555"

context = zmq.Context()

#  Socket to talk to server
print "Connecting to array server..."
client = context.socket(zmq.REQ)
client.connect(SERVER_ENDPOINT)

poll = zmq.Poller()
poll.register(client, zmq.POLLIN)


Connecting to array server...

In [25]:
shots_requested = 10
request = str(shots_requested)  # ask for one shot of data
print "I: Sending (%s)" % request

client.send(request)


I: Sending (10)

In [26]:
socks = dict(poll.poll(REQUEST_TIMEOUT))
if socks.get(client) == zmq.POLLIN:
    data_array = recv_array(client)
    #reply = client.recv()

    if len(data_array) > 1:  # TODO test for the right size array
        print "I: Server replied OK: " + str(data_array.shape)

    else:
        # print "E: Malformed reply from server: %s" % reply
        print "E: no reply from server"


I: Server replied OK: (400, 1340, 10)

In [27]:
imshow(data_array[:,:,0])


Out[27]:
<matplotlib.image.AxesImage at 0x625f210>

In [28]:
plot(data_array[200,:,0])


Out[28]:
[<matplotlib.lines.Line2D at 0x6959e10>]

In [29]:
imshow(data_array[:,:,1]-data_array[:,:,2])


Out[29]:
<matplotlib.image.AxesImage at 0x7440c90>

In [30]:
imshow(numpy.fft.fftshift(numpy.log(numpy.abs(numpy.fft.fft2(data_array[:,:,0],axes=[1]))),axes=[1]))


Out[30]:
<matplotlib.image.AxesImage at 0x79f1110>