Wall Thickness Workflow#

\(_{Yongtao}\) \(_{Liu,}\)
\(_{youngtaoliu@gmail.com}\)

\(_{Feb}\) \(_{2024}\)

Piezoresponse force microscopy (PFM) is a powerful technique to study ferroelectrics at the nanoscale. In PFM measurements, an AC voltage is applied to the sample surface through tip and the response of the material is detected, allowing researchers to characterize ferroelectric domains and domain walls. However, the behavior of ferroelectric domain walls can be influenced by the AC voltage and the force (i.e., driven amplitude and set point) applied to the sample surface. We have the chance to optimize the imaging conditions to better characterize and study ferroelectric domain walls by carefully choosing these parameters.

This notebook is the workflow to study ferroelectric domain walls as a function of drive amplitude and setpoint. This notebook contains two parts: first is experimentation, second is data analysis. Both parts work independently.

Experiment#

Import#

import os
import win32com.client
import numpy as np
import time
import h5py
import sidpy
import pyNSID
import matplotlib.pyplot as plt
from tqdm import tqdm
from AEcroscopy import Acquisition

Start BEPyAE.exe and set VI#

  • Start BEPyAE.ext

  • Set VI of BEPyAE; if this version includes PyScanner, also set VIs for PyScanner

newexp = Acquisition(exe_path = r"C:\Users\BEPyAE 060523 01\BEPyAE.exe")   
# exe_path is the directory of BEPyAE; 

Initialize Igor AR18#

  • Set offline development

  • Build a connection between BEPyAE and AR18

  • Get parameters in AR18

newexp.init_BEPyAE(offline_development = False) # set offline_development=True if doing offline development
                                                # executing this will also initlize AR18

Set tip parameters#

  • set setpoint, tip locations

newexp.tip_control(tip_parms_dict = {"set_point_V_00": 1, "next_x_pos_00": 0, "next_y_pos_01": 0},
                   do_move_tip = True, 
                   do_set_setpoint = True) # Executing this code will set setpoint to 1 V, 
                                           # and move tip to location [0, 0]

Set IO#

This defines IO parameters, such as AFM platform: AR18, amplifiers, channel data types, etc

newexp.define_io_cluster(IO_cluster_parms_dict = {"analog_output_amplifier_06": 1, 
                                                  "channel_01_type_07": 1, 
                                                  "channel_02_type_08": 2,
                                                  "channel_03_type_09": 3,})

Set BE pulse parameters#

# set BE parameters
newexp.define_be_parms(be_parms_dict = {"center_frequency_Hz_00": 350, "band_width_Hz_01": 100, "amplitude_V_02": 1, 
                                        "phase_variation_03": 1, "repeats_04": 4, "req_pulse_duration_s_05": 4,
                                        "auto_smooth_ring_06": 1},
                       do_create_be_waveform = True)

BE Line scan to check BE parameters#

  • This is a single BE line scan

  • This returns 5 datasets: quick_fitting, complex spectra, and 3 channels

# Do a single line scan
qk_fit, com_spec, chn1, chn2, chn3 = newexp.do_line_scan(line_scan_parms_dict = {"num_BE_pulses_01": 32,
                                                                                 "start_x_pos_00": -1, "start_y_pos_01": -1,
                                                                                 "stop_x_pos_02": 1, "stop_y_pos_03": 1},
                                                         upload_to_daq = True, do_line_scan = True)

Prior to expeirment, set a directory to save data#

os.chdir(r"D:\WEST User data\Experiment")

Experiment starts#

Step 1. Establish AC Amplitude and Setpoint Parameters#

# uniformly distributed AC amplitude
min_ac = 0.5
max_ac = 5
num_ac = 10
Vac = np.linspace(min_ac, max_ac, num_x)  # AC amplitude

# uniformly distributed setpoint values
min_setpoint = 0.5
max_setpoint = 5
num_setpoint = 10
setpoint = np.linspace(min_setpoint, max_setpoint, num_setpoint)  # Setpoint

# Establish AC and setpoint parameters array
Vac_setpoint = np.meshgrid(Vac, setpoint)
Vac = Vac_setpoint[0].reshape(-1)
setpoint = Vac_setpoint[1].reshape(-1)

print ("{} AC and setpoint parameters are ready for expierments".format(len(Vac)))
    
# save pulse condition
np.save("Vac_setpoint.npy", np.asarray([Vac, setpoint]))

Step 2. Perform BEPFM to image the domain wall with various AC and setpoint#

for i in tpdm(range(len(Vac))):
    # select AC and setpoint
    be_amp = Vac[i]
    spoint = setpoint[i]
    # Set setpoint
    newexp.tip_control(tip_parms_dict = {"set_point_V_00": spoint}, do_move_tip = False, do_set_setpoint = True)
    # Set BE pulse amplitude
    newexp.define_be_parms(be_parms_dict = {"center_frequency_Hz_00": 335, "band_width_Hz_01": 100, "amplitude_V_02": be_amp},
                           do_create_be_waveform = True)
    
    # Perform BEPFM image measurement
    dset_pfm, dset_chns, dset_cs = newexp.raster_scan(raster_parms_dict = {"tip_voltage": 0, "scan_pixel": 128, 
                                                                           "scan_x_start": -1.0, "scan_y_start": -1.0,
                                                                           "scan_x_stop": 1.0, "scan_y_stop": 1.0},
                                                      file_name = "Domain_wall_width", ploton = False)

    f, (ax1, ax2, ax3, ax4, ax5, ax6) = plt.subplots(1, 6, figsize = (30, 5), dpi = 100)
    ax1.imshow(dset_pfm[:,:,0], origin = "lower"); ax1.set_title("Amplitude")
    ax2.imshow(dset_pfm[:,:,1], origin = "lower"); ax2.set_title("Frequency")
    ax3.imshow(dset_pfm[:,:,2], origin = "lower"); ax3.set_title("Q Factor")
    ax4.imshow(dset_pfm[:,:,3], origin = "lower"); ax4.set_title("Phase")
    ax5.imshow(dset_chns[0,:,:], origin = "lower"); ax5.set_title("Topography")
    ax6.imshow(dset_chns[1,:,:], origin = "lower"); ax6.set_title("Deflection")
    plt.show()

Post Experiment Data Analysis#

Import#

import numpy as np
import matplotlib.pyplot as plt
import os
import h5py
import sidpy
import cv2
import imutils

Set the directory and root name of your dataset#

# directory
path = r"C:\Users\Experiment"

Load all data#

count_imgs = 64 # variable of how many images you have in the directory
pixel = 64  # pixel of your image

# change working directory
os.chdir(path)

# create arrays for all data
amplitude = np.zeros((count_imgs, pixel, pixel))
phase = np.zeros((count_imgs, pixel, pixel))
frequency = np.zeros((count_imgs, pixel, pixel))
qfactor = np.zeros((count_imgs, pixel, pixel))
topography = np.zeros((count_imgs, pixel, pixel))

for i in range (count_imgs):
    h5 = h5py.File('Domain_wall_width_1um_{}_0.hf5'.format(i), 'r+')
    be_qf = h5["BE Quick Fitting/Quick Fitting/Quick Fitting"]
    be_ch = h5["BE Channels/Channels/Channels"]
    amplitude[i,] = be_qf[:,:,0]
    phase[i,] = be_qf[:,:,3]
    frequency[i,] = be_qf[:,:,1]
    qfactor[i,] = be_qf[:,:,2]
    topography[i,] = be_ch[0,:,:,0]

nor_amplitude = (amplitude-amplitude.min())/amplitude.ptp()
nor_phase = (phase - phase.min())/phase.ptp()
nor_frequency = (frequency - frequency.min())/frequency.ptp()
nor_topography = (topography - topography.min())/topography.ptp()

Load Vac and Setpoint#

vac_setpoint = np.load("Vac_setpoint.npy")
vac_setpoint
array([[0.5, 1. , 1.5, 2. , 2.5, 3. , 3.5, 4. , 0.5, 1. , 1.5, 2. , 2.5,
        3. , 3.5, 4. , 0.5, 1. , 1.5, 2. , 2.5, 3. , 3.5, 4. , 0.5, 1. ,
        1.5, 2. , 2.5, 3. , 3.5, 4. , 0.5, 1. , 1.5, 2. , 2.5, 3. , 3.5,
        4. , 0.5, 1. , 1.5, 2. , 2.5, 3. , 3.5, 4. , 0.5, 1. , 1.5, 2. ,
        2.5, 3. , 3.5, 4. , 0.5, 1. , 1.5, 2. , 2.5, 3. , 3.5, 4. ],
       [0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 1. , 1. , 1. , 1. , 1. ,
        1. , 1. , 1. , 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 2. , 2. ,
        2. , 2. , 2. , 2. , 2. , 2. , 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5,
        2.5, 3. , 3. , 3. , 3. , 3. , 3. , 3. , 3. , 3.5, 3.5, 3.5, 3.5,
        3.5, 3.5, 3.5, 3.5, 4. , 4. , 4. , 4. , 4. , 4. , 4. , 4. ]])

Plot data#

Plot all results

for i in range (count_imgs):

    fig, axs = plt.subplots(1, 4, figsize=(16, 4), dpi = 100)
    fig.subplots_adjust(left=0.02, bottom=0.06, right=0.95, top=0.99, wspace=0.1)
    cm = 'viridis'
    shrink = 0.6

    im0 = axs[0].imshow(amplitude[i, ]*1000, origin = "lower", interpolation='nearest', cmap=cm)
    fig.colorbar(im0, ax=axs[0], shrink = shrink, label = "Amplitude (a.u.)")
    axs[0].axis("off")

    im1 = axs[1].imshow(phase[i, ], origin = "lower", interpolation='nearest', cmap=cm)
    fig.colorbar(im1, ax=axs[1], shrink = shrink, label = "Phase (rad)")
    axs[1].axis("off")

    im2 = axs[2].imshow(frequency[i, ]/1000, origin = "lower", interpolation='nearest', cmap=cm)
    fig.colorbar(im2, ax=axs[2], shrink = shrink, label = "Frequency (kHz)")
    axs[2].axis("off")

    im3 = axs[3].imshow(qfactor[i, ], origin = "lower", vmin = 0, vmax = 250, interpolation='nearest', cmap=cm)
    fig.colorbar(im3, ax=axs[3], shrink = shrink, label = "Q Factor")
    axs[3].axis("off")
    
    plt.show()
../_images/78a4f901ad1f7edfe252252cf24a86d05d96b84dff96b389f7071c0fdc36e6e7.png ../_images/36a0c6e06cff0eae254345904c8fe4716b0252fc7bca1eb504815a044a436854.png ../_images/2fae8c8e47936dd0f149895a0d625774769549b8bcb423f052cb014e168c5258.png ../_images/90919471272fcdf5e816689a8391913be435a1f9ee2f78f5ea0b655e2ae514d1.png ../_images/89f073371ed672cc9a60ee3db5ae1053c8fb4e78a14c357bb1342adbe67786c0.png ../_images/d1a04409f726af0fba93d85e574b4ac454ab1341fa62039bee09be680b453f15.png ../_images/3278109f28426bac7c454a9ad7971e7758dd56da01cbe4fb08f2e40f2e5211ba.png ../_images/d3e19d7f8fdbe540760ea75d67b6320325a4f6b5abf29887990da1dc30218714.png ../_images/d5b6808ef18a399ccbc7892950f948c4ebb9e7c3f96bcdf846df582bde040177.png ../_images/e749f9ac281f64af5f7a466122fd33f7cf5ce477a412ab223782dc12d4697765.png ../_images/1925970eed751252d6967f6e95b7bbe05df875b420c96d5874652061634157b9.png ../_images/b1a2654e07f81d5dfc3333bc2601a1c2ad72710d805e3cf9accc25041b83a926.png ../_images/03e12251561eacaff7720b4b21c9f0a39937776eec277d146cc1bb8244b200d9.png ../_images/856c5a93a715c6fbaa0ee6d776638d5729511f35ba8853588ce19f1ba16c5bac.png ../_images/4ad8f0134040248d5f68c9333bddd19b8c803eadce24c25d0a525a3cb52ad8ae.png ../_images/60b11ede50893daa0623cdb8407832b99c9742bfc2a4d4af88aa4a7723d5bb68.png ../_images/c68fb5e983c0bf27532a7f80c4edf42058ea57d3769682e9ded87d8910b4c7cd.png ../_images/a9ba0f025fc39c02a8c74352d85faf9be6bba0c267f3d3b9f0804318205fbbb0.png ../_images/bb3b228426bf3b0c5c69a8a68dc8a7f466e1969ddbbff6f30b353a5153a1a9bf.png ../_images/684b7280a1c89333cc3651ecfaadd4dcca5348bb63bccebf88ee91d71152d2c4.png ../_images/98ed9d7400afdbbf246d62932acbf94887fc2ea809a896f5e68a614d4cef852f.png ../_images/b6162a87de919da74c3332c22b409207324b236bdd83c43150e1bb3fe117f2e2.png ../_images/b211e738527629eda70cf93a1ac6d847c65de140e4291893cb55824a31d418dc.png ../_images/110dd98b7ce5637e50724aff3c86549f6d10a64fd3f547091b5c76179943162e.png ../_images/82f89b2ab4252544aa8a240573617998bdcc21b367411c1a4a4d1198c6424736.png ../_images/c9dd6d1aeb7c4525c82814ab24610af24b55ca8825ffca2fc5a9cd688cfe41e0.png ../_images/af73f893c7cd6894c5a3351b3185d6ff082c9bd041fd2df3b1fd70c6f484e757.png ../_images/350488626dda19a11793d087bcffeec4a38b499f2dbcec71309958b9a0c25a1d.png ../_images/6af2bd374123b2ebc803e6748a845bd791abffff89b02415cee61f359aef411f.png ../_images/fdaca0e51a258d75819406b84a579890ee862284356f8fc2a84ca3a78e9ece1f.png ../_images/a484980a5d18f950e929a04df949d8d7c47364c175cf9d6520ae0edafbb56ae2.png ../_images/f091d109294d4f95c4a58b0133b6fab2e7163b20164f2075422d44945fc9e50b.png ../_images/1231dea71a6ca117da74d3894fd76d1499ae8aa804a7fc3012c1983165b07133.png ../_images/30c8446ca944a99fb434e2e774b61c6d43ac5e043cda8b4c1b76c7d6ed205ea0.png ../_images/f3fc69ba0bf789d27a90926861feb88023149907d952a2321f8e7de0d04f05bd.png ../_images/84398e6c7993c6163ef874a6a604c93e62e25208bb06d9d1b7e5433862d38d26.png ../_images/5b479b678865bf7ed51423d4b7facacb985b874ce9cfcc9dd8a413cac9ef7afb.png ../_images/563a2cee75c023b4b4ef8bad84de230d344900abbc003e8e850ea5f479f023a4.png ../_images/37641ac959c138a783879c630ae0ee5f83c854185e9a90e21879d749c3a85c24.png ../_images/20caa8c2b6ab51429cbb1e7860c724ed6def4b92c75c85beb53f4c6d5ce340b7.png ../_images/ee55dd9cbb09e9c9030869ec021e87e7caee57b0e395df100202b0bc15a1cfbb.png ../_images/5a937390e1338c205eaa04ae6981dc51791ac390aa6ecca434f6e7d519ea924d.png ../_images/d3b656c95c32e74bbd36f3ec031a157a614aa6da85f3dfed4d8aff2144dd511d.png ../_images/3eacef7dd5f37c2cc969a1c0b9d9d72667b47dfa5685b402e35dc3fe5335b652.png ../_images/0080f2d161ab0178dff6b44b9c878d9fc2a52bf2a6e19de156a82f0f537fdd95.png ../_images/1dcbc716ea2b0fcce213c6db888e87c9ff478fe9917ed4b6290fe66e623c746d.png ../_images/fafa6ada6360ee36031528af16996c920417fc7a494e6367e100d30154fcaf32.png ../_images/b2fea95018cd6ae34e4a732b9dc4dcecf1a36d74c15157bfad201fbe9d1e975a.png ../_images/382aceab81a536498d617b52f34ebfda80b445547b4d99eedd5d1f05bdb59906.png ../_images/c5d5afd06c019008953029c2684f515f5da5de1a65eca4deb28516137f59780c.png ../_images/7de76b3c3fcbe93e8e95d267e16b3602c57812dc61bf34ecab8cc29428dbd900.png ../_images/3a84908160e19491162f2b8f02509d6222072c03354385d7b69e2c9527cfcd75.png ../_images/8e164e900016eba72a378a4265f3beacd804213b93271fdea2b226aef4cddb80.png ../_images/1efe6e66670188bba026b7edecefce3e66f635953d3b736ce5e3b640b31e5ea0.png ../_images/0416f123d7f79f28b068521d10e8d0260afa7748f865309dffc9b668e2631685.png ../_images/41f2478c7f67d5055db7e289ed765270f362657f614dec5db7bcc98c17e49dde.png ../_images/57ca71143f0ed80ccc7885225e02b8fb52cd92c80cf6253e4c353f558212a9f0.png ../_images/ca01d029d19b7da0b2adedec75c8bdcf9bc8e916cdc7495e3a2e81641a19b25c.png ../_images/b20a17f8a493d9f50b2f1e8736c4403e8cc40f9ad581685932830470364ab7c2.png ../_images/72a4de4349908cdac6007330db2f6a2725665002e4517e4cd11d8f22fae43ecb.png ../_images/1c558436881bdb3c39ced1be21c6b94225fc25a865aa3b856fab163bd533a3d5.png ../_images/55614e3dad021042659b3196cfcf667fb4aa5d31d8422ff84f241b9ca9829dd2.png ../_images/a5964d9e0a4c805c5f5001034466da6d7a7b731ad3811ef071c5e3020d2c1cfb.png ../_images/ef5dddfcd6c07fc15be15be4589051623396d8a9aa98030b8a3f575317221a02.png

Plot a specific channel together

num_vac = 8
num_stp = 8
fig, axes = plt.subplots(num_y, num_x, figsize=(num_vac, num_stp),
                         subplot_kw={'xticks':[], 'yticks':[]},
                         gridspec_kw=dict(hspace=0.02, wspace=0.02))

for ax, i in zip(axes.flat, range(count_imgs)):
    ax.imshow(amplitude[i,]*1000) # We are plotting amplitude now, you can change the channel to phase, frequency,etc
../_images/260c71135b97ce3025f02a44a01f4cab5e22ca0e9684941ce90cd5b9b07c15ef.png
num_vac = 8
num_stp = 8
fig, axes = plt.subplots(num_y, num_x, figsize=(num_vac, num_stp),
                         subplot_kw={'xticks':[], 'yticks':[]},
                         gridspec_kw=dict(hspace=0.02, wspace=0.02))

for ax, i in zip(axes.flat, range(count_imgs)):
    ax.imshow(phase[i,], origin = "lower")
../_images/208594e302f80f242ca199dab38eec39368ec3073fe61315f24ea3822c8aa08c.png