Skip to main content

Posts

Making a GUI in dm-script

 // 2 button dialog example  // To invert the most front image. // Modified from http://www.dmscripting.com/files/Example_Button_Enabling_Dialog.s // Renfong // 2021/03/24 // Global variables taggroup firstbutton, secondbutton number true=1 number false=0 image src // the class createbuttondialog is of the type user interface frame (UIFrame), and responds to interactions // with the dialog - in this case pressing buttons class CreateButtonDialog : uiframe { void button1response(object self) { //the response when the button is pressed self.SetElementIsEnabled("first", false); // these commands set the button as enabled or not enabled self.SetElementIsEnabled("second", true); // "second" in this command is the identifier of the button 'secondbutton' // put action1 here src.GetFrontImage() result(src.GetName()+" is picked.\n") }; void button2response(object self) { //the response when the second button is press...

Extract information from an existed TagGroup in DM

The dm3/dm4 files contain the acquisition parameters and other information in its unique data structure: "TagGroup". In this example, I will show you how to extract the information from an existed taggroup. The tag structure in an SI image is like this: The following code will show how to obtain the operation voltage from the tag group ====================================================== // An example shows how to extract info from an existed taggroup image src := GetFrontImage() TagGroup tg = src.ImageGetTagGroup() TagGroup parenttg string path, label // Asign tag path If (!GetString("Enter path to tag", "Microscope Info:Voltage", path)) Exit(0) result("path : " + path + "\n") tg.TagGroupParseTagPath(path, parenttg, label) parenttg.TagGroupOpenBrowserWindow("Parent of "+label, 0) // Get value from a given path number val TagGroupGetTagAsFloat(tg,path,val) result(label + " : "+val+"\n") ==================...

LatticeEnhancedFilterV2

This is a band-enhanced filter. ref: Ondrej L. Krivanek et. al., Nature 464, 571-574 ============================================================ // Lattice enhanced filter // Reference : Ondrej L. Krivanek et. al., Nature 464, 571-574 // // Version 2 // The filter enhance the lattice feature without removing background. // Set the weight factor in the background and high frequency region  = 1 // And the weight factor of the enhanced feature  = 3.5 // // The first window will show the radial average of the FFT of the image // enhanced feature (look for the peak) then key the value into the window // // 2021/03/15 // Renfong // windless@gmail.com // sub-function1 : radial average // This script is retrived and  modified from  // http://www.gatan.com/sites/default/files/Scripts/Rotational%20Average.s image Rotational_Average(image img) { // Define neccessary parameters and constants number xscale, yscale, xsize, ysize number centerx, centery, halfMi...

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((-...