Ejemplo n.º 1
0
def edit_file(ui):
    """
    Initializes the 'Edit config file' window.

    Parameters
    ------
    ui: the Ui_mainwindow object
        Instance is created in the main.py

    """

    if ui.experiment_queue.currentItem():
        filename = ui.experiment_queue.currentItem().data(3)
        config_data = parse_config_file(filename)
    else:
        warning(
            'Do you want to edit a existing config file? If so, please load it!'
        )
        return

    exp = None
    if 'CA' in filename:
        exp = CA_main(ui, config_data)
        CA_window_writer(exp, config_data)
    elif 'CV' in filename:
        exp = CV_main(ui, config_data)
        CV_window_writer(exp, config_data)
    elif 'LSV' in filename:
        exp = LSV_main(ui, config_data)
        LSV_window_writer(exp, config_data)
    if exp is None:
        warning('Please rename the file with experiment type: CA/CV/LSV!')

    ui.experiment_queue.clearSelection()
Ejemplo n.º 2
0
def find_port_main(ui):
    """
    This function is connected with 'Find Potentiostat' button.

    Parameters
    ----------
    ui: the mainwindow object.
        Instance is created in the main.py

    Returns
    -------
    com : string, the name of the port with the potentiostat on it
          Instance is created in the main.py

    board_objects = (board, a0, a2, d9).
                   board : serial communication for board
                   a0 : location of analog read pin 0
                   a2 : location of analog read pin 2
                   d9 : location of digital pwm pin 9
                   Instance is created in the main.py

    """

    com, board, a0, a2, d9 = startup_routine(ui)
    board_objects = (board, a0, a2, d9)
    icon_true = QIcon("../pics/icon_connected.ico")
    if com and board:
        ui.arduino_connection_indicator.setIcon(icon_true)
    if not com:
        warning('Please connect potentiostat!')
    return com, board_objects
Ejemplo n.º 3
0
def preview_CA(exp, grid):
    """
    This function is to show the preview and the experiment type.

    Parameters
    ------
    exp: the Ui_experiment object

    grid: QGridLayout object

    """
    stp_num = exp.experiment_step_number.text()
    ca_v = exp.experiment_voltage.text()
    ca_time = exp.experiment_time.text()
    if check(stp_num) and check(ca_v) and check(ca_time):
        stp_num = int(stp_num)
        ca_v = float(ca_v)
        ca_time = int(ca_time)
    else:
        warning(
            'Please make sure all the experiment parameters are either integer or float.'
        )
        return
    steps_list = np.linspace(ca_v, ca_v, stp_num + 1)
    times_step_list = np.linspace(0, ca_time, num=stp_num + 1)
    while grid.count() > 0:
        item = grid.takeAt(0)
        w = item.widget()
        if w:
            w.deleteLater()
    grid.addWidget(plot(times_step_list, steps_list))
    exp.experiment_duration.setText(time_converter(ca_time))
Ejemplo n.º 4
0
def preview_LSV(exp, grid):
    """
    This function is to show the preview and the experiment type.

    Parameters
    ------
    exp: the Ui_experiment object
    grid: QGridLayout object

    """
    stp_num = exp.experiment_step_number.text()
    lsv_sv = exp.experiment_start_voltage.text()
    lsv_ev = exp.experiment_end_voltage.text()
    lsv_sr = exp.experiment_sweep_rate.text()
    if check(stp_num) and check(lsv_sv) and check(lsv_ev) and check(lsv_sr):
        stp_num = int(stp_num)
        lsv_sv = float(lsv_sv)
        lsv_ev = float(lsv_ev)
        lsv_sr = float(lsv_sr)
    else:
        warning(
            'Please make sure all the experiment parameters are either integer or float.'
        )
        return
    voltage_range = abs(lsv_ev - lsv_sv)  # V
    time_for_range = voltage_range / (lsv_sr / 1000)  # s
    steps_list = np.linspace(lsv_sv, lsv_ev, num=stp_num + 1)
    times_step_list = np.linspace(0, time_for_range, num=stp_num + 1)
    while grid.count() > 0:
        item = grid.takeAt(0)
        w = item.widget()
        if w:
            w.deleteLater()
    grid.addWidget(plot(times_step_list, steps_list))
    exp.experiment_duration.setText(time_converter((times_step_list[-1])))
Ejemplo n.º 5
0
def write_to_file_CA(ui, CA, CA_window, AP_params):
    """
    This function is connect to save file button.

    Parameters
    ------
    CA : the Ui_CA object

    CA_window: the CA QMainWindow object

    AP_parameters: list that contains the advanced parameters

    """

    config_params = get_parameters(CA, 'CA', AP_params)
    data_out_name = config_params[3]
    data_out_path = config_params[4]
    filename_list = os.listdir(
        data_out_path)  # list all the filename in the folder
    config_writer_CA(*config_params)
    filename = os.path.join(data_out_path, data_out_name + "_CA_config.yml")
    filename_parse = filename.split('/')[-1].strip(
    )  # this contains the filename without the path,e.g. 0_CA_config.yml
    # list all the filename in the experiment queue, stored in queue_filename
    queue_filename = []
    for x in range(ui.experiment_queue.count()):
        queue_filename.append(
            ui.experiment_queue.item(x).data(2).split('.yml')[0] + '.yml')

    if filename_parse in filename_list:
        if warning('The filename exists. Do you want to overwrite it?'):
            CA_window.close()
            if filename_parse not in queue_filename:
                item = QListWidgetItem()
                icon = QIcon("../pics/icon_ca.ico")
                item.setData(1, icon)
                item.setData(2, filename_parse)
                item.setData(3, filename)
                ui.experiment_queue.addItem(item)
                return
            else:  # if the filename is already in the experiment queue,
                return  # we don't need to show it on the queue again
        else:
            return
    if warning('The file is saved. Do you want to exit the window?'):
        CA_window.close()
        item = QListWidgetItem()
        icon = QIcon("../pics/icon_ca.ico")
        item.setData(1, icon)
        item.setData(2, filename_parse)
        item.setData(3, filename)
        ui.experiment_queue.addItem(item)
Ejemplo n.º 6
0
def get_parameters(exp, exp_type, AP_parameters):
    """
    This function is to get all the parameters from the window

    Parameters
    ------
    exp : the Ui_Experiment object

    exp_type: string, experiment type

    AP_parameters: list that contains the advanced parameters

    Return
    ------
    config_params: list that contain all the experiment parameters

    """
    data_out_name = exp.experiment_file_name.text()
    data_out_path = exp.experiment_file_path.text()
    rt = exp.experiment_rest_time.text()
    stp_num = exp.experiment_step_number.text()
    if check(stp_num) and check(rt):
        move_on = True
        stp_num = int(stp_num)
        rt = int(rt)
    else:
        move_on = False
        warning('Please input all the parameters with the correct data type.')

    config_params = [exp_type, rt, stp_num, data_out_name, data_out_path
                     ] + AP_parameters
    cv_sv = exp.experiment_start_voltage.text()
    cv_ftv = exp.experiment_first_vertex_voltage.text()
    cv_stv = exp.experiment_second_vertex_voltage.text()
    cv_sr = exp.experiment_sweep_rate.text()
    cyc_num = exp.experiment_cycle_number.text()
    if check(cv_sv) and check(cv_ftv) and check(cv_stv) and check(
            cv_sr) and check(cyc_num):
        cv_sv = float(cv_sv)
        cv_ftv = float(cv_ftv)
        cv_stv = float(cv_stv)
        cv_sr = float(cv_sr)
        cyc_num = int(cyc_num)
    elif move_on:
        warning(
            'Please make sure all the experiment parameters are either integer or float.'
        )
    data = [cv_sv, cv_ftv, cv_stv, cv_sr, cyc_num]
    config_params += data

    return config_params
Ejemplo n.º 7
0
def write_to_file_LSV(ui, LSV, LSV_window, AP_params):
    """
    This function is connect to save file button.

    Parameters
    ------
    LSV : the Ui_LSV object

    LSV_window: the LSV QMainWindow object

    AP_parameters: list that contains the advanced parameters

    """
    config_params = get_parameters(LSV, 'LSV', AP_params)
    data_out_name = config_params[3]
    data_out_path = config_params[4]
    filename_list = os.listdir(data_out_path)
    config_writer_LSV(*config_params)
    filename = os.path.join(data_out_path, data_out_name + "_LSV_config.yml")
    filename_parse = filename.split('/')[-1].strip()
    queue_filename = []
    for x in range(ui.experiment_queue.count()):
        queue_filename.append(
            ui.experiment_queue.item(x).data(2).split('.yml')[0] + '.yml')

    if filename_parse in filename_list:
        if warning('The filename exists. Do you want to overwrite it?'):
            LSV_window.close()
            if filename_parse not in queue_filename:
                item = QListWidgetItem()
                icon = QIcon("../pics/icon_lsv.ico")
                item.setData(1, icon)
                item.setData(2, filename_parse)
                item.setData(3, filename)
                ui.experiment_queue.addItem(item)
                return
            else:
                return
        else:
            return
    if warning('The file is saved. Do you want to exit the window?'):
        LSV_window.close()
        item = QListWidgetItem()
        icon = QIcon("../pics/icon_lsv.ico")
        item.setData(1, icon)
        item.setData(2, filename_parse)
        item.setData(3, filename)
        ui.experiment_queue.addItem(item)
Ejemplo n.º 8
0
    def change_params():
        """
        This function is connected to 'Save' button to save changed parameters.

        """
        AP_params[0:7] = get_AP_parameters(AP)
        if warning('The file has been saved. Do you want to exit the window?'):
            AP_window.close()
Ejemplo n.º 9
0
def startup_routine(ui):
    """
    Initializes the communication port with the JUAMI potentistat

    Parameters
    ----------
    ui: the mainwindow object.
        Instance is created in the main.py

    Returns
    -------
    Map of hardware

    com : string, the name of the port with the potentiostat on it

    board : serial communication for board

    a0 : location of analog read pin 0

    a2 : location of analog read pin 2

    d9 : location of digital pwm pin 9

    """
    com = ui.arduino_connection_name.currentText()
    curr_ports = []
    for p in list(serial.tools.list_ports.comports()
                  ):  # Checking if com still connected
        curr_ports.append(p.device)
    if com:
        if com in curr_ports:
            board = _initialize_arduino(com)
            it = util.Iterator(board)
            it.start()

            # Setup Arduino pins
            a0 = board.get_pin("a:0:i")
            a2 = board.get_pin("a:2:i")
            d9 = board.get_pin("d:9:p")
            return com, board, a0, a2, d9
        else:
            warning('Current port not connected!')
    return com, None, None, None, None
Ejemplo n.º 10
0
def preview_CV(exp, grid):
    """
    This function is to show the preview and the experiment type.

    Parameters
    ------
    exp : the Ui_experiment object
    grid : QGridLayout object

    """
    stp_num = exp.experiment_step_number.text()
    cv_sv = exp.experiment_start_voltage.text()
    cv_ftv = exp.experiment_first_vertex_voltage.text()
    cv_stv = exp.experiment_second_vertex_voltage.text()
    cv_sr = exp.experiment_sweep_rate.text()
    cyc_num = exp.experiment_cycle_number.text()
    if check(stp_num) and check(cv_sv) and check(cv_ftv) and check(
            cv_stv) and check(cv_sr) and check(cyc_num):
        stp_num = int(stp_num)
        cv_sv = float(cv_sv)
        cv_ftv = float(cv_ftv)
        cv_stv = float(cv_stv)
        cv_sr = float(cv_sr)
        cyc_num = int(cyc_num)
    else:
        warning(
            'Please make sure all the experiment parameters are either integer or float.'
        )
        return
    x, y = CV_data(stp_num, cv_sv, cv_ftv, cv_stv, cv_sr)
    while grid.count() > 0:
        item = grid.takeAt(0)
        w = item.widget()
        if w:
            w.deleteLater()
    grid.addWidget(plot(x, y))
    exp.experiment_duration.setText(time_converter((x[-1] * cyc_num)))