def test_object_deletion(self): """ Checks that Connectors do not inhibit clean object deletion. """ # deletion without explicit garbage collection gc.collect() rel = sumpf.modules.RelabelSignal() rel.SetSignal(sumpf.Signal()) del rel self.assertEqual(gc.collect(), 0) # sumpf.collect_garbage sumpf.connect(self.obj1.GetValue, self.obj2.SetValue) sumpf.connect(self.obj2.GetText, self.obj1.SetText) sumpf.disconnect_all(self.obj1) gc.collect() current_instance_count = ExampleClass.instance_count sumpf.destroy_connectors(self.obj1) del self.obj1 gc.collect() if ExampleClass.instance_count != current_instance_count - 1: for o in gc.garbage: if isinstance(o, ExampleClass): collected = sumpf.collect_garbage() self.assertIsInstance(collected, int) # sumpf.collect_garbage shall return the integer number of collected items self.assertEqual(gc.garbage, []) # garbage collection should have removed all garbage return self.fail("The object has neither been deleted, nor has it been marked as garbage")
def Destroy(self): """ An override of the Window's Destroy method. This method also destroys the connectors, so that this dialog can be easily garbage collected. """ sumpf.destroy_connectors(self) Window.Destroy(self)
def destroy_connector_references(): """ A garbage collector function that helps to delete objects with connectors. Normally this is not needed, but when the object has a destructor method, the garbage collector does not know in which order it shall delete the object and the connector. This garbage collector function breaks this dependency cycle. """ for obj in gc.garbage: sumpf.destroy_connectors(obj)
def Delete(self): """ Shuts down the jack connection and prepares the instance for garbage collection. """ if not self.__deleted: jack.deactivate() jack.detach() sumpf.destroy_connectors(self) BaseIO.Delete(self) self.__deleted = True
def GetOutput(self): # get lengths from durations if self.__silence_duration != 0.0: d2l = sumpf.modules.DurationToLength(duration=self.__fade_out, samplingrate=self.__sampling_rate) fade_out_length = d2l.GetLength() d2l.SetDuration(duration=self.__fade_in) fade_in_length = d2l.GetLength() d2l.SetDuration(self.__silence_duration) silence_length = d2l.GetLength() sumpf.destroy_connectors(d2l) sweep_length = self.__length - silence_length # get signals slg = sumpf.modules.SilenceGenerator(samplingrate=self.__sampling_rate, length=silence_length) silence = slg.GetSignal() sumpf.destroy_connectors(slg) if (fade_out_length == 0.0 and fade_in_length ==0.0): interval = None else: interval = (fade_in_length, -fade_out_length) swg = sumpf.modules.SweepGenerator(start_frequency=self.__start_frequency, stop_frequency=self.__stop_frequency, function=self.__function, interval=interval, samplingrate=self.__sampling_rate, length=sweep_length) sweep = swg.GetSignal() sumpf.destroy_connectors(swg) if fade_in_length == 0.0: raise_interval = None else: raise_interval = (0,fade_in_length) wng = sumpf.modules.WindowGenerator(raise_interval= raise_interval, fall_interval=(-fade_out_length, -1), function=sumpf.modules.WindowGenerator.Hanning(), samplingrate=self.__sampling_rate, length=sweep_length) window = wng.GetSignal() sumpf.destroy_connectors(wng) # combine signals windowed_sweep = sweep * window cat = sumpf.modules.ConcatenateSignals(signal1=windowed_sweep, signal2=silence) concatenated_sweep = cat.GetOutput() sumpf.destroy_connectors(cat) else: print "normal sweep" concatenated_sweep = sumpf.modules.SweepGenerator(self.__start_frequency,self.__stop_frequency, samplingrate=self.__sampling_rate, length=self.__length,function=self.__function).GetSignal() self.__sweep_signal = sumpf.modules.AmplifySignal(concatenated_sweep) return self.__sweep_signal.GetOutput()
def get_impulse_response(excitation, response, start_freq, stop_freq): """ Calculate the impulse response of the system :param excitation: the input signal to the system :param response: the output signal of the system :param start_freq: the start frequency :param stop_freq: the stop frequency :return: the impulse response of the system """ transferfunction = get_transfer_function(excitation, response, start_freq, stop_freq) ifft = sumpf.modules.InverseFourierTransform(spectrum=transferfunction) result = ifft.GetSignal() sumpf.destroy_connectors(ifft) return result
def get_transfer_function(excitation, response, start_freq=20.0, stop_freq=20000.0): """ Calculate the transfer function of the system :param excitation: the input signal to the system :param response: the output signal of the system :param start_freq: the start frequency of the input :param stop_freq: the stop frequency of the input :return: the transfer function of the system """ fft = sumpf.modules.FourierTransform(signal=excitation) excitation_spectrum = fft.GetSpectrum() fft.SetSignal(response) response_spectrum = fft.GetSpectrum() sumpf.destroy_connectors(fft) rgi = sumpf.modules.RegularizedSpectrumInversion( spectrum=excitation_spectrum, start_frequency=start_freq, stop_frequency=stop_freq) regularized = rgi.GetOutput() sumpf.destroy_connectors(rgi) if len(regularized.GetChannels()) == 1 and len( response_spectrum.GetChannels()) != 1: cpy = sumpf.modules.CopySpectrumChannels( input=regularized, channelcount=len(response_spectrum.GetChannels())) regularized = cpy.GetOutput() sumpf.destroy_connectors(cpy) cls = sumpf.modules.CopyLabelsToSpectrum(data_input=response_spectrum * regularized, label_input=response) relabeled = cls.GetOutput() sumpf.destroy_connectors(cls) return relabeled
def Destroy(self): """ Destroys this ProgressIndicator instance, so it can be easily garbage collected. """ sumpf.destroy_connectors(self)