In [1]:
%matplotlib inline
import numpy as np
from karabo_data import RunDirectory, stack_detector_data
from karabo_data.geometry2 import AGIPD_1MGeometry
Fetch AGIPD detector data for one pulse to test with:
In [2]:
run = RunDirectory('/gpfs/exfel/exp/SPB/201831/p900039/proc/r0273/')
In [3]:
tid, train_data = run.select('*/DET/*', 'image.data').train_from_index(60)
In [4]:
stacked = stack_detector_data(train_data, 'image.data')
stacked_pulse = stacked[10]
stacked_pulse.shape
Out[4]:
Generate a simple geometry given the (x, y) coordinates of the first pixel in the first module of each quadrant, in pixel units relative to the centre, where the beam passes through the detector.
There are also methods to load and save CrystFEL format geometry files.
In [5]:
geom = AGIPD_1MGeometry.from_quad_positions(quad_pos=[
(-525, 625),
(-550, -10),
(520, -160),
(542.5, 475),
])
In [6]:
geom.inspect()
Out[6]:
The pixels are not necessarily all aligned, so precisely assembling data in a 2D array requires interpolation, which is slow:
In [7]:
%%time
data, centre_yx = geom.position_modules_interpolate(stacked_pulse)
print(data.shape)
But we know that the modules are closely aligned with the axes, so we can 'snap' the geometry to the grid and copy data more efficiently:
In [8]:
%%time
data, centre_yx = geom.position_modules_fast(stacked_pulse)
print(data.shape)
In [9]:
geom.plot_data_fast(np.clip(stacked_pulse, 0, 1000))
Out[9]: