Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 138 additions & 0 deletions how-to/3_Prepare_data/TransmissionAbsorptionConvertor.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Transmission-absorption convertor\n",
"##### This example shows how to use the `TransmissionAbsorptionConvertor` processor"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Get the example dataset `dataexample.WALNUT` using `download_data()` then `get()`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from cil.utilities import dataexample\n",
"dataexample.WALNUT.download_data(data_dir='.', prompt=False)\n",
"data = dataexample.WALNUT.get('.')"
Comment on lines +24 to +26
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only worked for me if I set prompt=True
With prompt=False:

image

]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Create a `TransmissionAbsorptionConvertor` procesor to convert from x-ray transmission data to x-ray absorption data using the Beer-Lambert law "
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Create a `TransmissionAbsorptionConvertor` procesor to convert from x-ray transmission data to x-ray absorption data using the Beer-Lambert law "
"Create a `TransmissionAbsorptionConvertor` processor to convert from x-ray transmission data to x-ray absorption data using the Beer-Lambert law "

]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"from cil.processors import TransmissionAbsorptionConverter\n",
"processor = TransmissionAbsorptionConverter()\n",
"processor.set_input(data)\n",
"data_abs = processor.get_output()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Display the data before and after applying the `TransmissionAbsorptionConverter()` processor"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from cil.utilities.display import show2D\n",
"show2D([data, data_abs], ['Before TransmissionAbsorptionConverter', 'After TransmissionAbsorptionConverter'])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If the data contains zeros or negative numbers, you may want to consider using `Normaliser` first (see our examples on the How-To's page). Otherwise you can specify a minium value to use in the `TransmissionAbsorptionConverter` to avoid 0 in the log calculation"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"min_intensity = 0.0001 # specify a minimum value to avoid 0 in log"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can also specify the value corresponding to the maximum transmission (white level), which will correspond to the transmission equalling zero, this might be useful if there are outliers in the data which you want to ignore"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"white_level = 1.2"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Run `TransmissionAbsorptionConverter` again and plot the data with the new arguments"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"processor = TransmissionAbsorptionConverter(min_intensity=min_intensity, white_level=white_level)\n",
"processor.set_input(data)\n",
"data_abs = processor.get_output()\n",
"show2D([data, data_abs], ['Transmission', 'Absorption'])"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "cil_tests",
"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.10.14"
}
},
"nbformat": 4,
"nbformat_minor": 2
}