Commit 0138e8a4 authored by myron's avatar myron

Added doc for detector translation

parent ad876173
Pipeline #28390 passed with stages
in 3 minutes
......@@ -11,7 +11,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
......@@ -28,7 +28,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
......@@ -46,7 +46,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
......@@ -69,7 +69,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
......@@ -85,7 +85,7 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 5,
"metadata": {},
"outputs": [
{
......@@ -94,7 +94,7 @@
"5.500000000034399"
]
},
"execution_count": 21,
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
......@@ -105,16 +105,7 @@
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [],
"source": [
"cor.find_shift(radio1, radio2flipped)### The Rotation axis is therefore at"
]
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 8,
"metadata": {},
"outputs": [
{
......@@ -123,7 +114,7 @@
"105.0"
]
},
"execution_count": 23,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
......@@ -133,6 +124,35 @@
"(200-1)/2.0 + 5.5"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"ename": "ValueError",
"evalue": "Fitted (y: -6.788950276243095, x: 11.000000000000012) positions are outide the input margins y: [-1.0, 1.0], and x: [10.0, 12.0]",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-9-d87bee88275b>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mradio2\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m120\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0mradio2_flipped\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfliplr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mradio2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 7\u001b[0;31m \u001b[0mcor\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfind_shift\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mradio1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mradio2_flipped\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;32m~/software/virtualenv_nabu/lib/python3.6/site-packages/nabu/preproc/alignment.py\u001b[0m in \u001b[0;36mfind_shift\u001b[0;34m(self, img_1, img_2, roi_yxhw, median_filt_shape, padding_mode, peak_fit_radius, high_pass, low_pass)\u001b[0m\n\u001b[1;32m 546\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 547\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mf_vals\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfv\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfh\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mextract_peak_region_2d\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcc\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mpeak_radius\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mpeak_fit_radius\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcc_vs\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mcc_vs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcc_hs\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mcc_hs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 548\u001b[0;31m \u001b[0mfitted_shifts_vh\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrefine_max_position_2d\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mf_vals\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfv\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfh\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 549\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 550\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mfitted_shifts_vh\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m/\u001b[0m \u001b[0;36m2.0\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m~/software/virtualenv_nabu/lib/python3.6/site-packages/nabu/preproc/alignment.py\u001b[0m in \u001b[0;36mrefine_max_position_2d\u001b[0;34m(f_vals, fy, fx)\u001b[0m\n\u001b[1;32m 127\u001b[0m raise ValueError(\n\u001b[1;32m 128\u001b[0m \"Fitted (y: {}, x: {}) positions are outide the input margins y: [{}, {}], and x: [{}, {}]\".format(\n\u001b[0;32m--> 129\u001b[0;31m \u001b[0mvertex_yx\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mvertex_yx\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mvertex_min_yx\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mvertex_max_yx\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mvertex_min_yx\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mvertex_max_yx\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 130\u001b[0m )\n\u001b[1;32m 131\u001b[0m )\n",
"\u001b[0;31mValueError\u001b[0m: Fitted (y: -6.788950276243095, x: 11.000000000000012) positions are outide the input margins y: [-1.0, 1.0], and x: [10.0, 12.0]"
]
}
],
"source": [
"# An exception is raised if the shift (here below the vertical one) is indetermined\n",
"radio1=np.zeros([100,200],\"f\")\n",
"radio2=np.zeros([100,200],\"f\") \n",
"radio1[:, 90]=1 \n",
"radio2[:, 120]=1 \n",
"radio2_flipped=np.fliplr(radio2)\n",
"cor.find_shift(radio1, radio2_flipped)"
]
},
{
"cell_type": "code",
"execution_count": null,
......
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Using the Nabu DetectorTranslationAlongBeam tool\n",
"\n",
"This notebook shows how to use the Nabu CenterOfRotation to find the vertical and horizontal shifts for translations of the detector along the beam direction.\n",
"These shifts are in pixels-per-unit-translation, and they are due to\n",
"the misalignment of the translation stage, with respect to the beam\n",
"propagation direction.\n",
"To compute the vertical and horizontal tilt angles from the obtained `shift_pix`:\n",
"\n",
" >>> tilt_deg = np.rad2deg(np.arctan(shift_pix * pixel_size))\n",
"\n",
"where `pixel_size` and and the input parameter `img_pos` have to be\n",
"expressed in the same units."
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"from nabu.preproc.alignment import DetectorTranslationAlongBeam as DTAB"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Instantiating an object of the class DetectorTranslationAlongBeam"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"dtab=DTAB()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Create four images which will be filled to mock a moving beam shape"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"stack = np.zeros([4, 512, 512])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Add a low frequency spurious component to show filtering capabilities."
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
"# Add low frequencymockingmocking spurious component\n",
"for i in range(4):\n",
" stack[i, 200 - i * 10, 200 - i * 10] = 1\n",
"import scipy.ndimage\n",
"stack = scipy.ndimage.filters.gaussian_filter(stack, [0, 10, 10.0]) * 100"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Add the beam shape"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Add the feature\n",
"x, y = np.meshgrid(np.arange(stack.shape[-1]), np.arange(stack.shape[-2]))\n",
"for i in range(4):\n",
" xc = x - (250 + i * 1.234)\n",
" yc = y - (250 + i * 1.234 * 2)\n",
" stack[i] += np.exp(-(xc * xc + yc * yc) * 0.5)\n",
"\n",
"# Image translation along the beam\n",
"img_pos = np.arange(4)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
"### find the beam shifts"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"-2.4668451834318583 -1.2356087967046534\n"
]
}
],
"source": [
"# Find the shifts from the features\n",
"shifts_v, shifts_h = dtab.find_shift(stack, img_pos, high_pass=1.0)\n",
"print(shifts_v, shifts_h)\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"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.6.9"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
......@@ -16,6 +16,21 @@ Tutorial: [CenterOfRotation](Tutorials/hello_CenterOfRotation)
API: [CenterOfRotation](apidoc/nabu.preproc.alignment.rst#nabu.preproc.alignment.CenterOfRotation)
### Detector Translation Along the Beam
When moving the detector along the longitudinal translation axis the beam shape image, recorder on the detector, can be seen moving if the translation is not parallel to the beam. The occurring shifts can be found using this class, and the beam tilt respect to the translaction axis ca be inferred.
The vertical and horizontal shifts are returned in pixels-per-unit-translation.
To compute the vertical and horizontal tilt angles from the obtained `shift_pix`:
>>> tilt_deg = np.rad2deg(np.arctan(shift_pix_per_unit_translation * pixel_size))
where `pixel_size` and and the input parameter `img_pos` have to be
expressed in the same units.
Tutorial: [DetectorTranslationAlongBeam](Tutorials/hello_DetectorTranslationAlongBeam)
API: [DetectorTranslationAlongBeam](apidoc/nabu.preproc.alignment.rst#nabu.preproc.alignment.DetectorTranslationAlongBeam)
### Flat-field normalization
This is usually the first step done on the radios. Each radio is normalized by the incoming beam intensity and CCD dark current as `radio = (radio - dark)/(flat - dark)`.
......
Markdown is supported
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