def segment(input_data, n_samples, overlap=DEFAULT_SEGMENT_OVERLAP): """Break into segments length n_samples. Overlap of 2.0 starts a new segment halfway into previous, overlap=1 is no overlap. overlap should divide into n_samples. Probably should consider a nicer definition such as in pyfusion 0 """ from pyfusion.data.base import DataSet from pyfusion.data.timeseries import TimeseriesData if isinstance(input_data, DataSet): output_dataset = DataSet() for ii,data in enumerate(input_data): try: output_dataset.update(data.segment(n_samples)) except AttributeError: pyfusion.logger.warning("Data filter 'segment' not applied to item in dataset") return output_dataset output_data = DataSet('segmented_%s, %d samples, %.3f overlap' %(datetime.now(), n_samples, overlap)) for el in arange(0,len(input_data.timebase), n_samples/overlap): if input_data.signal.ndim == 1: tmp_data = TimeseriesData(timebase=input_data.timebase[el:el+n_samples], signal=input_data.signal[el:el+n_samples], channels=input_data.channels, bypass_length_check=True) else: tmp_data = TimeseriesData(timebase=input_data.timebase[el:el+n_samples], signal=input_data.signal[:,el:el+n_samples], channels=input_data.channels, bypass_length_check=True) tmp_data.meta = input_data.meta.copy() tmp_data.history = input_data.history # bdb - may be redundant now meta is copied output_data.add(tmp_data) return output_data
def segment(input_data, n_samples, overlap=1.0, datalist= 0): """Break into segments length n_samples. Overlap of 2.0 starts a new segment halfway into previous, overlap=1 is no overlap. overlap should divide into n_samples. Probably should consider a nicer definition such as in pyfusion 0 if datalist = 0 returns a DataSet object otherwise, returns a OrderedDataSet object """ from pyfusion.data.base import DataSet, OrderedDataSet from pyfusion.data.timeseries import TimeseriesData if isinstance(input_data, DataSet): output_dataset = DataSet() for ii,data in enumerate(input_data): try: output_dataset.update(data.segment(n_samples)) except AttributeError: pyfusion.logger.warning("Data filter 'segment' not applied to item in dataset") return output_dataset #SH modification incase ordering is important... i.e you are doing #two processing two different arrays at the same time (in different Timeseries objects) #and you don't want to loose the time relationship between them if datalist: output_data = OrderedDataSet('segmented_%s, %d samples, %.3f overlap' %(datetime.now(), n_samples, overlap)) else: output_data = DataSet('segmented_%s, %d samples, %.3f overlap' %(datetime.now(), n_samples, overlap)) #SH : 24May2013 fixed bug here - before, the index was allowed to go past #the length of samples, gives smalled length data towards the end - fixed to finish the #last time we can get n_samples length #for el in arange(0,len(input_data.timebase), n_samples/overlap): for el in arange(0,len(input_data.timebase) - n_samples, n_samples/overlap): if input_data.signal.ndim == 1: tmp_data = TimeseriesData(timebase=input_data.timebase[el:el+n_samples], signal=input_data.signal[el:el+n_samples], channels=input_data.channels, bypass_length_check=True) else: tmp_data = TimeseriesData(timebase=input_data.timebase[el:el+n_samples], signal=input_data.signal[:,el:el+n_samples], channels=input_data.channels, bypass_length_check=True) tmp_data.meta = input_data.meta.copy() if datalist: output_data.append(tmp_data) else: output_data.add(tmp_data) return output_data
def segment(input_data, n_samples, overlap=1.0, datalist= 0): """Break into segments length n_samples. Overlap of 2.0 starts a new segment halfway into previous, overlap=1 is no overlap. overlap should divide into n_samples. Probably should consider a nicer definition such as in pyfusion 0 if datalist = 0 returns a DataSet object otherwise, returns a OrderedDataSet object """ from pyfusion.data.base import DataSet, OrderedDataSet from pyfusion.data.timeseries import TimeseriesData if isinstance(input_data, DataSet): output_dataset = DataSet() for ii,data in enumerate(input_data): try: output_dataset.update(data.segment(n_samples)) except AttributeError: pyfusion.logger.warning("Data filter 'segment' not applied to item in dataset") return output_dataset #SH modification incase ordering is important... i.e you are doing #two processing two different arrays at the same time (in different Timeseries objects) #and you don't want to loose the time relationship between them if datalist: output_data = OrderedDataSet('segmented_%s, %d samples, %.3f overlap' %(datetime.now(), n_samples, overlap)) else: output_data = DataSet('segmented_%s, %d samples, %.3f overlap' %(datetime.now(), n_samples, overlap)) #SH : 24May2013 fixed bug here - before, the index was allowed to go past #the length of samples, gives smalled length data towards the end - fixed to finish the #last time we can get n_samples length #for el in arange(0,len(input_data.timebase), n_samples/overlap): for el in arange(0,len(input_data.timebase) - n_samples, n_samples/overlap): if input_data.signal.ndim == 1: tmp_data = TimeseriesData(timebase=input_data.timebase[el:el+n_samples], signal=input_data.signal[el:el+n_samples], channels=input_data.channels, bypass_length_check=True) else: tmp_data = TimeseriesData(timebase=input_data.timebase[el:el+n_samples], signal=input_data.signal[:,el:el+n_samples], channels=input_data.channels, bypass_length_check=True) tmp_data.meta = input_data.meta.copy() if datalist: output_data.append(tmp_data) else: output_data.add(tmp_data) return output_data
def segment(input_data, n_samples, overlap=DEFAULT_SEGMENT_OVERLAP): """Break into segments length n_samples. Overlap of 2.0 starts a new segment halfway into previous, overlap=1 is no overlap. overlap should divide into n_samples. Probably should consider a nicer definition such as in pyfusion 0 """ from pyfusion.data.base import DataSet from pyfusion.data.timeseries import TimeseriesData if isinstance(input_data, DataSet): output_dataset = DataSet() for ii, data in enumerate(input_data): try: output_dataset.update(data.segment(n_samples)) except AttributeError: pyfusion.logger.warning( "Data filter 'segment' not applied to item in dataset") return output_dataset output_data = DataSet('segmented_%s, %d samples, %.3f overlap' % (datetime.now(), n_samples, overlap)) for el in arange(0, len(input_data.timebase), n_samples / overlap): if input_data.signal.ndim == 1: tmp_data = TimeseriesData( timebase=input_data.timebase[el:el + n_samples], signal=input_data.signal[el:el + n_samples], channels=input_data.channels, bypass_length_check=True) else: tmp_data = TimeseriesData( timebase=input_data.timebase[el:el + n_samples], signal=input_data.signal[:, el:el + n_samples], channels=input_data.channels, bypass_length_check=True) tmp_data.meta = input_data.meta.copy() tmp_data.history = input_data.history # bdb - may be redundant now meta is copied output_data.add(tmp_data) return output_data