snom_analysis.main module

This module contains the basic classes and functions for the snom analysis.

class snom_analysis.main.FileHandler(directory_name: str, title: str | None = None)[source]

Bases: PlotDefinitions

This class handles the measurement filetype and all toplevel functionality. This class will be called by each measurement type class to handle the filetype, measurement and channel dictionaries and the config file. When creating a new instance of this class the config file will be loaded and the filetype will be determined. Also the measurement tag dictionary will be created.

Parameters:
  • directory_name (str) – The path of the directory where the measurement files are stored.

  • title (str, optional) – The title of the measurement. Defaults to None.

Attributes:
vlimit_real
vmax_amp
vmax_height
vmax_phase
vmin_amp
vmin_height
vmin_phase

Methods

print_channel_tag_dict([channel])

This function prints the channel tag dict.

print_config([section])

This function prints the config file.

print_measurement_tag_dict()

This function prints the measurement tag dict.

print_config(section: str | None = None)[source]

This function prints the config file.

print_measurement_tag_dict()[source]

This function prints the measurement tag dict.

print_channel_tag_dict(channel=None)[source]

This function prints the channel tag dict.

Parameters:

channel (str, optional) – The channel to print. If None all channels will be printed. Defaults to None.

class snom_analysis.main.SnomMeasurement(directory_name: str, channels: list | None = None, title: str | None = None, autoscale: bool = True)[source]

Bases: FileHandler

This class opens a snom measurement and handels all the snom related functions.

Parameters:
  • directory_name (str) – path to the directory containing the measurement

  • channels (list, optional) – list of channels to load. Defaults to None.

  • title (str, optional) – title of the measurement. Defaults to None.

  • autoscale (bool, optional) – if True the data will be scaled to quadratic pixels. Defaults to True.

Attributes:
vlimit_real
vmax_amp
vmax_height
vmax_phase
vmin_amp
vmin_height
vmin_phase

Methods

add_channels(channels)

This function will add the specified channels to memory without changing the already existing ones.

correct_amplitude_drift_nonlinear([...])

This function corrects the amplitude drift in the y-direction by using a reference area across the full length of the scan.

correct_height_drift_nonlinear([channels, ...])

This function corrects the height drift in the y-direction by using a reference area across the full length of the scan.

correct_phase_drift([channels, export, ...])

This function asks the user to click on two points which should have the same phase value.

correct_phase_drift_nonlinear([channels, ...])

This function corrects the phase drift in the y-direction by using a reference area across the full length of the scan.

create_gif(amp_channel, phase_channel[, ...])

This function will create a gif from the amplitude and phase channel you specify.

create_gif_old(amp_channel, phase_channel[, ...])

Old gif creation method.

create_gif_v2(amp_channel, phase_channel[, ...])

This function will create a gif from the amplitude and phase channel you specify.

create_new_channel(data, channel_name, ...)

This function will create a new channel from the specified data and add it to memory.

cut_channels([channels, preview_channel, ...])

This function cuts the specified channels to the specified region.

delete_unwanted_files([mechanical_channels, ...])

Delete unwanted files to reduce the size of the measurement folder.

display_all_subplots([nrows, ncols])

This function displays all the subplots which have been created until this point.

display_channels([channels, nrows, ncols])

This function displays the channels in memory or the specified ones.

display_flattened_profile(phase_orientation)

This function will flatten all profiles in memory and display them.

display_overlay(channel1, channel2[, alpha])

This function displays an overlay of two channels.

display_phase_difference(reference_index)

This function will calculate the phase difference of all profiles relative to the profile specified by the reference index.

display_profiles([ylabel, labels])

This function will display all current profiles from memory.

fourier_filter_channels([channels])

This function applies the Fourier filter to all data in memory or specified channels.

fourier_filter_channels_V2([channels])

This function applies the Fourier filter to all data in memory or specified channels

gauss_filter_channels([channels, sigma])

This function will gauss filter the specified channels.

gauss_filter_channels_complex([channels, ...])

This fucton gauss filters the specified channels.

get_pixel_coordinates(channel)

This function returns the pixel coordinates of the clicked pixel.

get_pixel_value(channel[, coordinates, zone])

This function returns the pixel values of a channel at the specified coordinates.

heigth_mask_channels([channels, ...])

The treshold factor should be between 0 and 1.

initialize_channels([channels])

This function initializes the data in memory.

level_data_columnwise([channel_list, ...])

This function will level the data of the specified channels columnwise.

level_height_channels_3point([channels, coords])

This function levels all height channels which are either user specified or in the instance memory.

level_height_channels_forGui([channels])

This function levels all height channels which are either user specified or in the instance memory.

manually_create_complex_channel(amp_channel, ...)

This function will manually create a realpart channel depending on the amp and phase channel you give.

match_phase_offset([channels, ...])

This function matches the phase offset of all phase channels in memory to the reference channel.

overlay_forward_and_backward_channels(...[, ...])

This function is ment to overlay the backwards and forwards version of the specified channels.

overlay_forward_and_backward_channels_v2(...)

Caution! This variant is ment to keep the scan size identical!

print_channel_tag_dict([channel])

This function prints the channel tag dict.

print_config([section])

This function prints the config file.

print_measurement_tag_dict()

This function prints the measurement tag dict.

quadratic_pixels([channels])

This function scales the data such that each pixel is quadratic, eg.

realign([channels, bounds, axis, threshold])

This function corrects the drift of the piezo motor.

remove_last_subplots([times])

This function removes the last added subplots from the memory.

remove_subplots(index_array)

This function removes the specified subplot from the memory.

rotate_90_deg([orientation])

This function will rotate all data in memory by 90 degrees.

save_to_gsf([channels, appendix])

This function is ment to save all specified channels to external .gsf files.

save_to_txt([channels, appendix])

This function is ment to save all specified channels to external .txt files.

scale_channels([channels, scaling])

This function scales all the data in memory or the specified channels.

scalebar([channels, units, dimension, ...])

Adds a scalebar to all specified channels.

select_profile(profile_channel[, ...])

This function lets the user select a profile with given width in pixels and displays the data.

select_profiles(profile_channel[, ...])

This function lets the user select multiple profiles with given width in pixels and displays the data.

set_min_to_zero([channels])

This function sets the min value of the specified channels to zero.

shift_phase([shift, channels])

This function will prompt the user with a preview of the first phase channel in memory.

substract_channels(channel1, channel2)

This function will substract the data of channel2 from channel1 and save the result in a new channel.

switch_supplots([first_id, second_id])

This function changes the position of the subplots.

synccorrection(wavelength[, phasedir])

This function corrects all the phase channels for the linear phase gradient which stems from the synchronized measurement mode.

test_profile_selection([channel, selection])

Select a profile from the data.

text_regex_file_recognition

initialize_channels(channels: list | None = None) None[source]

This function initializes the data in memory. If no channels are specified the already existing data is used, which is created automatically in the instance init method. If channels are specified, the instance data is overwritten. Channels must be specified as a list of channels.

Parameters:

[list] (channels) – a list containing the channels you want to initialize

add_channels(channels: list) None[source]

This function will add the specified channels to memory without changing the already existing ones.

Parameters:

channels (list) – Channels to add to memory.

create_new_channel(data, channel_name: str, channel_tag_dict: dict, channel_label: str | None = None) None[source]

This function will create a new channel from the specified data and add it to memory.

Parameters:
  • data (np.ndarray) – Data array to create the new channel from.

  • channel_name (str) – Name of the new channel.

  • channel_tag_dict (dict) – Channel tag dictionary for the new channel.

  • channel_label (str, optional) – Label for the new channel. Defaults to None.

save_to_gsf(channels: list | None = None, appendix: str = 'default')[source]

This function is ment to save all specified channels to external .gsf files.

Parameters:
  • channels (list, optional) – list of the channels to be saved, if not specified, all channels in memory are saved. Careful! The data will be saved as it is right now, so with all the manipulations. Therefor the data should be saved with an appendix in the filename to keep the original data.

  • appendix (str, optional) – appendix/suffix to add to the filename, default is the default specified in the config of the current filetype.

save_to_txt(channels: list | None = None, appendix: str = 'default')[source]

This function is ment to save all specified channels to external .txt files.

Parameters:
  • channels (list, optional) – list of the channels to be saved, if not specified, all channels in memory are saved Careful! The data will be saved as it is right now, so with all the manipulations. Therefor the data will have an ‘_manipulated’ appendix in the filename.

  • appendix (str, optional) – appendix to add to the filename, default is the default specified in the config of the current filetype.

delete_unwanted_files(mechanical_channels=True, optical_channels=False, images_folder=True, gwy_file=True) None[source]

Delete unwanted files to reduce the size of the measurement folder. Careful! This will delete files from the measurement folder, so make sure to have a backup of the data before running this function. If you select mechanical_channels, all mechanical channels will be deleted. This does not include the mechanical amplitude and phase of the first demodulation and not the corrected height channels. This is the recommended choice for SNOM users. If you select optical_channels, all optical channels will be deleted. This in combination with mechanical_channels is the recommended choice for AFM only users. If you select images_folder, the images folder will be deleted. This is the recommended choice for all users as you probably don’t use the small preview images. If you select gwy_file, the gwy file will be deleted. This is the recommended choice for all users as you probably don’t use the gwy file and it contains an additional copy of all channels.

Parameters:
  • mechanical_channels (bool, optional) – Mechanical channels to delete, excluded are mechanical amp and phase and corrected height. Defaults to True.

  • optical_channels (bool, optional) – Optical channels to delete, this will delete all default optical channels. Defaults to False.

  • images_folder (bool, optional) – This will delete the images subfolder and its content. Defaults to True.

  • gwy_file (bool, optional) – This will delete the ‘gwy’ file if there is one. Defaults to True.

remove_subplots(index_array: list) None[source]

This function removes the specified subplot from the memory.

Parameters:

index_array (list) – The indices of the subplots to remove from the plot list

remove_last_subplots(times: int = 1) None[source]

This function removes the last added subplots from the memory. Times specifies how often the last subplot should be removed. Times=1 means only the last, times=2 means the two last, …

Parameters:

times (int) – how many subplots should be removed from the end of the list?

switch_supplots(first_id: int | None = None, second_id: int | None = None) None[source]

This function changes the position of the subplots. The first and second id corresponds to the positions of the two subplots which should be switched. This function will be repea you are satisfied.

Parameters:
  • first_id (int) – the first id of the two subplots which should be switched

  • second_id (int) – the second id of the two subplots which should be switched

display_all_subplots(nrows='auto', ncols='auto') None[source]

This function displays all the subplots which have been created until this point.

Parameters:
  • nrows (int, optional) – Number of rows for the subplots. Defaults to ‘auto’.

  • ncols (int, optional) – Number of columns for the subplots. Defaults to ‘auto’.

display_channels(channels: list | None = None, nrows='auto', ncols='auto') None[source]

This function displays the channels in memory or the specified ones.

Parameters:
  • channels (list, optional) – List of channels to display. If not specified all channels from memory will be plotted. Defaults to None.

  • nrows (int, optional) – Number of rows for the subplots. Defaults to ‘auto’.

  • ncols (int, optional) – Number of columns for the subplots. Defaults to ‘auto’.

display_overlay(channel1: str, channel2: str, alpha=0.5) None[source]

This function displays an overlay of two channels. The first channel is displayed in full color, the second channel is displayed width a specified alpha.

Parameters:
  • channel1 (str) – channel name of the first channel

  • channel2 (str) – channel name of the second channel

  • alpha (float, optional) – alpha value of the second channel. Defaults to 0.5.

scale_channels(channels: list | None = None, scaling: int = 4) None[source]

This function scales all the data in memory or the specified channels.

Parameters:
  • channels (list, optional) – List of channels to scale. If not specified all channels in memory will be scaled. Defaults to None.

  • scaling (int, optional) – Defines scaling factor. Each pixel will be scaled to scaling**2 subpixels. Defaults to 4.

set_min_to_zero(channels: list | None = None) None[source]

This function sets the min value of the specified channels to zero.

Parameters:

channels (list, optional) – List of channels to set min value to zero. If not specified this will apply to all height channels in memory. Defaults to None.

heigth_mask_channels(channels: list | None = None, mask_channel: str = None, threshold: float = None) None[source]

The treshold factor should be between 0 and 1. It sets the threshold for the height pixels. Every pixel below threshold will be set to 0. This also applies for all other channels. You can either specify specific channels to mask or if you don’t specify channels, all standard channels will be masked. If export is False only the channels in self.channels will be masked and nothing will be exported. For this function to also work with scaled data the height channel has to be specified and scaled as well!

Parameters:
  • channels (list) – list of channels, will override the already existing channels

  • mask_channel (str) – The channel to use for the height mask, if not specified the height channel will be used

  • threshold (float) – Threshold value to create the height mask from. Default is None, the user can select the threshold with a slider.

cut_channels(channels: list | None = None, preview_channel: str | None = None, autocut: bool = False, coords: list | None = None, reset_mask: bool = True) None[source]

This function cuts the specified channels to the specified region. If no coordinates are specified you will be prompted with a window to select an area. If you created a mask previously for this instance the old mask will be reused! Otherwise you should manually change the reset_mask parameter to True.

Parameters:
  • channels (list, optional) – List of channels you want to cut. If not specified all channels in memory will be cut. Defaults to None.

  • preview_channel (str, optional) – The channel to display for the area selection. If not specified the height channel will be used if it is in memory, otherwise the first of the specified channels will be used. Defaults to None

  • autocut (bool, optional) – If set to ‘True’ the program will automatically try to remove zero lines and columns, which can result from masking.

  • coords (list, optional) – If you already now the coordinates ([[x1,y1], [x2,y2]]), e.g. top left and bottom right coordinate of the rectangle to which you want to cut your data. Defaults to None.

  • reset_mask (bool, optional) – If you dont want to reuse an old mask set to True. Defaults to False.

scalebar(channels: list = [], units='m', dimension='si-length', label=None, length_fraction=None, height_fraction=None, width_fraction=None, location=None, loc=None, pad=None, border_pad=None, sep=None, frameon=None, color=None, box_color=None, box_alpha=None, scale_loc=None, label_loc=None, font_properties=None, label_formatter=None, scale_formatter=None, fixed_value=None, fixed_units=None, animated=False, rotation=None)[source]

Adds a scalebar to all specified channels.

Parameters:

channels (list) – List of channels the scalebar should be added to. various definitions for the scalebar, please look up ‘matplotlib_scalebar.scalebar’ for more information

rotate_90_deg(orientation: str = 'right')[source]

This function will rotate all data in memory by 90 degrees.

Parameters:

orientation (str, optional) – rotate clockwise (‘right’) or counter clockwise (‘left’). Defaults to ‘right’.

quadratic_pixels(channels: list | None = None)[source]

This function scales the data such that each pixel is quadratic, eg. the physical dimensions are equal. This is important because the pixels will be set to quadratic in the plotting function. However make shure that the pixel scaling x relative to y is an integer, otherwise the scaling will not work properly. This function will be applied to all channels in memory automatically when creating a measurement instance if autoscale is set to True.

Parameters:

[list] (channels) – list of channels the scaling should be applied to. If not specified the scaling will be applied to all channels

gauss_filter_channels(channels: list | None = None, sigma=2)[source]

This function will gauss filter the specified channels. If no channels are specified, the ones in memory will be used. Only for amplitude and height data, phase data will be ignored. Works fine, but the gauss_filter_channels_complex() function is more versatile.

Parameters:
  • channels (list, optional) – List of channels to blurr, if not specified all channels will be blurred. Should not be used for phase. Defaults to None.

  • sigma (int, optional) – The ‘width’ of the gauss blurr in pixels, you should scale the data before blurring. Defaults to 2.

gauss_filter_channels_complex(channels: list | None = None, scaling: int = 4, sigma: int = 2) None[source]

This fucton gauss filters the specified channels. If no channels are specified, all channels in memory will be used. The function is designed to work with complex data, where amplitude and phase are stored in separate channels. It will also blurr height, real part and imaginary part channels and amplitude channels without phase partner and phase channels without amplitude partner if you want to. If the data is not scaled already the function will do it automatically, the default scaling factor is 4, works good with sigma=2.

Parameters:
  • [list] (channels) – list of channels to blurr, must contain amplitude and phase of same channels.

  • [int] (sigma) – the scaling factor used for scaling the data, default is 4

  • [int] – the sigma used for blurring the data, bigger sigma means bigger blurr radius

fourier_filter_channels(channels: list | None = None) None[source]

This function applies the Fourier filter to all data in memory or specified channels.

Parameters:

[list] (channels) – list of channels, will override the already existing channels

fourier_filter_channels_V2(channels: list | None = None) None[source]

This function applies the Fourier filter to all data in memory or specified channels

Parameters:

[list] (channels) – list of channels, will override the already existing channels

synccorrection(wavelength: float, phasedir: int | None = None) None[source]

This function corrects all the phase channels for the linear phase gradient which stems from the synchronized measurement mode. The wavelength must be given in µm. The phasedir is either 1 or -1. If you are unshure about the direction just leave the parameter out. You will be shown a preview for both directions and then you must choose the correct one. The synccorrection will then be applied to all phase channels in memory. The corrected channels will then be saved as new files with the synccorrection appendix specified in the config.ini file. Afterwards the original channels and data will be reloaded in memory.

Parameters:
  • wavelenght (float) – please enter the wavelength in µm.

  • phasedir (int, optional) – the phase direction, leave out if not known and you will be prompted with a preview and can select the appropriate direction.

correct_phase_drift(channels: list | None = None, export: bool = False, phase_slope: float = None, zone: int = 1, point_based: bool = True) None[source]

This function asks the user to click on two points which should have the same phase value. Only the slow drift in y-direction will be compensated. Could in future be extended to include a percentual drift compensation along the x-direction. But should usually not be necessary.

Parameters:
  • channels (list, optional) – list of channels, will override the already existing channels

  • export (bool, optional) – do you want to aply the correction to all phase channels and export them?

  • phase_slope (float, optional) – if you already now the phase slope you can enter it, otherwise leave it out and it will prompt you with a preview to select two points to calculate the slope from

  • zone (int, optional) – defines the area which is used to calculate the mean around the click position in the preview, 0 means only the click position, 1 means the nearest 9 …

  • point_based (bool, optional) – if True the phase slope will be calculated based on two points the user clicks on, if False the phase slope will be calculated from a linear fit to a profile between two points the user clicks on. But careful, the profile will be along the y-direction in the middle of the two points.

correct_phase_drift_nonlinear(channels: list | None = None, reference_area: list = [None, None]) None[source]

This function corrects the phase drift in the y-direction by using a reference area across the full length of the scan. The reference area is used to calculate the average phase value per row. This value is then substracted from the phase data to level the phase. The reference area is specified by two coordinates, the left and right border. If no area is specified the whole image will be used. Make shure not to rotate the image prior to this function, since the reference area is defined in y-direction. This function is somewhat redundant to the level_data_columnwise function, which works for all channels (amplitude, height and phase).

Parameters:
  • channels (list, optional) – list of channels, will override the already existing channels

  • reference_area (list, optional) – The reference area to calculate the phase offset, specify as reference_area=[left-border, right-border]. If not specified the whole image will be used. Defaults to [None, None].

match_phase_offset(channels: list | None = None, reference_channel: str = None, reference_area=None, manual_width=5) None[source]

This function matches the phase offset of all phase channels in memory to the reference channel. The reference channel is the first phase channel in memory if not specified.

Parameters:
  • channels (list, optional) – list of channels, will override the already existing channels

  • reference_channel (str, optional) – The reference channel to which all other phase channels will be matched. If not specified the first phase channel in memory will be used. Defaults to None.

  • reference_area (list or str, optional) – The area in the reference channel which will be used to calculate the phase offset. If not specified the whole image will be used. You can also specify ‘manual’ then you will be asked to click on a point in the image. The area around that pixel will then be used as reference You can also specify a list like in the logfile to use a specific area. Defaults to None.

  • manual_width (int, optional) – The width of the manual reference area. Only applies if reference_area=’manual’. Defaults to 5.

correct_amplitude_drift_nonlinear(channels: list | None = None, reference_area: list = [None, None]) None[source]

This function corrects the amplitude drift in the y-direction by using a reference area across the full length of the scan. The reference area is used to calculate the average amplitude value per row. This value is then divided from the amplitude data to level the amplitude. The reference area is specified by two coordinates, the left and right border. If no area is specified the whole image will be used. Make shure not to rotate the image prior to this function, since the reference area is defined in y-direction. This function is somewhat redundant to the level_data_columnwise function, which works for all channels (amplitude, height and phase).

Parameters:
  • channels (list, optional) – list of channels, will override the already existing channels

  • reference_area (list, optional) – The reference area to calculate the amplitude offset, specify as reference_area=[left-border, right-border]. If not specified the whole image will be used. Defaults to [None, None].

correct_height_drift_nonlinear(channels: list | None = None, reference_area: list = [None, None]) None[source]

This function corrects the height drift in the y-direction by using a reference area across the full length of the scan. The reference area is used to calculate the average height value per row. This value is then divided from the height data to level the height. The reference area is specified by two coordinates, the left and right border. If no area is specified the whole image will be used. Make shure not to rotate the image prior to this function, since the reference area is defined in y-direction. This function is somewhat redundant to the level_data_columnwise function, which works for all channels (amplitude, height and phase).

Parameters:
  • channels (list, optional) – list of channels, will override the already existing channels

  • reference_area (list, optional) – The reference area to calculate the height offset, specify as reference_area=[left-border, right-border]. If not specified the whole image will be used. Defaults to [None, None].

level_height_channels_3point(channels: list | None = None, coords: list = None) None[source]

This function levels all height channels which are either user specified or in the instance memory. The leveling will prompt the user with a preview to select 3 points for getting the coordinates of the leveling plane.

Parameters:
  • channels (list, optional) – List of channels to level. If not specified all channels in memory will be used. Defaults to None.

  • coords (list, optional) – List of coordinates to use for the leveling. If not specified the user will be prompted to click on the points. Defaults to None.

level_height_channels_forGui(channels: list | None = None)[source]

This function levels all height channels which are either user specified or in the instance memory. The leveling will prompt the user with a preview to select 3 points for getting the coordinates of the leveling plane. This function is specifically for use with GUI.

Parameters:

channels (list, optional) – List of channels to level. If not specified all channels in memory will be used. Defaults to None.

shift_phase(shift: float = None, channels: list | None = None) None[source]

This function will prompt the user with a preview of the first phase channel in memory. Under the preview is a slider, by changing the slider value the phase preview will shift accordingly. If you are satisfied with the shift, hit the ‘accept’ button. The preview will close and the shift will be applied to all phase channels in memory.

Parameters:
  • shift (float, optional) – If you know the shift value already, you can enter values between 0 and 2*Pi

  • channels (list, optional) – List of channels to apply the shift to, only phase channels will be shifted though. If not specified all channels in memory will be used. Defaults to None.

realign(channels: list | None = None, bounds: list | None = None, axis=1, threshold=0.5)[source]

This function corrects the drift of the piezo motor. As of now it needs a reference region of the sample which is assumed to be straight. In the future this could be implemented with a general map containing the distortion created by the piezo motor, if it turns out to be temporally constant… Anyways, you will be prompted with a preview of the height data, please select an area of the scan with only one ‘straight’ reference. It will then calculate the index of the mean according to the specified axis. If you specify a threshold all values below this threshold will be set to zero. This makes the mean index calculation more robust. The bounds for the fitting routine are based on the lower and upper limit of this selection.

Parameters:
  • channels (list) – list of channels, will override the already existing channels

  • bounds (list) – The bounds for the fitting routine. If not specified you will be prompted with a window to select an area. Should be specified like this: [lower_bound, upper_bound] in px.

  • axis (int) – The axis along which the mean index should be calculated. 0 means x-axis, 1 means y-axis. Defaults to 1.

  • threshold (float, optional) – threshold, all values below will be set to zero to better estimate the mean index position. Defaults to 0.5.

overlay_forward_and_backward_channels(height_channel_forward: str, height_channel_backward: str, channels: list | None = None)[source]

This function is ment to overlay the backwards and forwards version of the specified channels. The function will create a mean version which can then be displayed and saved. Note that the new version will be larger then the previous ones. Also make shure to use leveled data if you want to apply to height data. The overlain data will be larger, because the programm automatically tries to shift the data to match the best. The data will also be gauss blurred for better overlap. This function is still quite experimental and might not work properly in all cases. But if it does you can basically double the integration time of your measurement. Works best for amplitude data, height data is also ok, to monitor the quality of the overlay. Phase channels don’t work well, because the phase is not continuous and the mean phase is not meaningful because there are typically some slight shifts between forward and backward channel.

Parameters:
  • height_channel_forward (str) – usual corrected height channel

  • height_channel_backward (str) – backwards height channel

  • channels (list, optional) – a list of all channels to be overlain. Defaults to None.

overlay_forward_and_backward_channels_v2(height_channel_forward: str, height_channel_backward: str, channels: list | None = None)[source]

Caution! This variant is ment to keep the scan size identical!

This function is ment to overlay the backwards and forwards version of the specified channels. You should only specify the forward version of the channels you want to overlay. The function will create a mean version which can then be displayed and saved.

Parameters:
  • height_channel_forward (str) – Usual corrected height channel

  • height_channel_backward (str) – Backwards height channel

  • channels (list, optional) – List of all channels to be overlain. Only specify the forward direction. Defaults to None. If not specified only the amp channels and the height channel will be overlain.

manually_create_complex_channel(amp_channel: str, phase_channel: str, complex_type: str | None = None) None[source]

This function will manually create a realpart channel depending on the amp and phase channel you give. The channels don’t have to be in memory. If they are not they will be loaded but not added to memory, only the realpart will be added. Carful, only for expert users!

Parameters:
  • amp_channel (str) – Amplitude channel.

  • phase_channel (str) – Phase channel.

  • complex_type (str, optional) – Type of the data you want to create. ‘real’ creates the realpart, ‘imag’ the imaginary part. If not specified both will be created. Defaults to None.

Returns:

None

substract_channels(channel1: str, channel2: str) None[source]

This function will substract the data of channel2 from channel1 and save the result in a new channel. The new channel will be named channel1-channel2.

Parameters:
  • channel1 (str) – Channel from which the data will be substracted.

  • channel2 (str) – Channel which will be substracted from channel1.

level_data_columnwise(channel_list: list | None = None, display_channel: str | None = None, selection: list | None = None) None[source]

This function will level the data of the specified channels columnwise. The function will use the data from the display channel to select the range for leveling. If no channels are specified all channels in memory will be leveled. If no display channel is specified the first channel in memory will be used.

Parameters:
  • channels (list, optional) – Channels from memory which should be leveled. Defaults to None.

  • display_channel (str, optional) – Channel to use to select the range for leveling. Defaults to None.

  • selection (list, optional) – Selection to use for leveling. Defaults to None.

  • like (You can specify the selection manually as a list with 4 elements) – [bound1 (int), bound2 (int), is_horizontal (bool), inverted (bool)].

create_gif(amp_channel: str, phase_channel: str, frames: int = 20, fps: int = 10, dpi=100) Path[source]

This function will create a gif from the amplitude and phase channel you specify. The gif will show the animated realpart by repeatedly adding a phase shift. The gif will be saved in the same directory as the measurement file and displayed afterwards.

Parameters:
  • amp_channel (str) – Amplitude channel.

  • phase_channel (str) – Phase channel.

  • frames (int, optional) – Number of frames the gif should have. Defaults to 20.

  • fps (int, optional) – Frames per second. Defaults to 10.

  • dpi (int, optional) – Dots per inch. Defaults to 100.

Returns:

Path to the saved gif.

Return type:

Path

create_gif_v2(amp_channel: str, phase_channel: str, frames: int = 20, fps: int = 10) None[source]

This function will create a gif from the amplitude and phase channel you specify. The gif will show the animated realpart by repeatedly adding a phase shift. The gif will be saved in the same directory as the measurement file and displayed afterwards.

Parameters:
  • amp_channel (str) – Amplitude channel.

  • phase_channel (str) – Phase channel.

  • frames (int, optional) – Number of frames the gif should have. Defaults to 20.

  • fps (int, optional) – Frames per second. Defaults to 10.

create_gif_old(amp_channel: str, phase_channel: str, frames: int = 20, fps: int = 10) None[source]

Old gif creation method.

Parameters:
  • amp_channel (str) – _description_

  • phase_channel (str) – _description_

  • frames (int, optional) – _description_. Defaults to 20.

  • fps (int, optional) – _description_. Defaults to 10.

get_pixel_coordinates(channel) list[source]

This function returns the pixel coordinates of the clicked pixel.

Parameters:

channel (str) – the channel to display

Returns:

the pixel coordinates

Return type:

list

get_pixel_value(channel, coordinates: list = None, zone: int = 1) list[source]

This function returns the pixel values of a channel at the specified coordinates. The zone specifies the number of neighbors. 0 means only the pixel itself. 1 means the pixel and the 8 nearest pixels. 2 means zone 1 plus the next 16, so a total of 25 with the pixel in the middle. If the channel is scaled the zone will be scaled as well.

Parameters:
  • channel (str) – the channel to display

  • coordinates (list, optional) – the pixel coordinates [[x1, y1], [x2, y2], …]. Defaults to None.

  • zone (int, optional) – the number of neighbors. Defaults to 1.

Returns:

the pixel values

Return type:

list

select_profile(profile_channel: str, preview_channel: str | None = None, orientation: Definitions = Definitions.vertical, width: int = 10, phase_orientation: int = 1, coordinates: list = None)[source]

This function lets the user select a profile with given width in pixels and displays the data. This is quite unfinished and only allows for profiles which extend over the whole image in the x-direction or y-direction.

Parameters:
  • profile_channel (str) – channel to use for profile data extraction

  • preview_channel (str, optional) – channel to preview the profile positions. If not specified the height channel will be used for that. Defaults to None.

  • orientation (Definitions, optional) – profiles can be horizontal or vertical. Defaults to Definitions.vertical.

  • width (int, optional) – width of the profile in pixels, will calculate the mean. Defaults to 10.

  • phase_orientation (int, optional) – only relevant for phase profiles. Necessary for the flattening to work properly. Defaults to 1.

  • coordinates (list, optional) – if you already now the position of your profile you can also specify the coordinates and skip the selection. Defaults to None.

select_profiles(profile_channel: str, preview_channel: str | None = None, orientation: Definitions = Definitions.vertical, width: int = 10, coordinates: list | None = None)[source]

This function lets the user select multiple profiles with given width in pixels and displays the data. Also unfinished, but allows for the selection of multiple profiles.

Parameters:
  • profile_channel (str) – channel to use for profile data extraction

  • preview_channel (str, optional) – channel to preview the profile positions. If not specified the height channel will be used for that. Defaults to None.

  • orientation (Definitions, optional) – profiles can be horizontal or vertical. Defaults to Definitions.vertical.

  • width (int, optional) – width of the profile in pixels, will calculate the mean. Defaults to 10.

  • coordinates (list, optional) – if you already now the position of your profile you can also specify the coordinates and skip the selection. Defaults to None.

display_profiles(ylabel: str | None = None, labels: list | None = None)[source]

This function will display all current profiles from memory.

Parameters:
  • ylabel (str, optional) – label of the y axis. The x axis label is in µm per default. Defaults to None.

  • labels (list, optional) – the description of the profiles. Will be displayed in the legend. Defaults to None.

display_flattened_profile(phase_orientation: int)[source]

This function will flatten all profiles in memory and display them. Only useful for phase profiles!

Parameters:

phase_orientation (int) – direction of the phase, must be ‘1’ or ‘-1’

display_phase_difference(reference_index: int)[source]

This function will calculate the phase difference of all profiles relative to the profile specified by the reference index.

Parameters:

reference_index (int) – index of the reference profile. Basically the nth-1 selected profile.

test_profile_selection(channel: str | None = None, selection: list | None = None) None[source]

Select a profile from the data. Allows the user to arbitrarily select a profile from the data.

Parameters:
  • channel (str, optional) – channel to get the profile data from. Defaults to None.

  • selection (list, optional) – Selection to use for the profile. Defaults to None. The selection must have the format [start, end, width].

Returns:

profile, start, end, width

Return type:

np.ndarray, int, int, int

text_regex_file_recognition(channel)[source]
class snom_analysis.main.ApproachCurve(directory_name: str, channels: list | None = None, title: str = None)[source]

Bases: FileHandler

This class opens an approach curve measurement and handels all the approach curve related functions.

Parameters:
  • directory_name (str) – Directory path of the measurement.

  • channels (list, optional) – List of channels to load. Defaults to None.

  • title (str, optional) – Title of the measurement. Defaults to None.

Attributes:
vlimit_real
vmax_amp
vmax_height
vmax_phase
vmin_amp
vmin_height
vmin_phase

Methods

display_channels([y_channels])

This function will display the specified channels in a plot.

display_channels_v2([y_channels])

This function will display the specified channels in a plot.

find_index(filepath, channel)

This function will find the index of the specified channel in the datafile.

print_channel_tag_dict([channel])

This function prints the channel tag dict.

print_config([section])

This function prints the config file.

print_measurement_tag_dict()

This function prints the measurement tag dict.

set_min_to_zero()

This function will set the minimum of the xdata array to zero.

find_header_length

set_min_to_zero() None[source]

This function will set the minimum of the xdata array to zero.

display_channels(y_channels: list | None = None)[source]

This function will display the specified channels in a plot. The x channel is always ‘Z’. If no y channels are specified all channels in memory will be displayed. All channels will share one axis.

Parameters:

y_channels (list, optional) – List of channels to display. Defaults to None.

display_channels_v2(y_channels: list | None = None)[source]

This function will display the specified channels in a plot. The x channel is always ‘Z’. If no y channels are specified all channels in memory will be displayed. Each channel will have its own axis. And if you specify two channels it will make use of the left and right axis. For more channels only the left axis will be used for the first channel.

Parameters:

y_channels (list, optional) – List of channels to display. Defaults to None.

find_header_length(filepath)[source]
find_index(filepath, channel)[source]

This function will find the index of the specified channel in the datafile.

Parameters:
  • filepath (str) – Path to the datafile.

  • channel (str) – Channel to find the index for.

class snom_analysis.main.Scan3D(directory_name: str, channels: list | None = None, title: str = None)[source]

Bases: FileHandler

A 3D scan is a measurement where one approach curve is saved per pixel. This class is ment to handle such measurements.

Parameters:
  • directory_name (str) – Directory path of the measurement.

  • channels (list, optional) – List of channels to load. Defaults to None.

  • title (str, optional) – Title of the measurement. Defaults to None.

Attributes:
vlimit_real
vmax_amp
vmax_height
vmax_phase
vmin_amp
vmin_height
vmin_phase

Methods

display_cutplane_realpart([axis, line, ...])

This function will display the cutplane of the realpart data of the channels of the specified demodulation order.

display_cutplane_v2_realpart([axis, line, ...])

This function will display the cutplane of the realpart data of the channels of the specified demodulation order.

display_cutplanes([axis, line, channels, ...])

This function will display the cutplanes of the specified channels.

find_index(filepath, channel)

This function will find the index of the specified channel in the datafile.

generate_all_cutplane_data([axis, line])

This function will generate the data of all cutplanes for all channels and store them in a dictionary.

get_cutplane_data([axis, line, channel])

This function will return the data of a cutplane of the 3D scan.

match_phase_offset([channels, ...])

This function matches the phase offset of all phase channels in memory to the reference channel.

print_channel_tag_dict([channel])

This function prints the channel tag dict.

print_config([section])

This function prints the config file.

print_measurement_tag_dict()

This function prints the measurement tag dict.

set_min_to_zero()

This function will set the minimum of the xdata array to zero.

shift_phase([shift, channels])

This function will prompt the user with a preview of the first phase channel in memory.

align_lines

average_data

cut_data

display_approach_curve

find_header_length

set_min_to_zero() None[source]

This function will set the minimum of the xdata array to zero.

get_cutplane_data(axis: str = 'x', line: int = 0, channel: str = None) ndarray[source]

This function will return the data of a cutplane of the 3D scan. The cutplane is defined by the axis and the line.

Parameters:
  • axis (str, optional) – Axis of the cutplane. Defaults to ‘x’.

  • line (int, optional) – Line of the cutplane. Defaults to 0.

  • channel (str, optional) – Channel to get the data from. Defaults to None.

Returns:

Data of the cutplane.

Return type:

np.ndarray

generate_all_cutplane_data(axis: str = 'x', line: int = 0)[source]

This function will generate the data of all cutplanes for all channels and store them in a dictionary.

Parameters:
  • axis (str, optional) – Axis of the cutplane. Defaults to ‘x’.

  • line (int, optional) – Line of the cutplane. Defaults to 0.

display_cutplanes(axis: str = 'x', line: int = 0, channels: list | None = None, auto_align: bool = False)[source]

This function will display the cutplanes of the specified channels. You can also autoalign the data which will apply a shift to align the approach curves, more physically correct but not perfect.

Parameters:
  • axis (str, optional) – Axis of the cutplane. Defaults to ‘x’.

  • line (int, optional) – Line of the cutplane. Defaults to 0.

  • channels (list, optional) – Channel to display, if you don’t specify some all channels in memory will be used. Defaults to None.

  • align (bool, optional) – Alignment of the approach curves.

  • False. (If set to True the individual approach curves will be shifted such that they start at the same Z corrdinate. Defaults to)

display_cutplane_v2_realpart(axis: str = 'x', line: int = 0, demodulation: int = 2, align='auto')[source]

This function will display the cutplane of the realpart data of the channels of the specified demodulation order. The data will be shifted to align the approach curves.

Parameters:
  • axis (str, optional) – Axis of the cutplane. Defaults to ‘x’.

  • line (int, optional) – Line of the cutplane. Defaults to 0.

  • demodulation (int, optional) – Demodulation order of the data. Defaults to 2.

  • align (str, optional) – Alignment of the approach curves. Defaults to ‘auto’.

display_cutplane_realpart(axis: str = 'x', line: int = 0, demodulation: int = 2, align='auto')[source]

This function will display the cutplane of the realpart data of the channels of the specified demodulation order. The data will be shifted to align the approach curves.

Parameters:
  • axis (str, optional) – Axis of the cutplane. Defaults to ‘x’.

  • line (int, optional) – Line of the cutplane. Defaults to 0.

  • demodulation (int, optional) – Demodulation order of the data. Defaults to 2.

  • align (str, optional) – Alignment of the approach curves. Defaults to ‘auto’.

display_approach_curve(x_pixel, y_pixel, x_channel: str = None, y_channels: list | None = None)[source]
match_phase_offset(channels: list | None = None, reference_channel=None, reference_area=None, manual_width=5, axis='x', line=0) None[source]

This function matches the phase offset of all phase channels in memory to the reference channel. The reference channel is the first phase channel in memory if not specified.

Parameters:
  • channels (list, optional) – list of channels, will override the already existing channels

  • reference_channel ([type], optional) – The reference channel to which all other phase channels will be matched. If not specified the first phase channel in memory will be used. Defaults to None.

  • reference_area ([type], optional) – The area in the reference channel which will be used to calculate the phase offset. If not specified the whole image will be used. You can also specify ‘manual’ then you will be asked to click on a point in the image. The area around that pixel will then be used as reference. Defaults to None.

  • manual_width (int, optional) – The width of the manual reference area. Only applies if reference_area=’manual’. Defaults to 5.

shift_phase(shift: float = None, channels: list | None = None) None[source]

This function will prompt the user with a preview of the first phase channel in memory. Under the preview is a slider, by changing the slider value the phase preview will shift accordingly. If you are satisfied with the shift, hit the ‘accept’ button. The preview will close and the shift will be applied to all phase channels in memory.

Parameters:
  • shift (float, optional) – If you know the shift value already, you can enter values between 0 and 2*Pi

  • channels (list, optional) – List of channels to apply the shift to, only phase channels will be shifted though. If not specified all channels in memory will be used. Defaults to None.

cut_data()[source]
average_data(channels: list | None = None)[source]
align_lines()[source]
find_header_length(filepath)[source]
find_index(filepath, channel)[source]

This function will find the index of the specified channel in the datafile.

Parameters:
  • filepath (str) – Path to the datafile.

  • channel (str) – Channel to find the index for.