Example #1
0
 def SetLowpass(self, frequency, order=16):
     if frequency is not None:
         sumpf.deactivate_output(self.__bypass_filter.GetOutput)
         method_pairs = [(self.__filter.SetFilterFunction, sumpf.modules.FilterGenerator.BUTTERWORTH(order=order)),
                         (self.__filter.SetFrequency, frequency),
                         (self.__bypass_filter.SetSelection, self.__FILTER)]
         sumpf.set_multiple_values(pairs=method_pairs, progress_indicator=self.__progress_indicator)
     else:
         self.__bypass_filter.SetSelection(self.__BYPASS)
Example #2
0
 def _Start(self):
     """
     Method that can be used from derived classes to start the averaging process.
     """
     self.Clear()
     self.__TriggerTrigger(0)
     sumpf.activate_output(self.TriggerDataCreation)
     for i in range(1, self.__number):
         self.__TriggerTrigger(i)
     sumpf.deactivate_output(self.TriggerDataCreation)
Example #3
0
 def prepare_for_loading():
     total_length = self.__properties.GetSignalLength()
     ratio = float(self.__sweep_duration.GetLength()) / float(self.__concatenation.GetOutputLength())
     sweep_length = total_length * ratio
     sumpf.deactivate_output(self.__concatenation.GetOutput)
     self.__playback_fft.SetSignal.NoticeAnnouncement(self.__concatenation.GetOutput)
     sumpf.activate_output(self.__properties)
     self.__sweep_duration.SetDuration(sweep_length / self.__properties.GetSamplingRate())
     self.__silence_duration.SetDuration((total_length - sweep_length) / self.__properties.GetSamplingRate())
     self.__record_fft.SetSignal(sumpf.modules.ConstantSignalGenerator(value=0.0, samplingrate=self.__properties.GetSamplingRate(), length=total_length).GetSignal())
     sumpf.activate_output(self.__concatenation.GetOutput)
Example #4
0
 def Clear(self):
     """
     Removes all kept spectrums.
     """
     sumpf.deactivate_output(self.__merge_utf)
     while self.__kept_ids != []:
         data_id = self.__kept_ids.pop()
         self.__merge_utf.RemoveInput(data_id)
     self.ShowRecent(True)
     self.__progress_indicator.AddMethod(self.__ifft.SetSpectrum)
     sumpf.activate_output(self.__merge_utf)
Example #5
0
 def __Load(self, merger, id_dict, filename):
     def prepare_for_loading():
         total_length = self.__properties.GetSignalLength()
         ratio = float(self.__sweep_duration.GetLength()) / float(self.__concatenation.GetOutputLength())
         sweep_length = total_length * ratio
         sumpf.deactivate_output(self.__concatenation.GetOutput)
         self.__playback_fft.SetSignal.NoticeAnnouncement(self.__concatenation.GetOutput)
         sumpf.activate_output(self.__properties)
         self.__sweep_duration.SetDuration(sweep_length / self.__properties.GetSamplingRate())
         self.__silence_duration.SetDuration((total_length - sweep_length) / self.__properties.GetSamplingRate())
         self.__record_fft.SetSignal(sumpf.modules.ConstantSignalGenerator(value=0.0, samplingrate=self.__properties.GetSamplingRate(), length=total_length).GetSignal())
         sumpf.activate_output(self.__concatenation.GetOutput)
     loaded = None
     ending = filename.split(".")[-1]
     if merger in [self.__merge_uir, self.__merge_pir]:
         filehandler = sumpf.modules.SignalFile()
         file_format = sumpf.modules.SignalFile.GetFormats()[0]
         for f in sumpf.modules.SignalFile.GetFormats():
             if f.ending == ending:
                 file_format = f
                 break
         filehandler.SetFormat(file_format)
         filehandler.SetFilename(filename)
         loaded = filehandler.GetSignal()
         if not self.__has_data:
             sumpf.deactivate_output(self.__properties)
             self.__properties.SetSignalLength(len(loaded))
             self.__properties.SetSamplingRate(loaded.GetSamplingRate())
             prepare_for_loading()
     else:
         filehandler = sumpf.modules.SpectrumFile()
         file_format = sumpf.modules.SpectrumFile.GetFormats()[0]
         for f in sumpf.modules.SpectrumFile.GetFormats():
             if f.ending == ending:
                 file_format = f
                 break
         filehandler.SetFormat(file_format)
         filehandler.SetFilename(filename)
         loaded = filehandler.GetSpectrum()
         if not self.__has_data:
             sumpf.deactivate_output(self.__properties)
             self.__properties.SetSpectrumLength(len(loaded))
             self.__properties.SetResolution(loaded.GetResolution())
             prepare_for_loading()
     data_id = merger.AddInput(loaded)
     if filename in id_dict:
         i = 2
         while filename + " (" + str(i) + ")" in id_dict:
             i += 1
         id_dict[filename + " (" + str(i) + ")"] = data_id
     else:
         id_dict[filename] = data_id
     self.__has_data = True
Example #6
0
 def SetNormalize(self, normalize, individual=False, frequency=1000.0):
     """
     @param normalize: False, to disable normalization, "average" to normalize to average, "frequency" to normalize to frequency
     """
     sumpf.deactivate_output(self.__bypass_normalize.GetOutput)
     if normalize in ("average", "frequency"):
         method_pairs = [(self.__bypass_normalize.SetSelection, self.__NORMALIZE)]
         if normalize == "average":
             method_pairs.append((self.__select_normalization.SetSelection, self.__AVERAGE))
             method_pairs.append((self.__normalize_avg.SetIndividual, individual))
         else:
             method_pairs.append((self.__select_normalization.SetSelection, self.__FREQUENCY))
             method_pairs.append((self.__normalize_frq.SetFrequency, frequency))
         sumpf.set_multiple_values(pairs=method_pairs, progress_indicator=self.__progress_indicator)
     else:
         self.__bypass_normalize.SetSelection(self.__BYPASS)
     sumpf.activate_output(self.__bypass_normalize.GetOutput)
Example #7
0
 def test_duplicate_calculation(self):
     """
     Tests if duplicate calculation in forked chains is avoided.
     """
     sumpf.connect(self.obj1.GetValue, self.obj2.SetValue)
     sumpf.connect(self.obj1.GetValue, self.obj2.SetValue2)
     sumpf.connect(self.obj2.GetValue, self.obj1.SetValueNoUpdate)
     self.obj2.history = []
     self.obj1.SetValue(1)
     self.assertEqual(self.obj2.history, [1])                        # the value should have been calculated only once
     sumpf.deactivate_output(self.obj1)
     self.obj2.history = []
     self.obj1.SetValue(2)
     sumpf.activate_output(self.obj1)
     self.assertEqual(self.obj2.history, [2])                        # the value should have been calculated only once after reactivating outputs
     sumpf.disconnect_all(self.obj1)
     sumpf.connect(self.obj1.GetValue, self.obj2.AddItemNoReplace)
     sumpf.connect(self.obj1.GetValue2, self.obj2.AddItemNoReplace)
     sumpf.connect(self.obj2.GetItems, self.obj1.TakeList)
     self.obj2.history = []
     self.obj1.SetValue2(3)
     self.assertEqual(self.obj2.history, [[3, 6]])                   # the list should have been calculated only once
Example #8
0
 def test_deactivate_output(self):
     """
     Tests if deactivating and reactivating outputs works.
     """
     self.obj1.SetValue(0)
     self.obj2.SetValue(1)
     sumpf.deactivate_output(self.obj1.GetValue)
     sumpf.connect(self.obj1.GetValue, self.obj2.SetValue)
     self.assertEqual(self.obj2.GetValue(), 1)               # A deactivated output shall not be passed while creating a connection
     sumpf.activate_output(self.obj1.GetValue)
     sumpf.connect(self.obj1.GetText, self.obj2.SetText)
     self.obj1.ComputeValueAndText(2)
     sumpf.deactivate_output(self.obj1)
     sumpf.deactivate_output(self.obj1)                      # Deactivating already deactivated outputs should not fail
     self.obj1.ComputeValueAndText(3)
     self.assertEqual(self.obj2.GetValue(), 2)               # No value should be passed through deactivated outputs
     sumpf.activate_output(self.obj1.GetValue)
     self.assertEqual(self.obj2.GetValue(), 3)               # Value should have been passed through reactivated output
     self.assertEqual(self.obj2.GetText(), "2")              # Text output should have remained deactivated
     sumpf.activate_output(self.obj1)
     self.assertEqual(self.obj2.GetText(), "3")              # Text should have been passed while globally enabling outputs
Example #9
0
 def __Unload(self, merger, id_dict, filenames):
     sumpf.deactivate_output(merger.GetOutput)
     for f in filenames:
         data_id = id_dict.pop(f)
         merger.RemoveInput(data_id)
     sumpf.activate_output(merger.GetOutput)