def create_dialog(self):
        """Create the dialog."""
        bbox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
        self.idx_ok = bbox.button(QDialogButtonBox.Ok)
        self.idx_cancel = bbox.button(QDialogButtonBox.Cancel)

        """ ------ FILE LOCATION ------ """

        box_file = QGroupBox('File location')

        filebutton = QPushButton('Choose')
        filebutton.clicked.connect(self.save_as)
        self.idx_filename = filebutton

        flayout = QFormLayout()
        box_file.setLayout(flayout)
        flayout.addRow('Filename',
                           self.idx_filename)

        """ ------ N_SEG ------ """

        box_nseg = QGroupBox('Info')

        self.show_nseg = QLabel('')

        form = QFormLayout(box_nseg)
        form.addRow(self.show_nseg)

        """ ------ LOCATION ------ """

        box_loc = QGroupBox('Location')

        cghl = QHBoxLayout()
        cghl.addWidget(QLabel('Channel group'))
        cghl.addWidget(self.idx_group)
        cghl.addStretch(1)

        grid = QGridLayout(box_loc)
        grid.addLayout(cghl, 0, 0, 1, 3)
        grid.addWidget(QLabel('Channel(s)'), 1, 0)
        grid.addWidget(QLabel('Cycle(s)'), 1, 1)
        grid.addWidget(QLabel('Stage(s)'), 1, 2)
        grid.addWidget(self.idx_chan, 2, 0)
        grid.addWidget(self.idx_cycle, 2, 1)
        grid.addWidget(self.idx_stage, 2, 2)

        """ ------ CHUNKING ------ """

        box_chunk = QGroupBox('Chunking')

        self.chunk = {}
        self.chunk['event'] = FormRadio('by e&vent')
        self.evt_chan_only = FormBool('Channel-specific')
        self.chunk['epoch'] = FormRadio('by e&poch')
        self.epoch_param = epop = {}
        self.lock_to_staging = FormBool('Lock to staging epochs')
        epop['dur_label'] = QLabel('Duration (sec)')
        epop['dur'] = FormFloat(30.)
        epop['overlap'] = FormRadio('Overlap (0-1)')
        epop['step'] = FormRadio('Step (sec)')
        epop['overlap_val'] = QDoubleSpinBox()
        epop['overlap_val'].setRange(0, 0.9)
        epop['overlap_val'].setSingleStep(0.1)
        epop['overlap_val'].setValue(0.)
        epop['step_val'] = FormFloat(30.)
        self.chunk['segment'] = FormRadio('by longest &run')

        evt_box = QListWidget()
        evt_box.setSelectionMode(QAbstractItemView.ExtendedSelection)
        self.idx_evt_type = evt_box

        chunk_grp = QButtonGroup(box_chunk)
        chunk_grp.addButton(self.chunk['event'])
        chunk_grp.addButton(self.chunk['epoch'])
        chunk_grp.addButton(self.chunk['segment'])

        epoch_grp = QButtonGroup(box_chunk)
        epoch_grp.addButton(epop['overlap'])
        epoch_grp.addButton(epop['step'])

        grid = QGridLayout(box_chunk)
        grid.addWidget(self.chunk['event'], 0, 0, 1, 3)
        grid.addWidget(QLabel('  '), 1, 0)
        grid.addWidget(self.evt_chan_only, 1, 1, 1, 2)
        grid.addWidget(self.idx_evt_type, 2, 1, 3, 2)
        grid.addWidget(self.chunk['epoch'], 0, 3, 1, 3)
        grid.addWidget(QLabel('  '), 1, 3)
        grid.addWidget(self.lock_to_staging, 1, 4, 1, 2)
        grid.addWidget(epop['dur_label'], 2, 4)
        grid.addWidget(epop['dur'], 2, 5)
        grid.addWidget(epop['overlap'], 3, 4)
        grid.addWidget(epop['overlap_val'], 3, 5)
        grid.addWidget(epop['step'], 4, 4)
        grid.addWidget(epop['step_val'], 4, 5)
        grid.addWidget(self.chunk['segment'], 0, 6)

        """ ------ REJECTION ------ """

        box_r = QGroupBox('Rejection')

        self.min_dur = FormFloat(0.0)
        self.reject_epoch = FormBool('Exclude Poor signal epochs')
        self.reject_event = FormMenu(['none', 'channel-specific',
                                      'from any channel'])

        flayout = QFormLayout()
        box_r.setLayout(flayout)
        flayout.addRow(self.reject_epoch)
        flayout.addRow('Exclude Artefact events',
                       self.reject_event)
        flayout.addRow('Minimum duration (sec)',
                           self.min_dur)

        """ ------ CONCATENATION ------ """

        box_c = QGroupBox('Concatenation')

        self.cat = {}
        self.cat['chan'] = FormBool('Concatenate channels')
        self.cat['cycle'] = FormBool('Concatenate cycles')
        self.cat['stage'] = FormBool('Concatenate between stages')
        self.cat['discontinuous'] = FormBool(''
                'Concatenate discontinuous signal')
        self.cat['evt_type'] = FormBool('Concatenate between event types')

        for box in self.cat.values():
            box.setEnabled(False)

        flayout = QFormLayout()
        box_c.setLayout(flayout)
        flayout.addRow(self.cat['stage'])
        flayout.addRow(self.cat['cycle'])
        flayout.addRow(self.cat['evt_type'])
        flayout.addRow(self.cat['discontinuous'])
        flayout.addRow(self.cat['chan'])

        """ ------ PRE-PROCESSING ------ """

        box_pp = QGroupBox('Pre-processing')

        self.trans = {}
        self.trans['diff'] = FormBool('Differentiate')

        ftypes = ['none', 'butter', 'cheby1', 'cheby2', 'ellip', 'bessel',
                  'diff']

        self.trans['bp'] = tbp = {}
        self.trans['bandpass'] = FormMenu(ftypes)
        tbp['order'] = QLabel('Order'), FormSpin(3, 0, 8, 1)
        tbp['f1'] = QLabel('Lowcut (Hz)'), FormFloat()
        tbp['f2'] = QLabel('Highcut (Hz)'), FormFloat()

        self.trans['n1'] = tn1 = {}
        self.trans['notch1'] = FormMenu(ftypes)
        tn1['order'] = QLabel('Order'), FormSpin(3, 0, 8, 1)
        tn1['cf'] = QLabel('CF (Hz)'), FormFloat()
        tn1['bw'] = QLabel('BW (Hz)'), FormFloat()

        self.trans['n2'] = tn2 = {}
        self.trans['notch2'] = FormMenu(ftypes)
        tn2['order'] = QLabel('Order'), FormSpin(3, 0, 8, 1)
        tn2['cf'] = QLabel('CF (Hz)'), FormFloat()
        tn2['bw'] = QLabel('BW (Hz)'), FormFloat()

        form1 = QFormLayout()
        form1.addRow('Bandpass', self.trans['bandpass'])
        form1.addRow(*tbp['order'])
        form1.addRow(*tbp['f1'])
        form1.addRow(*tbp['f2'])

        form2 = QFormLayout()
        form2.addRow('Notch 1', self.trans['notch1'])
        form2.addRow(*tn1['order'])
        form2.addRow(*tn1['cf'])
        form2.addRow(*tn1['bw'])

        form3 = QFormLayout()
        form3.addRow('Notch 2', self.trans['notch2'])
        form3.addRow(*tn2['order'])
        form3.addRow(*tn2['cf'])
        form3.addRow(*tn2['bw'])

        grid = QGridLayout(box_pp)
        grid.addWidget(self.trans['diff'], 0, 0, 1, 3)
        grid.addLayout(form1, 1, 0)
        grid.addLayout(form2, 1, 1)
        grid.addLayout(form3, 1, 2)

        """ ------ FREQUENCY ------ """

        self.tab_freq = tab_freq = QWidget()

        self.frequency = freq = {}

        box_freq_main = QGroupBox('Options')

        #freq['freq_on'] = FormBool('Compute frequency domain')
        freq['export_full'] = FormBool('Full spectrum')
        freq['export_band'] = FormBool('Band-limited')
        freq['plot_on'] = FormBool('Plot mean spectrum')
        freq['fooof_on'] = FormBool('Parametrize')
        freq['prep'] = FormBool('Pre-process')

        form = QFormLayout(box_freq_main)
        form.addRow(freq['prep'])
        form.addRow(freq['export_full'])
        form.addRow(freq['export_band'])
        form.addRow(freq['plot_on'])
        form.addRow(freq['fooof_on'])

        freq['box_param'] = QGroupBox('Parameters')

        freq['scaling'] = FormMenu(['power', 'energy', 'fieldtrip', 'chronux'])
        freq['taper'] = FormMenu(['boxcar', 'hann', 'dpss', 'triang',
            'blackman', 'hamming', 'bartlett', 'flattop', 'parzen', 'bohman',
                'blackmanharris', 'nuttall', 'barthann'])
        freq['detrend'] = FormMenu(['none', 'constant', 'linear'])
        freq['welch_on'] = FormBool("Time-averaged")
        freq['log_trans']= FormBool('Log-transform')

        form = QFormLayout(freq['box_param'])
        form.addRow('Scaling', freq['scaling'])
        form.addRow('Taper', freq['taper'])
        form.addRow('Detrend', freq['detrend'])
        form.addRow(freq['welch_on'])
        form.addRow(freq['log_trans'])

        freq['box_welch'] = QGroupBox("Time averaging")

        freq['duration'] = FormFloat(1)
        freq['overlap'] = FormRadio('Overlap (0-1)')
        freq['step'] = FormRadio('Step (sec)')
        freq['overlap_val'] = QDoubleSpinBox()
        freq['overlap_val'].setRange(0, 1)
        freq['overlap_val'].setSingleStep(0.1)
        freq['overlap_val'].setValue(0.5)
        freq['step_val'] = FormFloat(0.5)
        freq['centend'] = FormMenu(['mean', 'median'])

        grid = QGridLayout(freq['box_welch'])
        grid.addWidget(QLabel('Duration (sec)'), 0, 0)
        grid.addWidget(freq['duration'], 0, 1)
        grid.addWidget(freq['overlap'], 1, 0)
        grid.addWidget(freq['step'], 2, 0)
        grid.addWidget(freq['overlap_val'], 1, 1)
        grid.addWidget(freq['step_val'], 2, 1)
        grid.addWidget(QLabel('Central tendency'), 3, 0)
        grid.addWidget(freq['centend'], 3, 1)

        freq['box_mtap'] = QGroupBox('Multitaper method (DPSS) smoothing')

        freq['nhbw'] = FormBool('Normalized')
        freq['hbw'] = FormSpin(3, 0)
        freq['nhbw_val'] = FormSpin(min_val=0)

        grid = QGridLayout(freq['box_mtap'])
        grid.addWidget(QLabel('Half bandwidth (Hz)'), 0, 0)
        grid.addWidget(freq['nhbw'], 1, 0)
        grid.addWidget(freq['hbw'], 0, 1)
        grid.addWidget(freq['nhbw_val'], 1, 1)

        freq['box_output'] = QGroupBox('Output')

        freq['spectrald'] = FormRadio('Spectral density')
        freq['complex'] = FormRadio('Complex')
        freq['sides'] = FormSpin(min_val=1, max_val=2)

        grid = QGridLayout(freq['box_output'])
        grid.addWidget(freq['spectrald'], 0, 0, 1, 3)
        grid.addWidget(freq['complex'], 1, 0, 1, 3)
        #grid.addWidget(QLabel('      '), 2, 0)
        #grid.addWidget(QLabel('Side(s)'), 2, 1)
        #grid.addWidget(freq['sides'], 2, 2)

        freq['box_nfft'] = QGroupBox('FFT length')

        freq['nfft_seg'] = FormRadio('Same as segment')
        freq['nfft_fixed'] = FormRadio('Fixed:')
        freq['nfft_fixed_val'] = FormInt()
        freq['nfft_zeropad'] = FormRadio('Zero-pad to longest segment')

        grid = QGridLayout(freq['box_nfft'])
        grid.addWidget(freq['nfft_seg'], 0, 0, 1, 2)
        grid.addWidget(freq['nfft_fixed'], 1, 0)
        grid.addWidget(freq['nfft_fixed_val'], 1, 1)
        grid.addWidget(freq['nfft_zeropad'], 2, 0, 1, 2)

        freq['box_norm'] = QGroupBox('Normalization')

        freq['norm'] = FormMenu(['none', 'by integral of each segment',
           'by mean of event type(s)', 'by mean of stage(s)'])
        evt_box = QListWidget()
        evt_box.setSelectionMode(QAbstractItemView.ExtendedSelection)
        freq['norm_evt_type'] = evt_box
        stage_box = QListWidget()
        stage_box.setSelectionMode(QAbstractItemView.ExtendedSelection)
        stage_box.addItems(STAGE_NAME)
        freq['norm_stage'] = stage_box
        freq['norm_concat'] = FormBool('Concatenate')

        grid = QGridLayout(freq['box_norm'])
        grid.addWidget(freq['norm'], 0, 0, 1, 2)
        grid.addWidget(QLabel('Event type(s)'), 1, 0)
        grid.addWidget(QLabel('Stage(s)'), 1, 1)
        grid.addWidget(freq['norm_evt_type'], 2, 0)
        grid.addWidget(freq['norm_stage'], 2, 1)
        grid.addWidget(freq['norm_concat'], 3, 0, 1, 2)

        freq['box_cross'] = QGroupBox('Cross-spectrum')

        freq['csd'] = FormBool('Cross-spectrum')
        freq['gainphase'] = FormBool('Gain and phase shift')
        #freq['phaseshift'] = FormBool('Phase shift')
        freq['coh'] = FormBool('Coherence')

        form = QFormLayout(freq['box_cross'])
        form.addRow(freq['csd'])
        form.addRow(freq['gainphase'])
        #form.addRow(freq['phaseshift'])
        form.addRow(freq['coh'])

        freq['box_fooof'] = QGroupBox('Parametrization')

        freq['fo_min_freq'] = FormFloat(2.)
        freq['fo_max_freq'] = FormFloat(30.)
        freq['fo_pk_thresh'] = FormFloat(2.)
        freq['fo_pk_width_min'] = FormFloat(.5)
        freq['fo_pk_width_max'] = FormFloat(12.)
        freq['fo_max_n_pk'] = FormInt()
        freq['fo_min_pk_amp'] = FormFloat(0)
        freq['fo_bg_mode'] = FormMenu(['fixed', 'knee'])

        freqhbox = QHBoxLayout()
        freqhbox.addWidget(QLabel('Frequencies:'))
        freqhbox.addWidget(freq['fo_min_freq'])
        freqhbox.addWidget(QLabel('-'))
        freqhbox.addWidget(freq['fo_max_freq'])
        freqhbox.addWidget(QLabel('Hz'))

        widhbox = QHBoxLayout()
        widhbox.addWidget(QLabel('Peak width:'))
        widhbox.addWidget(freq['fo_pk_width_min'])
        widhbox.addWidget(QLabel('-'))
        widhbox.addWidget(freq['fo_pk_width_max'])
        widhbox.addWidget(QLabel('Hz'))

        form = QFormLayout(freq['box_fooof'])
        form.addRow(freqhbox)
        form.addRow(widhbox)
        form.addRow('Peak threshold (SD)',
                    freq['fo_pk_thresh'])
        form.addRow('Max. number of peaks',
                    freq['fo_max_n_pk'])
        form.addRow('Min. peak amplitude',
                    freq['fo_min_pk_amp'])
        form.addRow('Background fitting mode',
                    freq['fo_bg_mode'])

        freq['box_band'] = QGroupBox('Define bands')

        freq['band'] = FormStr()
        freq['band_help'] = QPushButton(QIcon(ICON['help-about']), '', self)

        hlayout = QHBoxLayout()
        hlayout.addWidget(freq['band'])
        hlayout.addWidget(freq['band_help'])

        vlayout = QVBoxLayout(freq['box_band'])
        vlayout.addLayout(hlayout)

        vlayout1 = QVBoxLayout()
        vlayout1.addWidget(box_freq_main)
        vlayout1.addWidget(freq['box_param'])
        vlayout1.addWidget(freq['box_welch'])
        vlayout1.addWidget(freq['box_nfft'])
        vlayout1.addWidget(freq['box_mtap'])
        vlayout1.addWidget(freq['box_output'])
        vlayout1.addStretch(1)

        vlayout2 = QVBoxLayout()
        vlayout2.addWidget(freq['box_band'])
        vlayout2.addWidget(freq['box_norm'])
        vlayout2.addWidget(freq['box_cross'])
        vlayout2.addWidget(freq['box_fooof'])
        vlayout2.addStretch(1)

        hlayout = QHBoxLayout()
        hlayout.addLayout(vlayout1)
        hlayout.addLayout(vlayout2)

        vlayout = QVBoxLayout(tab_freq)
        vlayout.addLayout(hlayout)

        """ ------ PAC ------ """
        if Pac is not None:

            self.tab_pac = tab_pac = QWidget()

            pac_metrics = [pacstr((x, 0, 0))[0] for x in range(1,6)]
            pac_metrics = [x[:x.index('(') - 1] for x in pac_metrics]
            pac_metrics[1] = 'Kullback-Leibler Distance' # corrected typo
            pac_surro = [pacstr((1, x, 0))[1] for x in range(5)]
            pac_norm = [pacstr((1, 0, x))[2] for x in range(5)]

            self.pac = pac = {}

            pac['box_complex'] = QGroupBox('Complex definition')

            pac['hilbert_on'] = FormRadio('Hilbert transform')
            pac['hilbert'] = hilb = {}
            hilb['filt'] = QLabel('Filter'), FormMenu(['fir1', 'butter',
                'bessel'])
            hilb['cycle_pha'] = QLabel('Cycles, phase'), FormInt(default=3)
            hilb['cycle_amp'] = QLabel('Cycles, amp'), FormInt(default=6)
            hilb['order'] = QLabel('Order'), FormInt(default=3)
            pac['wavelet_on'] = FormRadio('Wavelet convolution')
            pac['wav_width'] = QLabel('Width'), FormInt(default=7)

            grid = QGridLayout(pac['box_complex'])
            grid.addWidget(pac['hilbert_on'], 0, 0, 1, 2)
            grid.addWidget(hilb['filt'][0], 1, 0)
            grid.addWidget(hilb['filt'][1], 1, 1)
            grid.addWidget(hilb['cycle_pha'][0], 2, 0)
            grid.addWidget(hilb['cycle_pha'][1], 2, 1)
            grid.addWidget(hilb['cycle_amp'][0], 3, 0)
            grid.addWidget(hilb['cycle_amp'][1], 3, 1)
            grid.addWidget(hilb['order'][0], 4, 0)
            grid.addWidget(hilb['order'][1], 4, 1)
            grid.addWidget(pac['wavelet_on'], 0, 3, 1, 2)
            grid.addWidget(pac['wav_width'][0], 1, 3)
            grid.addWidget(pac['wav_width'][1], 1, 4)

            pac['box_metric'] = QGroupBox('PAC metric')

            pac['pac_on'] = FormBool('Compute PAC')
            pac['prep'] = FormBool('Pre-process')
            pac['metric'] = FormMenu(pac_metrics)
            pac['fpha'] = FormStr()
            pac['famp'] = FormStr()
            pac['band_help_p'] = QPushButton(QIcon(ICON['help-about']), '',
               self)
            pac['band_help_a'] = QPushButton(QIcon(ICON['help-about']), '',
               self)
            pac['nbin'] = QLabel('Number of bins'), FormInt(default=18)

            hlayoutp = QHBoxLayout()
            hlayoutp.addWidget(pac['fpha'])
            hlayoutp.addWidget(pac['band_help_p'])

            hlayouta = QHBoxLayout()
            hlayouta.addWidget(pac['famp'])
            hlayouta.addWidget(pac['band_help_a'])

            flayout = QFormLayout(pac['box_metric'])
            flayout.addRow(pac['pac_on'])
            flayout.addRow('PAC metric',
                               pac['metric'])
            flayout.addRow('Phase frequencies (Hz)',
                               hlayoutp)
            flayout.addRow('Amplitude frequencies (Hz)',
                               hlayouta)
            flayout.addRow(*pac['nbin'])

            pac['box_surro'] = QGroupBox('Surrogate data')

            pac['surro_method'] = FormMenu(pac_surro)
            pac['surro_norm'] = FormMenu(pac_norm)
            pac['surro'] = sur = {}
            sur['nperm'] = QLabel('Number of surrogates'), FormInt(default=200)
            sur['nblocks'] = (QLabel('Number of amplitude blocks'),
                              FormInt(default=2))
            sur['pval'] = FormBool('Get p-values'), None
            sur['save_surro'] = FormBool('Save surrogate data'), None

            flayout = QFormLayout(pac['box_surro'])
            flayout.addRow(pac['surro_method'])
            flayout.addRow(pac['surro_norm'])
            flayout.addRow(*sur['nperm'])
            flayout.addRow(*sur['nblocks'])
            flayout.addRow(sur['pval'][0])
            flayout.addRow(sur['save_surro'][0])

            pac['box_opts'] = QGroupBox('Options')

            pac['optimize'] = FormMenu(['True', 'False', 'greedy', 'optimal'])
            pac['njobs'] = FormInt(default=-1)

            flayout = QFormLayout(pac['box_opts'])
            flayout.addRow('Optimize einsum',
                               pac['optimize'])
            flayout.addRow('Number of jobs',
                               pac['njobs'])

            hlayout = QHBoxLayout()
            hlayout.addWidget(pac['pac_on'])
            hlayout.addWidget(pac['prep'])

            vlayout = QVBoxLayout(tab_pac)
            vlayout.addLayout(hlayout)
            #vlayout.addWidget(QLabel(''))
            vlayout.addWidget(pac['box_metric'])
            vlayout.addWidget(pac['box_complex'])
            vlayout.addWidget(pac['box_surro'])
            vlayout.addWidget(pac['box_opts'])
            vlayout.addStretch(1)

        """ ------ EVENTS ------ """

        self.tab_evt = tab_evt = QWidget()

        self.event = ev = {}
        ev['global'] = eg = {}
        eg['count'] = FormBool('Count')
        eg['density'] = FormBool('Density, per (sec)')
        eg['density_per'] = FormFloat(30.0)
        eg['all_local'] = FormBool('All')
        eg['all_local_prep'] = FormBool('')

        ev['local'] = el = {}
        el['dur'] = FormBool('Duration (sec)'), FormBool('')
        el['minamp'] = FormBool('Min. amplitude (uV)'), FormBool('')
        el['maxamp'] = FormBool('Max. amplitude (uV)'), FormBool('')
        el['ptp'] = FormBool('Peak-to-peak amplitude (uV)'), FormBool('')
        el['rms'] = FormBool('RMS (uV)'), FormBool('')
        el['power'] = FormBool('Power (uV^2)'), FormBool('')
        el['energy'] = FormBool('Energy (uV^2s)'), FormBool('')
        el['peakpf'] = FormBool('Peak power frequency (Hz)'), FormBool('')
        el['peakef'] = FormBool('Peak energy frequency (Hz)'), FormBool('')

        ev['f1'] = FormFloat()
        ev['f2'] = FormFloat()

        ev['sw'] = {}
        ev['sw']['invert'] = FormBool('Inverted (down-then-up)')
        ev['sw']['prep'] = FormBool('Pre-process')
        ev['sw']['avg_slope'] = FormBool('Average slopes (uV/s)')
        ev['sw']['max_slope'] = FormBool('Max. slopes (uV/s^2)')

        box_global = QGroupBox('Global')

        grid1 = QGridLayout(box_global)
        grid1.addWidget(eg['count'], 0, 0)
        grid1.addWidget(eg['density'], 1, 0)
        grid1.addWidget(eg['density_per'], 1, 1)

        box_local = QGroupBox('Local')

        grid2 = QGridLayout(box_local)
        grid2.addWidget(QLabel('Parameter'), 0, 0)
        grid2.addWidget(QLabel('  '), 0, 1)
        grid2.addWidget(QLabel('Pre-process'), 0, 2)
        grid2.addWidget(eg['all_local'], 1, 0)
        grid2.addWidget(eg['all_local_prep'], 1, 2)
        grid2.addWidget(el['dur'][0], 2, 0)
        grid2.addWidget(el['minamp'][0], 3, 0)
        grid2.addWidget(el['minamp'][1], 3, 2)
        grid2.addWidget(el['maxamp'][0], 4, 0)
        grid2.addWidget(el['maxamp'][1], 4, 2)
        grid2.addWidget(el['ptp'][0], 5, 0)
        grid2.addWidget(el['ptp'][1], 5, 2)
        grid2.addWidget(el['rms'][0], 6, 0)
        grid2.addWidget(el['rms'][1], 6, 2)
        grid2.addWidget(el['power'][0], 7, 0)
        grid2.addWidget(el['power'][1], 7, 2)
        grid2.addWidget(el['energy'][0], 8, 0)
        grid2.addWidget(el['energy'][1], 8, 2)
        grid2.addWidget(el['peakpf'][0], 9, 0)
        grid2.addWidget(el['peakpf'][1], 9, 2)
        grid2.addWidget(el['peakef'][0], 10, 0)
        grid2.addWidget(el['peakef'][1], 10, 2)

        ev['band_box'] = QGroupBox('Band of interest')

        form = QFormLayout(ev['band_box'])
        form.addRow('Lowcut (Hz)', ev['f1'])
        form.addRow('Highcut (Hz)', ev['f2'])

        box_sw = QGroupBox('Slow wave')

        form = QFormLayout(box_sw)
        form.addRow(ev['sw']['avg_slope'])
        form.addRow(ev['sw']['max_slope'])
        form.addRow(ev['sw']['prep'])
        form.addRow(ev['sw']['invert'])

        grid = QGridLayout()
        grid.addWidget(box_global, 0, 0)
        grid.addWidget(ev['band_box'], 0, 1)
        grid.addWidget(box_local, 1, 0, 1, 2)
        grid.addWidget(box_sw, 2, 0, 1, 2)

        vlayout = QVBoxLayout(tab_evt)
        vlayout.addLayout(grid)
        vlayout.addStretch(1)

        """ ------ TRIGGERS ------ """

        for button in self.chunk.values():
            button.toggled.connect(self.toggle_buttons)
            button.toggled.connect(self.toggle_freq)

        for lw in [self.idx_chan, self.idx_cycle, self.idx_stage,
                   self.idx_evt_type]:
            lw.itemSelectionChanged.connect(self.toggle_concatenate)

        for button in [x[0] for x in self.event['local'].values()]:
            button.connect(self.toggle_buttons)

        self.chunk['epoch'].toggled.connect(self.toggle_concatenate)
        self.chunk['event'].toggled.connect(self.toggle_concatenate)
        self.idx_group.activated.connect(self.update_channels)
        self.lock_to_staging.connect(self.toggle_buttons)
        self.lock_to_staging.connect(self.toggle_concatenate)
        self.cat['discontinuous'].connect(self.toggle_concatenate)
        self.evt_chan_only.connect(self.update_nseg)

        epop['dur'].editingFinished.connect(self.update_nseg)
        epop['overlap_val'].valueChanged.connect(self.update_nseg)
        epop['step_val'].editingFinished.connect(self.update_nseg)
        epop['overlap'].connect(self.update_nseg)
        epop['overlap'].connect(self.toggle_buttons)
        self.min_dur.textChanged.connect(self.update_nseg)
        self.reject_epoch.connect(self.update_nseg)
        self.reject_event.connect(self.update_nseg)

        for box in self.cat.values():
            box.connect(self.update_nseg)

        self.trans['bandpass'].connect(self.toggle_buttons)
        self.trans['notch1'].connect(self.toggle_buttons)
        self.trans['notch2'].connect(self.toggle_buttons)

        freq['export_full'].connect(self.toggle_freq)
        freq['export_band'].connect(self.toggle_freq)
        freq['plot_on'].connect(self.toggle_freq)
        freq['fooof_on'].connect(self.toggle_freq)
        freq['taper'].connect(self.toggle_freq)
        freq['welch_on'].connect(self.toggle_freq)
        freq['complex'].clicked.connect(self.toggle_freq)
        freq['overlap'].connect(self.toggle_freq)
        freq['nhbw'].connect(self.toggle_freq)
        freq['norm'].activated.connect(self.toggle_freq)
        freq['nfft_fixed'].connect(self.toggle_freq)
        freq['nfft_zeropad'].connect(self.toggle_freq)
        freq['csd'].connect(self.toggle_freq)
        freq['gainphase'].connect(self.toggle_freq)
        #freq['phaseshift'].connect(self.toggle_freq)
        freq['coh'].connect(self.toggle_freq)
        freq['band_help'].clicked.connect(self.band_help)

        if Pac is not None:
            pac['pac_on'].connect(self.toggle_pac)
            pac['hilbert_on'].toggled.connect(self.toggle_pac)
            pac['wavelet_on'].toggled.connect(self.toggle_pac)
            pac['metric'].connect(self.toggle_pac)
            pac['surro_method'].connect(self.toggle_pac)
            pac['surro_norm'].connect(self.toggle_pac)
            pac['band_help_p'].clicked.connect(self.band_help)
            pac['band_help_a'].clicked.connect(partial(self.band_help, 'amp'))

        eg['density'].connect(self.toggle_buttons)
        eg['all_local'].clicked.connect(self.check_all_local)
        eg['all_local_prep'].clicked.connect(self.check_all_local_prep)
        for button in el.values():
            button[0].clicked.connect(self.uncheck_all_local)
            button[1].clicked.connect(self.uncheck_all_local)
        #ev['sw']['all_slope'].connect(self.check_all_slopes)
        ev['sw']['avg_slope'].connect(self.toggle_buttons)
        ev['sw']['max_slope'].connect(self.toggle_buttons)

        bbox.clicked.connect(self.button_clicked)

        """ ------ SET DEFAULTS ------ """

        self.evt_chan_only.setChecked(True)
        self.lock_to_staging.setChecked(True)
        self.chunk['epoch'].setChecked(True)
        self.reject_epoch.setChecked(True)
        epop['overlap'].setChecked(True)

        freq['prep'].setEnabled(False)
        freq['plot_on'].setEnabled(False)
        freq['box_param'].setEnabled(False)
        freq['box_welch'].setEnabled(False)
        freq['box_nfft'].setEnabled(False)
        freq['box_mtap'].setEnabled(False)
        freq['box_output'].setEnabled(False)
        freq['box_norm'].setEnabled(False)
        freq['box_cross'].setEnabled(False)
        freq['box_fooof'].setEnabled(False)
        freq['welch_on'].set_value(True)
        freq['nfft_seg'].setChecked(True)
        freq['spectrald'].setChecked(True)
        freq['detrend'].set_value('linear')
        freq['overlap'].setChecked(True)

        if Pac is not None:
            pac['prep'].setEnabled(False)
            pac['hilbert_on'].setChecked(True)
            pac['hilbert']['filt'][1].set_value('butter')
            pac['metric'].set_value('Kullback-Leibler Distance')
            pac['optimize'].set_value('False')
            pac['box_metric'].setEnabled(False)
            pac['box_complex'].setEnabled(False)
            pac['box_surro'].setEnabled(False)
            pac['box_opts'].setEnabled(False)

        el['dur'][1].set_value(False)

        """ ------ LAYOUT MASTER ------ """

        box3 = QTabWidget()

        box3.addTab(tab_freq, 'Frequency')
        if Pac is not None:
            box3.addTab(tab_pac, 'PAC')
        box3.addTab(tab_evt, 'Events')

        btnlayout = QHBoxLayout()
        btnlayout.addStretch(1)
        btnlayout.addWidget(bbox)

        hlayout1 = QHBoxLayout()
        hlayout1.addWidget(box_file)
        hlayout1.addWidget(box_nseg)

        hlayout2 = QHBoxLayout()
        hlayout2.addWidget(box_r)
        hlayout2.addWidget(box_c)

        vlayout1 = QVBoxLayout()
        vlayout1.addLayout(hlayout1)
        vlayout1.addWidget(box_loc)
        vlayout1.addWidget(box_chunk)
        vlayout1.addLayout(hlayout2)
        vlayout1.addWidget(box_pp)
        vlayout1.addStretch(1)

        vlayout2 = QVBoxLayout()
        vlayout2.addWidget(box3)
        vlayout2.addLayout(btnlayout)

        mhlayout = QHBoxLayout()
        mhlayout.addLayout(vlayout1)
        mhlayout.addLayout(vlayout2)
        mhlayout.addStretch(1)

        self.setLayout(mhlayout)
def create_dialog ( self ) : bbox = QDialogButtonBox ( QDialogButtonBox . Ok | QDialogButtonBox . Cancel ) self . idx_ok = bbox . button ( QDialogButtonBox . Ok ) self . idx_cancel = bbox . button ( QDialogButtonBox . Cancel ) """ ------ FILE LOCATION ------ """ box_file = QGroupBox ( 'File location' ) filebutton = QPushButton ( 'Choose' ) filebutton . clicked . connect ( self . save_as ) self . idx_filename = filebutton flayout = QFormLayout ( ) box_file . setLayout ( flayout ) flayout . addRow ( 'Filename' , self . idx_filename ) """ ------ N_SEG ------ """ box_nseg = QGroupBox ( 'Info' ) self . show_nseg = QLabel ( '' ) form = QFormLayout ( box_nseg ) form . addRow ( self . show_nseg ) """ ------ LOCATION ------ """ box_loc = QGroupBox ( 'Location' ) cghl = QHBoxLayout ( ) cghl . addWidget ( QLabel ( 'Channel group' ) ) cghl . addWidget ( self . idx_group ) cghl . addStretch ( 1 ) grid = QGridLayout ( box_loc ) grid . addLayout ( cghl , 0 , 0 , 1 , 3 ) grid . addWidget ( QLabel ( 'Channel(s)' ) , 1 , 0 ) grid . addWidget ( QLabel ( 'Cycle(s)' ) , 1 , 1 ) grid . addWidget ( QLabel ( 'Stage(s)' ) , 1 , 2 ) grid . addWidget ( self . idx_chan , 2 , 0 ) grid . addWidget ( self . idx_cycle , 2 , 1 ) grid . addWidget ( self . idx_stage , 2 , 2 ) """ ------ CHUNKING ------ """ box_chunk = QGroupBox ( 'Chunking' ) self . chunk = { } self . chunk [ 'event' ] = FormRadio ( 'by e&vent' ) self . evt_chan_only = FormBool ( 'Channel-specific' ) self . chunk [ 'epoch' ] = FormRadio ( 'by e&poch' ) self . epoch_param = epop = { } self . lock_to_staging = FormBool ( 'Lock to staging epochs' ) epop [ 'dur_label' ] = QLabel ( 'Duration (sec)' ) epop [ 'dur' ] = FormFloat ( 30. ) epop [ 'overlap' ] = FormRadio ( 'Overlap (0-1)' ) epop [ 'step' ] = FormRadio ( 'Step (sec)' ) epop [ 'overlap_val' ] = QDoubleSpinBox ( ) epop [ 'overlap_val' ] . setRange ( 0 , 0.9 ) epop [ 'overlap_val' ] . setSingleStep ( 0.1 ) epop [ 'overlap_val' ] . setValue ( 0. ) epop [ 'step_val' ] = FormFloat ( 30. ) self . chunk [ 'segment' ] = FormRadio ( 'by longest &run' ) evt_box = QListWidget ( ) evt_box . setSelectionMode ( QAbstractItemView . ExtendedSelection ) self . idx_evt_type = evt_box chunk_grp = QButtonGroup ( box_chunk ) chunk_grp . addButton ( self . chunk [ 'event' ] ) chunk_grp . addButton ( self . chunk [ 'epoch' ] ) chunk_grp . addButton ( self . chunk [ 'segment' ] ) epoch_grp = QButtonGroup ( box_chunk ) epoch_grp . addButton ( epop [ 'overlap' ] ) epoch_grp . addButton ( epop [ 'step' ] ) grid = QGridLayout ( box_chunk ) grid . addWidget ( self . chunk [ 'event' ] , 0 , 0 , 1 , 3 ) grid . addWidget ( QLabel ( '  ' ) , 1 , 0 ) grid . addWidget ( self . evt_chan_only , 1 , 1 , 1 , 2 ) grid . addWidget ( self . idx_evt_type , 2 , 1 , 3 , 2 ) grid . addWidget ( self . chunk [ 'epoch' ] , 0 , 3 , 1 , 3 ) grid . addWidget ( QLabel ( '  ' ) , 1 , 3 ) grid . addWidget ( self . lock_to_staging , 1 , 4 , 1 , 2 ) grid . addWidget ( epop [ 'dur_label' ] , 2 , 4 ) grid . addWidget ( epop [ 'dur' ] , 2 , 5 ) grid . addWidget ( epop [ 'overlap' ] , 3 , 4 ) grid . addWidget ( epop [ 'overlap_val' ] , 3 , 5 ) grid . addWidget ( epop [ 'step' ] , 4 , 4 ) grid . addWidget ( epop [ 'step_val' ] , 4 , 5 ) grid . addWidget ( self . chunk [ 'segment' ] , 0 , 6 ) """ ------ REJECTION ------ """ box_r = QGroupBox ( 'Rejection' ) self . min_dur = FormFloat ( 0.0 ) self . reject_epoch = FormBool ( 'Exclude Poor signal epochs' ) self . reject_event = FormMenu ( [ 'none' , 'channel-specific' , 'from any channel' ] ) flayout = QFormLayout ( ) box_r . setLayout ( flayout ) flayout . addRow ( self . reject_epoch ) flayout . addRow ( 'Exclude Artefact events' , self . reject_event ) flayout . addRow ( 'Minimum duration (sec)' , self . min_dur ) """ ------ CONCATENATION ------ """ box_c = QGroupBox ( 'Concatenation' ) self . cat = { } self . cat [ 'chan' ] = FormBool ( 'Concatenate channels' ) self . cat [ 'cycle' ] = FormBool ( 'Concatenate cycles' ) self . cat [ 'stage' ] = FormBool ( 'Concatenate between stages' ) self . cat [ 'discontinuous' ] = FormBool ( '' 'Concatenate discontinuous signal' ) self . cat [ 'evt_type' ] = FormBool ( 'Concatenate between event types' ) for box in self . cat . values ( ) : box . setEnabled ( False ) flayout = QFormLayout ( ) box_c . setLayout ( flayout ) flayout . addRow ( self . cat [ 'stage' ] ) flayout . addRow ( self . cat [ 'cycle' ] ) flayout . addRow ( self . cat [ 'evt_type' ] ) flayout . addRow ( self . cat [ 'discontinuous' ] ) flayout . addRow ( self . cat [ 'chan' ] ) """ ------ PRE-PROCESSING ------ """ box_pp = QGroupBox ( 'Pre-processing' ) self . trans = { } self . trans [ 'diff' ] = FormBool ( 'Differentiate' ) ftypes = [ 'none' , 'butter' , 'cheby1' , 'cheby2' , 'ellip' , 'bessel' , 'diff' ] self . trans [ 'bp' ] = tbp = { } self . trans [ 'bandpass' ] = FormMenu ( ftypes ) tbp [ 'order' ] = QLabel ( 'Order' ) , FormSpin ( 3 , 0 , 8 , 1 ) tbp [ 'f1' ] = QLabel ( 'Lowcut (Hz)' ) , FormFloat ( ) tbp [ 'f2' ] = QLabel ( 'Highcut (Hz)' ) , FormFloat ( ) self . trans [ 'n1' ] = tn1 = { } self . trans [ 'notch1' ] = FormMenu ( ftypes ) tn1 [ 'order' ] = QLabel ( 'Order' ) , FormSpin ( 3 , 0 , 8 , 1 ) tn1 [ 'cf' ] = QLabel ( 'CF (Hz)' ) , FormFloat ( ) tn1 [ 'bw' ] = QLabel ( 'BW (Hz)' ) , FormFloat ( ) self . trans [ 'n2' ] = tn2 = { } self . trans [ 'notch2' ] = FormMenu ( ftypes ) tn2 [ 'order' ] = QLabel ( 'Order' ) , FormSpin ( 3 , 0 , 8 , 1 ) tn2 [ 'cf' ] = QLabel ( 'CF (Hz)' ) , FormFloat ( ) tn2 [ 'bw' ] = QLabel ( 'BW (Hz)' ) , FormFloat ( ) form1 = QFormLayout ( ) form1 . addRow ( 'Bandpass' , self . trans [ 'bandpass' ] ) form1 . addRow ( * tbp [ 'order' ] ) form1 . addRow ( * tbp [ 'f1' ] ) form1 . addRow ( * tbp [ 'f2' ] ) form2 = QFormLayout ( ) form2 . addRow ( 'Notch 1' , self . trans [ 'notch1' ] ) form2 . addRow ( * tn1 [ 'order' ] ) form2 . addRow ( * tn1 [ 'cf' ] ) form2 . addRow ( * tn1 [ 'bw' ] ) form3 = QFormLayout ( ) form3 . addRow ( 'Notch 2' , self . trans [ 'notch2' ] ) form3 . addRow ( * tn2 [ 'order' ] ) form3 . addRow ( * tn2 [ 'cf' ] ) form3 . addRow ( * tn2 [ 'bw' ] ) grid = QGridLayout ( box_pp ) grid . addWidget ( self . trans [ 'diff' ] , 0 , 0 , 1 , 3 ) grid . addLayout ( form1 , 1 , 0 ) grid . addLayout ( form2 , 1 , 1 ) grid . addLayout ( form3 , 1 , 2 ) """ ------ FREQUENCY ------ """ self . tab_freq = tab_freq = QWidget ( ) self . frequency = freq = { } box_freq_main = QGroupBox ( 'Options' ) freq [ 'export_full' ] = FormBool ( 'Full spectrum' ) freq [ 'export_band' ] = FormBool ( 'Band-limited' ) freq [ 'plot_on' ] = FormBool ( 'Plot mean spectrum' ) freq [ 'fooof_on' ] = FormBool ( 'Parametrize' ) freq [ 'prep' ] = FormBool ( 'Pre-process' ) form = QFormLayout ( box_freq_main ) form . addRow ( freq [ 'prep' ] ) form . addRow ( freq [ 'export_full' ] ) form . addRow ( freq [ 'export_band' ] ) form . addRow ( freq [ 'plot_on' ] ) form . addRow ( freq [ 'fooof_on' ] ) freq [ 'box_param' ] = QGroupBox ( 'Parameters' ) freq [ 'scaling' ] = FormMenu ( [ 'power' , 'energy' , 'fieldtrip' , 'chronux' ] ) freq [ 'taper' ] = FormMenu ( [ 'boxcar' , 'hann' , 'dpss' , 'triang' , 'blackman' , 'hamming' , 'bartlett' , 'flattop' , 'parzen' , 'bohman' , 'blackmanharris' , 'nuttall' , 'barthann' ] ) freq [ 'detrend' ] = FormMenu ( [ 'none' , 'constant' , 'linear' ] ) freq [ 'welch_on' ] = FormBool ( "Time-averaged" ) freq [ 'log_trans' ] = FormBool ( 'Log-transform' ) form = QFormLayout ( freq [ 'box_param' ] ) form . addRow ( 'Scaling' , freq [ 'scaling' ] ) form . addRow ( 'Taper' , freq [ 'taper' ] ) form . addRow ( 'Detrend' , freq [ 'detrend' ] ) form . addRow ( freq [ 'welch_on' ] ) form . addRow ( freq [ 'log_trans' ] ) freq [ 'box_welch' ] = QGroupBox ( "Time averaging" ) freq [ 'duration' ] = FormFloat ( 1 ) freq [ 'overlap' ] = FormRadio ( 'Overlap (0-1)' ) freq [ 'step' ] = FormRadio ( 'Step (sec)' ) freq [ 'overlap_val' ] = QDoubleSpinBox ( ) freq [ 'overlap_val' ] . setRange ( 0 , 1 ) freq [ 'overlap_val' ] . setSingleStep ( 0.1 ) freq [ 'overlap_val' ] . setValue ( 0.5 ) freq [ 'step_val' ] = FormFloat ( 0.5 ) freq [ 'centend' ] = FormMenu ( [ 'mean' , 'median' ] ) grid = QGridLayout ( freq [ 'box_welch' ] ) grid . addWidget ( QLabel ( 'Duration (sec)' ) , 0 , 0 ) grid . addWidget ( freq [ 'duration' ] , 0 , 1 ) grid . addWidget ( freq [ 'overlap' ] , 1 , 0 ) grid . addWidget ( freq [ 'step' ] , 2 , 0 ) grid . addWidget ( freq [ 'overlap_val' ] , 1 , 1 ) grid . addWidget ( freq [ 'step_val' ] , 2 , 1 ) grid . addWidget ( QLabel ( 'Central tendency' ) , 3 , 0 ) grid . addWidget ( freq [ 'centend' ] , 3 , 1 ) freq [ 'box_mtap' ] = QGroupBox ( 'Multitaper method (DPSS) smoothing' ) freq [ 'nhbw' ] = FormBool ( 'Normalized' ) freq [ 'hbw' ] = FormSpin ( 3 , 0 ) freq [ 'nhbw_val' ] = FormSpin ( min_val = 0 ) grid = QGridLayout ( freq [ 'box_mtap' ] ) grid . addWidget ( QLabel ( 'Half bandwidth (Hz)' ) , 0 , 0 ) grid . addWidget ( freq [ 'nhbw' ] , 1 , 0 ) grid . addWidget ( freq [ 'hbw' ] , 0 , 1 ) grid . addWidget ( freq [ 'nhbw_val' ] , 1 , 1 ) freq [ 'box_output' ] = QGroupBox ( 'Output' ) freq [ 'spectrald' ] = FormRadio ( 'Spectral density' ) freq [ 'complex' ] = FormRadio ( 'Complex' ) freq [ 'sides' ] = FormSpin ( min_val = 1 , max_val = 2 ) grid = QGridLayout ( freq [ 'box_output' ] ) grid . addWidget ( freq [ 'spectrald' ] , 0 , 0 , 1 , 3 ) grid . addWidget ( freq [ 'complex' ] , 1 , 0 , 1 , 3 ) freq [ 'box_nfft' ] = QGroupBox ( 'FFT length' ) freq [ 'nfft_seg' ] = FormRadio ( 'Same as segment' ) freq [ 'nfft_fixed' ] = FormRadio ( 'Fixed:' ) freq [ 'nfft_fixed_val' ] = FormInt ( ) freq [ 'nfft_zeropad' ] = FormRadio ( 'Zero-pad to longest segment' ) grid = QGridLayout ( freq [ 'box_nfft' ] ) grid . addWidget ( freq [ 'nfft_seg' ] , 0 , 0 , 1 , 2 ) grid . addWidget ( freq [ 'nfft_fixed' ] , 1 , 0 ) grid . addWidget ( freq [ 'nfft_fixed_val' ] , 1 , 1 ) grid . addWidget ( freq [ 'nfft_zeropad' ] , 2 , 0 , 1 , 2 ) freq [ 'box_norm' ] = QGroupBox ( 'Normalization' ) freq [ 'norm' ] = FormMenu ( [ 'none' , 'by integral of each segment' , 'by mean of event type(s)' , 'by mean of stage(s)' ] ) evt_box = QListWidget ( ) evt_box . setSelectionMode ( QAbstractItemView . ExtendedSelection ) freq [ 'norm_evt_type' ] = evt_box stage_box = QListWidget ( ) stage_box . setSelectionMode ( QAbstractItemView . ExtendedSelection ) stage_box . addItems ( STAGE_NAME ) freq [ 'norm_stage' ] = stage_box freq [ 'norm_concat' ] = FormBool ( 'Concatenate' ) grid = QGridLayout ( freq [ 'box_norm' ] ) grid . addWidget ( freq [ 'norm' ] , 0 , 0 , 1 , 2 ) grid . addWidget ( QLabel ( 'Event type(s)' ) , 1 , 0 ) grid . addWidget ( QLabel ( 'Stage(s)' ) , 1 , 1 ) grid . addWidget ( freq [ 'norm_evt_type' ] , 2 , 0 ) grid . addWidget ( freq [ 'norm_stage' ] , 2 , 1 ) grid . addWidget ( freq [ 'norm_concat' ] , 3 , 0 , 1 , 2 ) freq [ 'box_cross' ] = QGroupBox ( 'Cross-spectrum' ) freq [ 'csd' ] = FormBool ( 'Cross-spectrum' ) freq [ 'gainphase' ] = FormBool ( 'Gain and phase shift' ) freq [ 'coh' ] = FormBool ( 'Coherence' ) form = QFormLayout ( freq [ 'box_cross' ] ) form . addRow ( freq [ 'csd' ] ) form . addRow ( freq [ 'gainphase' ] ) form . addRow ( freq [ 'coh' ] ) freq [ 'box_fooof' ] = QGroupBox ( 'Parametrization' ) freq [ 'fo_min_freq' ] = FormFloat ( 2. ) freq [ 'fo_max_freq' ] = FormFloat ( 30. ) freq [ 'fo_pk_thresh' ] = FormFloat ( 2. ) freq [ 'fo_pk_width_min' ] = FormFloat ( .5 ) freq [ 'fo_pk_width_max' ] = FormFloat ( 12. ) freq [ 'fo_max_n_pk' ] = FormInt ( ) freq [ 'fo_min_pk_amp' ] = FormFloat ( 0 ) freq [ 'fo_bg_mode' ] = FormMenu ( [ 'fixed' , 'knee' ] ) freqhbox = QHBoxLayout ( ) freqhbox . addWidget ( QLabel ( 'Frequencies:' ) ) freqhbox . addWidget ( freq [ 'fo_min_freq' ] ) freqhbox . addWidget ( QLabel ( '-' ) ) freqhbox . addWidget ( freq [ 'fo_max_freq' ] ) freqhbox . addWidget ( QLabel ( 'Hz' ) ) widhbox = QHBoxLayout ( ) widhbox . addWidget ( QLabel ( 'Peak width:' ) ) widhbox . addWidget ( freq [ 'fo_pk_width_min' ] ) widhbox . addWidget ( QLabel ( '-' ) ) widhbox . addWidget ( freq [ 'fo_pk_width_max' ] ) widhbox . addWidget ( QLabel ( 'Hz' ) ) form = QFormLayout ( freq [ 'box_fooof' ] ) form . addRow ( freqhbox ) form . addRow ( widhbox ) form . addRow ( 'Peak threshold (SD)' , freq [ 'fo_pk_thresh' ] ) form . addRow ( 'Max. number of peaks' , freq [ 'fo_max_n_pk' ] ) form . addRow ( 'Min. peak amplitude' , freq [ 'fo_min_pk_amp' ] ) form . addRow ( 'Background fitting mode' , freq [ 'fo_bg_mode' ] ) freq [ 'box_band' ] = QGroupBox ( 'Define bands' ) freq [ 'band' ] = FormStr ( ) freq [ 'band_help' ] = QPushButton ( QIcon ( ICON [ 'help-about' ] ) , '' , self ) hlayout = QHBoxLayout ( ) hlayout . addWidget ( freq [ 'band' ] ) hlayout . addWidget ( freq [ 'band_help' ] ) vlayout = QVBoxLayout ( freq [ 'box_band' ] ) vlayout . addLayout ( hlayout ) vlayout1 = QVBoxLayout ( ) vlayout1 . addWidget ( box_freq_main ) vlayout1 . addWidget ( freq [ 'box_param' ] ) vlayout1 . addWidget ( freq [ 'box_welch' ] ) vlayout1 . addWidget ( freq [ 'box_nfft' ] ) vlayout1 . addWidget ( freq [ 'box_mtap' ] ) vlayout1 . addWidget ( freq [ 'box_output' ] ) vlayout1 . addStretch ( 1 ) vlayout2 = QVBoxLayout ( ) vlayout2 . addWidget ( freq [ 'box_band' ] ) vlayout2 . addWidget ( freq [ 'box_norm' ] ) vlayout2 . addWidget ( freq [ 'box_cross' ] ) vlayout2 . addWidget ( freq [ 'box_fooof' ] ) vlayout2 . addStretch ( 1 ) hlayout = QHBoxLayout ( ) hlayout . addLayout ( vlayout1 ) hlayout . addLayout ( vlayout2 ) vlayout = QVBoxLayout ( tab_freq ) vlayout . addLayout ( hlayout ) """ ------ PAC ------ """ if Pac is not None : self . tab_pac = tab_pac = QWidget ( ) pac_metrics = [ pacstr ( ( x , 0 , 0 ) ) [ 0 ] for x in range ( 1 , 6 ) ] pac_metrics = [ x [ : x . index ( '(' ) - 1 ] for x in pac_metrics ] pac_metrics [ 1 ] = 'Kullback-Leibler Distance' pac_surro = [ pacstr ( ( 1 , x , 0 ) ) [ 1 ] for x in range ( 5 ) ] pac_norm = [ pacstr ( ( 1 , 0 , x ) ) [ 2 ] for x in range ( 5 ) ] self . pac = pac = { } pac [ 'box_complex' ] = QGroupBox ( 'Complex definition' ) pac [ 'hilbert_on' ] = FormRadio ( 'Hilbert transform' ) pac [ 'hilbert' ] = hilb = { } hilb [ 'filt' ] = QLabel ( 'Filter' ) , FormMenu ( [ 'fir1' , 'butter' , 'bessel' ] ) hilb [ 'cycle_pha' ] = QLabel ( 'Cycles, phase' ) , FormInt ( default = 3 ) hilb [ 'cycle_amp' ] = QLabel ( 'Cycles, amp' ) , FormInt ( default = 6 ) hilb [ 'order' ] = QLabel ( 'Order' ) , FormInt ( default = 3 ) pac [ 'wavelet_on' ] = FormRadio ( 'Wavelet convolution' ) pac [ 'wav_width' ] = QLabel ( 'Width' ) , FormInt ( default = 7 ) grid = QGridLayout ( pac [ 'box_complex' ] ) grid . addWidget ( pac [ 'hilbert_on' ] , 0 , 0 , 1 , 2 ) grid . addWidget ( hilb [ 'filt' ] [ 0 ] , 1 , 0 ) grid . addWidget ( hilb [ 'filt' ] [ 1 ] , 1 , 1 ) grid . addWidget ( hilb [ 'cycle_pha' ] [ 0 ] , 2 , 0 ) grid . addWidget ( hilb [ 'cycle_pha' ] [ 1 ] , 2 , 1 ) grid . addWidget ( hilb [ 'cycle_amp' ] [ 0 ] , 3 , 0 ) grid . addWidget ( hilb [ 'cycle_amp' ] [ 1 ] , 3 , 1 ) grid . addWidget ( hilb [ 'order' ] [ 0 ] , 4 , 0 ) grid . addWidget ( hilb [ 'order' ] [ 1 ] , 4 , 1 ) grid . addWidget ( pac [ 'wavelet_on' ] , 0 , 3 , 1 , 2 ) grid . addWidget ( pac [ 'wav_width' ] [ 0 ] , 1 , 3 ) grid . addWidget ( pac [ 'wav_width' ] [ 1 ] , 1 , 4 ) pac [ 'box_metric' ] = QGroupBox ( 'PAC metric' ) pac [ 'pac_on' ] = FormBool ( 'Compute PAC' ) pac [ 'prep' ] = FormBool ( 'Pre-process' ) pac [ 'metric' ] = FormMenu ( pac_metrics ) pac [ 'fpha' ] = FormStr ( ) pac [ 'famp' ] = FormStr ( ) pac [ 'band_help_p' ] = QPushButton ( QIcon ( ICON [ 'help-about' ] ) , '' , self ) pac [ 'band_help_a' ] = QPushButton ( QIcon ( ICON [ 'help-about' ] ) , '' , self ) pac [ 'nbin' ] = QLabel ( 'Number of bins' ) , FormInt ( default = 18 ) hlayoutp = QHBoxLayout ( ) hlayoutp . addWidget ( pac [ 'fpha' ] ) hlayoutp . addWidget ( pac [ 'band_help_p' ] ) hlayouta = QHBoxLayout ( ) hlayouta . addWidget ( pac [ 'famp' ] ) hlayouta . addWidget ( pac [ 'band_help_a' ] ) flayout = QFormLayout ( pac [ 'box_metric' ] ) flayout . addRow ( pac [ 'pac_on' ] ) flayout . addRow ( 'PAC metric' , pac [ 'metric' ] ) flayout . addRow ( 'Phase frequencies (Hz)' , hlayoutp ) flayout . addRow ( 'Amplitude frequencies (Hz)' , hlayouta ) flayout . addRow ( * pac [ 'nbin' ] ) pac [ 'box_surro' ] = QGroupBox ( 'Surrogate data' ) pac [ 'surro_method' ] = FormMenu ( pac_surro ) pac [ 'surro_norm' ] = FormMenu ( pac_norm ) pac [ 'surro' ] = sur = { } sur [ 'nperm' ] = QLabel ( 'Number of surrogates' ) , FormInt ( default = 200 ) sur [ 'nblocks' ] = ( QLabel ( 'Number of amplitude blocks' ) , FormInt ( default = 2 ) ) sur [ 'pval' ] = FormBool ( 'Get p-values' ) , None sur [ 'save_surro' ] = FormBool ( 'Save surrogate data' ) , None flayout = QFormLayout ( pac [ 'box_surro' ] ) flayout . addRow ( pac [ 'surro_method' ] ) flayout . addRow ( pac [ 'surro_norm' ] ) flayout . addRow ( * sur [ 'nperm' ] ) flayout . addRow ( * sur [ 'nblocks' ] ) flayout . addRow ( sur [ 'pval' ] [ 0 ] ) flayout . addRow ( sur [ 'save_surro' ] [ 0 ] ) pac [ 'box_opts' ] = QGroupBox ( 'Options' ) pac [ 'optimize' ] = FormMenu ( [ 'True' , 'False' , 'greedy' , 'optimal' ] ) pac [ 'njobs' ] = FormInt ( default = - 1 ) flayout = QFormLayout ( pac [ 'box_opts' ] ) flayout . addRow ( 'Optimize einsum' , pac [ 'optimize' ] ) flayout . addRow ( 'Number of jobs' , pac [ 'njobs' ] ) hlayout = QHBoxLayout ( ) hlayout . addWidget ( pac [ 'pac_on' ] ) hlayout . addWidget ( pac [ 'prep' ] ) vlayout = QVBoxLayout ( tab_pac ) vlayout . addLayout ( hlayout ) vlayout . addWidget ( pac [ 'box_metric' ] ) vlayout . addWidget ( pac [ 'box_complex' ] ) vlayout . addWidget ( pac [ 'box_surro' ] ) vlayout . addWidget ( pac [ 'box_opts' ] ) vlayout . addStretch ( 1 ) """ ------ EVENTS ------ """ self . tab_evt = tab_evt = QWidget ( ) self . event = ev = { } ev [ 'global' ] = eg = { } eg [ 'count' ] = FormBool ( 'Count' ) eg [ 'density' ] = FormBool ( 'Density, per (sec)' ) eg [ 'density_per' ] = FormFloat ( 30.0 ) eg [ 'all_local' ] = FormBool ( 'All' ) eg [ 'all_local_prep' ] = FormBool ( '' ) ev [ 'local' ] = el = { } el [ 'dur' ] = FormBool ( 'Duration (sec)' ) , FormBool ( '' ) el [ 'minamp' ] = FormBool ( 'Min. amplitude (uV)' ) , FormBool ( '' ) el [ 'maxamp' ] = FormBool ( 'Max. amplitude (uV)' ) , FormBool ( '' ) el [ 'ptp' ] = FormBool ( 'Peak-to-peak amplitude (uV)' ) , FormBool ( '' ) el [ 'rms' ] = FormBool ( 'RMS (uV)' ) , FormBool ( '' ) el [ 'power' ] = FormBool ( 'Power (uV^2)' ) , FormBool ( '' ) el [ 'energy' ] = FormBool ( 'Energy (uV^2s)' ) , FormBool ( '' ) el [ 'peakpf' ] = FormBool ( 'Peak power frequency (Hz)' ) , FormBool ( '' ) el [ 'peakef' ] = FormBool ( 'Peak energy frequency (Hz)' ) , FormBool ( '' ) ev [ 'f1' ] = FormFloat ( ) ev [ 'f2' ] = FormFloat ( ) ev [ 'sw' ] = { } ev [ 'sw' ] [ 'invert' ] = FormBool ( 'Inverted (down-then-up)' ) ev [ 'sw' ] [ 'prep' ] = FormBool ( 'Pre-process' ) ev [ 'sw' ] [ 'avg_slope' ] = FormBool ( 'Average slopes (uV/s)' ) ev [ 'sw' ] [ 'max_slope' ] = FormBool ( 'Max. slopes (uV/s^2)' ) box_global = QGroupBox ( 'Global' ) grid1 = QGridLayout ( box_global ) grid1 . addWidget ( eg [ 'count' ] , 0 , 0 ) grid1 . addWidget ( eg [ 'density' ] , 1 , 0 ) grid1 . addWidget ( eg [ 'density_per' ] , 1 , 1 ) box_local = QGroupBox ( 'Local' ) grid2 = QGridLayout ( box_local ) grid2 . addWidget ( QLabel ( 'Parameter' ) , 0 , 0 ) grid2 . addWidget ( QLabel ( '  ' ) , 0 , 1 ) grid2 . addWidget ( QLabel ( 'Pre-process' ) , 0 , 2 ) grid2 . addWidget ( eg [ 'all_local' ] , 1 , 0 ) grid2 . addWidget ( eg [ 'all_local_prep' ] , 1 , 2 ) grid2 . addWidget ( el [ 'dur' ] [ 0 ] , 2 , 0 ) grid2 . addWidget ( el [ 'minamp' ] [ 0 ] , 3 , 0 ) grid2 . addWidget ( el [ 'minamp' ] [ 1 ] , 3 , 2 ) grid2 . addWidget ( el [ 'maxamp' ] [ 0 ] , 4 , 0 ) grid2 . addWidget ( el [ 'maxamp' ] [ 1 ] , 4 , 2 ) grid2 . addWidget ( el [ 'ptp' ] [ 0 ] , 5 , 0 ) grid2 . addWidget ( el [ 'ptp' ] [ 1 ] , 5 , 2 ) grid2 . addWidget ( el [ 'rms' ] [ 0 ] , 6 , 0 ) grid2 . addWidget ( el [ 'rms' ] [ 1 ] , 6 , 2 ) grid2 . addWidget ( el [ 'power' ] [ 0 ] , 7 , 0 ) grid2 . addWidget ( el [ 'power' ] [ 1 ] , 7 , 2 ) grid2 . addWidget ( el [ 'energy' ] [ 0 ] , 8 , 0 ) grid2 . addWidget ( el [ 'energy' ] [ 1 ] , 8 , 2 ) grid2 . addWidget ( el [ 'peakpf' ] [ 0 ] , 9 , 0 ) grid2 . addWidget ( el [ 'peakpf' ] [ 1 ] , 9 , 2 ) grid2 . addWidget ( el [ 'peakef' ] [ 0 ] , 10 , 0 ) grid2 . addWidget ( el [ 'peakef' ] [ 1 ] , 10 , 2 ) ev [ 'band_box' ] = QGroupBox ( 'Band of interest' ) form = QFormLayout ( ev [ 'band_box' ] ) form . addRow ( 'Lowcut (Hz)' , ev [ 'f1' ] ) form . addRow ( 'Highcut (Hz)' , ev [ 'f2' ] ) box_sw = QGroupBox ( 'Slow wave' ) form = QFormLayout ( box_sw ) form . addRow ( ev [ 'sw' ] [ 'avg_slope' ] ) form . addRow ( ev [ 'sw' ] [ 'max_slope' ] ) form . addRow ( ev [ 'sw' ] [ 'prep' ] ) form . addRow ( ev [ 'sw' ] [ 'invert' ] ) grid = QGridLayout ( ) grid . addWidget ( box_global , 0 , 0 ) grid . addWidget ( ev [ 'band_box' ] , 0 , 1 ) grid . addWidget ( box_local , 1 , 0 , 1 , 2 ) grid . addWidget ( box_sw , 2 , 0 , 1 , 2 ) vlayout = QVBoxLayout ( tab_evt ) vlayout . addLayout ( grid ) vlayout . addStretch ( 1 ) """ ------ TRIGGERS ------ """ for button in self . chunk . values ( ) : button . toggled . connect ( self . toggle_buttons ) button . toggled . connect ( self . toggle_freq ) for lw in [ self . idx_chan , self . idx_cycle , self . idx_stage , self . idx_evt_type ] : lw . itemSelectionChanged . connect ( self . toggle_concatenate ) for button in [ x [ 0 ] for x in self . event [ 'local' ] . values ( ) ] : button . connect ( self . toggle_buttons ) self . chunk [ 'epoch' ] . toggled . connect ( self . toggle_concatenate ) self . chunk [ 'event' ] . toggled . connect ( self . toggle_concatenate ) self . idx_group . activated . connect ( self . update_channels ) self . lock_to_staging . connect ( self . toggle_buttons ) self . lock_to_staging . connect ( self . toggle_concatenate ) self . cat [ 'discontinuous' ] . connect ( self . toggle_concatenate ) self . evt_chan_only . connect ( self . update_nseg ) epop [ 'dur' ] . editingFinished . connect ( self . update_nseg ) epop [ 'overlap_val' ] . valueChanged . connect ( self . update_nseg ) epop [ 'step_val' ] . editingFinished . connect ( self . update_nseg ) epop [ 'overlap' ] . connect ( self . update_nseg ) epop [ 'overlap' ] . connect ( self . toggle_buttons ) self . min_dur . textChanged . connect ( self . update_nseg ) self . reject_epoch . connect ( self . update_nseg ) self . reject_event . connect ( self . update_nseg ) for box in self . cat . values ( ) : box . connect ( self . update_nseg ) self . trans [ 'bandpass' ] . connect ( self . toggle_buttons ) self . trans [ 'notch1' ] . connect ( self . toggle_buttons ) self . trans [ 'notch2' ] . connect ( self . toggle_buttons ) freq [ 'export_full' ] . connect ( self . toggle_freq ) freq [ 'export_band' ] . connect ( self . toggle_freq ) freq [ 'plot_on' ] . connect ( self . toggle_freq ) freq [ 'fooof_on' ] . connect ( self . toggle_freq ) freq [ 'taper' ] . connect ( self . toggle_freq ) freq [ 'welch_on' ] . connect ( self . toggle_freq ) freq [ 'complex' ] . clicked . connect ( self . toggle_freq ) freq [ 'overlap' ] . connect ( self . toggle_freq ) freq [ 'nhbw' ] . connect ( self . toggle_freq ) freq [ 'norm' ] . activated . connect ( self . toggle_freq ) freq [ 'nfft_fixed' ] . connect ( self . toggle_freq ) freq [ 'nfft_zeropad' ] . connect ( self . toggle_freq ) freq [ 'csd' ] . connect ( self . toggle_freq ) freq [ 'gainphase' ] . connect ( self . toggle_freq ) freq [ 'coh' ] . connect ( self . toggle_freq ) freq [ 'band_help' ] . clicked . connect ( self . band_help ) if Pac is not None : pac [ 'pac_on' ] . connect ( self . toggle_pac ) pac [ 'hilbert_on' ] . toggled . connect ( self . toggle_pac ) pac [ 'wavelet_on' ] . toggled . connect ( self . toggle_pac ) pac [ 'metric' ] . connect ( self . toggle_pac ) pac [ 'surro_method' ] . connect ( self . toggle_pac ) pac [ 'surro_norm' ] . connect ( self . toggle_pac ) pac [ 'band_help_p' ] . clicked . connect ( self . band_help ) pac [ 'band_help_a' ] . clicked . connect ( partial ( self . band_help , 'amp' ) ) eg [ 'density' ] . connect ( self . toggle_buttons ) eg [ 'all_local' ] . clicked . connect ( self . check_all_local ) eg [ 'all_local_prep' ] . clicked . connect ( self . check_all_local_prep ) for button in el . values ( ) : button [ 0 ] . clicked . connect ( self . uncheck_all_local ) button [ 1 ] . clicked . connect ( self . uncheck_all_local ) ev [ 'sw' ] [ 'avg_slope' ] . connect ( self . toggle_buttons ) ev [ 'sw' ] [ 'max_slope' ] . connect ( self . toggle_buttons ) bbox . clicked . connect ( self . button_clicked ) """ ------ SET DEFAULTS ------ """ self . evt_chan_only . setChecked ( True ) self . lock_to_staging . setChecked ( True ) self . chunk [ 'epoch' ] . setChecked ( True ) self . reject_epoch . setChecked ( True ) epop [ 'overlap' ] . setChecked ( True ) freq [ 'prep' ] . setEnabled ( False ) freq [ 'plot_on' ] . setEnabled ( False ) freq [ 'box_param' ] . setEnabled ( False ) freq [ 'box_welch' ] . setEnabled ( False ) freq [ 'box_nfft' ] . setEnabled ( False ) freq [ 'box_mtap' ] . setEnabled ( False ) freq [ 'box_output' ] . setEnabled ( False ) freq [ 'box_norm' ] . setEnabled ( False ) freq [ 'box_cross' ] . setEnabled ( False ) freq [ 'box_fooof' ] . setEnabled ( False ) freq [ 'welch_on' ] . set_value ( True ) freq [ 'nfft_seg' ] . setChecked ( True ) freq [ 'spectrald' ] . setChecked ( True ) freq [ 'detrend' ] . set_value ( 'linear' ) freq [ 'overlap' ] . setChecked ( True ) if Pac is not None : pac [ 'prep' ] . setEnabled ( False ) pac [ 'hilbert_on' ] . setChecked ( True ) pac [ 'hilbert' ] [ 'filt' ] [ 1 ] . set_value ( 'butter' ) pac [ 'metric' ] . set_value ( 'Kullback-Leibler Distance' ) pac [ 'optimize' ] . set_value ( 'False' ) pac [ 'box_metric' ] . setEnabled ( False ) pac [ 'box_complex' ] . setEnabled ( False ) pac [ 'box_surro' ] . setEnabled ( False ) pac [ 'box_opts' ] . setEnabled ( False ) el [ 'dur' ] [ 1 ] . set_value ( False ) """ ------ LAYOUT MASTER ------ """ box3 = QTabWidget ( ) box3 . addTab ( tab_freq , 'Frequency' ) if Pac is not None : box3 . addTab ( tab_pac , 'PAC' ) box3 . addTab ( tab_evt , 'Events' ) btnlayout = QHBoxLayout ( ) btnlayout . addStretch ( 1 ) btnlayout . addWidget ( bbox ) hlayout1 = QHBoxLayout ( ) hlayout1 . addWidget ( box_file ) hlayout1 . addWidget ( box_nseg ) hlayout2 = QHBoxLayout ( ) hlayout2 . addWidget ( box_r ) hlayout2 . addWidget ( box_c ) vlayout1 = QVBoxLayout ( ) vlayout1 . addLayout ( hlayout1 ) vlayout1 . addWidget ( box_loc ) vlayout1 . addWidget ( box_chunk ) vlayout1 . addLayout ( hlayout2 ) vlayout1 . addWidget ( box_pp ) vlayout1 . addStretch ( 1 ) vlayout2 = QVBoxLayout ( ) vlayout2 . addWidget ( box3 ) vlayout2 . addLayout ( btnlayout ) mhlayout = QHBoxLayout ( ) mhlayout . addLayout ( vlayout1 ) mhlayout . addLayout ( vlayout2 ) mhlayout . addStretch ( 1 ) self . setLayout ( mhlayout )
Create the dialog.