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 
#	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
# 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 
#	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 =

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 
# 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 

# 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)

Thank you for this sample script. I’m starting coding Python scripts for Medipix3 Advacam devices.
My first question concerns the difference between the two methods doSimpleAcquisition and doSimpleIntegralAcquisition. They have the same signature (same type and number of parameters) and I did not manage to find an explicit documentation on what they are doing.
Could you help me please ?


Dear Yannick,

doSimpleAcquisition(acqCount, acqTime, fileType, fileName) runs several acquisitions, number of acquisitions is defined by acqCount parameter

doSimpleIntegralAcquisition(acqCount, acqTime, fileType, fileName) does the same, but the measured data of all acquisitions are added (integrated) into one frame

doSimpleAcquisition(10, 0.1, pixet.PX_FTYPE_AUTODETECT, ‘test.txt’) —> 10 frames are saved, each corresponding to 0.1 s acquisition

doSimpleIntegralAcquisition(10, 0.1, pixet.PX_FTYPE_AUTODETECT, ‘test.txt’) —> 1 frame is saved with resulting acquisition time 1 s


Dear Daniela,
Thank you for your answer. I have written a python script in order to perform a threshold scan in CSM mode, and I would like to test it.

However, I cannot have access to the Python Scripting option in the Tool menu in Pixet and I do not understand the problem.
I developed at home on a downloaded version of PIXET v1.7.1 (not connected to any Medipix device of course). On this PIXET version, in the Tool menu, I have the Python Scripting option, and then I can execute my script in the dedicated window.

However, at the company, a version of PIXET 1.6 is installed (due to the Linux distribution currently installed that only support Qt4), and PIXET is connected to an Advacam Medipix3 WidePix acquisition system. In the Tools menu, no Python Scripting is proposed and I did not manage to find it elsewhere.

Could you help me please ?

Thank you for your answer,
Keep safe,

Dear Yannik,

can you send me an email with log files from Pixet - they are located either in the Pixet directory - logs. Or in ~/.config/PixetPro/logs.

thank you