nomad_camels.bluesky_handling package

Submodules

nomad_camels.bluesky_handling.EpicsFieldSignal module

class nomad_camels.bluesky_handling.EpicsFieldSignal.EpicsFieldSignal(read_pv_name, name, value=0.0, timestamp=None, parent=None, labels=None, kind='hinted', tolerance=None, rtolerance=None, metadata=None, cl=None, attr_name='', conversion_function=None, set_conversion_function=None, putFunc=None)

Bases: Signal

A Signal used to address a single field of an EPICS PV.

get()

Reads the Signals value. If there is a conversion_function, the value is transformed by it.

just_readback()

Only returns the currently stored readback-value.

put(value, *, timestamp=None, force=False, metadata=None, **kwargs)

Puts the Signals value. If there is a set_conversion_function, the value is transformed by it. Also calls self.putFunc.

Parameters:
  • value

  • *

  • timestamp – (Default value = None)

  • force – (Default value = False)

  • metadata – (Default value = None)

  • **kwargs

subscriptions: ClassVar[FrozenSet[str]] = frozenset({'meta', 'value'})
class nomad_camels.bluesky_handling.EpicsFieldSignal.EpicsFieldSignalRO(read_pv_name, name, value=0.0, timestamp=None, parent=None, labels=None, kind='hinted', tolerance=None, rtolerance=None, metadata=None, cl=None, attr_name='', conversion_function=None, set_conversion_function=None, putFunc=None)

Bases: EpicsFieldSignal

The read-only implementation of EpicsFieldSignal. The only difference is that it raises an error, when one tries to put a value.

put(value, *, timestamp=None, force=False, metadata=None, **kwargs)
Parameters:
  • value

  • *

  • timestamp – (Default value = None)

  • force – (Default value = False)

  • metadata – (Default value = None)

  • **kwargs

subscriptions: ClassVar[FrozenSet[str]] = frozenset({'meta', 'value'})

nomad_camels.bluesky_handling.TriggerEpicsSignalRO module

class nomad_camels.bluesky_handling.TriggerEpicsSignalRO.TriggerEpicsSignalRO(read_pv, *, timeout=10, string=False, name=None, no_mdel=False, **kwargs)

Bases: EpicsSignalRO

Subclass that implements a simple ‘timed’ reading when called via bluesky’s ‘trigger_and_read’. Note that each PV that shall be read via this class also needs a second PV with the same name+:trig. That PV should provide a FLNK to the original PV.

callback_method(**kwargs)

If there is a status object from the trigger-method, it will be set to finished.

Parameters:

**kwargs

subscriptions: ClassVar[FrozenSet[str]] = frozenset({'meta', 'value'})
trigger()

Returns a status object that will be set to finished, when the PV-value is updated. Sets the trigger-PV to 1, thus triggering the process of the original PV.

nomad_camels.bluesky_handling.builder_helper_functions module

This module provides functions that are often used when building a protocol. It is not inside the protocol_builder module, since these functions are also called by the classes of the single protocol-steps.

nomad_camels.bluesky_handling.builder_helper_functions.get_plot_add_string(name, stream, subprotocol=False, n_tabs=1)

This function generates the necessary lines for the “steps_add_main” function in the protocol-script to open the plots of a sub-step of the protocol.

Parameters:
  • name (str) – The name of the calling protocol-step.

  • stream (str) – The bluesky-stream on which the plots should react.

  • subprotocol – (Default value = False) If True, the create_plots function will be called from the subprotocol’s module.

Returns:

The string to be added.

Return type:

add_main_string

nomad_camels.bluesky_handling.builder_helper_functions.plot_creator(plot_data, func_name='create_plots', multi_stream=False, plot_is_box=False, box_names='', skip_box=True)

Creates the create_plots function for the protocol.

Parameters:
  • plot_data (list[Plot_Info]) – A list of Plot_Info objects with all information for the plots.

  • func_name (str) – (Default value = ‘create_plots’) The name of the function in the protocol-script.

  • multi_stream – (Default value = False) Passes the multi_stream keyword to the plot-widgets. This is used if the plot should not only react to the stream that’s specified exactly.

Returns:

  • plot_string – The string containing the function for the protocol-script.

  • plotting – True if there actually was a plot. Otherwise the function will not be created in the script at all.

nomad_camels.bluesky_handling.custom_function_signal module

class nomad_camels.bluesky_handling.custom_function_signal.Custom_Function_Signal(name, value=0.0, timestamp=None, parent=None, labels=None, kind='hinted', tolerance=None, rtolerance=None, metadata=None, cl=None, attr_name='', put_function=None, read_function=None, trigger_function=None, retry_on_error=0, error_retry_function=None, force_sequential=None)

Bases: Signal

Overwrites ophyd’s Signal to add a simple python function that’s called when calling put, trigger or get.

put_function

Called when the Signal’s put method is called.

Type:

callable

read_function

Called when the Signal’s get method is called.

Type:

callable

trigger_function

Called when the Signal’s trigger method is called.

Type:

callable

describe()

Overwrites describe to add ‘Custom Function’ as ‘source’.

get()

Overwrites Signal’s get to add the defined read_function. For further information see ophyd’s documentation.

put(value, *, timestamp=None, force=False, metadata=None, **kwargs)

Overwrites Signal’s put to add the defined put_function. For further information see ophyd’s documentation.

read_configuration()

Dictionary mapping names to value dicts with keys: value, timestamp

subscriptions: ClassVar[FrozenSet[str]] = frozenset({'meta', 'value'})
trigger()

Overwrites Signal’s trigger to add the defined trigger_function. For further information see ophyd’s documentation.

class nomad_camels.bluesky_handling.custom_function_signal.Custom_Function_SignalRO(name, value=0.0, timestamp=None, parent=None, labels=None, kind='hinted', tolerance=None, rtolerance=None, metadata=None, cl=None, attr_name='', read_function=None, trigger_function=None, retry_on_error=0, error_retry_function=None, force_sequential=None)

Bases: SignalRO

Overwrites ophyd’s SignalRO to add a simple python function that’s called when calling, trigger or get.

read_function

Called when the Signal’s get method is called.

Type:

callable

trigger_function

Called when the Signal’s trigger method is called.

Type:

callable

describe()

Overwrites describe to add ‘Custom Function’ as ‘source’.

get()

Overwrites SignalRO’s get to add the defined read_function. For further information see ophyd’s documentation.

read_configuration()

Dictionary mapping names to value dicts with keys: value, timestamp

subscriptions: ClassVar[FrozenSet[str]] = frozenset({'meta', 'value'})
trigger()

Overwrites SignalRO’s trigger to add the defined trigger_function. For further information see ophyd’s documentation.

class nomad_camels.bluesky_handling.custom_function_signal.Sequential_Device(force_sequential=False, currently_reading=False, *args, **kwargs)

Bases: Device

component_names = ()
subscriptions: ClassVar[FrozenSet[str]] = frozenset({'acq_done'})
nomad_camels.bluesky_handling.custom_function_signal.retry_function(func, retries: int, *args, error_retry_function=None, parent=None, **kwargs)

This function attempts to execute a given function multiple times until it succeeds or the maximum number of retries is reached. If a parent object is provided and it is currently reading, the function waits until the parent is no longer reading before attempting to execute the function.

Parameters: func (callable): The function to be executed. retries (int): The maximum number of times to retry executing the function. *args: Variable length argument list for the function to be executed. error_retry_function (callable, optional): A function to be called when an error occurs. Defaults to None. parent (object, optional): An object (the instrument class) that the function checks for a currently_reading attribute. If currently_reading is True, the function waits until it is False before executing. Defaults to None. **kwargs: Arbitrary keyword arguments for the function to be executed.

Returns: The return value of the function to be executed.

Raises: Exception: If the function fails to execute after the specified number of retries, an exception is raised with details of the last exception encountered.

nomad_camels.bluesky_handling.evaluation_helper module

class nomad_camels.bluesky_handling.evaluation_helper.Evaluator(*args, namespace=None, **kwargs)

Bases: CallbackBase

This class can be used to evaluate strings with names known in bluesky at any point, as well inside the run itself.

eval(eval_str: str, do_not_reraise=False)

Evaluates the string within the given namespace. Checks if the namespace is up to date before evaluating.

Parameters:

eval_str (str) – The string to be evaluated.

Returns:

The evaluated value.

Return type:

Value

eval_string(eval_str: str)

Evaluates the given string through the provided namespace to another string. The string is split at quotation marks and the parts of the string are tried to be evaluated. If that is not possible, they are just added back to the string as is. Checks if the namespace is up to date before evaluating.

Parameters:

eval_str (str) – The string to be evaluated.

Returns:

The evaluated string.

Return type:

return_str

Raises:

ValueError – If there is a bigger problem.

event(doc)

Overwrites the event method to add the variable ‘time’ to the namespace and update the last_update attribute for checking before evaluation. See bluesky’s documentation for more information.

is_to_date(t)

Compares whether the given t is the same as the Evaluator’s last_update.

start(doc)

Overwrites the start method to add the variable ‘StartTime’ to the namespace. See bluesky’s documentation for more information.

update_namespace()

Updates the namespace with the add_namespace dictionary. Since this is exactly the given namespace from __init__, it can be easily updated from outside the class. Also the variable ‘ElapsedTime’ is added to the namespace.

nomad_camels.bluesky_handling.evaluation_helper.get_eval(eval_str, namespace, evaluator=None)

This evaluates the given string within the given namespace. Most functionality is taken from bluesky.utils.call_or_eval_one.

nomad_camels.bluesky_handling.helper_functions module

Functions to be used in protocols.

The functions in this module may be used inside a protocol. It is much simpler to use these than writing them as a string into the protocol-file.

class nomad_camels.bluesky_handling.helper_functions.BoxHelper

Bases: QWidget

Helper-class to start the execution of Prompts and other boxes from within the protocol.

executor
staticMetaObject = PySide6.QtCore.QMetaObject("BoxHelper" inherits "QWidget": Methods:   #33 type=Signal, signature=executor() )
class nomad_camels.bluesky_handling.helper_functions.Commenting_Box(parent=None)

Bases: QWidget

A widget to add comments to the protocol.

closeEvent(self, event: PySide6.QtGui.QCloseEvent) None
closing
finish_comment()

Sets the flag _is_finished to True.

get_metadata()

Get the text of the comment.

staticMetaObject = PySide6.QtCore.QMetaObject("Commenting_Box" inherits "QWidget": Methods:   #33 type=Signal, signature=closing() )
class nomad_camels.bluesky_handling.helper_functions.Prompt_Box(icon='', text='', title='', parent=None, abortable=False)

Bases: QMessageBox

A subclass of QMessageBox that is used in the prompt-step. The protocol is paused until self.done_flag is True.

Parameters:
  • icon (str) – If ‘Error’, the QMessagebox.Critical icon is displayed, if ‘Warning’, then QMessagebox.Warning is used, otherwise QMessagebox.Information.

  • text (str) – The text to be displayed by the prompt.

  • title (str) – The window-title of the prompt.

abort_action()

If the abort button is clicked, the protocol is stopped.

set_done()

Sets self.done_flag to True.

start_execution()

Sets self.done_flag to False and starts self.exec().

staticMetaObject = PySide6.QtCore.QMetaObject("Prompt_Box" inherits "QMessageBox": )
class nomad_camels.bluesky_handling.helper_functions.Value_Box(text='', title='', variables=None, channels=None, free_variables=False, free_channels=False, parent=None, devs=None, comboboxes=None)

Bases: QDialog

Dialog to set variables or channels at runtime of a protocol.

Parameters:
  • text (str) – A text to be displayed with the box.

  • title (str) – The window title of the box.

  • variables (list, default: None) – The variables that should be set by the user. A QLineEdit will be provided for each of the variables.

  • channels (list, default: None) – The channels that should be set by the user. A QLineEdit will be provided for each of the channels.

  • free_variables (bool, default: False) – Whether the user is allowed to freely set any variables.

  • free_channels (bool, default: False) – Whether the user is allowed to freely set any channels.

  • devs (dict, default: None) – Dictionary of the available devices. Only needed, if free_channels is True, to provide the available channels.

accept() None

Reads all the values to be set to channels / variables and saves them in self.set_channels and self.set_variables respectively, then sets self.done_flag to True, allowing the protocol to go on and accepts the dialog.

reject() None

Sets self.done_flag to True, allowing the protocol to go on before rejecting the dialog.

start_execution()

Sets self.done_flag to False and starts self.exec().

staticMetaObject = PySide6.QtCore.QMetaObject("Value_Box" inherits "QDialog": )
class nomad_camels.bluesky_handling.helper_functions.Value_Setter(parent=None)

Bases: QWidget

A widget to set a value and a wait-time for a waiting bar.

hide_signal
set_signal
set_wait_time(wait_time)

Set the wait time for the waiting bar.

staticMetaObject = PySide6.QtCore.QMetaObject("Value_Setter" inherits "QWidget": Methods:   #33 type=Signal, signature=set_signal(double), parameters=double   #34 type=Signal, signature=hide_signal() )
update_timer()

Update the timer of the waiting bar.

class nomad_camels.bluesky_handling.helper_functions.Waiting_Bar(parent=None, title='', skipable=True, with_timer=False, display_bar=True, plot=None)

Bases: QWidget

A widget to show a waiting bar.

Used in the wait step with a progress bar or also to wait for a condition and display the list plot of the condition.

Parameters:
  • parent (QWidget) – The parent widget.

  • title (str) – The title of the waiting bar.

  • skipable (bool) – (Default value = True) Whether the waiting bar can be skipped and shows a skip button.

  • with_timer (bool) – (Default value = False) Whether the waiting bar has a timer.

  • display_bar (bool) – (Default value = True) Whether the waiting bar should be displayed.

  • plot (QWidget, optional) – A plot to be displayed together with the waiting bar.

setValue(value)

Set the value of the progress bar.

skipping()

Set the skip flag to True and hide the waiting bar.

start_execution()

Sets self.done_flag to False and starts self.exec().

staticMetaObject = PySide6.QtCore.QMetaObject("Waiting_Bar" inherits "QWidget": )
nomad_camels.bluesky_handling.helper_functions.clear_plots(plots, stream='primary')

Clears all given plots if they correspond to the given stream.

Parameters:
  • plots (list) – List of the plots to be cleared.

  • stream (str) – (Default value = ‘primary’) The stream to which the plots that should be cleared correspond.

nomad_camels.bluesky_handling.helper_functions.create_venv_run_file_delete_venv(packages, script_to_run)

Create a virtual environment, install the specified packages in it, run the specified Python script, and then delete the virtual environment.

nomad_camels.bluesky_handling.helper_functions.evaluate_python_file_output(stdout, namespace)

Evaluates the stdout of a Python file execution and writes the returned key value pairs to the namespace, so CAMELS can access their values

nomad_camels.bluesky_handling.helper_functions.export_function(runs, save_path, do_export, new_file_each=True, export_csv=False, export_json=False, plot_data=None, do_nexus_output=True)

Export the given runs to the given path.

Parameters:
  • runs (list[databroker.core.BlueskyRun]) – The runs to be exported.

  • save_path (str) – The path where the files should be saved.

  • do_export (bool) – Whether the runs should be exported.

  • new_file_each (bool, optional) – (Default value = True) Whether a new file should be created for each run. If True, the files are padded with the start-time of the run. Ignored if do_export is False.

  • export_csv (bool, optional) – (Default value = False) Whether the data should be exported to a csv file.

  • export_json (bool, optional) – (Default value = False) Whether the metadata should be exported to a json file.

  • plot_data (dict, optional) – (Default value = None) The data to be plotted.

nomad_camels.bluesky_handling.helper_functions.get_channels(dev)

Goes through the components of the given ophyd device and returns all that are not read-only and not config.

Parameters:

dev (ophyd.Device) – The device that is checked for output channels.

Returns:

channels – The keys are the channels in CAMELS-style. The values are [dev.name, <name_of_the_component>].

Return type:

dict

nomad_camels.bluesky_handling.helper_functions.get_fit_results(fits, namespace, yielding=False, stream='primary')

Updates and reads all the fits that correspond to the given stream and resets the fits in the end.

Parameters:
  • fits (dict) – Dictionary of all the fits to take into account.

  • namespace (dict) – Namespace dictionary where to write the fit results.

  • yielding (bool, optional) – (Default value = False) If True, the fits will be triggered and updated.

  • stream (str, optional) – (Default value = ‘primary’) The stream on which the regarded fits should run. Only the fits which have stream_name equal to stream will be used.

nomad_camels.bluesky_handling.helper_functions.get_inner_range(start, stop, points, sweep_mode, endpoint, use_distance=False, distance=nan)

Used for get_range, to make the split up ranges if doing a hysteresis sweep.

Parameters:
  • start (float, str) – The starting position for the sweep / loop.

  • stop (float, str) – The end position for the sweep / loop.

  • points (float, str) – The number of points in the range. If using min_val / max_val, points is the distance between those two.

  • sweep_mode (str) – (Default value = ‘linear’) The type how the distance between the points is calculated. If ‘linear’, they are equidistant, if ‘logarithmic’, the points between log(start) and log(stop) are equidistant, if ‘exponential’, between exp(start) and exp(stop), otherwise they are equidistant between 1/start and 1/stop.

  • endpoint (bool) – (Default value = True) Whether to include the endpoint into the range.

Return type:

An array of the calculated range.

nomad_camels.bluesky_handling.helper_functions.get_newest_file(directory)

Return the newest file in the given directory.

Parameters:

directory (str) – The directory where the newest file should be found.

Returns:

newest_file – The path to the newest file in the directory.

Return type:

str

nomad_camels.bluesky_handling.helper_functions.get_opyd_and_py_file_contents(classname, md, device_name)

Reads the content of the .py and _opyd.py driver files of the given instrument and adds them to the metadata dictionary. If the files are not found, it adds a corresponding message to the dictionary.

Parameters:
  • classname (class or function) – The class or function whose associated files’ contents are to be read.

  • md (dict) – The metadata dictionary where the content of the files should be added.

  • device_name (str) – The name of the device associated with the classname.

Returns:

md – The updated metadata dictionary with the content of the files added or with a message indicating that the file was not found.

Return type:

dict

Raises:

FileNotFoundError – If the .py or _opyd.py files associated with the classname are not found.

nomad_camels.bluesky_handling.helper_functions.get_range(evaluator, start, stop, points: int, min_val=nan, max_val=nan, loop_type='start - stop', sweep_mode='linear', endpoint=True, distance=nan, use_distance=False)

Helper function for steps like sweeps and the for loop.

Using the evaluator, it creates the range of iterations given the other values.

Parameters:
  • evaluator (Evaluator) – Used to evaluate the given expressions (start, stop, points, min_val, max_val).

  • start (float, str) – The starting position for the sweep / loop.

  • stop (float, str) – The end position for the sweep / loop.

  • points (int, str) – The number of points in the range. If using min_val / max_val, points is the distance between those two.

  • min_val (float, str) – (Default value = np.nan) Minimum value of the loop / sweep. Useful for hysteresis-sweeps.

  • max_val (float, str) – (Default value = np.nan) Minimum value of the loop / sweep. Useful for hysteresis-sweeps.

  • loop_type (str) – (Default value = ‘start - stop’) Possible values: ‘start - stop’, ignoring min_val and max_val ‘start - min - max - stop’ going to minimum first, then maximum ‘start - max - min - stop’, or anything not-specified.

  • sweep_mode (str) – (Default value = ‘linear’) The type how the distance between the points is calculated. If ‘linear’, they are equidistant, if ‘logarithmic’, the points between log(start) and log(stop) are equidistant, if ‘exponential’, between exp(start) and exp(stop), otherwise they are equidistant between 1/start and 1/stop.

  • endpoint (bool) – (Default value = True) Whether to include the endpoint into the range.

  • distance (float, str) – (Default value = np.nan) The distance between the points.

  • use_distance (bool) – (Default value = False) If True, the distance is used to calculate the range.

Return type:

An array of the calculated range.

nomad_camels.bluesky_handling.helper_functions.gradient_descent(max_iterations, threshold, w_init, func_text, evaluator, set_channel, read_channels, min_step, max_step, min_val, max_val, stream_name='gradient_descent', learning_rate=0.05, momentum=0.8, max_step_for_diff=None)

Helper function for the gradient descent protocol-step. It follows a simple gradient descent algorithm to find an optimum.

Parameters:
  • max_iterations (int) – The maximum number of iterations until the algorithm should stop if it did not arrive at the threshold yet.

  • threshold (float) – If the difference between two measurements is smaller than this threshold, the algorithm recognizes the value as the optimum and stops.

  • w_init (float) – The initial set-value from where the algorithm should start.

  • func_text (str) – This string is evaluated by the given evaluator to give the target function.

  • evaluator (Evaluator) – Used to evaluate the read values.

  • set_channel (ophyd.Signal) – The channel which is used for the optimization.

  • read_channels (list) – A list of all the channels which are read for the optimization.

  • min_step (float) – The minimum step size.

  • max_step (float) – The maximum step size.

  • min_val (float) – The minimum value that should be given to the set_channel.

  • max_val (float) – The maximum value that should be given to the set_channel.

  • stream_name (str) – (Default value = ‘gradient_descent’) The bluesky stream in which everything should run.

  • learning_rate (float) – (Default value = 0.05) A weight for the learning of the gradient descent. The next shift delta_w is calculated as: delta_w = -learning_rate * <current_gradient> + momentum * <last_delta_w>

  • momentum (float) – (Default value = 0.8) A momentum to keep up the last direction. The next shift delta_w is calculated as: delta_w = -learning_rate * <current_gradient> + momentum * <last_delta_w>

  • max_step_for_diff (float, None) – If none, max_step_for_diff = 10 * min_step Only if the last step was smaller than max_step_for_diff, the algorithm breaks if the threshold is reached.

Returns:

  • w_history – The history of values of set_channel

  • f_history – The history of evaluated values

nomad_camels.bluesky_handling.helper_functions.make_recoursive_plot_list_of_sub_steps(sub_dict, plot_list=None)
nomad_camels.bluesky_handling.helper_functions.read_wo_trigger(devices, grp=None, stream='primary')

Used if not reading by trigger_and_read, but splitting both. This function only reads, without triggering.

Parameters:
  • devices (list[ophyd.Device]) – List of the devices that should be read.

  • grp (string (or any hashable object), optional) – identifier used by ‘wait’; None by default

  • stream (string, optional) – event stream name, a convenient human-friendly identifier; default name is ‘primary’

Returns:

ret – The readings of the devices.

Return type:

dict

nomad_camels.bluesky_handling.helper_functions.saving_function(name, start_doc, path, new_file_each=True, plot_data=None, do_nexus_output=True)

Create a Serializer and return it.

The serializer is from the suitcase.nomad_camels_hdf5 module and used to save the data during a run.

Parameters:
  • name (str) – The name of the file.

  • start_doc (dict) – The start document of the run.

  • path (str) – The path where the file should be saved.

  • new_file_each (bool, optional) – (Default value = True) Whether a new file should be created for each run. If True, the files are padded with the start-time of the run.

  • plot_data (dict, optional) – (Default value = None) The data to be plotted.

Returns:

  • serializers (list) – The serializers to be used.

  • resources (list) – The resources to be used. In this case, an empty list.

nomad_camels.bluesky_handling.helper_functions.simplify_configs_dict(configs)

Returns a simplified version of the given dictionary configs by returning confs[key] = configs[key][‘value’].

Parameters:

configs (dict) – The dictionary to be simplified.

Returns:

confs – The simplified dictionary.

Return type:

dict

nomad_camels.bluesky_handling.helper_functions.trigger_multi(devices, grp=None)

Trigger multiple devices.

Parameters:
  • devices (list[ophyd.Device]) – List of the devices that should be triggered.

  • grp (string (or any hashable object), optional) – identifier used by ‘wait’; None by default

nomad_camels.bluesky_handling.loop_step_functions_api_call module

nomad_camels.bluesky_handling.loop_step_functions_api_call.evaluate_message_body(message_body, eva)

This function evaluates the values of the message_body items if the value is empty. This allows you to use variables and values that are obtained during the script execution.

nomad_camels.bluesky_handling.loop_step_functions_api_call.execute_camels_api_call(host: str, port: str, api_type: str, message_body: dict, authentication_type: str, authentication_string: str, selected_camels_function_index: int, camels_function_parameters: dict)

This function executes the CAMELS API call and returns the results.

nomad_camels.bluesky_handling.loop_step_functions_api_call.execute_generic_api_call(host: str, port: str, api_type: str, api_url: str, http_method: str, message_body: dict, authentication_type: str, authentication_string: str, http_parameters: dict)

This function executes the generic API call and returns the results.

nomad_camels.bluesky_handling.loop_step_functions_api_call.get_available_camels_api_functions(host, port, camels_function_parameters)

This function gets all the available CAMELS API functions.

nomad_camels.bluesky_handling.loop_step_functions_api_call.save_API_response_to_variable(response, namespace, protocol_step_name)

This function saves the API response to the namespace. This allows you to use the response values in the script and following protocol steps.

nomad_camels.bluesky_handling.make_catalog module

nomad_camels.bluesky_handling.make_catalog.make_yml(datapath, catalog_name='CAMELS_CATALOG', ask_restart=False)

Creates the yml file for the databroker (where it is looking for them) to configure a simple catalog for measurements with CAMELS.

Parameters:
  • datapath (str, path) – The path where the measurement data of the catalog should be saved to.

  • catalog_name (str) – (Default value = ‘CAMELS_CATALOG’) The name, the catalog should have.

nomad_camels.bluesky_handling.protocol_builder module

This module provides the functionalities needed for CAMELS to produce a running python script for its protocols.

The overview of the protocol-file looks like this:

  • import sys

  • add path_to_camels, path_to_camels/nomad_camels, path to instruments to path

  • standard_string

  • variable_string

  • device_import_string

  • plot-string

  • outer protocol string (things like plots from single steps)

  • plan-string (including the inner plan, w/o start/stop and the outer)

  • add-main-string (protocol or step specific things that should be done in the main function)

  • standard_run_string

  • further metadata (user / sample, file)

  • standard_start_string

  • set up databroker and progress bar

  • devices_string

  • standard_start_string2

  • save_string

  • final_string

  • standard_start_string3

giving shortly:

  • imports/variables…

  • def protocol_plan_inner

  • def protocol_plan

  • def create_plots

  • def steps_add_main (plots of steps, etc.)

  • def uid_collector

  • def run_protocol_main

  • def main

  • if __name__ == “__main__”

With the call chain as follows:

  • if –> main

  • main –> create_plots, steps_add_main, run_protocol_main

  • run_protocol_main –> uid_collector, protocol_plan

  • protocol_plan –> protocol_plan_inner

nomad_camels.bluesky_handling.protocol_builder.build_from_path(path, save_path='test.nxs', catalog='CAMELS_CATALOG', userdata=None, sampledata=None)

Creating the runable python file from a given protocol.

Parameters:
  • path (str, path) – The path to the protocol that should be built.

  • save_path (str, path) – (Default value = ‘test.nxs’) The path, where the data should be saved to.

  • catalog (str) – (Default value = ‘CAMELS_CATALOG’) The name of the databroker catalog that should be used.

  • userdata (dict, None) – (Default value = None) Metadata that describes the user.

  • sampledata (dict, None) – (Default value = None) Metadata that describes the sample.

nomad_camels.bluesky_handling.protocol_builder.build_protocol(protocol, file_path, save_path='test.nxs', catalog='CAMELS_CATALOG', userdata=None, sampledata=None)

Creating the runable python file from a given protocol.

Parameters:
  • protocol (main_classes.protocol_class.Measurement_Protocol) – The protocol that provides the information for the python file.

  • file_path (str, path) – The path, where the file should be saved.

  • save_path (str, path) – (Default value = ‘test.nxs’) The path, where the data should be saved to.

  • catalog (str) – (Default value = ‘CAMELS_CATALOG’) The name of the databroker catalog that should be used.

  • userdata (dict, None) – (Default value = None) Metadata that describes the user.

  • sampledata (dict, None) – (Default value = None) Metadata that describes the sample.

nomad_camels.bluesky_handling.protocol_builder.import_protocol_string(protocol_path, n_tabs=0)

Imports the subprotocol as <protocol_name>_mod.

nomad_camels.bluesky_handling.protocol_builder.make_plots_string_of_protocol(protocol_path, use_own_plots=True, data_output='sub-stream', n_tabs=1)

Creates the string to add the plots of the protocol to the main protocol.

Parameters:

protocol_path (str) – The path to the protocol that should be built.

Returns:

plot_string – The string that adds the plots of the protocol to the main protocol.

Return type:

str

nomad_camels.bluesky_handling.protocol_builder.sub_protocol_string(protocol_path, n_tabs=1, variables_in=None, variables_out=None, data_output='sub-stream')

Overwrites the signal for the progressbar and the number of steps in the subprotocol’s module. Evaluates the input variables, then writes them into the subprotocol’s namespace and starts the subprotocol’s _plan_inner function. Afterwards the output variables are written to the main namespace.

nomad_camels.bluesky_handling.protocol_builder.user_sample_string(userdata, sampledata)

Returns the string adding userdata and sampledata to the md.

Parameters:
  • userdata (dict) – data on the user

  • sampledata (dict) – data on the sample

Returns:

u_s_string – the string containing the data and adding it to the metadata

Return type:

str

nomad_camels.bluesky_handling.special_plan_stubs module

nomad_camels.bluesky_handling.special_plan_stubs.trigger_and_read_devices(devices, name='primary')

A wrapper for the plan stup trigger_and_read that implements trigger/read for a device with several components by simply splitting up the device and using a list of its components.

Parameters:
  • devices (list[ophyd.Device]) – List of the devices that should be triggered and read

  • name (str) – (Default value = ‘primary’) Name of the stream where to save the data

nomad_camels.bluesky_handling.variable_reading module

class nomad_camels.bluesky_handling.variable_reading.Variable_Signal(name, value=None, timestamp=None, parent=None, labels=None, kind='normal', tolerance=None, rtolerance=None, metadata=None, cl=None, attr_name='', variables_dict=None)

Bases: SignalRO

describe()

Provide schema and meta-data for read()

This keys in the OrderedDict this method returns must match the keys in the OrderedDict return by read().

This provides schema related information, (ex shape, dtype), the source (ex PV name), and if available, units, limits, precision etc.

Returns:

data_keys – The keys must be strings and the values must be dict-like with the event_model.event_descriptor.data_key schema.

Return type:

OrderedDict

get()

The readback value

subscriptions: ClassVar[FrozenSet[str]] = frozenset({'meta', 'value'})

nomad_camels.bluesky_handling.visa_signal module

class nomad_camels.bluesky_handling.visa_signal.VISA_Device(prefix='', *, name, kind=None, read_attrs=None, configuration_attrs=None, parent=None, resource_name='', read_termination='\r\n', write_termination='\r\n', baud_rate=9600, timeout=2000, retry_on_error=0, retry_on_timeout=False, **kwargs)

Bases: Device

Subclasses ophyd’s Device class. Automatically opens the specified VISA resource.

Parameters:
  • resource_name (str) – The name of the VISA-resource.

  • read_termination (str) – (Default = ‘rn’) The line termination for reading from the instrument.

  • write_termination (str) – (Default = ‘rn’) The line termination for writing to the instrument.

  • baud_rate (int) – (Default = 9600) The communication baud rate.

  • retry_on_error (int) – (Default = 0) The number of times the reading / setting should be tried again if there is an error (e.g. a VISA-IO-error). It is handed to all components that do not have a retry_on_error already defined.

component_names = ()
subscriptions: ClassVar[FrozenSet[str]] = frozenset({'acq_done'})
class nomad_camels.bluesky_handling.visa_signal.VISA_Signal(name, value=0.0, timestamp=None, parent=None, labels=None, kind='hinted', tolerance=None, rtolerance=None, metadata=None, cl=None, attr_name='', write=None, parse=None, parse_return_type=None, retry_on_error=0, write_delay=0, retry_on_timeout=False)

Bases: Signal

change_instrument(resource_name)

Changes the visa_instrument to the one with the given resource_name.

Parameters:

resource_name (str) – Name of the new instrument to be used.

describe()

Adding “VISA” as the source for the description.

put(value, *, timestamp=None, force=False, metadata=None, **kwargs)

Overwrites ophyd.Signal.put. The value is converted to a string, using self.write. If self.parse is not None, a query instead of a simple write is being performed, in that case, the value given to super().put is the returned value from the query.

subscriptions: ClassVar[FrozenSet[str]] = frozenset({'meta', 'value'})
class nomad_camels.bluesky_handling.visa_signal.VISA_Signal_RO(name, value=0.0, timestamp=None, parent=None, labels=None, kind='hinted', tolerance=None, rtolerance=None, metadata=None, cl=None, attr_name='', query='', parse=None, parse_return_type='float', retry_on_error=0, write_delay=0, retry_on_timeout=False)

Bases: SignalRO

describe()

Adding “VISA” as the source for the description.

get()

Overwrites ophyd.SignalRO.get, performing a query to the instrument. The returned string is parsed regarding self.parse and converted to the datatype specified by self.parse_return_type.

subscriptions: ClassVar[FrozenSet[str]] = frozenset({'meta', 'value'})
nomad_camels.bluesky_handling.visa_signal.close_resources()

Goes through all the opened resources and closes them.

nomad_camels.bluesky_handling.visa_signal.list_resources()

Gives the results of ResourceManager.list_resources.

nomad_camels.bluesky_handling.visa_signal.retry_query_or_write(write_text, visa_instrument, retries, just_write=False, write_delay=0, retry_on_timeout=False)
nomad_camels.bluesky_handling.visa_signal.single_query_or_write(write_text, visa_instrument, just_write=False)

nomad_camels.bluesky_handling.watchdogs module

class nomad_camels.bluesky_handling.watchdogs.Watchdog(channels=None, condition='', execute_at_condition='', read_periodic=False, read_timer=10, active=True, name='watchdog')

Bases: QObject

add_device(device_name, ophyd_device)

Subscribes the respective channels corresponding to the device

callback(value, **kwargs)
condition_met
get_definition()
get_device_list()

Goes through the cannels and returns a list of all needed devices

read()
remove_device(device_name, ophyd_device)

Unsubscribes the respective channels corresponding to the device

staticMetaObject = PySide6.QtCore.QMetaObject("Watchdog" inherits "QObject": Methods:   #4 type=Signal, signature=condition_met(QObject*), parameters=QObject* )
update_settings()
class nomad_camels.bluesky_handling.watchdogs.Watchdog_Definer(parent=None)

Bases: QDialog

accept(self) None
staticMetaObject = PySide6.QtCore.QMetaObject("Watchdog_Definer" inherits "QDialog": )
update_watchdog_view()
update_watchdogs()
class nomad_camels.bluesky_handling.watchdogs.Watchdog_View(parent=None, watchdogs=None)

Bases: QWidget

get_data()
read_check_changed()
staticMetaObject = PySide6.QtCore.QMetaObject("Watchdog_View" inherits "QWidget": )
update_watchdog(watchdog_name)

Module contents