Sample scripts for Medipix3 (MPX3) device

Sample script #1:
Detector settings (operation mode, counter depth, range, threshold), simple acquisition

# get list of all connected Medipix3 devices
devices = pixet.devicesByType(pixet.PX_DEVTYPE_MPX3)

# get first device from list
dev = devices[0] # returns IDevMpx3 object

# set operation mode 
dev.setOperationMode(pixet.PX_MPX3_OPM_SPM_1CH)
#	SPM 1 CH:  pixet.PX_MPX3_OPM_SPM_1CH (0)
#	SPM 2 CH:  pixet.PX_MPX3_OPM_SPM_2CH (1)
#	CSM:       pixet.PX_MPX3_OPM_CSM (2)

# get operation mode
print('Operation mode: ' + str(dev.operationMode()))
# set counter depth
dev.setCounterDepth(pixet.PX_MPX3_CNTD_24B)
# 12 bits:  pixet.PX_MPX3_CNTD_12B (2)
# 24 bits:  pixet.PX_MPX3_CNTD_24B (3)

# get counter depth
print('Counter depth: ' + str(dev.counterDepth()))

# set range 
dev.setGain(pixet.PX_MPX3_GAIN_SUPERHIGH)
#	Super Narrow: pixet.PX_MPX3_GAIN_SUPERHIGH (0)
#	Narrow:       pixet.PX_MPX3_GAIN_HIGH (1)
#	Broad:        pixet.PX_MPX3_GAIN_SUPERLOW (3)

# set threshold
th_index = pixet.PX_MPX3_TH0  # index of threshold to be changed
# THL 0: pixet.PX_MPX3_TH0 (0)
# THL 1: pixet.PX_MPX3_TH1 (1)
chip = 4                      # chip index (chips are counted from 0!)
# chip #1:   0 
# chip #5:   4
# all chips: pixet.PX_CHIP_ALL (-1)
th_energy = 30                # new value of threshold in keV
dev.setThreshold(chip, th_index, th_energy, pixet.PX_THLFLG_ENERGY)

# acquisition
acqCount = 1        # number of acquisitions
acqTime = 10        # time of acquisition in seconds
dev.doSimpleAcquisition(acqCount, acqTime, pixet.PX_FTYPE_NONE, '')

# get last acquired image 
frame = dev.lastAcqFrameRefInc()
data = frame.data()

Sample script #2:
Integral acquisition, saving the data

# get first device from list of all connected Medipix3 devices
dev = pixet.devicesByType(pixet.PX_DEVTYPE_MPX3)[0]

# set operation mode 
dev.setOperationMode(pixet.PX_MPX3_OPM_SPM_2CH)
# set acquisition parameters
acqCount = 10           # number of acquisitions for integral measurement
acqTime = 0.1           # time of one acquisition
fileName = './test/image.txt'

# integral acquisition, saving
dev.doSimpleIntegralAcquisition(acqCount, acqTime, pixet.PX_FTYPE_AUTODETECT, fileName) # data are automatically saved

Sample script #3:
Threshold scan

# get first device from list of all connected Medipix3 devices
dev = pixet.devicesByType(pixet.PX_DEVTYPE_MPX3)[0]

# set operation mode 
dev.setOperationMode(pixet.PX_MPX3_OPM_CSM)

# set acquisition parameters
th = pixet.PX_MPX3_TH1  # index of threshold to be changed
ths = range(10,45,5)    # thresholds in keV
acqCounts = [1 for number in ths] 
acqTimes = [0.1 for number in ths]
output = './test_'      # destination path

# threshold scan
for i in range(len(ths)):        
    print('TH: {}'.format(ths[i]))
    dev.setThreshold(pixet.PX_CHIP_ALL, th, ths[i], pixet.PX_THLFLG_ENERGY)

    fileName = output + str(ths[i]).zfill(3) + 'keV.txt'

    dev.doSimpleIntegralAcquisition(acqCounts[i], acqTimes[i], pixet.PX_FTYPE_AUTODETECT, fileName)