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>

In [31]:
plot(data_array[200,:,1] - data_array[200,:,5])


Out[31]:
[<matplotlib.lines.Line2D at 0x7a1c450>]

In [22]:
noise = data_array[200,:,1] - data_array[200,:,4]

In [23]:
import scipy.stats

In [64]:
noise.std()


Out[64]:
61.135537480026386

In [53]:
hist_data, bin_edges = numpy.histogram(noise,bins=20)

In [55]:
bar(bin_edges[:-1], hist_data,width=20)


Out[55]:
<Container object of 20 artists>

Statistics

The standard deviation is $\sigma=61$ for the warm CCD. Check this again when cold.


In [ ]: