def load_file(self): ''' Loads a signal from the given file. ''' start = end = None start_millis = self.startTime.time().msecsSinceStartOfDay() if start_millis > 0: start = start_millis end_millis = self.endTime.time().msecsSinceStartOfDay() if end_millis < self.__duration or start is not None: end = end_millis channel = int(self.channelSelector.currentText()) from model.preferences import ANALYSIS_TARGET_FS from app import wait_cursor with wait_cursor(f"Loading {self.__info.name}"): self.__signal = readWav( 'analysis', self.__preferences, self.__info.name, channel=channel, start=start, end=end, target_fs=self.__preferences.get(ANALYSIS_TARGET_FS)) self.__filtered_signals = {} self.__init_resolution_selector(self.__signal) self.show_chart()
def signaldata_from_json(o, preferences): ''' Converts the given dict to a SignalData if it is compatible. :param o: the dict (from json). :return: the SignalData (or an error) ''' from model.signal import SingleChannelSignalData, BassManagedSignalData if '_type' not in o: raise ValueError(f"{o} is not SignalData") elif o['_type'] == BassManagedSignalData.__name__: channels = [signaldata_from_json(c, preferences) for c in o['channels']] lpf_fs = float(o['bm']['lpf_fs']) lpf_position = o['bm']['lpf_position'] offset = float(o['offset']) bmsd = BassManagedSignalData(channels, lpf_fs, lpf_position, preferences, offset=offset) bmsd.bm_headroom_type = o['bm']['headroom_type'] bmsd.clip_before = o['clip']['before'] bmsd.clip_after = o['clip']['after'] return bmsd elif o['_type'] == SingleChannelSignalData.__name__ or o['_type'] == 'SignalData': filt = o.get('filter', None) if filt is not None: filt = filter_from_json(filt) data = o['data'] avg = xydata_from_json(data['avg']) peak = xydata_from_json(data['peak']) median = xydata_from_json(data['median']) if 'median' in data else None xy_data = [avg, peak] if median is None else [avg, peak, median] metadata = o.get('metadata', None) offset = float(o.get('offset', 0.0)) signal = None if metadata is not None: try: if os.path.isfile(metadata['src']): from model.signal import readWav signal = readWav(o['name'], preferences, input_file=metadata['src'], channel=metadata['channel'], start=metadata['start'], end=metadata['end'], target_fs=o['fs'], offset=offset) except: logger.exception(f"Unable to load signal from {metadata['src']}") if 'duration_seconds' in o: signal_data = SingleChannelSignalData(o['name'], o['fs'], xy_data=xy_data, filter=filt, duration_seconds=o.get('duration_seconds', None), start_seconds=o.get('start_seconds', None), signal=signal, offset=offset) elif 'duration_hhmmss' in o: h, m, s = o['duration_hhmmss'].split(':') duration_seconds = (int(h) * 3600) + int(m) * (60 + float(s)) h, m, s = o['start_hhmmss'].split(':') start_seconds = (int(h) * 3600) + int(m) * (60 + float(s)) signal_data = SingleChannelSignalData(o['name'], o['fs'], xy_data=xy_data, filter=filt, duration_seconds=duration_seconds, start_seconds=start_seconds, signal=signal, offset=offset) else: signal_data = SingleChannelSignalData(o['name'], o['fs'], xy_data=xy_data, filter=filt, signal=signal, offset=offset) return signal_data raise ValueError(f"{o._type} is an unknown signal type")