{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Notebook 02 and 03 - Noise Analysis and eV conversion"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"#Imports \n",
"%matplotlib qt\n",
"\n",
"import hyperspy.api as hs\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"\n",
"from matplotlib.colors import SymLogNorm\n",
"from scipy.stats import chi2"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"#Helper functions for statistical analysis\n",
"def hist_var(n,mids,minpoints=5) -> np.float:\n",
" \"\"\"Helper function to compute sample variance from a 1d histogram\"\"\"\n",
" if n.sum()>=minpoints:\n",
" mean = np.average(mids, weights=n)\n",
" var = np.average((mids - mean)**2, weights=n)\n",
" else:\n",
" var = np.nan\n",
" \n",
" return var\n",
"\n",
"def lo_conf_int(var,npts,alpha=0.025) -> float:\n",
" \"\"\"Helper function to compute the lower confidence interval using chi squared distribution\"\"\"\n",
" return (npts-1)*var/chi2.ppf(1-alpha/2,npts)\n",
"\n",
"def hi_conf_int(var,npts,alpha=0.025) -> float:\n",
" \"\"\"Helper function to compute the higher confidence interval using chi squared distribution\"\"\"\n",
" return (npts-1)*var/chi2.ppf(alpha/2,npts)\n",
"\n",
"def hist_var_confint(n,mids,alpha=0.025,minpoints=5) -> np.array([float,float]):\n",
" \"\"\"Helper function to compute the complete confidence interval using chi squared distribution\"\"\"\n",
" var = hist_var(n,mids,minpoints)\n",
" npts = n.sum()\n",
" return np.array([lo_conf_int(var,npts,alpha),hi_conf_int(var,npts,alpha)])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Loading the data"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"#Loading the map cleaned of imaging shift and other basic corrections\n",
"dat = hs.load(\"clmap_IIB-HPHT-diamond_cleaned.hspy\")"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"
< Axes manager, axes: (63, 64|875) >
\n",
"\n",
"\n",
" \n",
"Navigation axis name | \n",
"size | \n",
"index | \n",
"offset | \n",
"scale | \n",
"units |
\n",
" \n",
"Width | \n",
"63 | \n",
"0 | \n",
"0.0 | \n",
"3.3711 | \n",
"µm |
\n",
" \n",
"Height | \n",
"64 | \n",
"0 | \n",
"0.0 | \n",
"3.3711 | \n",
"µm |
\n",
"\n",
"\n",
" \n",
"Signal axis name | \n",
"size | \n",
" | \n",
"offset | \n",
"scale | \n",
"units |
\n",
" \n",
"Wavelength | \n",
"875 | \n",
" | \n",
"206.90001127123833 | \n",
"0.06405988335609436 | \n",
"nm |
\n"
],
"text/plain": [
"\n",
" Name | size | index | offset | scale | units \n",
"================ | ====== | ====== | ======= | ======= | ====== \n",
" Width | 63 | 0 | 0 | 3.4 | µm \n",
" Height | 64 | 0 | 0 | 3.4 | µm \n",
"---------------- | ------ | ------ | ------- | ------- | ------ \n",
" Wavelength | 875 | 0 | 2.1e+02 | 0.064 | nm "
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dat.axes_manager"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/html": [
"\n",
" \n",
" \n",
" - \n",
" Object_0_Channel_0\n",
"
\n",
" \n",
" \n",
" \n",
" - \n",
" Header\n",
"
\n",
" \n",
" \n",
" - H01_Signature = DIGITAL SURF
\n",
" \n",
" \n",
" \n",
" \n",
" - H03_Number_of_Objects = 1
\n",
" \n",
" \n",
" \n",
" \n",
" - H05_Object_Type = 21
\n",
" \n",
" \n",
" - H06_Object_Name = HYPCard
\n",
" \n",
" \n",
" - H07_Operator_Name =
\n",
" \n",
" \n",
" \n",
" \n",
" - H09_Acquisition_Type = 0
\n",
" \n",
" \n",
" - H10_Range_Type = 0
\n",
" \n",
" \n",
" - H11_Special_Points = 0
\n",
" \n",
" \n",
" \n",
" \n",
" - H13_Gauge_Resolution = 0.0
\n",
" \n",
" \n",
" \n",
" \n",
" - H15_Size_of_Points = 32
\n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" - H18_Number_of_Points = 64
\n",
" \n",
" \n",
" - H19_Number_of_Lines = 64
\n",
" \n",
" \n",
" - H20_Total_Nb_of_Pts = 4096
\n",
" \n",
" \n",
" - H21_X_Spacing = 2.0885674953460693
\n",
" \n",
" \n",
" - H22_Y_Spacing = 2.0885674953460693
\n",
" \n",
" \n",
" - H23_Z_Spacing = 1.0
\n",
" \n",
" \n",
" - H24_Name_of_X_Axis = Width
\n",
" \n",
" \n",
" - H25_Name_of_Y_Axis = Height
\n",
" \n",
" \n",
" - H26_Name_of_Z_Axis = CL Intensity
\n",
" \n",
" \n",
" - H27_X_Step_Unit = um
\n",
" \n",
" \n",
" - H28_Y_Step_Unit = um
\n",
" \n",
" \n",
" - H29_Z_Step_Unit = a.u.
\n",
" \n",
" \n",
" - H30_X_Length_Unit = um
\n",
" \n",
" \n",
" - H31_Y_Length_Unit = um
\n",
" \n",
" \n",
" - H32_Z_Length_Unit = a.u.
\n",
" \n",
" \n",
" - H33_X_Unit_Ratio = 1.0
\n",
" \n",
" \n",
" - H34_Y_Unit_Ratio = 1.0
\n",
" \n",
" \n",
" - H35_Z_Unit_Ratio = 1.0
\n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" - H39_Obsolete = b'\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00'
\n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" - H46_Day_of_week = 0
\n",
" \n",
" \n",
" - H47_Measurement_duration = 2048.0
\n",
" \n",
" \n",
" - H48_Compressed_data_size = 0
\n",
" \n",
" \n",
" - H49_Obsolete = b'\\x00\\x00\\x00\\x00\\x00\\x00'
\n",
" \n",
" \n",
" - H50_Comment_size = 2664
\n",
" \n",
" \n",
" - H51_Private_size = 0
\n",
" \n",
" \n",
" \n",
" \n",
" - H53_X_Offset = 0.0
\n",
" \n",
" \n",
" - H54_Y_Offset = 0.0
\n",
" \n",
" \n",
" - H55_Z_Offset = 0.0
\n",
" \n",
" \n",
" - H56_T_Spacing = 0.06405988335609436
\n",
" \n",
" \n",
" - H57_T_Offset = 202.09552001953125
\n",
" \n",
" \n",
" - H58_T_Axis_Name = Wavelength
\n",
" \n",
" \n",
" - H59_T_Step_Unit = nm
\n",
" \n",
" \n",
" - H60_Comment = $_WAFER\n",
"$Lot Number=LOT_0000\n",
"$ID=WAFER_0000\n",
"$Type=ROUNDWITHFLAT\n",
"$Center Positi ... 12\n",
"$Start_Y=0\n",
"$Size_Y=512\n",
"$Rotate=311.000000 deg\n",
"$InitialRotate=180.000000 deg
\n",
"
\n",
" \n",
" \n",
" - \n",
" Parsed\n",
"
\n",
" \n",
" \n",
" \n",
" - \n",
" CCD\n",
"
\n",
" \n",
" \n",
" - Baseline Clamp = Off
\n",
" \n",
" \n",
" - Camera Model = A.920
\n",
" \n",
" \n",
" - Capture Depth = 1024
\n",
" \n",
" \n",
" - Exposure Time = 0.5
\n",
" \n",
" \n",
" - Exposure Time_units = s
\n",
" \n",
" \n",
" - Horizontal Binning = 1
\n",
" \n",
" \n",
" - Pixel Width = 0.026
\n",
" \n",
" \n",
" - Pixel Width_units = mm
\n",
" \n",
" \n",
" \n",
" \n",
" - Readout Rate (horizontal pixel shift) = 50Khz
\n",
" \n",
" \n",
" - Signal Amplification = x4
\n",
" \n",
" \n",
" - Speed (vertical pixel shift) = 1.7
\n",
" \n",
" \n",
" \n",
" \n",
" - Temperature_units = °C
\n",
" \n",
" \n",
" - Voltage Amplitude (vertical pixel shift) = normal
\n",
"
\n",
" \n",
" \n",
" - \n",
" CHANNELS\n",
"
\n",
" \n",
" \n",
" \n",
" \n",
"
\n",
" \n",
" \n",
" - \n",
" SCAN\n",
"
\n",
" \n",
" \n",
" - HYP Dwelltime = 500.0
\n",
" \n",
" \n",
" - HYP Dwelltime_units = ms
\n",
" \n",
" \n",
" - InitialRotate = 180.0
\n",
" \n",
" \n",
" - InitialRotate_units = deg
\n",
" \n",
" \n",
" \n",
" \n",
" - Reference_Size_X = 512
\n",
" \n",
" \n",
" - Reference_Size_Y = 512
\n",
" \n",
" \n",
" \n",
" \n",
" - Resolution_X_units = pixels
\n",
" \n",
" \n",
" \n",
" \n",
" - Resolution_Y_units = pixels
\n",
" \n",
" \n",
" \n",
" \n",
" - Rotate_units = deg
\n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" - Voltage Calibration Range_X = 9.2
\n",
" \n",
" \n",
" - Voltage Calibration Range_X_units = V
\n",
" \n",
" \n",
" - Voltage Calibration Range_Y = 9.2
\n",
" \n",
" \n",
" - Voltage Calibration Range_Y_units = V
\n",
"
\n",
" \n",
" \n",
" - \n",
" SEM\n",
"
\n",
" \n",
" \n",
" \n",
" \n",
" - Aperture Chamber Pressure = 1.6501e-07
\n",
" \n",
" \n",
" - Aperture Chamber Pressure_units = Torr
\n",
" \n",
" \n",
" - Aperture_units = um
\n",
" \n",
" \n",
" - Astigmatism 1 X = -0.01
\n",
" \n",
" \n",
" - Astigmatism 1 X_units = V
\n",
" \n",
" \n",
" - Astigmatism 1 Y = 0.0
\n",
" \n",
" \n",
" - Astigmatism 1 Y_units = V
\n",
" \n",
" \n",
" - Astigmatism 2 X = -3.64
\n",
" \n",
" \n",
" - Astigmatism 2 X_units = V
\n",
" \n",
" \n",
" - Astigmatism 2 Y = 0.6
\n",
" \n",
" \n",
" - Astigmatism 2 Y_units = V
\n",
" \n",
" \n",
" - Attomic ReadedMagnification = 353.0
\n",
" \n",
" \n",
" \n",
" \n",
" - Beam Current = 12.7
\n",
" \n",
" \n",
" - Beam Current_units = uA
\n",
" \n",
" \n",
" - Beam Energy = 10001.39
\n",
" \n",
" \n",
" - Beam Energy_units = V
\n",
" \n",
" \n",
" \n",
" \n",
" - Blanker_units = um
\n",
" \n",
" \n",
" - Cathode Heating Current = 2.31
\n",
" \n",
" \n",
" - Cathode Heating Current_units = A
\n",
" \n",
" \n",
" - Cathode Heating Voltage = 1.9
\n",
" \n",
" \n",
" - Cathode Heating Voltage_units = V
\n",
" \n",
" \n",
" - Deflector 1 X = -1.17
\n",
" \n",
" \n",
" - Deflector 1 X_units = V
\n",
" \n",
" \n",
" - Deflector 1 Y = 18.75
\n",
" \n",
" \n",
" - Deflector 1 Y_units = V
\n",
" \n",
" \n",
" - Deflector 2 X = -0.01
\n",
" \n",
" \n",
" - Deflector 2 X_units = V
\n",
" \n",
" \n",
" - Deflector 2 Y = -0.01
\n",
" \n",
" \n",
" - Deflector 2 Y_units = V
\n",
" \n",
" \n",
" - Emission Current = 89.3
\n",
" \n",
" \n",
" - Emission Current_units = uA
\n",
" \n",
" \n",
" - Emission Status = ON
\n",
" \n",
" \n",
" - Extractor Voltage = 4896.93
\n",
" \n",
" \n",
" - Extractor Voltage_units = V
\n",
" \n",
" \n",
" - Gun Chamber Pressure = 6.6005e-10
\n",
" \n",
" \n",
" - Gun Chamber Pressure_units = Torr
\n",
" \n",
" \n",
" - Gun Lens = 1.546139
\n",
" \n",
" \n",
" - Gun Lens_units = A
\n",
" \n",
" \n",
" - Isolation Valve = Opened
\n",
" \n",
" \n",
" - Objective Lens = 0.43547
\n",
" \n",
" \n",
" - Objective Lens_units = A
\n",
" \n",
" \n",
" - Real Magnification = 996.141174
\n",
" \n",
" \n",
" - Reference Field of view = 131.58
\n",
" \n",
" \n",
" - Reference Field of view_units = um
\n",
" \n",
" \n",
" - Reference Screen Size = 131.072
\n",
" \n",
" \n",
" - Reference Screen Size_units = mm
\n",
" \n",
" \n",
" - Scintillator Voltage = 6023.0
\n",
" \n",
" \n",
" - Scintillator Voltage_units = V
\n",
" \n",
" \n",
" - Suppressor Bias = 955.92
\n",
" \n",
" \n",
" - Suppressor Bias_units = V
\n",
"
\n",
" \n",
" \n",
" - \n",
" SITE IMAGE\n",
"
\n",
" \n",
" \n",
" - Dwell Time = 500000.0
\n",
" \n",
" \n",
" - Dwell Time_units = us
\n",
" \n",
" \n",
" - Number of pixels (x axis) = 64
\n",
" \n",
" \n",
" - Number of pixels (x axis)_units = px
\n",
" \n",
" \n",
" - Number of pixels (y axis) = 64
\n",
" \n",
" \n",
" - Number of pixels (y axis)_units = px
\n",
" \n",
" \n",
" - Reference Field of view = 131.58
\n",
" \n",
" \n",
" - Reference Field of view_units = um
\n",
" \n",
" \n",
" - stage_model = 10010
\n",
" \n",
" \n",
" - stage_position_x = -0.884512
\n",
" \n",
" \n",
" - stage_position_y = 1.319661
\n",
" \n",
" \n",
" - stage_position_z = 0.679464
\n",
" \n",
" \n",
" - stage_rotation_x = -0.0
\n",
" \n",
" \n",
" - stage_rotation_y = 0.0
\n",
" \n",
" \n",
" - stage_rotation_z = -0.0
\n",
"
\n",
" \n",
" \n",
" - \n",
" SPECTROMETER\n",
"
\n",
" \n",
" \n",
" - Calibrated Wavelength Offset[1200/250] = 0.0
\n",
" \n",
" \n",
" - Calibrated Wavelength Offset[1200/250]_units = nm
\n",
" \n",
" \n",
" - Camera Tilt Angle = 0.0
\n",
" \n",
" \n",
" - Camera Tilt Angle_units = deg
\n",
" \n",
" \n",
" - Central wavelength = 235.0
\n",
" \n",
" \n",
" - Central wavelength_units = nm
\n",
" \n",
" \n",
" - Distortion Polynomial[1200/250] = 0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000
\n",
" \n",
" \n",
" \n",
" \n",
" - Ebert Angle_units = deg
\n",
" \n",
" \n",
" - Entrance slit width = 7000
\n",
" \n",
" \n",
" - Entrance slit width_units = um
\n",
" \n",
" \n",
" - Exit mirror position = lateral
\n",
" \n",
" \n",
" - Exit slit width = 0
\n",
" \n",
" \n",
" - Exit slit width_units = um
\n",
" \n",
" \n",
" - Exit spectral resolution = 0
\n",
" \n",
" \n",
" - Exit spectral resolution_units = nm
\n",
" \n",
" \n",
" \n",
" \n",
" - Grating = 1200/250
\n",
" \n",
" \n",
" - Grating - Blaze Angle = 0
\n",
" \n",
" \n",
" - Grating - Groove Density = 1200
\n",
" \n",
" \n",
" - Grating - Groove Density_units = gr/mm
\n",
" \n",
" \n",
" - Optical Magnification = 0.0
\n",
" \n",
" \n",
" - Scan Orientation = 0.0
\n",
" \n",
" \n",
" - Spectrometer Focal Length = 0.0
\n",
" \n",
" \n",
" - Spectrometer Focal Length_units = mm
\n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" - Turret_units = 320
\n",
"
\n",
" \n",
" \n",
" - \n",
" WAFER\n",
"
\n",
" \n",
" \n",
" - Center Position X = 0.0
\n",
" \n",
" \n",
" - Center Position X_units = mm
\n",
" \n",
" \n",
" - Center Position Y = 0.0
\n",
" \n",
" \n",
" - Center Position Y_units = mm
\n",
" \n",
" \n",
" \n",
" \n",
" - Diameter_units = mm
\n",
" \n",
" \n",
" - Edge Exclusion = 0.0
\n",
" \n",
" \n",
" - Edge Exclusion_units = mm
\n",
" \n",
" \n",
" \n",
" \n",
" - Flat Length_units = mm
\n",
" \n",
" \n",
" \n",
" \n",
" - Lot Number = LOT_0000
\n",
" \n",
" \n",
" \n",
" \n",
" - Orientation_units = deg
\n",
" \n",
" \n",
" - Type = ROUNDWITHFLAT
\n",
"
"
],
"text/plain": [
"└── Object_0_Channel_0\n",
" ├── Header\n",
" │ ├── H01_Signature = DIGITAL SURF\n",
" │ ├── H02_Format = 0\n",
" │ ├── H03_Number_of_Objects = 1\n",
" │ ├── H04_Version = 1\n",
" │ ├── H05_Object_Type = 21\n",
" │ ├── H06_Object_Name = HYPCard\n",
" │ ├── H07_Operator_Name = \n",
" │ ├── H08_P_Size = 1\n",
" │ ├── H09_Acquisition_Type = 0\n",
" │ ├── H10_Range_Type = 0\n",
" │ ├── H11_Special_Points = 0\n",
" │ ├── H12_Absolute = 1\n",
" │ ├── H13_Gauge_Resolution = 0.0\n",
" │ ├── H14_W_Size = 1024\n",
" │ ├── H15_Size_of_Points = 32\n",
" │ ├── H16_Zmin = 0\n",
" │ ├── H17_Zmax = 65535\n",
" │ ├── H18_Number_of_Points = 64\n",
" │ ├── H19_Number_of_Lines = 64\n",
" │ ├── H20_Total_Nb_of_Pts = 4096\n",
" │ ├── H21_X_Spacing = 2.0885674953460693\n",
" │ ├── H22_Y_Spacing = 2.0885674953460693\n",
" │ ├── H23_Z_Spacing = 1.0\n",
" │ ├── H24_Name_of_X_Axis = Width\n",
" │ ├── H25_Name_of_Y_Axis = Height\n",
" │ ├── H26_Name_of_Z_Axis = CL Intensity\n",
" │ ├── H27_X_Step_Unit = um\n",
" │ ├── H28_Y_Step_Unit = um\n",
" │ ├── H29_Z_Step_Unit = a.u.\n",
" │ ├── H30_X_Length_Unit = um\n",
" │ ├── H31_Y_Length_Unit = um\n",
" │ ├── H32_Z_Length_Unit = a.u.\n",
" │ ├── H33_X_Unit_Ratio = 1.0\n",
" │ ├── H34_Y_Unit_Ratio = 1.0\n",
" │ ├── H35_Z_Unit_Ratio = 1.0\n",
" │ ├── H36_Imprint = 0\n",
" │ ├── H37_Inverted = 0\n",
" │ ├── H38_Levelled = 0\n",
" │ ├── H39_Obsolete = b'\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00'\n",
" │ ├── H40_Seconds = 0\n",
" │ ├── H41_Minutes = 0\n",
" │ ├── H42_Hours = 0\n",
" │ ├── H43_Day = 0\n",
" │ ├── H44_Month = 0\n",
" │ ├── H45_Year = 0\n",
" │ ├── H46_Day_of_week = 0\n",
" │ ├── H47_Measurement_duration = 2048.0\n",
" │ ├── H48_Compressed_data_size = 0\n",
" │ ├── H49_Obsolete = b'\\x00\\x00\\x00\\x00\\x00\\x00'\n",
" │ ├── H50_Comment_size = 2664\n",
" │ ├── H51_Private_size = 0\n",
" │ ├── H52_Client_zone = \n",
" │ ├── H53_X_Offset = 0.0\n",
" │ ├── H54_Y_Offset = 0.0\n",
" │ ├── H55_Z_Offset = 0.0\n",
" │ ├── H56_T_Spacing = 0.06405988335609436\n",
" │ ├── H57_T_Offset = 202.09552001953125\n",
" │ ├── H58_T_Axis_Name = Wavelength\n",
" │ ├── H59_T_Step_Unit = nm\n",
" │ └── H60_Comment = $_WAFER\n",
"$Lot Number=LOT_0000\n",
"$ID=WAFER_0000\n",
"$Type=ROUNDWITHFLAT\n",
"$Center Positi ... 12\n",
"$Start_Y=0\n",
"$Size_Y=512\n",
"$Rotate=311.000000 deg\n",
"$InitialRotate=180.000000 deg\n",
" └── Parsed\n",
" ├── CCD\n",
" │ ├── Baseline Clamp = Off\n",
" │ ├── Camera Model = A.920\n",
" │ ├── Capture Depth = 1024\n",
" │ ├── Exposure Time = 0.5\n",
" │ ├── Exposure Time_units = s\n",
" │ ├── Horizontal Binning = 1\n",
" │ ├── Pixel Width = 0.026\n",
" │ ├── Pixel Width_units = mm\n",
" │ ├── ReadMode = FVB\n",
" │ ├── Readout Rate (horizontal pixel shift) = 50Khz\n",
" │ ├── Signal Amplification = x4\n",
" │ ├── Speed (vertical pixel shift) = 1.7\n",
" │ ├── Temperature = -69\n",
" │ ├── Temperature_units = °C\n",
" │ └── Voltage Amplitude (vertical pixel shift) = normal\n",
" ├── CHANNELS\n",
" │ ├── Channel1 = SE\n",
" │ └── Channel2 = CCD\n",
" ├── SCAN\n",
" │ ├── HYP Dwelltime = 500.0\n",
" │ ├── HYP Dwelltime_units = ms\n",
" │ ├── InitialRotate = 180.0\n",
" │ ├── InitialRotate_units = deg\n",
" │ ├── Mode = HYP\n",
" │ ├── Reference_Size_X = 512\n",
" │ ├── Reference_Size_Y = 512\n",
" │ ├── Resolution_X = 64\n",
" │ ├── Resolution_X_units = pixels\n",
" │ ├── Resolution_Y = 64\n",
" │ ├── Resolution_Y_units = pixels\n",
" │ ├── Rotate = 311.0\n",
" │ ├── Rotate_units = deg\n",
" │ ├── Size_X = 512\n",
" │ ├── Size_Y = 512\n",
" │ ├── Start_X = 0\n",
" │ ├── Start_Y = 0\n",
" │ ├── Voltage Calibration Range_X = 9.2\n",
" │ ├── Voltage Calibration Range_X_units = V\n",
" │ ├── Voltage Calibration Range_Y = 9.2\n",
" │ └── Voltage Calibration Range_Y_units = V\n",
" ├── SEM\n",
" │ ├── Aperture = 100\n",
" │ ├── Aperture Chamber Pressure = 1.6501e-07\n",
" │ ├── Aperture Chamber Pressure_units = Torr\n",
" │ ├── Aperture_units = um\n",
" │ ├── Astigmatism 1 X = -0.01\n",
" │ ├── Astigmatism 1 X_units = V\n",
" │ ├── Astigmatism 1 Y = 0.0\n",
" │ ├── Astigmatism 1 Y_units = V\n",
" │ ├── Astigmatism 2 X = -3.64\n",
" │ ├── Astigmatism 2 X_units = V\n",
" │ ├── Astigmatism 2 Y = 0.6\n",
" │ ├── Astigmatism 2 Y_units = V\n",
" │ ├── Attomic ReadedMagnification = 353.0\n",
" │ ├── Attomic zoom = 4\n",
" │ ├── Beam Current = 12.7\n",
" │ ├── Beam Current_units = uA\n",
" │ ├── Beam Energy = 10001.39\n",
" │ ├── Beam Energy_units = V\n",
" │ ├── Blanker = Off\n",
" │ ├── Blanker_units = um\n",
" │ ├── Cathode Heating Current = 2.31\n",
" │ ├── Cathode Heating Current_units = A\n",
" │ ├── Cathode Heating Voltage = 1.9\n",
" │ ├── Cathode Heating Voltage_units = V\n",
" │ ├── Deflector 1 X = -1.17\n",
" │ ├── Deflector 1 X_units = V\n",
" │ ├── Deflector 1 Y = 18.75\n",
" │ ├── Deflector 1 Y_units = V\n",
" │ ├── Deflector 2 X = -0.01\n",
" │ ├── Deflector 2 X_units = V\n",
" │ ├── Deflector 2 Y = -0.01\n",
" │ ├── Deflector 2 Y_units = V\n",
" │ ├── Emission Current = 89.3\n",
" │ ├── Emission Current_units = uA\n",
" │ ├── Emission Status = ON\n",
" │ ├── Extractor Voltage = 4896.93\n",
" │ ├── Extractor Voltage_units = V\n",
" │ ├── Gun Chamber Pressure = 6.6005e-10\n",
" │ ├── Gun Chamber Pressure_units = Torr\n",
" │ ├── Gun Lens = 1.546139\n",
" │ ├── Gun Lens_units = A\n",
" │ ├── Isolation Valve = Opened\n",
" │ ├── Objective Lens = 0.43547\n",
" │ ├── Objective Lens_units = A\n",
" │ ├── Real Magnification = 996.141174\n",
" │ ├── Reference Field of view = 131.58\n",
" │ ├── Reference Field of view_units = um\n",
" │ ├── Reference Screen Size = 131.072\n",
" │ ├── Reference Screen Size_units = mm\n",
" │ ├── Scintillator Voltage = 6023.0\n",
" │ ├── Scintillator Voltage_units = V\n",
" │ ├── Suppressor Bias = 955.92\n",
" │ └── Suppressor Bias_units = V\n",
" ├── SITE IMAGE\n",
" │ ├── Dwell Time = 500000.0\n",
" │ ├── Dwell Time_units = us\n",
" │ ├── Number of pixels (x axis) = 64\n",
" │ ├── Number of pixels (x axis)_units = px\n",
" │ ├── Number of pixels (y axis) = 64\n",
" │ ├── Number of pixels (y axis)_units = px\n",
" │ ├── Reference Field of view = 131.58\n",
" │ ├── Reference Field of view_units = um\n",
" │ ├── stage_model = 10010\n",
" │ ├── stage_position_x = -0.884512\n",
" │ ├── stage_position_y = 1.319661\n",
" │ ├── stage_position_z = 0.679464\n",
" │ ├── stage_rotation_x = -0.0\n",
" │ ├── stage_rotation_y = 0.0\n",
" │ └── stage_rotation_z = -0.0\n",
" ├── SPECTROMETER\n",
" │ ├── Calibrated Wavelength Offset[1200/250] = 0.0\n",
" │ ├── Calibrated Wavelength Offset[1200/250]_units = nm\n",
" │ ├── Camera Tilt Angle = 0.0\n",
" │ ├── Camera Tilt Angle_units = deg\n",
" │ ├── Central wavelength = 235.0\n",
" │ ├── Central wavelength_units = nm\n",
" │ ├── Distortion Polynomial[1200/250] = 0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000\n",
" │ ├── Ebert Angle = 0.0\n",
" │ ├── Ebert Angle_units = deg\n",
" │ ├── Entrance slit width = 7000\n",
" │ ├── Entrance slit width_units = um\n",
" │ ├── Exit mirror position = lateral\n",
" │ ├── Exit slit width = 0\n",
" │ ├── Exit slit width_units = um\n",
" │ ├── Exit spectral resolution = 0\n",
" │ ├── Exit spectral resolution_units = nm\n",
" │ ├── Filter = None\n",
" │ ├── Grating = 1200/250\n",
" │ ├── Grating - Blaze Angle = 0\n",
" │ ├── Grating - Groove Density = 1200\n",
" │ ├── Grating - Groove Density_units = gr/mm\n",
" │ ├── Optical Magnification = 0.0\n",
" │ ├── Scan Orientation = 0.0\n",
" │ ├── Spectrometer Focal Length = 0.0\n",
" │ ├── Spectrometer Focal Length_units = mm\n",
" │ ├── Turret = IHR\n",
" │ ├── Turret id = 0\n",
" │ └── Turret_units = 320\n",
" └── WAFER\n",
" ├── Center Position X = 0.0\n",
" ├── Center Position X_units = mm\n",
" ├── Center Position Y = 0.0\n",
" ├── Center Position Y_units = mm\n",
" ├── Diameter = 0\n",
" ├── Diameter_units = mm\n",
" ├── Edge Exclusion = 0.0\n",
" ├── Edge Exclusion_units = mm\n",
" ├── Flat Length = 0.0\n",
" ├── Flat Length_units = mm\n",
" ├── ID = WAFER_0000\n",
" ├── Lot Number = LOT_0000\n",
" ├── Orientation = 0.0\n",
" ├── Orientation_units = deg\n",
" └── Type = ROUNDWITHFLAT"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#How to display the instrument metadata\n",
"dat.original_metadata"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"dat.plot(norm='linear')"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"plt.close('all')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Signal Variance Computation\n",
"\n",
"### First step: PCA decomposition\n",
"\n",
"PCA decomposition, creation of data and residue signal objects\n",
"\n",
"Number of significant components are estimated from hyperspy's standard method to find knee of scree plot.\n",
"\n",
"See https://ieeexplore.ieee.org/document/5961514"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Decomposition info:\n",
" normalize_poissonian_noise=False\n",
" algorithm=SVD\n",
" output_dimension=None\n",
" centre=None\n"
]
}
],
"source": [
"#PCA decomposition\n",
"dat.decomposition()\n",
"#Creation of the PCA signal map\n",
"PCA_signal_map = dat.get_decomposition_model(dat.learning_results.number_significant_components)\n",
"#Creation of the PCA noise map\n",
"PCA_noise_map = dat-PCA_signal_map"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Second step: 2d signal vs noise histogram"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"#Unit bins range.Integer bins between min and max of all data\n",
"Xbin = np.arange(0,int(PCA_signal_map.data.max()))\n",
"Ybin = np.arange(int(PCA_noise_map.data.min()),int(PCA_noise_map.data.max()))\n",
"\n",
"#Plotting the histogram\n",
"fig = plt.figure()\n",
"\n",
"heatmap, xedges, yedges,img = plt.hist2d(PCA_signal_map.data.ravel(),\n",
" PCA_noise_map.data.ravel(),\n",
" bins=(Xbin,Ybin),\n",
" norm=SymLogNorm(linthresh=1.0,vmin=0,vmax=1e4),\n",
" density=False\n",
" )\n",
"\n",
"plt.colorbar(mappable=img,ticks=(0,1,1e1,1e2,1e3,1e4,1e5),label='Occurences')\n",
"fig.set_size_inches((220/25.4,100/25.4))\n",
"plt.xlabel('PCA Signal [Counts]')\n",
"plt.ylabel('PCA Noise [Counts]')\n",
"plt.tight_layout()"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"#Storing the histogram as a hyperspy signal1D object, ie as a serie of 1d histogram. \n",
"#Other solutions are naturally possible, but I found this to be the easiest.\n",
"\n",
"#Formatting some nice axes\n",
"xax = {'name': 'Signal Intensity (counts)',\n",
" 'units': 'au',\n",
" 'navigate': True,\n",
" 'size': len(xedges)-1,\n",
" 'scale': np.diff(xedges)[0],\n",
" 'offset': 0.5*(xedges[0]+xedges[1])}\n",
"yax = {'name': 'PCA_noise_map',\n",
" 'units': 'au',\n",
" 'navigate': False,\n",
" 'size': len(yedges)-1,\n",
" 'scale': np.diff(yedges)[0],\n",
" 'offset': 0.5*(yedges[0]+yedges[1])}\n",
"#Signal initialisation\n",
"hist2ddata = hs.signals.Signal1D(heatmap,axes=[xax,yax])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Third step: Pseudo-photon-transfer-curve of the data"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"WARNING:hyperspy.signal:The default iterpath will change in HyperSpy 2.0.\n",
"WARNING:hyperspy.signal:The default iterpath will change in HyperSpy 2.0.\n"
]
}
],
"source": [
"#Computation of the Pseudo-photon-transfer-curve with confidence intervals\n",
"\n",
"#We do not use signal levels where less than 10 histogram points are available\n",
"mids = hist2ddata.axes_manager.signal_axes[0].axis\n",
"pseudo_PTC = hist2ddata.map(function=hist_var,show_progressbar=False,inplace=False,mids=mids,minpoints=10)\n",
"\n",
"#Confidence intervals computation using chi squared interval evaluation.\n",
"confint_var = hist2ddata.map(function=hist_var_confint,show_progressbar=False,inplace=False,mids=mids,minpoints=10)\n",
"confint_var.axes_manager.signal_axes[0].offset = 2.5\n",
"confint_var.axes_manager.signal_axes[0].scale = 95\n",
"confint_var.axes_manager.signal_axes[0].name = 'confidence'\n",
"confint_var.axes_manager.signal_axes[0].units = '%'"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"fit range stop: 246 counts. Fit result: var = 0.458*counts + 23\n"
]
}
],
"source": [
"#Relative uncertainty of the variance estimation computed from the confidence interval\n",
"rel_unc = (confint_var-pseudo_PTC)/pseudo_PTC\n",
"\n",
"#Setting a threshold for the fit range. 25% is a good value\n",
"threshold = 0.25\n",
"#We exclude from the fit data from the first point it exceeds the uncertainty threshold\n",
"start = 0\n",
"stop = np.min(np.argmax(((rel_unc<-1*threshold)+(rel_unc>threshold)).data,axis=0))\n",
"\n",
"#Fit of the affine model on the Pseudo-PTC\n",
"x = pseudo_PTC.axes_manager.navigation_axes[0].axis\n",
"y = pseudo_PTC.data\n",
"poly = np.polyfit(x[start:stop],y[start:stop],1)\n",
"\n",
"print(f\"fit range stop: {stop} counts. Fit result: var = {poly[0]:.3f}*counts + {poly[1]:.0f}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Custom plot of the pseudo-ptc with confidence interval"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"plt.figure()\n",
"\n",
"plt.loglog(x,y,'k.',label='data',markersize=1)\n",
"plt.fill_between(x,confint_var.data[:,1],confint_var.data[:,0],label='95% confidence interval')\n",
"\n",
"plt.plot(x[start:stop],np.polyval(poly,x[start:stop]),\n",
" '-',color='darkgreen',linewidth=1.5,\n",
" label = f'fit: {poly[0]:.2f} Signal + {poly[1]:.0f}')\n",
"\n",
"plt.plot(x[stop:],np.polyval(poly,x[stop:]),\n",
" '-',color='darkred',linewidth=1.5,label='fit extension'\n",
" )\n",
"\n",
"plt.legend()\n",
"plt.ylabel('Variance (Counts)')\n",
"plt.xlabel('Signal (Counts)')\n",
"plt.xlim(1,1300)\n",
"plt.ylim(10,1000)\n",
"plt.tight_layout()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Fourth step: Creation of the variance map\n",
"Fitting an affine model on the data"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"#Creation of the variance map object\n",
"varmap = PCA_signal_map.deepcopy()*poly[0] + poly[1]\n",
"varmap.metadata.General.title = \"Variance map\"\n",
"varmap.metadata.Signal.quantity = \"sigma**2 [au]\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The variance map is a hyperspy object with the same dimensions as the signal object: it indicates us the variance of the detected signal at each wavelength channel of each pixel. Counts measurements std map can be obtained with: `varmap**0.5`"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"< Axes manager, axes: (63, 64|875) >
\n",
"\n",
"\n",
" \n",
"Navigation axis name | \n",
"size | \n",
"index | \n",
"offset | \n",
"scale | \n",
"units |
\n",
" \n",
"Width | \n",
"63 | \n",
"0 | \n",
"0.0 | \n",
"3.3711 | \n",
"µm |
\n",
" \n",
"Height | \n",
"64 | \n",
"0 | \n",
"0.0 | \n",
"3.3711 | \n",
"µm |
\n",
"\n",
"\n",
" \n",
"Signal axis name | \n",
"size | \n",
" | \n",
"offset | \n",
"scale | \n",
"units |
\n",
" \n",
"Wavelength | \n",
"875 | \n",
" | \n",
"206.90001127123833 | \n",
"0.06405988335609436 | \n",
"nm |
\n"
],
"text/plain": [
"\n",
" Name | size | index | offset | scale | units \n",
"================ | ====== | ====== | ======= | ======= | ====== \n",
" Width | 63 | 0 | 0 | 3.4 | µm \n",
" Height | 64 | 0 | 0 | 3.4 | µm \n",
"---------------- | ------ | ------ | ------- | ------- | ------ \n",
" Wavelength | 875 | 0 | 2.1e+02 | 0.064 | nm "
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"varmap.axes_manager"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
"varmap.plot()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Conversion to eV, setting the variance property of the signal"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Here a new signal is computed from the original one. A functional axis is built through $ hc/\\lambda $, intensity values are renormalized through the jacobian of the variable change so that the integral of the signal is preserved"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
"ax = dat.axes_manager.signal_axes[0]"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1239.8419843320025"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from scipy import constants as cst\n",
"hc = cst.h*cst.c/cst.e*1e9 #hc product in nm/eV\n",
"hc"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [],
"source": [
"#Creating a copy of the data object\n",
"sev = dat.deepcopy()\n",
"#Changing the axis of the copy\n",
"sev.axes_manager.signal_axes[0].convert_to_functional_data_axis(\\\n",
" expression=\"a/x\",\n",
" name='Energy',\n",
" units='eV',\n",
" a=hc,\n",
" )\n",
"#Reverting the orientation of signal to have increasing Energy\n",
"sev = sev.isig[::-1]\n",
"#Jacobian transformation\n",
"Eax = sev.axes_manager.signal_axes[0].axis\n",
"sev *= hc/Eax**2"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Plot of the eV signal"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {
"scrolled": false
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\users\\nicolastappy\\documents\\git\\hyperspy\\hyperspy\\signal.py:3702: UserWarning: You are summing over an unbinned, non-uniform axis. The result can not be used as an approximation of the integral of the signal. For this functionality, use integrate1D instead.\n",
" warnings.warn(\"You are summing over an unbinned, non-uniform axis. \"\n"
]
}
],
"source": [
"sev.plot()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The variance map is also converted to eV, but there the intensities have to be multiplied by the square of the jacobian according to\n",
"${\\rm Var}(aX) = a^2{\\rm Var}(X) $"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [],
"source": [
"sev_varmap = sev._deepcopy_with_new_data(varmap.isig[::-1].data*(hc/Eax**2)**2)"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\users\\nicolastappy\\documents\\git\\hyperspy\\hyperspy\\signal.py:3702: UserWarning: You are summing over an unbinned, non-uniform axis. The result can not be used as an approximation of the integral of the signal. For this functionality, use integrate1D instead.\n",
" warnings.warn(\"You are summing over an unbinned, non-uniform axis. \"\n"
]
}
],
"source": [
"sev_varmap.plot()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Variance properties of the whole map can then be set. In hyperspy, they will automatically be used as weights for the fit"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [],
"source": [
"sev.estimate_poissonian_noise_variance(sev_varmap)"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {
"scrolled": false
},
"outputs": [
{
"data": {
"text/html": [
"\n",
" \n",
" \n",
" - \n",
" Variance_linear_model\n",
"
\n",
" \n",
" \n",
" - correlation_factor = 1
\n",
" \n",
" \n",
" \n",
" \n",
"
\n",
" \n",
" - variance = <BaseSignal, title: Variance of , dimensions: (63, 64|875)>
\n",
" "
],
"text/plain": [
"├── Variance_linear_model\n",
"│ ├── correlation_factor = 1\n",
"│ ├── gain_factor = 1\n",
"│ └── gain_offset = 0\n",
"└── variance = "
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sev.metadata.Signal.Noise_properties"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [],
"source": [
"sev.save('clmap_IIB-HPHT-diamond_eV_with_variance.hspy')"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [],
"source": [
"plt.close('all')"
]
}
],
"metadata": {
"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.6.13"
}
},
"nbformat": 4,
"nbformat_minor": 2
}