Commit 89bf35de authored by Hafiz Emin Kosar's avatar Hafiz Emin Kosar
Browse files

bug fixes: dirac is plotted beautifully, GUI working fine

parent b12b21e2
%% Cell type:code id: tags:
``` python
from ipywidgets import interact, interactive, fixed, HBox, VBox
import ipywidgets as widgets
from IPython.display import clear_output, display, HTML
from IPython.display import Markdown as md
from ient_nb.ient_plots import *
from src.laplace.laplace_plot import pzPoint, pzPlot
from src.laplace.inline_plot import inline_plot
%matplotlib inline
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
import numpy as np
```
%% Cell type:code id: tags:
``` python
inline_plot('right')
```
%% Cell type:code id: tags:
``` python
inline_plot('left')
```
%% Cell type:code id: tags:
``` python
%matplotlib notebook
%matplotlib notebook
pzp = pzPlot()
filter_type = interactive(pzp.update_filter,filtr=widgets.Dropdown(options=list(pzp.filter_types.keys()), value="Sprungfunktion", description='Filter'))
action_type = interactive(pzp.update_action,action=widgets.Dropdown(options=list(pzp.action_types.keys()),value="Hinzufügen", description='Modus'))
point_type = interactive(pzp.update_mode,mode=widgets.Dropdown(options=list(pzp.mode_types.keys()), value="Polstelle", description='Typ'))
amp_type = interactive(pzp.update_amp, H0=widgets.IntSlider(min=1,max=10,step=1,value=1), description="H0")
left_box = VBox([filter_type, amp_type])
right_box = VBox([action_type, point_type])
HBox([left_box, right_box])
```
%% Cell type:code id: tags:
``` python
# Achse wandert hoch - ient_axis?
# update_signal todos beachten
# dirac spitzer!
```
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
......
......@@ -47,6 +47,9 @@ class pzPlot():
self.H0 = 1
self.filter = 'unit'
self.arrow = None
self.arrow_txt = None
self.H0_txt = None
self.length = 1024
......@@ -120,6 +123,7 @@ class pzPlot():
self.handles['axH'].set_title('Übertragungsfunktion', fontsize='16', fontweight='bold')
self.handles['axH'].set_xlabel(r'$\rightarrow f$')
self.handles['axH'].set_ylabel(r'$\uparrow \mathrm{|S(f)|}$')
self.handles['lineH'], = self.handles['axH'].plot(self.f, self.f)
ient_axis(self.handles['axH'])
self.handles['axH'].spines['bottom'].set_position(('outward', 0))
......@@ -373,7 +377,6 @@ class pzPlot():
# plt.close(backend.fig)
def update_plot(self):
# Won't work with dirac
poles = np.array(list((x.p for x in self.pp)), dtype=complex)
poles_order = np.array(list((x.order for x in self.pp)))
zeroes = np.array(list((x.p for x in self.pz)), dtype=complex)
......@@ -387,17 +390,32 @@ class pzPlot():
s_t, S_f, signal_type = func.calc_laplace(self.t, self.f, H0, poles, zeroes, poles_order, zeroes_order, roc)
# process signals
if not np.isnan(s_t[0]): # if pbz was not successful
# TODO - Das Ausrechnen von Minimal- und Maximalwerten für die Achsenlimitbestimmung dauert zu lange
# delete existing dirac
if self.arrow is not None:
try:
self.arrow.remove()
self.arrow_txt.remove()
except ValueError:
pass
if not np.isnan(s_t[0]): # if pbz was successful
self.pbzErrortxt.set_visible(False)
if signal_type == '': # if signal does not contain any diracs -> set y-lims according to min, max in array
s_t_extr = [np.amin(np.real(s_t)), np.amax(np.real(s_t))]
self.handles['axh'].set_ylim(s_t_extr[0] + s_t_extr[0] / 10, s_t_extr[1] + s_t_extr[1] / 10)
elif signal_type == 'dirac': # if signal contains diracs -> plot dirac and set y-data
# TODO - plot dirac
_, value = func.findDirac(s_t)
self.handles['axh'].set_ylim(0, np.amax(value) + 0.2)
else:
# just one dirac is plotted for now
ind, value = func.findDirac(s_t)
x_value = self.t[ind[0]]
y_value = value[0]
self.arrow = self.handles['axh'].arrow(x_value, 0, 0, y_value, width=0.1, head_width=0.5,
head_length=2 * y_value/10, fc="k", ec="k", length_includes_head=False)
self.arrow_txt = self.handles['axh'].text(x_value, y_value, "(" + str(y_value) + ")")
s_t[ind[0]] = np.NaN
self.handles['axh'].set_ylim(np.nanmin(np.append(s_t, value[0])) - 0.2, np.nanmax(np.append(s_t, value[0])) + 0.2)
else: # if pbz was not successful
self.handles['axh'].set_ylim(-1, 1)
self.pbzErrortxt.set_visible(True)
......@@ -407,8 +425,6 @@ class pzPlot():
self.handles['axH'].set_ylim(S_f_extr[0] + S_f_extr[0] / 10, S_f_extr[1] + S_f_extr[1] / 10)
# TODO - Eigene Funktion plottet s(t) nicht, was läuft hier schief?
#plot(self.t, s_t, self.handles['axh'])
self.handles['lineh'].set_ydata(s_t)
plot(self.f, S_f, self.handles['axH'])
self.handles['lineH'].set_ydata(S_f)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment