Commit b2321879 authored by Thomas Kluyver's avatar Thomas Kluyver
Browse files

Add example notebook

parent 0d270641
/build/
*.c
.ipynb_checkpoints/
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import h5py\n",
"\n",
"from pycrystfel.bindings import inspect_geom_file, find_peaks_single_panel, Detector"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"n_panels: 128\n",
"panel names: [b'p0a0', b'p0a1', b'p0a2', b'p0a3', b'p0a4', b'p0a5', b'p0a6', b'p0a7', b'p1a0', b'p1a1', b'p1a2', b'p1a3', b'p1a4', b'p1a5', b'p1a6', b'p1a7', b'p2a0', b'p2a1', b'p2a2', b'p2a3', b'p2a4', b'p2a5', b'p2a6', b'p2a7', b'p3a0', b'p3a1', b'p3a2', b'p3a3', b'p3a4', b'p3a5', b'p3a6', b'p3a7', b'p4a0', b'p4a1', b'p4a2', b'p4a3', b'p4a4', b'p4a5', b'p4a6', b'p4a7', b'p5a0', b'p5a1', b'p5a2', b'p5a3', b'p5a4', b'p5a5', b'p5a6', b'p5a7', b'p6a0', b'p6a1', b'p6a2', b'p6a3', b'p6a4', b'p6a5', b'p6a6', b'p6a7', b'p7a0', b'p7a1', b'p7a2', b'p7a3', b'p7a4', b'p7a5', b'p7a6', b'p7a7', b'p8a0', b'p8a1', b'p8a2', b'p8a3', b'p8a4', b'p8a5', b'p8a6', b'p8a7', b'p9a0', b'p9a1', b'p9a2', b'p9a3', b'p9a4', b'p9a5', b'p9a6', b'p9a7', b'p10a0', b'p10a1', b'p10a2', b'p10a3', b'p10a4', b'p10a5', b'p10a6', b'p10a7', b'p11a0', b'p11a1', b'p11a2', b'p11a3', b'p11a4', b'p11a5', b'p11a6', b'p11a7', b'p12a0', b'p12a1', b'p12a2', b'p12a3', b'p12a4', b'p12a5', b'p12a6', b'p12a7', b'p13a0', b'p13a1', b'p13a2', b'p13a3', b'p13a4', b'p13a5', b'p13a6', b'p13a7', b'p14a0', b'p14a1', b'p14a2', b'p14a3', b'p14a4', b'p14a5', b'p14a6', b'p14a7', b'p15a0', b'p15a1', b'p15a2', b'p15a3', b'p15a4', b'p15a5', b'p15a6', b'p15a7']\n",
"photon energy: 4972.0\n"
]
}
],
"source": [
"inspect_geom_file('../agipd_simple_2d.geom')"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Image shape: (1000, 1000)\n"
]
}
],
"source": [
"with h5py.File('../monolithic_img_1.h5', 'r') as f:\n",
" arr = f['data/data'][()]\n",
"print(\"Image shape:\", arr.shape)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Loaded geometry with 1 panels\n"
]
},
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>ss</th>\n",
" <th>fs</th>\n",
" <th>rx</th>\n",
" <th>ry</th>\n",
" <th>rz</th>\n",
" <th>intensity</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>3.500000</td>\n",
" <td>524.250000</td>\n",
" <td>2.505115e-318</td>\n",
" <td>2.340294e-310</td>\n",
" <td>2.340294e-310</td>\n",
" <td>18701.500000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>4.500000</td>\n",
" <td>328.000000</td>\n",
" <td>2.352760e-318</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>19184.888672</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>18.250000</td>\n",
" <td>577.750000</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>19427.628906</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>22.928572</td>\n",
" <td>362.928558</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>33865.886719</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>30.500000</td>\n",
" <td>651.750000</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>19319.771484</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>120</th>\n",
" <td>955.200012</td>\n",
" <td>317.399994</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>48995.921875</td>\n",
" </tr>\n",
" <tr>\n",
" <th>121</th>\n",
" <td>960.166687</td>\n",
" <td>793.166687</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>14225.445312</td>\n",
" </tr>\n",
" <tr>\n",
" <th>122</th>\n",
" <td>961.166687</td>\n",
" <td>372.500000</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>13649.546875</td>\n",
" </tr>\n",
" <tr>\n",
" <th>123</th>\n",
" <td>994.500000</td>\n",
" <td>518.833313</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>14537.181641</td>\n",
" </tr>\n",
" <tr>\n",
" <th>124</th>\n",
" <td>996.500000</td>\n",
" <td>521.000000</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>0.000000e+00</td>\n",
" <td>9605.000000</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>125 rows × 6 columns</p>\n",
"</div>"
],
"text/plain": [
" ss fs rx ry rz \\\n",
"0 3.500000 524.250000 2.505115e-318 2.340294e-310 2.340294e-310 \n",
"1 4.500000 328.000000 2.352760e-318 0.000000e+00 0.000000e+00 \n",
"2 18.250000 577.750000 0.000000e+00 0.000000e+00 0.000000e+00 \n",
"3 22.928572 362.928558 0.000000e+00 0.000000e+00 0.000000e+00 \n",
"4 30.500000 651.750000 0.000000e+00 0.000000e+00 0.000000e+00 \n",
".. ... ... ... ... ... \n",
"120 955.200012 317.399994 0.000000e+00 0.000000e+00 0.000000e+00 \n",
"121 960.166687 793.166687 0.000000e+00 0.000000e+00 0.000000e+00 \n",
"122 961.166687 372.500000 0.000000e+00 0.000000e+00 0.000000e+00 \n",
"123 994.500000 518.833313 0.000000e+00 0.000000e+00 0.000000e+00 \n",
"124 996.500000 521.000000 0.000000e+00 0.000000e+00 0.000000e+00 \n",
"\n",
" intensity \n",
"0 18701.500000 \n",
"1 19184.888672 \n",
"2 19427.628906 \n",
"3 33865.886719 \n",
"4 19319.771484 \n",
".. ... \n",
"120 48995.921875 \n",
"121 14225.445312 \n",
"122 13649.546875 \n",
"123 14537.181641 \n",
"124 9605.000000 \n",
"\n",
"[125 rows x 6 columns]"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"peaks_tbl = find_peaks_single_panel(arr, '../1panel.geom')\n",
"peaks_tbl"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"det = Detector.from_filename('../agipd_simple_2d.geom')"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"128"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"det.n_panels"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['p0a0',\n",
" 'p0a1',\n",
" 'p0a2',\n",
" 'p0a3',\n",
" 'p0a4',\n",
" 'p0a5',\n",
" 'p0a6',\n",
" 'p0a7',\n",
" 'p1a0',\n",
" 'p1a1']"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"det.panel_names()[:10]"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "xfel",
"language": "python",
"name": "xfel"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
%% Cell type:code id: tags:
``` python
import h5py
from pycrystfel.bindings import inspect_geom_file, find_peaks_single_panel, Detector
```
%% Cell type:code id: tags:
``` python
inspect_geom_file('../agipd_simple_2d.geom')
```
%%%% Output: stream
n_panels: 128
panel names: [b'p0a0', b'p0a1', b'p0a2', b'p0a3', b'p0a4', b'p0a5', b'p0a6', b'p0a7', b'p1a0', b'p1a1', b'p1a2', b'p1a3', b'p1a4', b'p1a5', b'p1a6', b'p1a7', b'p2a0', b'p2a1', b'p2a2', b'p2a3', b'p2a4', b'p2a5', b'p2a6', b'p2a7', b'p3a0', b'p3a1', b'p3a2', b'p3a3', b'p3a4', b'p3a5', b'p3a6', b'p3a7', b'p4a0', b'p4a1', b'p4a2', b'p4a3', b'p4a4', b'p4a5', b'p4a6', b'p4a7', b'p5a0', b'p5a1', b'p5a2', b'p5a3', b'p5a4', b'p5a5', b'p5a6', b'p5a7', b'p6a0', b'p6a1', b'p6a2', b'p6a3', b'p6a4', b'p6a5', b'p6a6', b'p6a7', b'p7a0', b'p7a1', b'p7a2', b'p7a3', b'p7a4', b'p7a5', b'p7a6', b'p7a7', b'p8a0', b'p8a1', b'p8a2', b'p8a3', b'p8a4', b'p8a5', b'p8a6', b'p8a7', b'p9a0', b'p9a1', b'p9a2', b'p9a3', b'p9a4', b'p9a5', b'p9a6', b'p9a7', b'p10a0', b'p10a1', b'p10a2', b'p10a3', b'p10a4', b'p10a5', b'p10a6', b'p10a7', b'p11a0', b'p11a1', b'p11a2', b'p11a3', b'p11a4', b'p11a5', b'p11a6', b'p11a7', b'p12a0', b'p12a1', b'p12a2', b'p12a3', b'p12a4', b'p12a5', b'p12a6', b'p12a7', b'p13a0', b'p13a1', b'p13a2', b'p13a3', b'p13a4', b'p13a5', b'p13a6', b'p13a7', b'p14a0', b'p14a1', b'p14a2', b'p14a3', b'p14a4', b'p14a5', b'p14a6', b'p14a7', b'p15a0', b'p15a1', b'p15a2', b'p15a3', b'p15a4', b'p15a5', b'p15a6', b'p15a7']
photon energy: 4972.0
%% Cell type:code id: tags:
``` python
with h5py.File('../monolithic_img_1.h5', 'r') as f:
arr = f['data/data'][()]
print("Image shape:", arr.shape)
```
%%%% Output: stream
Image shape: (1000, 1000)
%% Cell type:code id: tags:
``` python
peaks_tbl = find_peaks_single_panel(arr, '../1panel.geom')
peaks_tbl
```
%%%% Output: stream
Loaded geometry with 1 panels
%%%% Output: execute_result
ss fs rx ry rz \
0 3.500000 524.250000 2.505115e-318 2.340294e-310 2.340294e-310
1 4.500000 328.000000 2.352760e-318 0.000000e+00 0.000000e+00
2 18.250000 577.750000 0.000000e+00 0.000000e+00 0.000000e+00
3 22.928572 362.928558 0.000000e+00 0.000000e+00 0.000000e+00
4 30.500000 651.750000 0.000000e+00 0.000000e+00 0.000000e+00
.. ... ... ... ... ...
120 955.200012 317.399994 0.000000e+00 0.000000e+00 0.000000e+00
121 960.166687 793.166687 0.000000e+00 0.000000e+00 0.000000e+00
122 961.166687 372.500000 0.000000e+00 0.000000e+00 0.000000e+00
123 994.500000 518.833313 0.000000e+00 0.000000e+00 0.000000e+00
124 996.500000 521.000000 0.000000e+00 0.000000e+00 0.000000e+00
intensity
0 18701.500000
1 19184.888672
2 19427.628906
3 33865.886719
4 19319.771484
.. ...
120 48995.921875
121 14225.445312
122 13649.546875
123 14537.181641
124 9605.000000
[125 rows x 6 columns]
%% Cell type:code id: tags:
``` python
det = Detector.from_filename('../agipd_simple_2d.geom')
```
%% Cell type:code id: tags:
``` python
det.n_panels
```
%%%% Output: execute_result
128
%% Cell type:code id: tags:
``` python
det.panel_names()[:10]
```
%%%% Output: execute_result
['p0a0',
'p0a1',
'p0a2',
'p0a3',
'p0a4',
'p0a5',
'p0a6',
'p0a7',
'p1a0',
'p1a1']
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment