EasyManua.ls Logo

Dectris EIGER 2 - Page 40

Dectris EIGER 2
41 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
[]$_ Python Code
import json
import numpy
import requests
from base64 import b64encode, b64decode
IP = '169.254.254.1'
PORT = '80'
def get_mask(ip, port):
"""
Return the pixel mask of host EIGER system as numpy.ndarray
"""
url = 'http://{}:{}/detector/api/1.8.0/config/pixel_mask'.format(ip, port)
reply = requests.get(url)
darray = reply.json()['value']
return numpy.frombuffer(b64decode(darray['data']),
dtype=numpy.dtype(str(darray['type']))).reshape(darray['shape'])
def set_mask(ndarray, ip, port):
"""
Put a pixel mask as ndarray on host EIGER system and return its reply
"""
url = 'http://%s:%s/detector/api/1.8.0/config/pixel_mask' % (ip, port)
data_json = json.dumps({'value': {
'__darray__': (1,0,0),
'type': ndarray.dtype.str,
'shape': ndarray.shape,
'filters': ['base64'],
'data': b64encode(ndarray.data).decode('ascii') }
})
headers = {'Content-Type': 'application/json'}
return requests.put(url, data= data_json, headers=headers)
if __name__ == '__main__':
# initialize the detector
url = 'http://{}:{}/detector/api/1.8.0/command/initialize'.format(IP, PORT)
assert (requests.put(url).status_code == 200), 'Detector could not be initialized'
# get the mask
mask = get_mask(ip=IP, port=PORT)
# copy the mask to writeable buffer, necessary for numpy>=1.16.0
mask = numpy.copy(mask)
# set a new dead pixel [y,x]
mask[123, 234] = 2
# set a new noisy pixel [y,x]
mask[234, 123] = 8
# upload the new mask
reply = set_mask(mask, ip=IP, port=PORT)
# reply.status_code should be 200, then arm and disarm to test the system
if reply.status_code == 200:
for command in ('arm', 'disarm'):
url = 'http://{}:{}/detector/api/1.8.0/command/%s'.format(IP, PORT, command)
requests.put(url)
else:
print reply.content
DECTRIS EIGER
®
2 User Manual v1.8.2 35 | 36

Table of Contents