Skip to main content

Posts

Showing posts from 2021

conda env list

 all the env would be listed in users/current_user/.conda/environments.txt the content is : C:\ProgramData\miniconda3 C:\ProgramData\miniconda3\envs\GMS_VENV_PYTHON C:\ProgramData\Miniconda3\envs\GMS_VENV_PYTHON C:\ProgramData\Miniconda3\envs\em C:\ProgramData\Miniconda3\envs\tf

UI template II

https://github.com/Renfong/dm-script-tool/blob/master/UI_Template_2.s // Interactive UI template // // 2021/05/06 // Renfong interface call_functions{ number GetBoxNumber(object self); }; class UI_Functions : object { number true, false number UIObjectID object MainUI void SetUIObjectID(object self, number id) { UIObjectID = id MainUI = GetScriptObjectFromID(UIObjectID) }; UI_Functions(object self) { true = 1; false = 0 result("Obect \"UI_Functions\" ["+self.ScriptObjectGetID()+"] constructed. \n") }; ~UI_Functions(object self) { true = 1; false = 0 result("Obect\"UI_Functions\" ["+self.ScriptObjectGetID()+"] deconstructed. \n") }; void btn1response(object self) { number num = MainUI.GetBoxNumber() OKdialog("Number = "+num) }; }; class MainUI : UIFrame { TagGroup btn1, numbox object UI_Functions number true, false, ver MainUI(object self){ true = 1...

How to do PCA for EELS SI in python

PCA is the popular statistic tool to denoise the EELS spectrum image. Here is the simple example to apply PCA by numpy package ================================== """ ref: https://stackoverflow.com/questions/13224362/principal-component-analysis-pca-in-python/49629816#49629816 @author: renfong """ import numpy as np import matplotlib.pyplot as plt import hyperspy.api as hs from numpy import argsort from numpy.linalg import eigh #%% load data data = hs.load('t1.dm3').data #%% define pca def pca(data, pc_count = None):     """     Principal component analysis using eigenvalues     note: this mean-centers and auto-scales the data (in-place)     """     C = np.dot(data.T, data)       # covariance matrix     E, V = eigh(C)     key = argsort(E)[::-1][:pc_count]     E, V = E[key], V[:, key]     U = data @ V  # equvalent to np.dot(data, V)     return U, E, V #%% reconstruc...

Simple Pushbuttons UI Template for dm-script

 // Pushbutton UI template // // 2021/04/21 // Renfong class UI_Handler : object { number true, false number UIObjectID void SetUIObjectID(object self, number id) { UIObjectID = id }; UI_Handler(object self) { true = 1; false = 0 result("Obect \"UI_Handler\" ["+self.ScriptObjectGetID()+"] constructed. \n") }; ~UI_Handler(object self) { true = 1; false = 0 result("Obect\"UI_Handler\" ["+self.ScriptObjectGetID()+"] deconstructed. \n") }; void btn1response(object self) { OKdialog("This is a template") }; }; class MainUI : UIFrame { TagGroup btn1 object UI_Handler number true, false, ver MainUI(object self){ true = 1; false = 0; ver=0.1; UI_Handler = alloc(UI_Handler) result("Obect \"MainUI\" ["+self.ScriptObjectGetID()+"] constructed. \n") }; ~MainUI(object self){ result("Obect \"MainUI\" ["+self.Scr...

numpy.polyfit example

 #%% load package import numpy as np import matplotlib.pyplot as plt #%% example 1: simple second order fitting # assume y=2x**2 xx = np.arange(-3,3,step=0.2) yy = 2*xx**2  yy +=  (np.random.random(len(xx))-0.5)  # add noise plt.figure(1, dpi=150) plt.plot(xx, yy, 'ro') # curve fitting lin_fit = np.polyfit(xx, yy, 2) print(lin_fit) x2 = np.arange(-3,3,step=.01) y2 = np.polyval(lin_fit, x2) plt.figure(1) plt.plot(x2,y2, 'k') plt.legend(['raw data','fitting curve']) plt.legend(['raw data','fitting curve']) plt.plot(x2[np.argmin(y2)], np.min(y2), 'b*', markersize=10) plt.text(x2[np.argmin(y2)], np.min(y2)-1,           'min: (%.2f, %.2f)'%(x2[np.argmin(y2)], np.min(y2))) plt.axis([-3,3,-2,20]) plt.show() #================================================= #%% example 2 # assume y-y0 = a*(x-x0)**2 # --> y = ax**2 - 2a*x0*x + a*x0**2 + y0 # let a=-1, x0=1.2, y0=0.7, i.e. the maximum value is located at (1.2, 0.7) # --> y = ...

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