nomad_camels.utility package

Submodules

nomad_camels.utility.databroker_export module

nomad_camels.utility.device_handling module

nomad_camels.utility.dict_recursive_string module

nomad_camels.utility.dict_recursive_string.dict_recursive_string(data, indent=0)

Recursively adds the given dictionary data to a string in the format “key: value” where each key-value pair has its own line and nested dictionaries are indented. Returns the resulting string.

nomad_camels.utility.exception_hook module

nomad_camels.utility.fit_variable_renaming module

Provides a function to rename typical names for fit-variables to valid python-names

nomad_camels.utility.fit_variable_renaming.replace_name(var_name)

Replaces mathematical symbols with text so that the variable name becomes a valid name.

Parameters:

var_name (str) – The variable that should be renamed.

nomad_camels.utility.load_save_functions module

nomad_camels.utility.load_save_helper_functions module

Helping functions for loading/saving. These are not in load_save_functions, so they may also be imported by modules that are imported by load_save_functions.

nomad_camels.utility.load_save_helper_functions.load_plots(plots: list, plot_data)

Loads the data from plot_data into Plot_Info objects. Then adds them to the plots list.

Parameters:
  • plots (list) – the list, where to add the plot information

  • plot_data (list[dict]) – list of dictionaries containing the necessary information for Plot_Info

Returns:

plots – the modified list with the loaded plots added

Return type:

list

nomad_camels.utility.logging_settings module

nomad_camels.utility.number_formatting module

nomad_camels.utility.number_formatting.format_number(value)

Format a number-string the way it is specified in the preferences.

Parameters:

value (float, int) – The number that should be displayed as string.

Returns:

The formatted string of the number.

Return type:

str

nomad_camels.utility.password_widgets module

class nomad_camels.utility.password_widgets.Password_Dialog(parent=None, double_pass=False, compare_hash=None)

Bases: QDialog

Dialog to enter a password or create a new one. If double_pass is True or compare_hash is None, after accepting the dialog, the entered password can be accessed via the password attribute.

Parameters:
  • parent (QWidget) – Parent widget.

  • double_pass (bool, optional) – Whether to ask for a password twice, by default False. Use this, if the user should create a new password.

  • compare_hash (str, optional) – Hashed password to compare with, by default None. Use this, if the entered password should be compared directly.

accept(self, /) None
staticMetaObject = PySide6.QtCore.QMetaObject("Password_Dialog" inherits "QDialog": )
nomad_camels.utility.password_widgets.hash_password(password)

nomad_camels.utility.plot_placement module

This module helps to place the plots on the screen without too much overlap between the plots. The positions are saved into the global variables, since this module may be imported by several other modules.

nomad_camels.utility.plot_placement.current_screen

the number of the currently used screen to place plots

Type:

int

nomad_camels.utility.plot_placement.current_pos

the x and y coordinates of the current placement

Type:

list[int, int]

nomad_camels.utility.plot_placement.max_height_in_row

the maximum height a plot window has within the currently populated row

Type:

int

nomad_camels.utility.plot_placement.iteration

if the screens were full once, it is increased and the next plots are slightly shifted

Type:

int

nomad_camels.utility.plot_placement.horizontal_margin

the horizontal distance between the plot windows

Type:

int

nomad_camels.utility.plot_placement.vertical_margin

the vertical distance between the plot windows

Type:

int

nomad_camels.utility.plot_placement.place_widget(widget: QWidget, top_left_x: str = '', top_left_y: str = '', plot_width: str = '', plot_height: str = '')

This function places the given widget on the next free spot on the screen. First all widgets are placed next to each other in a row, until one would be outside the screen, then the next row is started. If it would “flow out” the bottom of the screen, a second screen (if available) is used. If all available screens are full, it restarts on the first screen, slightly shifting the widgets in comparison to the first ones.

Parameters:

widget (QWidget) – the widget that should be placed

nomad_camels.utility.plot_placement.reset_variables()

nomad_camels.utility.qthreads module

CURRENTLY DEPRECATED MODULE, NOTHING IS USED This module contains various threads that may be run from the main UI.

class nomad_camels.utility.qthreads.Additional_Imports_Thread(parent=None)

Bases: QThread

run() None
staticMetaObject = PySide6.QtCore.QMetaObject("Additional_Imports_Thread" inherits "QThread": )
class nomad_camels.utility.qthreads.Manual_Device_Thread(device, ophyd_class)

Bases: QThread

DEPRECATED

staticMetaObject = PySide6.QtCore.QMetaObject("Manual_Device_Thread" inherits "QThread": )
update_config_settings(config=None, settings=None)
Parameters:
  • config – (Default value = None)

  • settings – (Default value = None)

nomad_camels.utility.theme_changing module

This module is used to change the UI-theme of CAMELS. It provides some default color palettes light_palette and dark_palette.

nomad_camels.utility.theme_changing.change_theme(theme, main_app=None, material_theme=None, dark_mode=False)
Parameters:
  • theme (str) – The name of the used theme. Possible values are the themes from QStyleFactory and “qt-material”.

  • main_app (QMainWindow) – (Default value = None) The main UI-window. If it is None, it is looked for with QApplication.instance().

  • material_theme (str) – (Default value = None) If theme==”qt-material”, the qt-material color palette is chosen with this theme name.

  • dark_mode (bool) – (Default value = False) If True, the color palettes are switched to dark mode.

nomad_camels.utility.tqdm_progress_bar module

class nomad_camels.utility.tqdm_progress_bar.ProgressBar(n_steps)

Bases: object

Provides a progress bar for protocols run directly from the script. With the emit method, the bar can be updated the same way signals are used when running the protocol from the UI.

n_steps

the number of total (expected) steps of the protocol

Type:

int

bar

the actual progress bar

Type:

tqdm

emit(n)

Updates the progress bar to the next step. The parameter n is only so the function has the same shape as the emit function for the signal used with the main UI.

Parameters:

n (int) – has no function, only there to be able to give this method a value

nomad_camels.utility.treeView_functions module

nomad_camels.utility.treeView_functions.getItemIndex(item_model, data: str, starts_with=False)

Iteration over the item_model to return the index of an item with given data.

Parameters:
  • item_model (QStandardItemModel) – the searched item_model

  • data (str :) – the data which the looked-for item has

  • starts_with (bool, default False) – also return an item, if it only starts with the searched data (Default value = False)

  • data

nomad_camels.utility.treeView_functions.get_substeps(parent)

Helper function, to get the substeps of loop_step with children.

Parameters:

parent

nomad_camels.utility.treeView_functions.iterItem(item, data, startWith=False)

Iteration over the children of the given item to return the index of an item with given data. Called by getItemIndex. Runs recursively, if the children-items also have children.

Parameters:
  • item (QStandardItem) – item whose children are iterated over

  • data (str) – the data which the looked-for item has

  • startWith (bool, default False) – also return an item, if it only starts with the searched data (Default value = False)

nomad_camels.utility.update_camels module

A module used to update CAMELS. The import of nomad_camels is necessary, since otherwise it would not show in the imported distributions for reading its current version.

nomad_camels.utility.update_camels.auto_update(parent)

Called if auto-update is set in the preferences. If the currently installed version is not up to date, question_message_box is called.

Parameters:

parent (QWidget) – (Default value = None) The parent widget to be used for the message boxes.

nomad_camels.utility.update_camels.check_up_to_date()

Gets the installed and available version of CAMELS and checks whether they are the same. Returns the outcome as a bool.

nomad_camels.utility.update_camels.get_latest_version()

Checks the latest version of nomad-camels and returns it.

nomad_camels.utility.update_camels.get_version()

checks the installed version of nomad-camels and returns it.

nomad_camels.utility.update_camels.question_message_box(parent=None)

Retrieves the currently installed version and the available version of nomad-camels. If the are the same, a message is displayed, and function exits. Otherwise, a question-box appears, whether the user wants to install the newer version of CAMELS. If yes, first update_camels and then restart_camels are called.

Parameters:

parent (QWidget) – (Default value = None) The parent widget to be used for the message boxes.

nomad_camels.utility.update_camels.read_readme_from_metadata(package_name)
nomad_camels.utility.update_camels.restart_camels(parent=None, ask_restart=True)

Restarts CAMELS. If ask_restart, a question-messagebox appears first, to make sure the user actually wants to restart.

Parameters:
  • parent (QWidget) – (Default value = None) The parent widget to be used for the message boxes.

  • ask_restart (bool) – (Default value = True) If True, the user is asked whether to restart CAMELS.

nomad_camels.utility.update_camels.show_release_notes()
nomad_camels.utility.update_camels.update_camels()

Calls a subprocess that updates CAMELS via pip.

nomad_camels.utility.variables_handling module

This module helps to synchronize information between different modules. To this aim, it holds several variables that may be read from different places. Furthermore, some functions to work with those variables are provided.

nomad_camels.utility.variables_handling.preset

The name of the currently used preset of CAMELS.

Type:

str

nomad_camels.utility.variables_handling.device_driver_path

The path, where to find local drivers.

Type:

str, path

nomad_camels.utility.variables_handling.meas_files_path

The path, where to write the measurement files, i.e. data.

Type:

str, path

nomad_camels.utility.variables_handling.CAMELS_path

The path to the current installation of CAMELS.

Type:

str, path

nomad_camels.utility.variables_handling.preferences

The currently used preferences.

Type:

dict

nomad_camels.utility.variables_handling.protocols

The available protocols.

Type:

dict{“<protocol_name>”: protocol}

nomad_camels.utility.variables_handling.protocol_variables

The variables provided by the currently viewed protocol.

Type:

dict{“<name>”: <value>}

nomad_camels.utility.variables_handling.channels

All available channels provided by the configured instruments.

Type:

dict{“<name>”: channel}

nomad_camels.utility.variables_handling.loop_step_variables

The variables provided by the steps of the currently viewed protocol.

Type:

dict{“<name>”: <value>}

nomad_camels.utility.variables_handling.devices

All configured instruments/devices.

Type:

dict

current_protocol = Measurement_Protocol

The protocol, that is currently being used.

nomad_camels.utility.variables_handling.dark_mode

Whether dark-mode is currently active.

Type:

bool

nomad_camels.utility.variables_handling.copied_step

The last step, that was copied.

Type:

Loop_Step

nomad_camels.utility.variables_handling.read_channel_sets

Sets of the different channel-compositions for read-channels. Used to distinguish different reads with different channels for bluesky

Type:

list[set]

nomad_camels.utility.variables_handling.read_channel_names

Names of the different read-channel steps in use. Used to distinguish the different reads.

Type:

list[str]

nomad_camels.utility.variables_handling.evaluation_functions_names

Used to provide the right-click menu to use mathematical functions.

Type:

dict

nomad_camels.utility.variables_handling.operator_names

Used to provide the right-click menu to use mathematical operators.

Type:

dict

nomad_camels.utility.variables_handling.add_actions_from_dict(dictionary, actions, connect_function, add_string='')

The values of dictionary are handed to the connect_function when clicking on the respective action named with the keys of the dictionary. The created actions are added to actions.

Parameters:
  • dictionary (dict) – the keys become the names of the actions, the values are handed to the connect_function

  • actions (list) – the created actions will be added to this list

  • connect_function (callable) – this function is called, when one of the actions is clicked

  • add_string (str) – (Default value = ‘’) added in front of the values of the dictionary for the connect_function

nomad_camels.utility.variables_handling.check_data_type(s)

Returns the datatype of the string-evaluation of s.

Parameters:

s (str) – the string that should be checked

nomad_camels.utility.variables_handling.check_eval(s, use_aliases=True)

Checks, whether the string s can be evaluated. Returns True if it is possible, otherwise False.

Parameters:

s (str) – the string that should be checked

nomad_camels.utility.variables_handling.check_variable_name(name, raise_not_warn=False, parent=None)

Checks whether name is a valid name for a variable. It checks, whether the name mirrors a builtin function or keyword. If not, it is tried with ast to parse the statement <name> = None, i.e. whether it works as a variable name. If anything fails, either an exception is raised (if raise_not_warn) or a WarnPopup is called.

Parameters:
  • name (str) – the name that should be checked

  • raise_not_warn (bool) – (Default value = False) if True, an exception is raised if a check fails, otherwise a WarnPopup

  • parent (QWidget) – (Default value = None) the parent widget for a possibly called WarnPopup

nomad_camels.utility.variables_handling.get_channels(use_aliases=True)

Returns the channels

nomad_camels.utility.variables_handling.get_color(color='', string=False)

Returns the respective QColor or rgb-code(if string) for color, taking dark-mode into account.

Parameters:
  • color (str) – (Default value = ‘’) The name of the color asked for. Possible values are “red” / “r”, “strong_red”, “green” / “g”, “dark_green”, “grey” / “gray”, “blue” / “b” “black” (white if dark_mode), “orange”. Otherwise white (or black, if dark_mode) is returned.

  • string (bool) – (Default value = False) If True, only the string of the rgb will be returned, not the QColor.

nomad_camels.utility.variables_handling.get_data(s)

Used instead of get_eval when there is no specific namespace. It simply uses ast.literal_eval and if it does not work, the string s is returned.

Parameters:

s (str) – the string to be evaluated

nomad_camels.utility.variables_handling.get_eval(s, use_aliases=True)

Evaluates the string s with the namespace of protocol_variables and loop_step_variables in addition to evaluation_helper.base_namespace. Returns the evaluated value.

Parameters:

s (str) – the string that should be evaluated

nomad_camels.utility.variables_handling.get_menus(connect_function, pretext='Insert', use_aliases=True)

Providing QMenus with the connect_function for each action, containing all the variables, channels, functions and operators.

Parameters:
  • connect_function (callable) – The function that should be executed when the action is clicked. It gets the variable’s name as a value.

  • pretext (str) – (Default value = ‘Insert’) This string will be written in front of the menus.

Returns:

  • menus (list[QMenu]) – the created menus

  • actions (list[list[QAction]]) – lists of the individual actions in the menus

nomad_camels.utility.variables_handling.get_non_channel_functions()
nomad_camels.utility.variables_handling.get_output_channels(use_aliases=True)

Goes through all channels and returns a list of the names of those, that are outputs.

nomad_camels.utility.variables_handling.get_user_default_command(ext)
nomad_camels.utility.variables_handling.get_write_from_data_type(s)

Used for writing longer strings. Since the strings should stay strings in the written files, if the evaluated datatype of s is str, quotation marks will be added around the value, otherwise nothing is done.

Open a link or file path using the default program.

On Windows:

If a .py file’s default association appears to run it (its command contains “python”), the function instead opens it in an editor (or reveals it in Explorer).

On macOS:

If the default application’s bundle identifier for the file contains “python”, reveal the file in Finder; otherwise open with the default association.

On Linux:

If the file is a .py file and its default association (queried via MIME) contains “python”, open its containing folder; otherwise, open normally.

Parameters:

link (str) – The file path to open.

Module contents