User's Guide
============

Getting started
---------------
To get started, it is recommended to first configure a few essential :ref:`sec:settings`.
Chose your :ref:`data path<data_path>`, :ref:`config path<config_path>` and if applicable :ref:`plugin path<plugin_path>`.
Enable a few devices, scans, and other plugins in the plugin manager.
Select which live displays should be visible.
Activate the test mode to simulate device communication while you familiarize yourself with the user interface.
Record a few scans and inspect the generated file structure and files.
Make use of tool tips and integrated documentation (questionmark icons) to learn about the plugins and settings.

User interface overview
-----------------------

By default, the user interface, shown in :numref:`fig:overview`, is structured into five main sections.
The tabs on the left contain all controls for :ref:`sec:confman`
including :ref:`sec:settings`, :ref:`sec:explorer`, :ref:`sec:devices`, :ref:`sec:scans`, and other controls.
During and after the measurement, results are displayed using various
:ref:`sec:displays` on the right. The most important signals of
any deposition experiment, including the real-time ion-currents, are always
visible in a dedicated :ref:`sec:live_displays` on the top.
The :ref:`sec:device_manager` is a central interface that allows to control all devices simultaneously.
Finally, there is a hidden :ref:`sec:console` for status messages
and advanced features that can be opened from :ref:`sec:settings`.
Users are free to rearrange the user interface by dragging and tearing components.
All devices will be disconnected and turned off to leave them in a save
state when the software is closed. All numeric inputs can be
conveniently adjusted using the arrow keys. All plugins can be detached
and rearranged using the float icon or by dragging them inside or out of
the main window. All plugins provide basic documentation via the
question mark in their toolbar.

.. _`fig:overview`:
.. figure:: 2023-10_ESIBD_GUI.png

   **ESIBD Explorer user interface.** Colored boxes highlight the five main sections. :blue:`Live displays` showing
   data from several devices. Central :darkorange:`device manager`.
   :red:`Configuration and management` section including settings, file explorer, as well devices, scans and other
   controls. :orange:`Displays` of supported files
   including saved and running scans. :green:`Console` for
   debugging and plugin development.

.. _sec:confman:

Configuration and management
----------------------------

This is the main control section used to define and access most plugin
settings, device configurations, and scans.

.. _`sec:settings`:

Settings
~~~~~~~~

.. automodule:: esibd.plugins.Settings
   :noindex:

General settings
^^^^^^^^^^^^^^^^

The most important parameters are:

.. _`data_path`:

Data path
    Defines where measurement files generated by scans or other plugins will be saved.

.. _`config_path`:

Config path
    Defines where all settings and plugin configurations are saved to restore them when
    restarting the software.

.. _`plugin_path`:

Plugin path
    Defines where the software will look for custom plugins to load while starting.

These parameters are saved in the registry and will be restored independent of the .ini file.

Further settings in this section allow to change the resolution used for
graphs, change between dark and light mode, and enable the test mode.
All device plugins have access to the test mode and should simulate
communication if it is active. This is used for development on machines
that are not connected to the hardware.

.. _`sec:session_settings`:

Session settings
^^^^^^^^^^^^^^^^

All results are automatically saved to the *Session path* (inside *Data
path*), based on the date, time, substrate, ion, session type, and
automatically incremented measurement number. This ensures a consistent
file structure that makes it easy to find related sessions. The session
path is updated automatically when any of its elements is changed and
maintained if the program is restarted. If the software is extended for
other types of experiments, the components of the session path can be
replaced by more appropriate ones.

.. _`sec:acquisition_settings`:

Acquisition settings
^^^^^^^^^^^^^^^^^^^^

This section allows to reduce the number of displayed data points to
increase performance. It also allows to chose if data should be restored
after a restart.

Other settings
^^^^^^^^^^^^^^

Any plugin can define additional settings and add them here in a
dedicated section (e.g., see :ref:`sec:device_settings`). Alternatively, plugins can
use the same built-in functions to manage settings internally (e.g., see :ref:`sec:scan_settings`).

.. _`sec:explorer`:

Explorer
~~~~~~~~

.. automodule:: esibd.plugins.Explorer
   :noindex:

.. _`sec:devices`:

Devices
~~~~~~~

.. automodule:: esibd.plugins.Device
   :noindex:

.. _`sec:device_settings`:

Device settings
^^^^^^^^^^^^^^^

Each device adds a section with the following settings to the :ref:`sec:settings` section.

.. _`acquisition_interval`:

Interval
   Data acquisition interval in ms.

Interval (measured)
   Measured plot interval in ms. If this deviates multiple times in a
   row, the number of display points will be reduced and eventually
   acquisition will be stopped to ensure the application remains
   responsive.

Max storage
    Maximum amount of storage used to store history in MB.

Max data points
   Maximum number of data points saved per channel, based on max
   storage. If this is reached, older data will be thinned to allow to
   keep longer history.

Other
   Additional device specific settings, e.g. COM ports or IP addresses
   for communication.

.. _`sec:channels`:

Channels
~~~~~~~~

.. automodule:: esibd.core.Channel
   :noindex:

The following defines basic channel properties.

Select
   In the advanced mode, this is used to select a channel to be
   duplicated, moved, or deleted.

Enabled
   If enabled, the channel will communicate with the device.

Name
   Each channel should have a unique name that will be used to link to
   the channel from other plugins. The same name may be used for an
   input and an output channel. Warnings will be displayed if a channel
   name is repeated.

Value
   The value to be applied to or read from the physical channel.

Monitor
   The read back used to confirm a value has been applied correctly.

Min
   Minimal limit for value. Values will be coerced to limits.

Max
   Maximal limit for value. Values will be coerced to limits.

Optimize
   If selected, the value will be included in optimization using the :ref:`genetic algorithm<sec:genetic_algorithm>`.

.. _`equation`:

Equation
   The equation is used to determine the value if the channel is not active.
   For input devices, this can be used simplify the setup by reducing
   the number of independent parameters. Any input channel from any
   device can be linked. For output devices this could be used, e.g., to
   record differences between two channels. There are no special requirements for
   the format of the equation as long as it evaluates to a valid python
   expression after replacing the names with the values from the
   corresponding channels. Take care to avoid circular definitions and
   non unique names!

Background
   For output channels, background signals can be defined manually or
   using the *set current value as background* option in the
   corresponding :ref:`live display<sec:live_displays>`. Each value will be saved with a
   corresponding background. Backgrounds can be optionally and temprarily subtracted 
   without loosing the raw data.

Display
   If selected, channel will be shown in the corresponding :ref:`live display<sec:live_displays>`.

Active
   See :ref:`equation`. If channels are not active, they will only be visible
   in the advanced mode.

Real
   Real channels correspond to a real physical input or output. A
   channel that is not real is a virtual channel. It can be used to in
   combination with equations to create a more intuitive set of
   parameters for the user. For example, a deflector lens with four
   elements can be controlled by virtual *offset, **up-down*, and *left-right*
   parameters.

Linewidth
   The linewith is used to highlight the relative importance of channels in
   the :ref:`live display<sec:live_displays>`.

Color
   The channel color can be used to visually group related channels
   allowing for easier navigation in a long list of channels. The
   channel color will also be used for the corresponding graphs in the
   :ref:`display<sec:displays>` and :ref:`live display<sec:live_displays>`.

Other
   Additional device specific channel parameters like *ID*, *COM*,
   *Module*, ect.

.. _`sec:scans`:

Scans
~~~~~

.. automodule:: esibd.plugins.Scan
   :noindex:

.. _`sec:scan_settings`:

Scan settings
^^^^^^^^^^^^^

Notes
   Add specific notes and metadata to the current scan. Will be reset
   after scan is saved.

Display
   List of output channels. All defined display channels are recorded
   but only the selected channel is displayed. A corresponding control in
   the display allows to change which channel is displayed.

Wait
   Wait time between small steps in ms.

Wait long
   Wait time between steps larger than :ref:`large step<large_step>` in ms.

.. _`large_step`:

Large step
   Threshold step size to use longer wait time. This can be useful if
   the effect of changing the input is delayed or there is a pickup that
   needs to decay before measuring.

Average
   Time used for averaging in ms.

Scan time
   Estimated scan time based on the other settings.

Channel
   Input channel to be scanned.

From
   Scan will start at this value.

To
   Scan will stop at this value.

Step
   Scan will use this step size.

Other
   Additional scan specific parameters.

.. _`sec:genetic_algorithm`:

Genetic algorithm (GA)
~~~~~~~~~~~~~~~~~~~~~~

.. automodule:: esibd.plugins_internal.scans.Scans.GA
   :noindex:

Omni scan
~~~~~~~~~

.. automodule:: esibd.plugins_internal.scans.Scans.Omni
   :noindex:

Custom extensions
~~~~~~~~~~~~~~~~~

.. automodule:: esibd.plugins_internal.examples.Custom.CustomControl
   :noindex:

Custom device extensions
~~~~~~~~~~~~~~~~~~~~~~~~

.. automodule:: esibd.plugins_internal.examples.CustomDevice.CustomDevice
   :noindex:

.. _sec:displays:

Displays
--------

A variety of displays are implemented and selected automatically by the
corresponding plugin or based on the file type. This includes common
file types like .txt, .tex, .png, .jpg, .bmp, .gif, .svg, .wav, .mp3,
.ogg, .pdf, .h5, .hdf5, .npy, .star, .pdb1, .css, .py, .js, .html, .ini,
.bat, and more. :ref:`sec:devices` and :ref:`scans<sec:scans>` will also come with internal
display plugins that are tailored to visualize their specific data.
Being able to get all required information form these files without
switching to external software avoids clutter and allows to keep an eye
on the live signals of the experiment while working with complementary
information. Graphs are made with matplotlib, pyqtgraph, or both,
allowing the user to choose between complementary ways of data
representations and interaction.

All build in display plugins may serve as examples for the development
of similar plugins for other purposes. See :ref:`sec:plugin_system` for more information.

.. _`sec:browser`:

Browser
~~~~~~~

.. automodule:: esibd.plugins.Browser
   :noindex:

.. _`sec:notes`:

Notes
~~~~~

.. automodule:: esibd.plugins.Notes
   :noindex:

.. _`sec:text`:

Text
~~~~

.. automodule:: esibd.plugins.Text
   :noindex:

Tree
~~~~

.. automodule:: esibd.plugins.Tree
   :noindex:

MS
~~

.. automodule:: esibd.plugins_internal.displays.Displays.MS
   :noindex:

Line
~~~~

.. automodule:: esibd.plugins_internal.displays.Displays.LINE
   :noindex:

PDB
~~~

.. automodule:: esibd.plugins_internal.displays.Displays.PDB
   :noindex:

Holo
~~~~

.. automodule:: esibd.plugins_internal.displays.Displays.HOLO
   :noindex:

.. _`sec:live_displays`:

Live displays
-------------

.. automodule:: esibd.plugins.LiveDisplay
   :noindex:

.. _`sec:device_manager`:

Device manager
--------------

.. automodule:: esibd.plugins.DeviceManager
   :noindex:

.. _`sec:console`:

Console
-------

.. automodule:: esibd.plugins.Console
   :noindex:

ESIBD specific plugins
----------------------

The following plugins are specific for ESIBD experiments but may be very
similar to what is needed for other applications. If you do ESIBD
experiments, make sure to get familiar with those plugins, otherwise
consider using them as templates for your own custom plugins. See :ref:`sec:plugin_system` for
more information.

.. _`sec:ISEG`:

ISEG
~~~~

.. automodule:: esibd.plugins_internal.devices.ISEG.Voltage
   :noindex:

RBD
~~~

.. automodule:: esibd.plugins_internal.devices.RBD.Current
   :noindex:

Pressure
~~~~~~~~

.. automodule:: esibd.plugins_internal.devices.Pressure.Pressure
   :noindex:

.. _`sec:Temperature`:

Temperature
~~~~~~~~~~~

.. automodule:: esibd.plugins_internal.devices.Temperature.Temperature
   :noindex:

Beam
~~~~

.. automodule:: esibd.plugins_internal.scans.Scans.Beam
   :noindex:

Spectra
~~~~~~~

.. automodule:: esibd.plugins_internal.scans.Scans.Spectra
   :noindex:

Energy
~~~~~~

.. automodule:: esibd.plugins_internal.scans.Scans.Energy
   :noindex:

Depo
~~~~

.. automodule:: esibd.plugins_internal.scans.Scans.Depo
   :noindex:


