From ab9fd59148e7d9c8aacbefdb76e06e13e5dc2a46 Mon Sep 17 00:00:00 2001 From: Clemens Barth Date: Mon, 12 Dec 2022 08:15:56 +0100 Subject: [PATCH] Nanonis: ISO-8859-1 and Multipass mode - Nanonis files: ISO-8859-1 decoding implemented - Nanonis => Multipass mode: first code lines --- AFM_thumbs.py | 8 +++ AFM_thumbs/Channel.py | 1 + AFM_thumbs/SPECS_Nanonis.py | 51 ++++++++++++++---- AFM_thumbs/Variables.py | 4 +- .../__pycache__/Variables.cpython-38.pyc | Bin 13798 -> 13797 bytes 5 files changed, 53 insertions(+), 11 deletions(-) diff --git a/AFM_thumbs.py b/AFM_thumbs.py index d14f3b5..05f3cb0 100755 --- a/AFM_thumbs.py +++ b/AFM_thumbs.py @@ -40,6 +40,14 @@ # First git visibility : 2022/04/08, Clemens Barth # # +# 2022/12/09 +# ========== +# - Nanonis files: ISO-8859-1 decoding implemented (reading +# the header) +# - Nanonis - Multipass mode: first code lines inserted. +# Still to be done: title with "[Px]_" identifier for each +# image => This needs to be done in Channel.py. +# # 2022/04/08 # ========== # - First upload of AFM_thumbs.py onto our git server. diff --git a/AFM_thumbs/Channel.py b/AFM_thumbs/Channel.py index a1da9b2..53c5bf1 100755 --- a/AFM_thumbs/Channel.py +++ b/AFM_thumbs/Channel.py @@ -33,6 +33,7 @@ from AFM_thumbs.Variables import globvar_color_dict from AFM_thumbs.Variables import globvar_spaces +# _________________________________________________________________ Definitions def rename_channel(name): diff --git a/AFM_thumbs/SPECS_Nanonis.py b/AFM_thumbs/SPECS_Nanonis.py index 6e10694..8fa46ed 100755 --- a/AFM_thumbs/SPECS_Nanonis.py +++ b/AFM_thumbs/SPECS_Nanonis.py @@ -26,6 +26,7 @@ import sys import os +import chardet import numpy as np from AFM_thumbs.Variables import globvar_AFMdata @@ -48,6 +49,22 @@ from AFM_thumbs.Channel import plane_fit from AFM_thumbs.Channel import rename_channel +# ___________________________________________________________________ Constants + + +# This is used for checking the channels in the 'Multipass mode'. +multi_pass_ident = ["[P1]_", + "[P2]_", + "[P3]_", + "[P4]_", + "[P5]_", + "[P6]_", + "[P7]_", + "[P8]_", + "[P9]_", + "[P10]_"] + + # _________________________________________________________________ Definitions def is_SPECS_Nanonis_file(directory, files): @@ -76,14 +93,17 @@ def is_SPECS_Nanonis_file(directory, files): # an .sxm into the parameter class of AFM_thumbs. def read_SPECS_Nanonis_image_data(nanonis_file): - # # Print the entire header. - # nanonis_file_path = os.path.join(globvar_AFMdir.working_directory, nanonis_file) - # nanonis_file_p = open(nanonis_file_path, "rb") - # line = "" - # while line!=b':SCANIT_END:': - # line = nanonis_file_p.readline().rstrip() - # print(line) - # nanonis_file_p.close() + # Debug: Print the entire header. + FLAG_debug = False + if FLAG_debug: + nanonis_file_path = os.path.join(globvar_AFMdir.working_directory, nanonis_file) + nanonis_file_p = open(nanonis_file_path, "rb") + line = "" + while line!=b':SCANIT_END:': + line = nanonis_file_p.readline().rstrip() + print(line) + nanonis_file_p.close() + exit(-1) initialize_AFM_data() @@ -97,7 +117,15 @@ def read_SPECS_Nanonis_image_data(nanonis_file): list_line = [] while line_!=b':SCANIT_END:': line_ = nanonis_file_p.readline().rstrip() - list_line.append(line_.decode("utf-8")) + + # If it is a special standard, like ISO-8859-1, then treat + # it as such. + encoding = chardet.detect(line_)['encoding'] + if encoding == "ISO-8859-1": + line_ = line_.decode("iso-8859-1") + list_line.append(line_) + else: + list_line.append(line_.decode("utf-8")) # Offset position of the data inside the sxm file. It is said that these # are normally 4 bytes after the identifier ':SCANIT_END:'. However, @@ -124,6 +152,7 @@ def read_SPECS_Nanonis_image_data(nanonis_file): globvar_AFMdata.date += ", " + line if ":SCAN_FILE:" in list_line[i]: i += 1 + #print(list_line[i]) line = list_line[i].rstrip().strip() globvar_AFMdata.datfile = [line] if ":SCAN_RANGE:" in list_line[i]: @@ -229,6 +258,10 @@ def read_SPECS_Nanonis_image_data(nanonis_file): if channel_name in channels_not_supported: continue + # For the "Multipass mode": Cut the '[Px]_' prefix. + if channel_name[:5] in multi_pass_ident: + channel_name = channel_name[5:] + # Assign the correct channel names if channel_name == "Current": channel_name = "I" diff --git a/AFM_thumbs/Variables.py b/AFM_thumbs/Variables.py index 8e51192..4d25245 100755 --- a/AFM_thumbs/Variables.py +++ b/AFM_thumbs/Variables.py @@ -66,8 +66,8 @@ globvar_contributions = "Reinhard Olbrich (testing)\n" \ "Alexander v Schmidtsfeld (testing)\n" \ "..." -globvar_year = "2022-04-09" -globvar_version = "3.0.0" +globvar_year = "2022-12-09" +globvar_version = "3.00111" globvar_spaces = " " globvar_name = "AFM thumbs v" + globvar_version diff --git a/AFM_thumbs/__pycache__/Variables.cpython-38.pyc b/AFM_thumbs/__pycache__/Variables.cpython-38.pyc index df4c0014c7bf5d0c41f2efedeb3f0d0d7d04553e..e5806f84b98683a787344ebc2d3526276313c2c3 100644 GIT binary patch delta 36 qcmaEs{WP05l$V!_0SF3?1SZLE