<commit_before>import wx
import numpy as np
from FileHandler import ReadXYZ
from scipy.signal import butter, filtfilt


class Results():

    def __init__(self):
        """EMPTY INITIATION"""

    def updateAll(self, Data):

        # Get Specifications
        self.removeDC = Data.Specs.CheckboxDC.GetValue()
        self.average = Data.Specs.CheckboxAverage.GetValue()
        self.newReference = Data.Specs.DropDownNewRef.GetValue()
        self.doPass = Data.Specs.CheckboxPass.GetValue()
        try:
            self.lowcut = float(Data.Specs.LowPass.GetValue())
        except ValueError:
            self.lowcut = 80.0
            Data.Specs.LowPass.SetValue(str(self.lowcut))
        try:
            self.highcut = float(Data.Specs.HighPass.GetValue())
        except ValueError:
            self.highcut = 0.1
            Data.Specs.HighPass.SetValue(str(self.highcut))
        self.doNotch = Data.Specs.CheckboxNotch.GetValue()
        try:
            self.notchValue = float(Data.Specs.Notch.GetValue())
        except ValueError:
            self.notchValue = 50.0
            Data.Specs.Notch.SetValue(str(self.notch))
        try:
            self.preEpoch = float(Data.Specs.PreEpoch.GetValue())
        except ValueError:
            self.preEpoch = 100.0
            Data.Specs.PreEpoch.SetValue(str(self.preEpoch))
        try:
            self.postEpoch = float(Data.Specs.PostEpoch.GetValue())
        except ValueError:
            self.postEpoch = 500.0
            Data.Specs.PostEpoch.SetValue(str(self.postEpoch))
        self.sampleRate = Data.Datasets[0].sampleRate

        # Data object to save original epoch information
        Data.Orig = type('Orig', (object,), {})()

        # Filter Channel Signal
        for i, d in enumerate(Data.Datasets):
            dataset = np.copy(d.rawdata)

            # 1. Remove DC
            if self.removeDC:
                dataset -= np.vstack(dataset.mean(axis=1))

            # 2. Average or specific reference
            if self.average:
                dataset -= dataset.mean(axis=0)
            elif self.newReference != '':
                electrodeID = np.where(d.labelsChannel == self.newReference)[0]
                if self.newReference != 'Average':
                    dataset -= dataset[electrodeID]

            # 3. Run Butterworth Low-, High- or Bandpassfilter
            if self.doPass:
                if self.lowcut != 0 and self.highcut != 0:
                    dataset = butter_bandpass_filter(dataset,
                                                     d.sampleRate,
                                                     highcut=self.highcut,
                                                     lowcut=self.lowcut)

            # 4. Notch Filter
            if self.doNotch:
                dataset = butter_bandpass_filter(dataset,
                                                 d.sampleRate,
                                                 notch=self.notchValue)

            # Create epochs
            self.preFrame = int(
                np.round(self.preEpoch * self.sampleRate * 0.001))
            self.preCut = np.copy(self.preFrame)
            self.postFrame = int(
                np.round(self.postEpoch * self.sampleRate * 0.001))
            self.postCut = np.copy(self.postFrame)

            """
            # time pre stimuli should be at least 200ms for visualization
            if self.preEpoch < 200.0:
                self.preCut = int(self.sampleRate * .2)<commit_msg>FIX: put butterworth filter from cartool into place<commit_after>import wx
import numpy as np
from FileHandler import ReadXYZ
from scipy.signal import butter, filtfilt


class Results():

    def __init__(self):
        """EMPTY INITIATION"""

    def updateAll(self, Data):

        # Get Specifications
        self.removeDC = Data.Specs.CheckboxDC.GetValue()
        self.average = Data.Specs.CheckboxAverage.GetValue()
        self.newReference = Data.Specs.DropDownNewRef.GetValue()
        self.doPass = Data.Specs.CheckboxPass.GetValue()
        try:
            self.lowcut = float(Data.Specs.LowPass.GetValue())
        except ValueError:
            self.lowcut = 80.0
            Data.Specs.LowPass.SetValue(str(self.lowcut))
        try:
            self.highcut = float(Data.Specs.HighPass.GetValue())
        except ValueError:
            self.highcut = 0.1
            Data.Specs.HighPass.SetValue(str(self.highcut))
        self.doNotch = Data.Specs.CheckboxNotch.GetValue()
        try:
            self.notchValue = float(Data.Specs.Notch.GetValue())
        except ValueError:
            self.notchValue = 50.0
            Data.Specs.Notch.SetValue(str(self.notch))
        try:
            self.preEpoch = float(Data.Specs.PreEpoch.GetValue())
        except ValueError:
            self.preEpoch = 100.0
            Data.Specs.PreEpoch.SetValue(str(self.preEpoch))
        try:
            self.postEpoch = float(Data.Specs.PostEpoch.GetValue())
        except ValueError:
            self.postEpoch = 500.0
            Data.Specs.PostEpoch.SetValue(str(self.postEpoch))
        self.sampleRate = Data.Datasets[0].sampleRate

        # Data object to save original epoch information
        Data.Orig = type('Orig', (object,), {})()

        # Filter Channel Signal
        for i, d in enumerate(Data.Datasets):
            dataset = np.copy(d.rawdata)

            # 1. Remove DC
            if self.removeDC:
                dataset -= np.vstack(dataset.mean(axis=1))

            # 2. Average or specific reference
            if self.average:
                dataset -= dataset.mean(axis=0)
            elif self.newReference != '':
                electrodeID = np.where(d.labelsChannel == self.newReference)[0]
                if self.newReference != 'Average':
                    dataset -= dataset[electrodeID]

            # 3. Run Butterworth Low-, High- or Bandpassfilter
            if self.doPass:
                if self.lowcut != 0 and self.highcut != 0:
                    dataset = butter_bandpass_filter_old(dataset,
                                                         d.sampleRate,
                                                         highcut=self.highcut,
                                                         lowcut=self.lowcut)

            # 4. Notch Filter
            if self.doNotch:
                dataset = butter_bandpass_filter_old(dataset,
                                                     d.sampleRate,
                                                     notch=self.notchValue)

            # Create epochs
            self.preFrame = int(
                np.round(self.preEpoch * self.sampleRate * 0.001))
            self.preCut = np.copy(self.preFrame)
            self.postFrame = int(
                np.round(self.postEpoch * self.sampleRate * 0.001))
            self.postCut = np.copy(self.postFrame)

            """
            # time pre stimuli should be at least 200ms for visualization
            if self.preEpoch < 200.0:
                self.preCut = int(self.sampleRate * .2)
{'fraction_non_alphanumeric': 0.0957838143746463, 'fraction_numerical': 0.011884550084889643, 'mean_word_length': 1.5049610205527995, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '443656', 'n_tokens_mistral': 2013, 'n_tokens_neox': 1899, 'n_words': 376}