def change_time_base(input_data, new_time_base): '''New from SH.... ''' from pyfusion.data.base import DataSet from pyfusion.data.timeseries import Signal, Timebase if isinstance(input_data, DataSet): #output_dataset = input_data.copy() #output_dataset.clear() output_dataset = DataSet(input_data.label+'_new_time_base') for data in input_data: try: output_dataset.append(data.change_time_base(new_time_base)) except AttributeError: pyfusion.logger.warning("Data filter 'change_time_base' not applied to item in dataset") return output_dataset #cut the signal and timebase matrices to the correct size new_data = copy.deepcopy(input_data) n_channels = input_data.signal.shape[0] new_data.signal = Signal(np.zeros((n_channels,new_time_base.shape[0]),dtype=np.float32)) new_data.timebase = Timebase(new_time_base) for i in range(input_data.signal.shape[0]): new_data.signal[i,:] = np.interp(new_time_base, input_data.timebase, input_data.signal[i,:]) #if input_data.signal.ndim == 1: # input_data.signal = input_data.signal[new_time_args[0]:new_time_args[1]] #else: # input_data.signal = input_data.signal[:,new_time_args[0]:new_time_args[1]] return new_data
def reduce_time(input_data, new_time_range, fftopt=False): """ reduce the time range of the input data in place(copy=False) or the returned Dataset (copy=True - default at present). if fftopt, then extend time if possible, or if not reduce it so that ffts run reasonably fast. Should consider moving this to actual filters? But this way users can obtain optimum fft even without filters. The fftopt is only visited when it is a dataset, and this isn't happening """ from pyfusion.data.base import DataSet if pyfusion.VERBOSE > 1: print('Entering reduce_time, fftopt={0}, isinst={1}'.format( fftopt, isinstance(input_data, DataSet))) pyfusion.logger.warning("Testing: can I see this?") if isinstance(input_data, DataSet): if fftopt: new_time_range = get_optimum_time_range(input_data, new_time_range) #output_dataset = input_data.copy() #output_dataset.clear() print('****new time range={n}'.format(n=new_time_range)) output_dataset = DataSet(input_data.label + '_reduce_time') for data in input_data: try: output_dataset.append(data.reduce_time(new_time_range)) except AttributeError: pyfusion.logger.warning( "Data filter 'reduce_time' not applied to item in dataset") return output_dataset #??? this should not need to be here - should only be called from # above when passed as a dataset (more efficient) if fftopt: new_time_range = get_optimum_time_range(input_data, new_time_range) new_time_args = searchsorted(input_data.timebase, new_time_range) input_data.timebase = input_data.timebase[ new_time_args[0]:new_time_args[1]] if input_data.signal.ndim == 1: input_data.signal = input_data.signal[ new_time_args[0]:new_time_args[1]] else: input_data.signal = input_data.signal[:, new_time_args[0]: new_time_args[1]] if pyfusion.VERBOSE > 1: print( 'reduce_time to length {l}'.format(l=np.shape(input_data.signal))), return input_data
def reduce_time(input_data, new_time_range): from pyfusion.data.base import DataSet if isinstance(input_data, DataSet): #output_dataset = input_data.copy() #output_dataset.clear() output_dataset = DataSet(input_data.label+'_reduce_time') for data in input_data: try: output_dataset.append(data.reduce_time(new_time_range)) except AttributeError: pyfusion.logger.warning("Data filter 'reduce_time' not applied to item in dataset") return output_dataset new_time_args = searchsorted(input_data.timebase, new_time_range) input_data.timebase =input_data.timebase[new_time_args[0]:new_time_args[1]] if input_data.signal.ndim == 1: input_data.signal = input_data.signal[new_time_args[0]:new_time_args[1]] else: input_data.signal = input_data.signal[:,new_time_args[0]:new_time_args[1]] return input_data
def reduce_time(input_data, new_time_range, fftopt=False): """ reduce the time range of the input data in place(copy=False) or the returned Dataset (copy=True - default at present). if fftopt, then extend time if possible, or if not reduce it so that ffts run reasonably fast. Should consider moving this to actual filters? But this way users can obtain optimum fft even without filters. The fftopt is only visited when it is a dataset, and this isn't happening """ from pyfusion.data.base import DataSet if pyfusion.VERBOSE>1: print('Entering reduce_time, fftopt={0}, isinst={1}' .format(fftopt,isinstance(input_data, DataSet) )) pyfusion.logger.warning("Testing: can I see this?") if isinstance(input_data, DataSet): if fftopt: new_time_range = get_optimum_time_range(input_data, new_time_range) #output_dataset = input_data.copy() #output_dataset.clear() print('****new time range={n}'.format(n=new_time_range)) output_dataset = DataSet(input_data.label+'_reduce_time') for data in input_data: try: output_dataset.append(data.reduce_time(new_time_range)) except AttributeError: pyfusion.logger.warning("Data filter 'reduce_time' not applied to item in dataset") return output_dataset #??? this should not need to be here - should only be called from # above when passed as a dataset (more efficient) if fftopt: new_time_range = get_optimum_time_range(input_data, new_time_range) new_time_args = searchsorted(input_data.timebase, new_time_range) input_data.timebase =input_data.timebase[new_time_args[0]:new_time_args[1]] if input_data.signal.ndim == 1: input_data.signal = input_data.signal[new_time_args[0]:new_time_args[1]] else: input_data.signal = input_data.signal[:,new_time_args[0]:new_time_args[1]] if pyfusion.VERBOSE>1: print('reduce_time to length {l}' .format(l=np.shape(input_data.signal))), return input_data
def reduce_time(input_data, new_time_range, fftopt=0, copy=True): """ reduce the time range of the input data in place(copy=False) or the returned Dataset (copy=True - default at present). if fftopt, then extend time if possible, or if not reduce it so that ffts run reasonably fast. Should consider moving this to actual filters? But this way users can obtain optimum fft even without filters. The fftopt is only visited when it is a dataset, and this isn't happening """ if not copy: raise ValueError("copy=False not supported now") from pyfusion.data.base import DataSet if pyfusion.VERBOSE > 1: print('Entering reduce_time, fftopt={0}, isinst={1}'.format( fftopt, isinstance(input_data, DataSet))) pyfusion.logger.warning("Testing: can I see this?") # not clear that this helps if (np.nanmin(input_data.timebase) >= new_time_range[0] and np.nanmax(input_data.timebase) <= new_time_range[1]): print('time range is already reduced') return (input_data) if fftopt > 0: new_time_range = get_optimum_time_range(input_data, new_time_range, fftopt) # the -1 option doesn't really do what I want yet elif fftopt < 0: new_time_range = get_optimum_time_range(input_data, new_time_range, try_more=fftopt) if isinstance(input_data, DataSet): # if copy: output_dataset = input_data.copy() # output_dataset.clear() print('****new time range={n}'.format(n=new_time_range)) output_dataset = DataSet(input_data.label + '_reduce_time') for data in input_data: try: output_dataset.append(data.reduce_time(new_time_range)) except AttributeError: pyfusion.logger.warning( "Data filter 'reduce_time' not applied to item in dataset") return output_dataset # else: this is effectively a matching 'else' - omit to save indentation # ??? this should not need to be here - should only be called from # above when passed as a dataset (more efficient) new_time_args = searchsorted(input_data.timebase, new_time_range) input_data.timebase = input_data.timebase[ new_time_args[0]:new_time_args[1]] if input_data.signal.ndim == 1: input_data.signal = input_data.signal[ new_time_args[0]:new_time_args[1]] else: input_data.signal = input_data.signal[:, new_time_args[0]: new_time_args[1]] if pyfusion.VERBOSE > 1: print( 'reduce_time to length {l}'.format(l=np.shape(input_data.signal))), if len(input_data.signal) == 0: raise LookupError('no samples in time_range of {trg} in {nm}'.format( trg=str(new_time_range), nm=input_data.config_name)) return input_data