{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# EDS-TEM quantification of core shell nanoparticles\n",
"\n",
"Using machine learning methods, such as independent component analysis (ICA), the composition of embedded nanostructures, such as core-shell nanoparticles, can be accurately measured as demonstrated by D. Roussow et al., Nano Letters, 2015 (see the [full article](https://www.repository.cam.ac.uk/bitstream/handle/1810/248102/Roussouw%20et%20al%202015%20Nano%20Letters.pdf?sequence=1)). Using the same data, this notebook reproduces the main results of this article.\n",
"\n",
"\n",
"## Author\n",
"\n",
"* 13/04/2015 Pierre Burdet - Developed for HyperSpy workshop at University of Cambridge\n",
"\n",
"## Changes\n",
"\n",
"* 29/05/2016 Duncan Johnstone. Update the syntax for HyperSpy 0.8.5 (Python 3 compatibility)\n",
"* 03/08/2016 Francisco de la Peña. Update the syntax for HyperSpy 1.1\n",
"* 06/08/2016 Francisco de la Peña. Update the syntax for HyperSpy 0.8.1\n",
"* 27/08/2016 Pierre Burdet. Update for workshop at EMC Lyon\n",
"* 04/04/2018 Joshua Taillon. Bugfix and update for workshop at NIST\n",
"* 18/07/2019 Katherine MacArthur. Update to include basic quantification, for M&M 2019 Portland\n",
"\n",
"## Requirements\n",
"\n",
"* HyperSpy 1.5.1\n",
"\n",
"## Contents\n",
"\n",
"1. Specimen & Data\n",
"2. Loading and viewing data\n",
"3. Extracting Counts \n",
"4. Basic Quantification \n",
"5. Blind source separation of core/shell nanoparticles\n",
"6. Representative spectrum from bare cores\n",
"7. Comparison and quantification\n",
"8. Going father: Isolating the nanoparticles\n",
"\n",
"# 1. Specimen & Data\n",
"\n",
"The sample and the data used in this tutorial are described in \n",
"D. Roussow, et al., Nano Letters, In Press (2015) (see the [full article](https://www.repository.cam.ac.uk/bitstream/handle/1810/248102/Roussouw%20et%20al%202015%20Nano%20Letters.pdf?sequence=1)).\n",
"\n",
"FePt@Fe$_3$O$_4$ core-shell nanoparticles are investigated with an EDS/TEM experiment (FEI Osiris TEM, 4 EDS detectors). The composition of the core can be measured with ICA (see figure 1c). To prove the accuracy of the results, measurements on bare FePt bimetallic nanoparticles from a synthesis prior to the shell addition step are used."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"Figure 1: (a) A spectrum image obtained from a cluster of core-shell nanoparticles. (b) The nanoparticles are comprised of a bi-metallic Pt/Fe core surrounded by an iron oxide shell on a carbon support. (c) ICA decomposes the mixed EDX signals into components representing the core (IC#0), shell (IC#1) and support (IC#2)."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"#Download the data (1MB)\n",
"from urllib.request import urlretrieve, urlopen\n",
"from zipfile import ZipFile\n",
"files = urlretrieve(\"https://www.dropbox.com/s/ecdlgwxjq04m5mx/HyperSpy_demos_EDS_TEM_files.zip?raw=1\", \"./HyperSpy_demos_EDX_TEM_files.zip\")\n",
"with ZipFile(\"HyperSpy_demos_EDX_TEM_files.zip\") as z:\n",
" z.extractall()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 2. Loading and viewing data"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" Table of contents"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Import HyperSpy, numpy and matplotlib libraries.\n",
"\n",
"*Remember, if at any point you do not understand how a function operates, its help file can be loaded by typing the name of the command followed by a '?' into a cell and then running that cell.*"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"%matplotlib widget\n",
"import hyperspy.api as hs"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Load the spectrum images of the bare nanoparticles and those with a core-shell structure."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"c = hs.load(\"bare_core.hdf5\", reader=\"hspy\")\n",
"cs = hs.load(\"core_shell.hdf5\", reader=\"hspy\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Check the metadata has imported correctly. In particular whether the list of elements you wish to analyse is correct."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"├── Acquisition_instrument\n",
"│ └── TEM\n",
"│ ├── Detector\n",
"│ │ └── EDS\n",
"│ │ ├── azimuth_angle = 0.0\n",
"│ │ ├── elevation_angle = 35.0\n",
"│ │ └── energy_resolution_MnKa = 130.0\n",
"│ ├── Stage\n",
"│ │ └── tilt_alpha = 0.0\n",
"│ ├── acquisition_mode = STEM\n",
"│ ├── beam_energy = 200.0\n",
"│ └── microscope = Microscope TecnaiOsiris 200 kV D658 AnalyticalTwin\n",
"├── General\n",
"│ ├── date = 14.10.2014\n",
"│ └── title = Core shell\n",
"├── Sample\n",
"│ ├── elements = array(['Fe', 'Pt'], dtype=' 3. Extracting count maps of elements\n",
"\n",
" Table of contents\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If they're not already added it is important to make sure all the elements you want to extract the intensities for are in the metadata of the sample."
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"cs.set_elements(['Fe','Pt'])\n",
"cs.set_lines(['Fe_Ka', 'Pt_La'])\n",
"\n",
"c.set_elements(['Fe','Pt'])\n",
"c.set_lines(['Fe_Ka', 'Pt_La'])\n",
"#cs.add_elements and cs.add_lines also work if you don't want to override what is \n",
"#already in the metadata."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Extracting lines can be done without any background or integration window parameters. However if none are specified the default integration window is 1 FWHM and no background subtraction is carried out."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Line_width is the distance from the x-ray line (in FWHM) the the background window is taken [left, right] allowing different distances for the two directions.\n",
"An asymmetric value is used here because otherwise the Pt background windows overlap with the Cu K$_β$ line from the sample grid."
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"bw = cs.estimate_background_windows(line_width=[5.0, 2.0])\n",
"iw = cs.estimate_integration_windows(windows_width=3)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"It is important to plot the windows to check that they are selecting the data correctly otherwise errors, particularly in background subtraction arise.\n",
"\n",
"The integration windows are represented by dashed lines and background windows by solid lines. The estimated background is the plotted by the close to horizontal black lines."
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"cs.sum().plot(True, background_windows=bw, integration_windows=iw)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"*Try running the previous two cells of code above with line_width=[3.0,3.0] and see how this results in an erroneous, background subtraction by plotting the background lines. (You might need to zoom in to see it)*"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"How accurate background subtraction will be on a pixel-by-pixel basis can be see with this plot. \n",
"\n",
"The x and y sliders select a pixel in the particle images we plotted earlier. \n",
"\n",
"You should be able to find some examples (e.g. the Fe K$_α$ line at X=39, Y=44) of where the background subtraction still fails due to a poor signal-to-noise ratio in the data.\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "1e0acbdd4cc24875aefaea6e23ecb77d",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VBox(children=(HBox(children=(Label(value='x', layout=Layout(width='15%')), IntSlider(value=0, description='in…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"cs.plot(True, background_windows=bw, navigator='slider')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Another way to adjust the location of the background windows is by changing specific numbers in the background window array individually.\n",
"\n",
"Running the 'bw' command will output the array, which contains keV coordinates corresponding to the position of the background windows. Each row corresponds to a different element in the list given in the metadata. Remember arrays in Python start at (0,0).\n",
"\n",
"These two commands therefore alter the position of the start and end points of the left-hand background window for Pt."
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[5.59527895, 5.73004913, 6.67344035, 6.80821052],\n",
" [8.44 , 8.65 , 9.7630891 , 9.92358364]])"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"bw[1, 0] = 8.44\n",
"bw[1, 1] = 8.65\n",
"bw"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Often it is prudent to rebin the data such that counts per pixel are increased and a more reliable background subtraction can be carried out. This can be easily done with the rebin function to any new scale.\n",
"\n",
"These functions will perform rebinning on both the core-shell ('cs') data and the core-only ('c') data. We define using the 'scale' parameter that we want 2x binning in X, 2x binning in Y, and 1x binning in Z (our counts).\n",
"\n",
"*Note, as we are re-defining 'cs' or 'c', this overwrites our previously-imported data. This means running this command multiple times will re-bin the data multiple times. If you accidentally run this command too many times, simply re-import the data by running the 'hs.load' commands at the top of this workbook'.*"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"cs = cs.rebin(scale=(2,2,1))\n",
"c = c.rebin(scale=(2,2,1))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Finally, once the background subtraction windows have been selected to be in careful positions it is possible to extract the intensities. \n",
"\n",
"Note that exactly the same windows have been used for analysis of both the 'core' and 'core-shell' data sets. This is critical here as we are comparing the two datasets."
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"cs_intensities = cs.get_lines_intensity(background_windows=bw, integration_windows=iw)\n",
"c_intensities = c.get_lines_intensity(background_windows=bw, integration_windows=iw)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Each 'get_lines_intensity' command will create a list of images, again in the same order of the list of elements in the list of metadata. If the element is not in the metadata its intensity map will not be extracted.\n",
"\n",
"We can then run 'cs_intensities' to confirm the that we have extracted intensity maps for all our elements of interest."
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[,\n",
" ]"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"cs_intensities"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
"# Plotting one particular image (in this case, the first, Fe_Ka map) can be done with:\n",
"cs_intensities[0].plot()"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[,\n",
" ]"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#All the intensity maps can be plotted using:\n",
"hs.plot.plot_images(cs_intensities, cmap='viridis', axes_decor=None, scalebar='all')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Plotting and extracting intensity for both data sets can be condensed into one line."
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
"axes = hs.plot.plot_images((c.get_lines_intensity(background_windows=bw, integration_windows=iw)\n",
" + cs.get_lines_intensity(background_windows=bw, integration_windows=iw)),\n",
" scalebar='all', axes_decor=None, per_row=2, cmap='viridis')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 4. Quantification of count maps\n",
"\n",
" Table of contents"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Hyperspy is able to carry out EDX quantification using k-factors 'CL', zeta-factors 'zeta', or cross_sections 'cross_sections'. \n",
"\n",
"All these methods are applied in the same way using the combination of the stack of intensities and and original data."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"For 'zeta' or 'cross_section' quantification both a 'live_time' and a 'beam_current' should be in the metadata."
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
"#Setting these parameters in the metadata.\n",
"cs.set_microscope_parameters(live_time = 6.15) #in seconds\n",
"cs.set_microscope_parameters(beam_current = 0.5) #in nA"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [],
"source": [
"#From Brucker software (Esprit) k-factors\n",
"factors = [1.450226, 5.75602]"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/macark/Documents/Git/hyperspy/hyperspy/misc/material.py:42: RuntimeWarning: invalid value encountered in true_divide\n",
" atomic_percent[i] /= sum_weight\n"
]
}
],
"source": [
"quant = cs.quantification(cs_intensities, 'CL', factors=factors)"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[,\n",
" ]"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"quant"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Again as with the intensities the quantification function result produces a list of images with atomic percent of each element (at least in the 'CL' case). \n",
"\n",
"In the 'zeta' and 'cross_section' methods more information is outputed from quantification. See the [EDS quantification](http://hyperspy.org/hyperspy-doc/current/user_guide/eds.html#eds-quantification) section of the documentation for more details."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Alternatively, if the factors are treated as cross_sections then the output result contains two lists of images, the first is a list of atomic *percent* maps (Index [0]) the second is a list of atomic *number* maps (Index [1]). This allows us to 'zero-out' regions of the image with too few counts."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"*Please note these values aren't accurate cross-sections but can be used as such for the purpose of this demo.*"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Ignore the warning produced, in this case we want to use a 1nm$^2$ probe size. As long as the pixel scale is calibrated in your spectrum image, probe size is taken as the pixel unless otherwise specified using s.set_microscope_parameters(probe_area = ?)."
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/macark/Documents/Git/hyperspy/hyperspy/_signals/eds_tem.py:654: UserWarning: Please note your probe_area is set to the default value of 1 nm². The function will still run. However if 1 nm² is not correct, please read the user documentations for how to set this properly.\n",
" warnings.warn('Please note your probe_area is set to '\n",
"/Users/macark/Documents/Git/hyperspy/hyperspy/misc/eds/utils.py:528: RuntimeWarning: invalid value encountered in true_divide\n",
" composition = number_of_atoms / total_atoms\n"
]
}
],
"source": [
"quant = cs.quantification(cs_intensities, 'cross_section', factors=factors)"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"([,\n",
" ],\n",
" [,\n",
" ])"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"quant"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Summing all the images containing numbers of atoms (quant[1]) gives us an image mapping out the total number of estimated atoms in the sample."
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [],
"source": [
"No_of_atoms = quant[1][0] + quant[1][1]\n",
"No_of_atoms.plot()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This 'total number of atoms' image can be used to make a mask and 'zero-out' any region of the image where the total counts equate to less than 1 atom count. This could also be done on an element by element basis instead."
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[,\n",
" ]"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Mask = No_of_atoms > 1.\n",
"hs.plot.plot_images([Mask*quant[0][0], Mask*quant[0][1]], scalebar ='all', cmap='viridis',\n",
" label=['Fe', 'Pt'], axes_decor='off', vmin=0, vmax=100)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 5. Blind source separation of core/shell nanoparticles"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" Table of contents"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Apply blind source separation (ICA) to obtain a factor (spectrum) corresponding to the core."
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [],
"source": [
"cs.change_dtype('float')\n",
"cs.decomposition()"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [],
"source": [
"ax = cs.plot_explained_variance_ratio()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"ICA on the three first components."
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [],
"source": [
"cs.blind_source_separation(3)"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [],
"source": [
"axes = cs.plot_bss_loadings()"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [],
"source": [
"axes = cs.plot_bss_factors()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The first component corresponds to the core."
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [],
"source": [
"s_bss = cs.get_bss_factors().inav[0]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 6. Representative spectrum from bare cores"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" Table of contents"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To obtain an integrated representative spectrum of the bare nanoparticles, the low intensity of Pt L$_{\\alpha}$ is masked."
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {},
"outputs": [],
"source": [
"pt_la = c.get_lines_intensity(['Pt_La'])[0]\n",
"mask = pt_la > 12"
]
},
{
"cell_type": "code",
"execution_count": 63,
"metadata": {},
"outputs": [],
"source": [
"axes = hs.plot.plot_images((mask, pt_la * mask), axes_decor=None, colorbar=None,\n",
" label=['Mask', 'Pt Lα intensity'], cmap='viridis')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To apply the mask, the navigation dimensions of the mask must be manipulated to match the navigation dimensions of the EDS spectrum image. This is achieved crudely via first generating a mask using the built in vacuum_mask() method and then overwriting the data with the mask generated above."
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {},
"outputs": [],
"source": [
"c_mask = c.sum(-1)\n",
"c_mask.data = mask.data"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The sum over the particles is used as a bare core spectrum."
]
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {},
"outputs": [],
"source": [
"s_bare = (c * c_mask).sum()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 7. Model fitting and quantification"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" Table of contents"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"With a greater signal to noise ratio from integrating the spectrum curve fitting now beceoms possible as a method of intensity extraction. \n",
"\n",
"First we stack together the spectrum of bare particles and the first ICA component."
]
},
{
"cell_type": "code",
"execution_count": 43,
"metadata": {},
"outputs": [],
"source": [
"s_bare.change_dtype('float')\n",
"s = hs.stack([s_bare, s_bss], new_axis_name='Bare or BSS')\n",
"s.metadata.General.title = 'Bare or BSS'"
]
},
{
"cell_type": "code",
"execution_count": 44,
"metadata": {},
"outputs": [],
"source": [
"axes = hs.plot.plot_spectra(s, style='mosaic', legend=['Bare particles', 'BSS #0'])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Method 1 - Window extraction\n",
"\n",
"X-ray intensities measurement with background subtraction, using the windows created earlier."
]
},
{
"cell_type": "code",
"execution_count": 45,
"metadata": {},
"outputs": [],
"source": [
"s.plot(background_windows=bw, integration_windows=iw)"
]
},
{
"cell_type": "code",
"execution_count": 46,
"metadata": {},
"outputs": [],
"source": [
"sI = s.get_lines_intensity(background_windows=bw, integration_windows=iw)"
]
},
{
"cell_type": "code",
"execution_count": 47,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Bare core Fe_Ka/Pt_La ratio: \t0.19\n",
"BSS Fe_Ka/Pt_La ratio: \t\t0.18\n"
]
}
],
"source": [
"print('Bare core Fe_Kα/Pt_Lα ratio: \\t{:.2f}'.format(list(sI[0].inav[0].data / sI[1].inav[0].data)[0]))\n",
"print('BSS Fe_Kα/Pt_Lα ratio: \\t\\t{:.2f}'.format(list(sI[0].inav[1].data / sI[1].inav[1].data)[0]))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Method 2 - Model fitting\n",
"\n",
"Measure X-ray intensity by fitting a Gaussian model"
]
},
{
"cell_type": "code",
"execution_count": 48,
"metadata": {},
"outputs": [],
"source": [
"#Removing the low energy part of the spectrum as this is not a region we're interested in.\n",
"m = s.isig[5.:15.].create_model()"
]
},
{
"cell_type": "code",
"execution_count": 49,
"metadata": {},
"outputs": [],
"source": [
"#These lines needed to be added to the model because they are not in the metadata. \n",
"#In this way they are included in the curve fitting but not in the final quantification.\n",
"m.add_family_lines(['Cu_Ka', 'Co_Ka'])"
]
},
{
"cell_type": "code",
"execution_count": 50,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
" # | Attribute Name | Component Name | Component Type\n",
"---- | ------------------- | ------------------- | -------------------\n",
" 0 | background_order_6 | background_order_6 | Polynomial\n",
" 1 | Fe_Ka | Fe_Ka | Gaussian\n",
" 2 | Fe_Kb | Fe_Kb | Gaussian\n",
" 3 | Pt_La | Pt_La | Gaussian\n",
" 4 | Pt_Lg1 | Pt_Lg1 | Gaussian\n",
" 5 | Pt_Lb3 | Pt_Lb3 | Gaussian\n",
" 6 | Pt_Ll | Pt_Ll | Gaussian\n",
" 7 | Pt_Lb2 | Pt_Lb2 | Gaussian\n",
" 8 | Pt_Ln | Pt_Ln | Gaussian\n",
" 9 | Pt_Lb1 | Pt_Lb1 | Gaussian\n",
" 10 | Pt_Lg3 | Pt_Lg3 | Gaussian\n",
" 11 | Pt_Lb4 | Pt_Lb4 | Gaussian\n",
" 12 | Cu_Ka | Cu_Ka | Gaussian\n",
" 13 | Cu_Kb | Cu_Kb | Gaussian\n",
" 14 | Co_Ka | Co_Ka | Gaussian\n",
" 15 | Co_Kb | Co_Kb | Gaussian"
]
},
"execution_count": 50,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"m.components"
]
},
{
"cell_type": "code",
"execution_count": 51,
"metadata": {},
"outputs": [],
"source": [
"m.plot()"
]
},
{
"cell_type": "code",
"execution_count": 52,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "92086ab9725c4a1ca022ca68dc01cab9",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(IntProgress(value=0, max=2), HTML(value='')))"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n"
]
}
],
"source": [
"m.multifit()"
]
},
{
"cell_type": "code",
"execution_count": 53,
"metadata": {},
"outputs": [],
"source": [
"m.fit_background()"
]
},
{
"cell_type": "code",
"execution_count": 54,
"metadata": {},
"outputs": [],
"source": [
"m.calibrate_energy_axis()"
]
},
{
"cell_type": "code",
"execution_count": 55,
"metadata": {},
"outputs": [],
"source": [
"m.plot()"
]
},
{
"cell_type": "code",
"execution_count": 56,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[,\n",
" ]"
]
},
"execution_count": 56,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sI = m.get_lines_intensity()[:2]\n",
"sI"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Set up the kfactors for Fe K$_{\\alpha}$ and Pt L$_{\\alpha}$."
]
},
{
"cell_type": "code",
"execution_count": 57,
"metadata": {},
"outputs": [],
"source": [
"#From Brucker software (Esprit)\n",
"kfactors = [1.450226, 5.075602]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Quantify with Cliff Lorimer."
]
},
{
"cell_type": "code",
"execution_count": 58,
"metadata": {},
"outputs": [],
"source": [
"composition = s.quantification(method=\"CL\", intensities=sI, factors=kfactors)"
]
},
{
"cell_type": "code",
"execution_count": 59,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" |-----------------------------|\n",
" | Atomic compositions |\n",
" |-----------------------------|\n",
" | Bare core | BSS Signal |\n",
"|------------|-------------|---------------|\n",
"| Fe (at. %) | 16.64 | 15.98 |\n",
"| Pt (at. %) | 83.36 | 84.02 |\n",
"|------------|-------------|---------------|\n"
]
}
],
"source": [
"print(' |-----------------------------|')\n",
"print(' | Atomic compositions |')\n",
"print(' |-----------------------------|')\n",
"\n",
"print(' \\t | Bare core | BSS Signal |')\n",
"print('|------------|-------------|---------------|')\n",
"print('| Fe (at. %) | {:.2f} | {:.2f} |'.format(composition[0].data[0], composition[0].data[1]))\n",
"print('| Pt (at. %) | {:.2f} | {:.2f} |'.format(composition[1].data[0], composition[1].data[1]))\n",
"print('|------------|-------------|---------------|')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 6. Going further"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" Table of contents"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Further image processing with [scikit-image](http://scikit-image.org/) and [scipy](http://www.scipy.org/). Apply a watershed transformation to isolate the nanoparticles."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"- Transform the mask into a distance map.\n",
"- Find local maxima.\n",
"- Apply the watershed to the distance map using the local maximum as seed (markers).\n",
"\n",
"Adapted from this scikit-image [example](http://scikit-image.org/docs/dev/auto_examples/plot_watershed.html)."
]
},
{
"cell_type": "code",
"execution_count": 60,
"metadata": {},
"outputs": [],
"source": [
"from scipy.ndimage import distance_transform_edt, label\n",
"from skimage.morphology import watershed\n",
"from skimage.feature import peak_local_max"
]
},
{
"cell_type": "code",
"execution_count": 61,
"metadata": {},
"outputs": [],
"source": [
"distance = distance_transform_edt(mask.data)\n",
"local_maxi = peak_local_max(distance, indices=False,\n",
" min_distance=2, labels=mask.data)\n",
"labels = watershed(-distance, markers=label(local_maxi)[0],\n",
" mask=mask.data)"
]
},
{
"cell_type": "code",
"execution_count": 62,
"metadata": {},
"outputs": [],
"source": [
"axes = hs.plot.plot_images(\n",
" [pt_la.T, mask.T, hs.signals.Signal2D(distance), hs.signals.Signal2D(labels)],\n",
" axes_decor='off', per_row=2, colorbar=None, cmap=['viridis','tab20'],\n",
" label=['Pt Lα intensity', 'Mask',\n",
" 'Distances', 'Separated particles'])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"anaconda-cloud": {},
"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.5.6"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {
"00cba520fba44e8b8aff67cc4cc8df96": {
"model_module": "jupyter-js-widgets",
"model_module_version": "~2.1.4",
"model_name": "LabelModel",
"state": {
"_model_module_version": "~2.1.4",
"_view_module_version": "~2.1.4",
"disabled": true,
"layout": "IPY_MODEL_cbc72a976a784078b6d2b83f0470632d"
}
},
"0fc57571dd6c4a018297a70b2542752b": {
"model_module": "jupyter-js-widgets",
"model_module_version": "~2.1.4",
"model_name": "IntSliderModel",
"state": {
"_model_module_version": "~2.1.4",
"_view_module_version": "~2.1.4",
"description": "index",
"layout": "IPY_MODEL_86a46aaa88e044b4979f85d70097ad32",
"max": 1,
"style": "IPY_MODEL_c362d1c08eef4831ab43c7509f770861",
"value": 1
}
},
"19b521e12d69469d8d4e0c780d30e276": {
"model_module": "jupyter-js-widgets",
"model_module_version": "~2.1.4",
"model_name": "LayoutModel",
"state": {
"_model_module_version": "~2.1.4",
"_view_module_version": "~2.1.4",
"display": "flex",
"flex_flow": "row",
"justify_content": "space-between"
}
},
"25bc44f15c134063af9b6e6468d5cfb0": {
"model_module": "jupyter-js-widgets",
"model_module_version": "~2.1.4",
"model_name": "CheckboxModel",
"state": {
"_model_module_version": "~2.1.4",
"_view_module_version": "~2.1.4",
"description": "Continous update",
"disabled": false,
"layout": "IPY_MODEL_e669ffd1c5be471e9deefa5809267169",
"value": true
}
},
"26081e9ea06540fd9f6d0d8c0397283b": {
"model_module": "jupyter-js-widgets",
"model_module_version": "~2.1.4",
"model_name": "LayoutModel",
"state": {
"_model_module_version": "~2.1.4",
"_view_module_version": "~2.1.4"
}
},
"3a9d69275c204f7cbe2d3949d3ae78c6": {
"model_module": "jupyter-js-widgets",
"model_module_version": "~2.1.4",
"model_name": "VBoxModel",
"state": {
"_model_module_version": "~2.1.4",
"_view_module_version": "~2.1.4",
"children": [
"IPY_MODEL_9c905befed534b95acf2c4cf7efdd7bf",
"IPY_MODEL_25bc44f15c134063af9b6e6468d5cfb0"
],
"layout": "IPY_MODEL_f58d7a1edfe2466db9c8d091e80e1795"
}
},
"3d9f6ee4cac2449ebd64250ea8de54aa": {
"model_module": "jupyter-js-widgets",
"model_module_version": "~2.1.4",
"model_name": "LayoutModel",
"state": {
"_model_module_version": "~2.1.4",
"_view_module_version": "~2.1.4"
}
},
"56b34ef901d64361a1325c6bc59771e4": {
"model_module": "jupyter-js-widgets",
"model_module_version": "~2.1.4",
"model_name": "LabelModel",
"state": {
"_model_module_version": "~2.1.4",
"_view_module_version": "~2.1.4",
"layout": "IPY_MODEL_fc549aa8931c452096bd07da6ae82231",
"value": "Bare or BSS"
}
},
"86a46aaa88e044b4979f85d70097ad32": {
"model_module": "jupyter-js-widgets",
"model_module_version": "~2.1.4",
"model_name": "LayoutModel",
"state": {
"_model_module_version": "~2.1.4",
"_view_module_version": "~2.1.4"
}
},
"9c905befed534b95acf2c4cf7efdd7bf": {
"model_module": "jupyter-js-widgets",
"model_module_version": "~2.1.4",
"model_name": "HBoxModel",
"state": {
"_model_module_version": "~2.1.4",
"_view_module_version": "~2.1.4",
"children": [
"IPY_MODEL_56b34ef901d64361a1325c6bc59771e4",
"IPY_MODEL_0fc57571dd6c4a018297a70b2542752b",
"IPY_MODEL_aa153f962c2c4da5aaa4ed65cf0a95e3",
"IPY_MODEL_00cba520fba44e8b8aff67cc4cc8df96"
],
"layout": "IPY_MODEL_3d9f6ee4cac2449ebd64250ea8de54aa"
}
},
"aa153f962c2c4da5aaa4ed65cf0a95e3": {
"model_module": "jupyter-js-widgets",
"model_module_version": "~2.1.4",
"model_name": "FloatTextModel",
"state": {
"_model_module_version": "~2.1.4",
"_view_module_version": "~2.1.4",
"description": "value",
"layout": "IPY_MODEL_26081e9ea06540fd9f6d0d8c0397283b",
"max": 1,
"min": 0,
"step": 1,
"value": 1
}
},
"c362d1c08eef4831ab43c7509f770861": {
"model_module": "jupyter-js-widgets",
"model_module_version": "~2.1.4",
"model_name": "SliderStyleModel",
"state": {
"_model_module_version": "~2.1.4",
"_view_module_version": "~2.1.4"
}
},
"cbc72a976a784078b6d2b83f0470632d": {
"model_module": "jupyter-js-widgets",
"model_module_version": "~2.1.4",
"model_name": "LayoutModel",
"state": {
"_model_module_version": "~2.1.4",
"_view_module_version": "~2.1.4",
"width": "5%"
}
},
"e669ffd1c5be471e9deefa5809267169": {
"model_module": "jupyter-js-widgets",
"model_module_version": "~2.1.4",
"model_name": "LayoutModel",
"state": {
"_model_module_version": "~2.1.4",
"_view_module_version": "~2.1.4"
}
},
"f58d7a1edfe2466db9c8d091e80e1795": {
"model_module": "jupyter-js-widgets",
"model_module_version": "~2.1.4",
"model_name": "LayoutModel",
"state": {
"_model_module_version": "~2.1.4",
"_view_module_version": "~2.1.4"
}
},
"fc549aa8931c452096bd07da6ae82231": {
"model_module": "jupyter-js-widgets",
"model_module_version": "~2.1.4",
"model_name": "LayoutModel",
"state": {
"_model_module_version": "~2.1.4",
"_view_module_version": "~2.1.4",
"width": "15%"
}
}
},
"version_major": 1,
"version_minor": 0
}
}
},
"nbformat": 4,
"nbformat_minor": 4
}