In [1]:
import zmq
import numpy
In [2]:
%pylab inline
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)
In [25]:
shots_requested = 10
request = str(shots_requested) # ask for one shot of data
print "I: Sending (%s)" % request
client.send(request)
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"
In [27]:
imshow(data_array[:,:,0])
Out[27]:
In [28]:
plot(data_array[200,:,0])
Out[28]:
In [29]:
imshow(data_array[:,:,1]-data_array[:,:,2])
Out[29]:
In [30]:
imshow(numpy.fft.fftshift(numpy.log(numpy.abs(numpy.fft.fft2(data_array[:,:,0],axes=[1]))),axes=[1]))
Out[30]:
In [31]:
plot(data_array[200,:,1] - data_array[200,:,5])
Out[31]:
In [22]:
noise = data_array[200,:,1] - data_array[200,:,4]
In [23]:
import scipy.stats
In [64]:
noise.std()
Out[64]:
In [53]:
hist_data, bin_edges = numpy.histogram(noise,bins=20)
In [55]:
bar(bin_edges[:-1], hist_data,width=20)
Out[55]:
In [ ]: