Skip to content

3. Scripts

Pieter-Jan Stas edited this page Sep 21, 2023 · 5 revisions

Wavemonitor lock

.json file structure:

{
    "servers" : [
        {
            "type" : "wavelength_meter_config_folder",
            "config" : "wavelength_meter_config",
            "auto_launch" : "False"
        }
        {
            "type" : "analog_voltage_output_config_folder",
            "config" : "analog_voltage_output_config"
        }
    ],
    "script" : "path2pylabnet/pylabnet/pylabnet/scripts/lasers/wlm_monitor.py",
    "device_id" : "what_you_want_to_name_this_wavemonitor_lock",
    "script_service" : "True",
    "wm_type": [
        "wavelength_meter_config_folder"
    ],
    "num_lasers": 1 (max is 2),
    "channels" : {
        "1" : {
            "channel" : channel_on_wavelength_meter,
            "name" : "what_you_want_to_name_this_channel",
            "ao" : {
                "client" : "analog_voltage_output_config_folder",
                "config" : "analog_voltage_output_config",
                "channel" : "analog_voltage_output_name"
            },
            "pid" : {
                "p" : p_value,
                "i" : i_value,
                "d" : d_value
            },
            "memory" : memory_value_for_id,
            "voltage_monitor" : "True",
            "min_voltage" : min_voltage,
            "max_voltage" : max_voltage,
            "gain" : gain_value
        }
    }
}

269077573-225cad42-fd89-4707-94ca-641e433eb38c

Wavemonitor lock is used to lock laser frequencies. Up to 3 lasers can be locked with one wavemonitor lock script. The script will need to access a wavelength meter (to read the wavelength of a given laser) and an analog voltage output (to update the piezo voltage of the laser). When "Lock active" is clicked, a PID locks the laser frequency to the setpoint. The setpoint value can be changed both by writing in the setpoint field or clicking on the setpoint field and using arrow keys to go up or down in frequency. If the error is too large, "Lock error" will turn red. The setpoint value and actual laser frequency value are plotted on the top graph, and the error and voltage sent to the piezo on the bottom graph (left and right are two different lasers). PID values can be changed be updating the fields next to "P", "I", and "D", and then clicking "Update PID parameters".

Datataker

.json file structure:

{
    "servers": [
        {
            "type": "some_device_you_want_to_use_config_folder",
            "config": "some_device_you_want_to_use_config"
        }
    ],
    "script": "path2pylabnet/pylabnet/pylabnet/pylabnet/scripts/data_center/take_data.py",
    "exp_path" : "path/to/experiment/folder",
    "save_path": "path/to/save/folder",
    "auto_save": "True" or "False"
}

image-28

Datataker is a general script that runs experiments and plots data according to experiment files located in the "exp_path" folder. The "Clients" window contains the clients to all hardware devices you want to use for a given experiment. The "Experiments" window contains all folders and files in the "exp_path" folder. The "Input Dict" window allows for setting of parameters when configuring an experiment. The workflow is as follows:

  1. Click on an experiment you want to run in the "Experiments" window. This will populate the "Input Dict" window according to the chosen experiment file
  2. Fill the input dict with desired parameters.
  3. Click on "Configure".
  4. Click on "Run". This will run the experiments continuously and turn the "Run" button into a "Stop" button.
  5. You can stop the experiment, clear the data, or save the data at any point by clicking the appropriate buttons.

The experiment code file will have the following structure:

import importlib.util
from pylabnet.scripts.data_center.take_data import ExperimentThread
from pylabnet.scripts.data_center.datasets import InfiniteRollingLine, Dataset

# define the type of dataset the main dataset is
def define_dataset():
    return 'Dataset'

def data_manipulation(dataset, prev_dataset):
    manipulated_data = some_function(dataset.data)
    prev_dataset.set_data(manipulated_data)

# dictionary to populate the Input Dict window
INIT_DICT = {
    "input_parameter":
        {"Some input parameter you want to set:" : value}
}

def configure(**kwargs):
    dataset : Dataset = kwargs['dataset']

    # retrieve input parameter from input dict
    input_parameter = dataset.get_input_parameter("input_parameter")

    # Configure any devices you want, or add children datasets to your main dataset:
    dataset.add_child(
        name='some metric to plot',
        data_type=InfiniteRollingLine,
        data_length = len_value,
        mapping = data_manipulation
    )


def experiment(**kwargs):
    thread : ExperimentThread = kwargs['thread']
    dataset : Dataset = kwargs['dataset']

    # If you add a loop in the experiment function, you can add the following
    # lines to break out of the loop and stop the experiment when 
    # "Stop" button is clicked:
    if not thread.running:
        break

    # retrieve data, for example from one of your devices
    data = some_function_to_retrieve_data()
    dataset.set_data(data)

The INIT_DICT dictionary is used to populate the "Input Dict" window in the datataker guy when the experiment script is clicked. The configure() function is called when the "Configure" button is clicked. The experiment() function gets called repeatedly when the "Run" button is clicked (and until the "Stop" button is clicked). There is a main dataset to which data gets sent (through the dataset.set_data() command in the experiment), and children datasets under this main dataset that will automatically get updated according to the given mapping (in the above case: the data_manipulation function) whenever the main dataset is updated. The available datatypes (in the example above: Dataset, InfiniteRollingLine) can be found in the path2pylabnet/pylabnet/scripts/data_center/datasets.py file.

Staticline

.json file structure

{
    "servers" : [
        {
            "type": "some_device_you_want_to_use_config_folder",
            "config": "some_device_you_want_to_use_config"
        }
    ],
    "script" : "path2pylabnet/pylabnet/pylabnet/pylabnet/scripts/staticlines/staticline.py",
    "lines": {
        "Line (block of buttons) name (only one device per block)":
        {
            "hardware_type": "some_device_you_want_to_use_config_folder",
            "config_name": "some_device_you_want_to_use_config",
            "staticline_names": ["Name of output 1",
                                 "Name of output 2",
                                 "Name of output 3"],
            "staticline_configs": [
                {"type":"digital", "extra_parameters": ... },
                {"type":"analog", "extra_parameters": ... },
                {"type":"adjustable_digital", "extra_parameters": ... }
            ]
        }
    }
}

image-29

Staticline is a script that contains toggling buttons and analog output setting. There are three types of staticlines:

  • "digital": can only be set high or low
  • "analog": can set some analog voltage
  • "adjustable_digital": can be set to some analog high voltage and 0 V

Writing a new script

A script needs a .py file located in path2pylabnet/pylabnet/scripts and a GUI .ui file in path2pylabnet/pylabnet/gui/pyqt/gui_templates (which can be created and edited with Qt Designer).

Clone this wiki locally