Exemple #1
0
    def items_to_save(self) -> Dict:
        """
        Returns a dictionary containing the parameters which should be saved
        when using the "save data" option.
        """
        # Window type or wavelet type.
        if self.transform == _wft:
            window_type_name = "window_type"
            window_type = self.get_item("Window")
        else:
            window_type_name = "wavelet_type"
            window_type = self.get_item("Wavelet")

        out = {
            "transform_type": self.transform.upper(),
            "sampling_frequency": self.fs,
            window_type_name: window_type,
            "fmax": self.get_item(_fmax),
            "fmin": self.get_item(_fmin),
            "cut_edges": self.get_item(_cut_edges),
            "fr": self.get_item(_f0),
            "preprocessing": self.get_item(_preprocess),
            "implementation": self.get_item("implementation"),
        }
        return sanitise(out)
Exemple #2
0
    def get(self) -> dict:
        """
        Gets the parameters to supply to the wt/wft function as a dictionary.

        Removes values which are None, because they cannot be passed to Matlab.
        """
        return sanitise(self.data)
Exemple #3
0
    def items_to_save(self) -> Dict:
        tf = super().items_to_save()

        out = {
            "surr_count": self.surr_count,
            "surr_type": self.surr_method,
            **tf
        }
        return sanitise(out)
Exemple #4
0
 def items_to_save(self) -> Dict:
     return sanitise({
         "crop": self.crop,
         "surrogates": self.surr_count,
         "sigma": self.sigma,
         "scale_max": self.scale_max,
         "scale_min": self.scale_min,
         "time_res": self.time_res,
     })
Exemple #5
0
    async def coro_get_data_to_save(self) -> Dict:
        if not self.opt or not self.params:
            return

        output_data: List[BAOutputData] = [
            s.output_data for s, _ in self.signals.get_pairs()
        ]
        cols = len(output_data)

        first = output_data[0]

        amp = np.empty((*first.amp_wt1.shape, cols * 2))
        avg_amp = np.empty((first.avg_amp_wt1.shape[0], cols * 2))

        b111 = np.empty((*first.bispxxx.shape, cols))
        b222 = np.empty(b111.shape)
        b122 = np.empty(b111.shape)
        b211 = np.empty(b111.shape)

        freq = first.freq
        time = first.times
        preproc = []  # TODO: Save this and other params

        for index in range(0, len(output_data) * 2, 2):
            d = output_data[index]

            amp[:, :, index] = d.amp_wt1[:]
            avg_amp[:, index] = d.avg_amp_wt1[:]

            amp[:, :, index + 1] = d.amp_wt2[:]
            avg_amp[:, index + 1] = d.avg_amp_wt2[:]

            b111[:, :, index] = d.bispxxx
            b222[:, :, index] = d.bispppp
            b122[:, :, index] = d.bispxpp
            b211[:, :, index] = d.bisppxx

        ba_data = {
            "amplitude": amp,
            "avg_amplitude": avg_amp,
            "frequency": freq,
            "time": time,
            "preprocessed_signals": preproc,
            "b111": b111,
            "b222": b222,
            "b122": b122,
            "b211": b211,
            "fr": self.view.get_f0() or 1,
            "fmin": self.opt["fmin"],
            "fmax": self.opt["fmax"],
            "preprocessing": "on" if self.params.preprocess else "off",
            "sampling_frequency": self.params.fs,
        }
        return {"BAData": sanitise(ba_data)}
Exemple #6
0
    async def coro_get_data_to_save(self) -> Dict:
        if not self.params:
            return None

        preproc = await self.coro_preprocess_all_signals()
        preproc_arr = np.asarray(preproc)
        preprocess = self.params.preprocess

        for s in self.signals:
            if not hasattr(s, "data"):
                s.data = None

        output_data = [s.data for s in self.signals]
        cols = len(output_data)

        freq = [d[0] if d else None for d in output_data]
        res = [d[1] if d else None for d in output_data]
        pos1 = [d[2] if d else None for d in output_data]
        pos2 = [d[3] if d else None for d in output_data]

        first = 0
        while output_data[first] is None:
            first += 1

        freq_arr = np.empty((cols, *freq[first].shape))
        res_arr = np.empty((cols, *res[first].shape))
        pos1_arr = np.empty((cols, *pos1[first].shape))
        pos2_arr = np.empty((cols, *pos2[first].shape))

        for i in range(cols):
            if freq[i] is not None:
                freq_arr[i, :] = freq[i]
                res_arr[i, :, :] = res[i]
                pos1_arr[i, :, :] = pos1[i]
                pos2_arr[i, :, :] = pos2[i]
            else:
                freq_arr[i, :] = np.NaN
                res_arr[i, :, :] = np.NaN
                pos1_arr[i, :, :] = np.NaN
                pos2_arr[i, :, :] = np.NaN

        dh_data = {
            "res": res_arr,
            "freq": freq_arr,
            "pos1": pos1_arr,
            "pos2": pos2_arr,
            "preprocessed_signals": preproc_arr if preprocess else None,
            **self.params.items_to_save(),
        }

        return {"DHData": sanitise(dh_data)}
Exemple #7
0
    async def coro_get_data_to_save(self) -> Optional[Dict]:
        tf_data = await super().coro_get_data_to_save()
        if not tf_data:
            return None

        output_data: List[TFOutputData] = [s.output_data for s in self.signals]
        cols = len(output_data)

        r_intervals = []
        r_freq = np.empty((tf_data["TFData"]["time"].size, cols))
        r_phase = np.empty(r_freq.shape)
        r_bands = np.empty(r_freq.shape)
        r_bands_phi = np.empty(r_freq.shape)
        r_bands_amp = np.empty(r_freq.shape)

        for index, d in enumerate(output_data):
            for key, value in d.ridge_data.items():
                filt, freq, phase = value

                if key not in r_intervals:
                    r_intervals.append(key)

                r_freq[:, index] = freq
                r_phase[:, index] = phase

            try:
                for key, value in d.band_data.items():
                    bands, phi, amp = value

                    if key not in r_intervals:
                        r_intervals.append(key)

                    r_bands[:, index] = bands
                    r_bands_phi[:, index] = phi
                    r_bands_amp[:, index] = amp
            except:
                pass

        ridge = {
            "frequency_bands": r_intervals,
            "ridge_frequency": r_freq,
            "ridge_phase": r_phase,
        }

        re_data = {**tf_data["TFData"], **ridge}

        return {"REData": sanitise(re_data)}
Exemple #8
0
    async def coro_get_data_to_save(self) -> Optional[Dict]:
        """
        Gets all the data which will be saved in a file, and returns it as a dictionary.

        :return: a dictionary containing the current results
        """
        if not self.params:
            return None

        preproc = await self.coro_preprocess_all_signals()
        preproc_arr = np.empty((len(preproc[0]), len(preproc)))

        for index, p in enumerate(preproc):
            try:
                preproc_arr[:, index] = p[:, 0]
            except IndexError:
                preproc_arr[:, index] = p[:]

        output_data: List[TFOutputData] = [s.output_data for s in self.signals]
        cols = len(output_data)

        first = [d for d in output_data if d.is_valid()][0]

        amp = np.empty((*first.ampl.shape, cols))
        avg_amp = np.empty((first.avg_ampl.shape[0], cols))

        freq = first.freq
        time = first.times

        for index, d in enumerate(output_data):
            if d.is_valid():
                avg_amp[:, index] = d.avg_ampl[:]
                amp[:, :, index] = d.ampl[:]
            else:
                avg_amp[:, index] = np.NAN
                amp[:, :, index] = np.NAN

        tfr_data = {
            "amplitude": amp,
            "avg_amplitude": avg_amp,
            "frequency": freq,
            "time": time,
            "preprocessed_signals": preproc_arr,
            **self.params.items_to_save(),
        }
        return {"TFData": sanitise(tfr_data)}
Exemple #9
0
    async def coro_get_data_to_save(self) -> Optional[Dict]:
        if not self.results:
            return None

        try:
            freq, coh1, coh2, surr1, surr2 = self.results
        except ValueError:
            freq, coh1, surr1 = self.results
            coh2 = None
            surr2 = None

        gc_data = {
            "coherence1": coh1,
            "coherence2": coh2,
            "surrogates1": surr1,
            "surrogates2": surr2,
            "frequency": freq,
            "significance": self.stats,
            **self.params,
        }

        return {"GCData": sanitise(gc_data)}
Exemple #10
0
    async def coro_get_data_to_save(self) -> Optional[Dict]:
        if not self.params:
            return None

        output_data: List[TFOutputData] = [
            s[0].output_data for s in self.signals.get_pairs()
        ]
        cols = len(output_data)

        first = [d for d in output_data if d.is_valid()][0]

        coh = np.empty((*first.phase_coherence.shape, cols))
        avg_coh = np.empty((first.overall_coherence.shape[0], cols))

        avg_surrogates = np.empty((len(first.surrogate_avg), cols))

        amp = np.empty((*first.ampl.shape, cols))
        avg_amp = np.empty((first.avg_ampl.shape[0], cols))

        freq = first.freq
        time = first.times

        preproc = await self.coro_preprocess_all_signals()
        preproc_arr = np.empty((len(preproc[0]), len(preproc)))

        for index, p in enumerate(preproc):
            preproc_arr[:, index] = p[:, 0]

        for index, d in enumerate(output_data):
            if d.is_valid():
                try:
                    avg_surrogates[:, index] = d.surrogate_avg[:, 0]
                except:
                    avg_surrogates[:, index] = np.NAN

                coh[:, :, index] = d.phase_coherence[:, :]
                avg_coh[:, index] = d.overall_coherence[:, index]

                amp[:, :, index] = d.ampl[:, :]
                avg_amp[:, index] = d.avg_ampl[:]
            else:
                avg_surrogates[:, index] = np.NAN

                amp[:, :, index] = np.NAN
                coh[:, :, index] = np.NAN

                avg_amp[:, index] = np.NAN
                avg_coh[:, index] = np.NAN

        pc_data = {
            "coherence": coh,
            "avg_coherence": avg_coh,
            "avg_surrogates": avg_surrogates,
            "amplitude": amp,
            "avg_amplitude": avg_amp,
            "frequency": freq,
            "time": time,
            "preprocessed_signals": preproc_arr,
            **self.params.items_to_save(),
        }
        return {"PCData": sanitise(pc_data)}