224 lines
8.6 KiB
Python
Executable File
224 lines
8.6 KiB
Python
Executable File
# ##### BEGIN GPL LICENSE BLOCK #####
|
|
#
|
|
# This program is free software; you can redistribute it and/or
|
|
# modify it under the terms of the GNU General Public License
|
|
# as published by the Free Software Foundation; either version 2
|
|
# of the License, or (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program; if not, write to the Free Software Foundation,
|
|
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
#
|
|
# ##### END GPL LICENSE BLOCK #####
|
|
#
|
|
# This is part of the python program 'AFM_thumbs'. Please, read the
|
|
# full licence text and other comments in the file 'AFM_thumbs.py'
|
|
#
|
|
# Dr. Clemens Barth (barth@root-1.de), project manager.
|
|
#
|
|
# DO NOT REMOVE THIS PREAMBLE !!!
|
|
#
|
|
|
|
import os
|
|
import shutil
|
|
|
|
from AFM_thumbs.Variables import globvar_AFMdata
|
|
from AFM_thumbs.Variables import globvar_AFMdir
|
|
from AFM_thumbs.Variables import globvar_ThumbPara
|
|
from AFM_thumbs.Variables import globvar_spaces
|
|
from AFM_thumbs.Variables import globvar_configfile_path
|
|
from AFM_thumbs.Variables import globvar_configfile
|
|
from AFM_thumbs.Variables import globvar_python_directory
|
|
from AFM_thumbs.Variables import globvar_default_config
|
|
from AFM_thumbs.Variables import RHK_PositionCounter
|
|
|
|
|
|
def initialize_position_counter():
|
|
RHK_PositionCounter.position = 0
|
|
|
|
|
|
def initialize_AFM_data():
|
|
globvar_AFMdata.date = ""
|
|
globvar_AFMdata.x_size = ""
|
|
globvar_AFMdata.y_size = ""
|
|
globvar_AFMdata.x_pixel = ""
|
|
globvar_AFMdata.y_pixel = ""
|
|
globvar_AFMdata.x_off = ""
|
|
globvar_AFMdata.y_off = ""
|
|
globvar_AFMdata.voltage = ""
|
|
globvar_AFMdata.measurement_type = ""
|
|
globvar_AFMdata.feedback = ""
|
|
globvar_AFMdata.gain = ""
|
|
globvar_AFMdata.gain_prop = ""
|
|
globvar_AFMdata.gain_int = ""
|
|
globvar_AFMdata.gain_xy = ""
|
|
globvar_AFMdata.gain_signal = ""
|
|
globvar_AFMdata.gain_z = ""
|
|
globvar_AFMdata.speed = ""
|
|
globvar_AFMdata.res_freq = ""
|
|
globvar_AFMdata.amplitude = ""
|
|
globvar_AFMdata.angle = ""
|
|
globvar_AFMdata.scan_updown = ""
|
|
globvar_AFMdata.sweep_f0 = ""
|
|
globvar_AFMdata.sweep_phase = ""
|
|
globvar_AFMdata.sweep_A_exec = ""
|
|
globvar_AFMdata.sweep_Q = ""
|
|
globvar_AFMdata.NONE = ""
|
|
globvar_AFMdata.datfile[:] = []
|
|
globvar_AFMdata.channel[:] = []
|
|
globvar_AFMdata.unit[:] = []
|
|
globvar_AFMdata.z_average = 0.0
|
|
globvar_AFMdata.z_factor[:] = []
|
|
globvar_AFMdata.z_offset[:] = []
|
|
globvar_AFMdata.z_calibration[:] = []
|
|
globvar_AFMdata.z_amplitude[:] = []
|
|
globvar_AFMdata.z_min[:] = []
|
|
globvar_AFMdata.z_max[:] = []
|
|
globvar_AFMdata.scandir[:] = []
|
|
globvar_AFMdata.spec_x_unit[:] = []
|
|
globvar_AFMdata.spec_x_label[:] = []
|
|
globvar_AFMdata.spec_y_unit[:] = []
|
|
globvar_AFMdata.spec_y_label[:] = []
|
|
globvar_AFMdata.spec_y_factor[:] = []
|
|
globvar_AFMdata.spec_points[:] = []
|
|
globvar_AFMdata.spec_feedback[:] = []
|
|
globvar_AFMdata.spec_acquisition[:] = []
|
|
globvar_AFMdata.spec_delay[:] = []
|
|
globvar_AFMdata.spec_time[:] = []
|
|
globvar_AFMdata.spec_position[:] = []
|
|
globvar_AFMdata.spec_files[:] = []
|
|
|
|
|
|
def initialize_dir():
|
|
# If the user chooses 'Cancel' -> exit
|
|
if not globvar_AFMdir.working_directory:
|
|
return False
|
|
|
|
# The pdfs shall not be replaced if 0
|
|
if globvar_ThumbPara.pdfs == 0:
|
|
# There is no special path for the pdfs ...
|
|
if globvar_AFMdir.pdf_path == "":
|
|
# The name of the pdf that may exist
|
|
file_pdf = os.path.abspath(globvar_AFMdir.working_directory) + \
|
|
globvar_ThumbPara.extension+".pdf"
|
|
|
|
# ... there is a special path for the pdfs!
|
|
else:
|
|
# The name of the pdf that may exist
|
|
file_pdf = os.path.basename(globvar_AFMdir.working_directory) + \
|
|
globvar_ThumbPara.extension + \
|
|
".pdf"
|
|
file_pdf = os.path.join(globvar_AFMdir.pdf_path, file_pdf)
|
|
|
|
|
|
# If the pdf does exist, then simply do nothing => return False!
|
|
if os.path.isfile(file_pdf):
|
|
print(globvar_spaces + "The pdf file\n" +
|
|
globvar_spaces +
|
|
"'" + file_pdf + "'\n" +
|
|
globvar_spaces +
|
|
"does already exist !\n")
|
|
return False
|
|
|
|
|
|
# Name of directory
|
|
globvar_AFMdir.data_directory_name = \
|
|
os.path.basename(globvar_AFMdir.working_directory)
|
|
|
|
# Thumbnail directory will be created in the working directory
|
|
globvar_AFMdir.thumbnail_directory = \
|
|
os.path.join(globvar_AFMdir.working_directory,
|
|
"thumbnails" + globvar_ThumbPara.extension)
|
|
|
|
# If some thumbnails are already existing but shall be deleted, then do ...
|
|
if globvar_ThumbPara.thumbs_before == True:
|
|
if os.path.isdir(globvar_AFMdir.thumbnail_directory):
|
|
delete_string = globvar_AFMdir.thumbnail_directory
|
|
shutil.rmtree(delete_string)
|
|
#==============================================================================
|
|
# delete_string = "rm -rf \""+globvar_AFMdir.thumbnail_directory+"\""
|
|
# os.system(delete_string)
|
|
#==============================================================================
|
|
|
|
|
|
# Name of superior directory
|
|
superior_directory = os.path.dirname(globvar_AFMdir.working_directory)
|
|
|
|
# Name of directory even above
|
|
if (len(superior_directory)-superior_directory.rfind(os.pathsep))>0:
|
|
superior_2_times_directory = os.path.dirname(superior_directory)
|
|
|
|
if globvar_ThumbPara.extra_direct == True:
|
|
|
|
# Create, if it doesn't exist, a directory 'WSxM' and 'Gwyddion', which
|
|
# are on the same level as 'sample'.
|
|
# This is for future work, where treated WSxM and Gwyddion files can
|
|
# hutil be stored in these directories and ...
|
|
directory_WSxM = os.path.join(superior_2_times_directory,"WSxM")
|
|
if not os.path.isdir(directory_WSxM):
|
|
os.mkdir(directory_WSxM)
|
|
|
|
directory_Gwyddion = os.path.join(superior_2_times_directory,
|
|
"Gwyddion")
|
|
if not os.path.isdir(directory_Gwyddion):
|
|
os.mkdir(directory_Gwyddion)
|
|
|
|
# ... in the respective sub directories
|
|
directory_WSxM_data = os.path.join(directory_WSxM,
|
|
globvar_AFMdir.data_directory_name)
|
|
if not os.path.isdir(directory_WSxM_data):
|
|
os.mkdir(directory_WSxM_data)
|
|
|
|
directory_Gwyddion_data = os.path.join(directory_Gwyddion,
|
|
globvar_AFMdir.data_directory_name)
|
|
if not os.path.isdir(directory_Gwyddion_data):
|
|
os.mkdir(directory_Gwyddion_data)
|
|
|
|
# Thumbnail directory in working directory
|
|
if not os.path.isdir(globvar_AFMdir.thumbnail_directory):
|
|
os.mkdir(globvar_AFMdir.thumbnail_directory)
|
|
|
|
return True
|
|
|
|
|
|
# Determine the config file.
|
|
def initialize_check_config(file_config):
|
|
|
|
if file_config == None:
|
|
file_config = os.path.join(globvar_configfile_path,globvar_configfile)
|
|
|
|
path_rel_default_config = os.path.join(globvar_python_directory,
|
|
globvar_default_config)
|
|
|
|
if not os.path.isfile(file_config):
|
|
print(globvar_spaces + "Attention: The config file\n" +
|
|
globvar_spaces + file_config + "\n" + globvar_spaces +
|
|
"does not exist!\n" + globvar_spaces +
|
|
"The default config file '" +
|
|
path_rel_default_config +
|
|
"' " +
|
|
"is now used!\n" + globvar_spaces +
|
|
"If you have your own config file, put in the correct " +
|
|
"file name and path\n" + globvar_spaces +
|
|
"in 'AFM_thumbs/Variables.py' => " +
|
|
"'globvar_configfile' and 'globvar_configfile_path'\n")
|
|
|
|
filepath_program = os.path.realpath(__file__)
|
|
path_program = os.path.dirname(filepath_program)
|
|
file_config = os.path.join(path_program,globvar_default_config)
|
|
|
|
if not os.path.isfile(file_config):
|
|
print(globvar_spaces +
|
|
"Attention, MAJOR ERROR !!! The default config file\n" +
|
|
globvar_spaces + file_config + "\n" + globvar_spaces +
|
|
"does not exist! Re-install the whole program.\n" +
|
|
globvar_spaces + "Exit!\n")
|
|
exit(-1)
|
|
|
|
return file_config
|