Skip to main content

Posts

Web resources of EM techniques

EM https://www.globalsino.com/EM/   EBSD OI website : http://ebsd.cn/ https://ebsd.com/   EDAX website : https://www.edax.com.cn/resources/applications-literature https://www.edax.com/resources/applications-literature   https://edaxblog.com/   https://www.edax.com.cn/resources/eds-ebsd-published-resources https://www.edax.com/resources/eds-ebsd-published-resources   Others : http://www.imim.pl/files/SD/Power/Introduction%20to%20Electron%20Backscatter%20Diffraction.pdf   CathodoLuminescence https://whatiscl.info/   EELS https://eels.info/   DM-Script https://www.felmi-zfe.at/dm-script/ http://www.dmscripting.com/ http://digitalmicrograph-scripting.tavernmaker.de/HowToScript_index.htm   Python (EM related) https://hyperspy.readthedocs.io/en/stable/index.html# https://atomap.org/ https://pyxem.github.io/pyxem-website/ ----  updating time: 2021/02/17

HyperSpy for EELS

HyperSpy is really an awesome package for EELS analysis in python. It's very convenient for use and we can get more detail information from the dm files. Here are some sample code of HyperSpy for EELS spectrum image. ====================================  import hyperspy.api as hs ds=hs.load('si.dm3') ch=100 w=3 # average spectrum w=w//2 linesig=ds.inav[ch-w:ch+w+1].mean() # Get the x-axis and y-axis values xx=linesig.axes_manager[-1].axis yy=linesig.data print(' Figure 1 ') plt.figure(1) plt.plot(xx,yy) plt.xlabel(' %s (%s) ' % (linesig.axes_manager[-1].name, linesig.axes_manager[-1].units)) plt.ylabel(' Counts (a.u.) ') plt.legend([' smooth data ']) plt.show() # signal silcing E0=405 Ee=580 print( 'Assignd by energy range --> using float(E0)' ) E0=float(E0) Ee=float(Ee) lin01=linesig.isig[E0:Ee] print(' E0=%6.0f. , Ee=%6.0f. , data points=%i ' % (E0,Ee,linesig.isig[E0:Ee].axes_man...

HyperSpy - read the calibration information in a dm3/dm4 file

Some example of dm3 file reading by using Python HyperSpy package, which can read the detail information of the dm file. -- # import packages import numpy as np import hyperspy.api as hs # load file sp=hs.load('sp.dm3') # Read the axis information      # Print all the calibration detail print(sp.axes_manager) ''' <Axes manager, axes: (272|2042)>             Name |   size |  index |  offset |   scale |  units  ================ | ======= | ====== | ======= | ======= | ======                     x |    272 |      0 |       -0 |  0.0025 |     µm   --------------- |  ------ | ----- |  ------ | ------- | ------    Energy loss |  2042 |         | 3.2e+02 |       1 |     eV...

k-means clustering

In order to clustering data to reduce the noise, we can use the simple k-means clustering algorithm. The idea of k-means is quite simple. Here is the step of the k-means algorithm. 1. Randomly pick samples (depending on how many groups we want to cluster) as the references. 2. Compute the distance between each data point and references. 3. Comparing the distance to each reference, grouping the data points from the shortest distance. 4. Compute the centroid of each group as the new reference. 5. Repeat 2-4, until the centroids are the same with the previous result. Here is the Matlab code: ======================================= % An example for k-means clustering % % Renfong 2018/12/19 % % create test data % There are 3 types of sigal % 1-20, 36-70, 91-100 are the group 1 % 21-35 are group 2 % 71-90 are group 3 xx=0:1:1024; cen=[120, 360, 780]; amp=[100, 60, 55]; sig=[50, 10, 30]; % peak 1+3 for i=1:20     sp(i,:)=amp(1)*exp((-...

MLLS in matlab

MLLS stands for  multiple linear least squares fitting, which is the common strategy for the solving EELS edge overlapping and which is also built-in the GMS software. The target spectrum Y and the reference spectrum X Y = A * X Assuming Y is 1*256 matrix and we have three reference spectrums, ie, X is 3*256 matrix. So A is 1*3 matrix. The target is to solve A. If Y and X are n*n matrices, we can use the simple formula Y * inv(X) = A * X * inv(X), ie., A = Y * inv(X). However, Y and X are not n*n  matrices, it is necessary to have some trick to solve it. We can multiply the transpose matrix to produce n*n matrix. Y * X' = A * X * X'  (ps X' means the transpose matrix of X) so A = Y * X' * inv(X * X') Here is the Matlab code: =========  % create target spectrum x=0:256; c=[90,120,155]; sig=[5,10,8]; int=[5,10,8]; xn=zeros(size(x)); ref=zeros(length(c),length(x)); factor=rand(size(c))'; for i=1:length(c)     xn=xn+int(i)*ex...

Image binng in matlab

Here are my own image binning codes. The first one was built on 2015/3/2. And the second one was written on 2018/11/5. I think I have a big improvement. Ha~ ==== function [ox,oy]=binning(x,y,nbins) % This function is used to bin data to average %  % x: x-axis data % y: y-axis data % nbins: binning factor % % 2015/03/02  % Renfong m=max(size(x)); n0=fix(m/nbins); n1=mod(m,nbins); if n1==0 ox=zeros(n0,1); oy=zeros(n0,1); for ii=1:n0 for jj=1:nbins ox(ii)=ox(ii)+x((ii-1)*nbins+jj); oy(ii)=oy(ii)+y((ii-1)*nbins+jj); end ox(ii)=ox(ii); oy(ii)=oy(ii); end else ox=zeros(n0+1,1); oy=zeros(n0+1,1); for ii=1:n0 for jj=1:nbins ox(ii)=ox(ii)+x((ii-1)*nbins+jj); oy(ii)=oy(ii)+y((ii-1)*nbins+jj); end ox(ii)=ox(ii); oy(ii)=oy(ii); end for ii=1:n1 ox(n0+1)=ox(n0+1)+x(n0*nbins+ii); oy(n0+1)=oy(n0+1)+y(n0*nbins+ii); end ox(n0+1)=ox(n0+1)*nbins/n1; oy(n0+1)=oy(n0+1)*nbins/n1; end ==== function out=xy_bins(img,nbins) ...

Drift correction in Matlab

In order to improve S/N ratio, microscopist uses several short acquisition time images, and then sum them up. So the drift correction is very important. Here is the demo of how to use Matlab do drift correction. In the first, load an image, and using circshift function to shift the object in the image. Then use fft cross correlation to compute the moving distance. Finally, shift the object to the origial position. Here is the testing code: == % Demo of drift correction % 2018/11/15  by Renfong im1= imread('cameraman.tif');    % reference image [sy,sx]=size(im1); % shift the object im2=circshift(im1,[20,10]);    % the object moved down 20 pixels and moved right 10 pixels. figure(1); subplot(121);imshow(im1); subplot(122);imshow(im2); % Using fft cross correlations to detect the moving distance[1] fftim1=fft2(im1); fftim2=fft2(im2); cc=fftshift(ifft2(fftim1.*conj(fftim2))); [shiftY,shiftX]=find(cc==max(cc(:))...