def __init__(self, name: str, values: GraphValues, x_magnitude, y_magnitude): self.name = name self.values = values self.x_magnitude = get_magnitude_from_string(x_magnitude) if type(x_magnitude) is str else x_magnitude self.y_magnitude = get_magnitude_from_string(y_magnitude) if type(y_magnitude) is str else y_magnitude
def remove_function_from_list(self, name: str): name = name.replace(' ', '', 1) splitted = name.split(',') for step in range(1, self.reader.get_mc_steps()): self.graphFunctionList.remove( GraphFunction( splitted[0] + '_' + str(step), GraphValues(self.get_x_axis_values(), self.get_y_axis_labels()), GraphMagnitude.Frequency.value if self.isBode else GraphMagnitude.Time.value, get_magnitude_from_string(splitted[1])))
def onAdd(self): dialog = PlotterDialog() if dialog.exec(): if dialog.name.text() in [ plotter_model.name for plotter_model in self.session.plotter_models ]: QMessageBox.warning( self, "Error message", "Error detected adding a new graph. Name already used!") else: # Creating model, view, data instances plotterData = GraphPlotter( get_magnitude_from_string(dialog.xMagnitude.currentText()), dialog.name.text()) self.addPlotter(plotterData)
def getGraphFunction(self) -> list: """ Result of the TransferDialog is returned. """ graphFunctions = [] if self.type.currentText() == "Frequency Response": # When the option is enabled... if self.freqEnable.isChecked(): minFreq = self.freqMin.value() maxFreq = self.freqMax.value() points = self.freqPoints.value() w = arange(minFreq * 2 * pi, maxFreq * 2 * pi, 2 * pi * (maxFreq - minFreq) / points) frequency, magnitudes = self.transferFunction.freqresp(w) else: frequency, magnitudes = self.transferFunction.freqresp() if self.xMagnitude.currentText() == GraphMagnitude.Frequency.value: frequency = frequency / (2 * pi) if self.freqModule.isChecked(): graphFunctions.append( GraphFunction( self.name.text() + "_mod", GraphValues(frequency, [abs(magnitude) for magnitude in magnitudes]), get_magnitude_from_string(self.xMagnitude.currentText()), get_magnitude_from_string(self.yMagnitude.currentText()) ) ) if self.freqPhase.isChecked(): graphFunctions.append( GraphFunction( self.name.text() + "_pha", GraphValues(frequency, [degrees(angle(magnitude)) for magnitude in magnitudes]), get_magnitude_from_string(self.xMagnitude.currentText()), GraphMagnitude.Phase ) ) elif self.type.currentText() == "Bode": # When the option is enabled... if self.bodeEnable.isChecked(): minFreq = self.bodeMin.value() maxFreq = self.bodeMax.value() points = self.bodePoints.value() w = arange(minFreq * 2 * pi, maxFreq * 2 * pi, 2 * pi * (maxFreq - minFreq) / points) frequency, magnitudes, phases = self.transferFunction.bode(w) else: frequency, magnitudes, phases = self.transferFunction.bode() if self.xMagnitude.currentText() == GraphMagnitude.Frequency.value: frequency = frequency / (2 * pi) if self.bodeModule.isChecked(): graphFunctions.append( GraphFunction( self.name.text() + "_mod", GraphValues(frequency, [magnitude for magnitude in magnitudes]), get_magnitude_from_string(self.xMagnitude.currentText()), GraphMagnitude.Decibel ) ) if self.bodePhase.isChecked(): graphFunctions.append( GraphFunction( self.name.text() + "_pha", GraphValues(frequency, [phase for phase in phases]), get_magnitude_from_string(self.xMagnitude.currentText()), GraphMagnitude.Phase ) ) elif self.type.currentText() == "Temporal Response": if self.signalFunction is not None: t, y, x = self.transferFunction.output(self.signalFunction.values.y, self.signalFunction.values.x) graphFunctions.append( GraphFunction( self.name.text(), GraphValues(t, y), self.signalFunction.x_magnitude, get_magnitude_from_string(self.yMagnitude.currentText()) ) ) if self.impulsive.isChecked(): t, y = self.transferFunction.impulse() graphFunctions.append( GraphFunction( self.name.text(), GraphValues(t, y), GraphMagnitude.Time, get_magnitude_from_string(self.yMagnitude.currentText()) ) ) if self.step.isChecked(): t, y = self.transferFunction.step() graphFunctions.append( GraphFunction( self.name.text(), GraphValues(t, y), GraphMagnitude.Time, get_magnitude_from_string(self.yMagnitude.currentText()) ) ) return graphFunctions
def getGraphFunction(self) -> list: """ When the SignalDialog has ended with an accepted() signal from the user, the result will be received through this method. """ graphFunctions = [] times = arange(self.fromInput.value(), self.toInput.value(), (self.toInput.value() - self.fromInput.value()) / 1000) if self.waveformsInput.currentText() == "Sinusoidal": amplitude = float(self.sinAmplitude.value()) frequency = float(self.sinFrequency.value()) phase = float(self.sinPhase.value()) dc = float(self.sinDc.value()) values = [ amplitude * sin(time * 2 * pi * frequency + radians(phase)) + dc for time in times ] graphFunctions.append( GraphFunction( self.nameInput.text(), GraphValues(list(times), values), get_magnitude_from_string( self.xMagnitudeInput.currentText()), get_magnitude_from_string( self.yMagnitudeInput.currentText()))) elif self.waveformsInput.currentText() == "Step": amplitude = float(self.stepAmplitude.value()) values = [amplitude * heaviside(time, amplitude) for time in times] graphFunctions.append( GraphFunction( self.nameInput.text(), GraphValues(list(times), list(values)), get_magnitude_from_string( self.xMagnitudeInput.currentText()), get_magnitude_from_string( self.yMagnitudeInput.currentText()))) elif self.waveformsInput.currentText() == "Square": amplitude = float(self.squareAmplitude.value()) frequency = float(self.squareFrequency.value()) duty = float(self.squareDuty.value()) dc = float(self.squareDc.value()) values = amplitude * square(2 * pi * frequency * times, duty / 100) + dc graphFunctions.append( GraphFunction( self.nameInput.text(), GraphValues(list(times), list(values)), get_magnitude_from_string( self.xMagnitudeInput.currentText()), get_magnitude_from_string( self.yMagnitudeInput.currentText()))) elif self.waveformsInput.currentText() == "Triangle": amplitude = float(self.triangleAmplitude.value()) frequency = float(self.triangleFrequency.value()) symmetry = float(self.triangleSymmetry.value()) dc = float(self.triangleDc.value()) def triangle(time: float) -> float: t = time % (1 / frequency) if t < symmetry / (frequency * 100): return (100 * t * frequency * amplitude) / symmetry else: return ((amplitude * 100) / (symmetry - 100)) * (frequency * t - 1) values = [triangle(t) + dc for t in times] graphFunctions.append( GraphFunction( self.nameInput.text(), GraphValues(list(times), list(values)), get_magnitude_from_string( self.xMagnitudeInput.currentText()), get_magnitude_from_string( self.yMagnitudeInput.currentText()))) return graphFunctions