def reScale(self): "Re-scale all data vectors for better understability" journal.I('Space3Mgui {} reScale...'.format(self.title), 10) for key, lst in self.data.items(): pL = list(lst) # Urobim si kopiu listu na pokusy :-) pL.sort() # Najdem vhodny koeficient if pL[-1] - pL[0] > 1e-12: c = ('p', 1e+12) if pL[-1] - pL[0] > 1e-09: c = ('n', 1e+09) if pL[-1] - pL[0] > 1e-06: c = ('ยต', 1e+06) if pL[-1] - pL[0] > 1e-03: c = ('m', 1e+03) if pL[-1] - pL[0] > 1e+00: c = ('', 1e+00) if pL[-1] - pL[0] > 1e+03: c = ('K', 1e-03) if pL[-1] - pL[0] > 1e+06: c = ('M', 1e-06) if pL[-1] - pL[0] > 1e+09: c = ('G', 1e-09) if pL[-1] - pL[0] > 1e+12: c = ('T', 1e-12) # Preskalujem udaje for i in range(len(lst)): lst[i] = lst[i] * c[1] self.meta[key]['unit'] = c[0] self.meta[key]['coeff'] = c[1] journal.M( 'Space3Mgui {} Data list {} was re-scaled by {:e} with preposition {}' .format(self.title, key, c[1], c[0]), 10) journal.O('Space3Mgui {} reScale done'.format(self.title), 10)
def __init__(self, name, pos, eV=1): "Call constructor of PartMassLess and initialise it" journal.I('PartMassLess constructor for {}...'.format(name), 10) super().__init__(name, pos, eV) self.type = 'MassLess' journal.O('PartMassLess {} created'.format(self.name), 10)
def getDataSlice(self): "Return a slice of data for given actValS" sDim = 'g' + self.values[self.actValS] sCut = self.sVal journal.I( "Space3Mgui {} getDataSlice will use Dim='{}' with cut={}".format( self.title, sDim, sCut), 10) x = [] y = [] u = [] v = [] xDim = self.values[self.actValX] yDim = self.values[self.actValY] uDim = self.values[self.actValU] vDim = self.values[self.actValV] i = 0 for sValue in self.data[sDim]: if sValue == sCut: x.append(self.data[xDim][i]) y.append(self.data[yDim][i]) u.append(self.data[uDim][i]) v.append(self.data[vDim][i]) i += 1 X = np.array(x) journal.M( "Space3Mgui {} getDataSlice X dimension is {} in <{:.3}, {:.3}>". format(self.title, xDim, X.min(), X.max()), 10) Y = np.array(y) journal.M( "Space3Mgui {} getDataSlice Y dimension is {} in <{:.3}, {:.3}>". format(self.title, yDim, Y.min(), Y.max()), 10) U = np.array(u) journal.M( "Space3Mgui {} getDataSlice U dimension is {} in <{:.3}, {:.3}>". format(self.title, uDim, U.min(), U.max()), 10) V = np.array(v) journal.M( "Space3Mgui {} getDataSlice V dimension is {} in <{:.3}, {:.3}>". format(self.title, vDim, V.min(), V.max()), 10) journal.O( "Space3Mgui {} getDataSlice return 4 x {} data points".format( self.title, len(x)), 10) return (X, Y, U, V)
def __init__(self, name, pos, eV): "Call constructor of PartCommon and initialise it" journal.I('PartCommon constructor for {}...'.format(name), 10) self.name = name # unique name for particle in Your project self.type = 'common' # type of particle, used in inherited classes self.pos = pos # position of probability density amplitude origin self.eV = eV # energy of article in [eV] journal.O( 'PartCommon {} created with {:e} eV'.format(self.name, self.eV), 10)
def __init__(self, name, massLess, m, v): "Call constructor of Particle3M and initialise it" journal.I('Particle3M constructor for {}...'.format(name), 10) self.name = name # unique name for particle in Your project self.type = 'common' # type of particle, used in inherited classes self.massLess = massLess # is massless particle ? self.m = m # rest mass or energy for massless particle in [eV/c2] self.v = v # wave vector {'vx', 'vy', 'vz'} in [meter/second] self.pos = {'x': 0, 'y': 0, 'z': 0, 't': 0} # Default position journal.O('Particle3M {} created'.format(self.name), 10)
def toSpace(self, space, pos='nil'): "Write particle to Minkowski space" journal.I('Particle3M {} toSpace...'.format(self.name), 10) if pos != 'nil': self.pos = pos for cell in space.act.values(): pos = cell['pos'] val = cell['val'] val['phi'] = space.getDPos(self.pos, pos) journal.O('Particle3M {} toSpace done'.format(self.name), 10)
#============================================================================== # package's constants #------------------------------------------------------------------------------ #============================================================================== # package's tools #------------------------------------------------------------------------------ #============================================================================== # Functions #------------------------------------------------------------------------------ #------------------------------------------------------------------------------ #------------------------------------------------------------------------------ if __name__ == '__main__': journal.I('Main loop') # Vytvorim testovaci space3M st = Space3M('Photon') st.createSpace( { 'xMin': -30, 'xMax': 30, 'yMin': -10, 'yMax': 50, 'zMin': 0, 'zMax': 1, 'tMin': -20, 'tMax': 50 }, 0.05)
def __init__(self, space): "Create and show GUI for Minkowski space" journal.I('Space3Mgui constructor...', 10) #---------------------------------------------------------------------- # Internal data self.space3M = space self.title = self.space3M.name self.axes = { 1: 'Scatter chart', 2: 'Quiver chart', 3: '3D projection', 4: 'Line chart' } self.actAxe = 1 self.values = { 1: 'x', 2: 'y', 3: 'z', 4: 't', 5: 'reDt', 6: 'imDt', 7: 'abDt', 8: 'reAmN', 9: 'imAmN', 10: 'abAmN', 11: 'reAmR', 12: 'imAmR', 13: 'abAmR', 14: 'Prob' } self.actValX = 1 self.actValY = 4 self.actValU = 7 self.actValV = 13 self.setActValS() #---------------------------------------------------------------------- # Ziskanie realnych dat na zobrazenie z podkladoveho priestoru dat = self.space3M.getPlotData() self.meta = dat['meta'] self.data = dat['data'] self.reScale() #---------------------------------------------------------------------- # Create output window win = tk.Tk() win.title(self.title) win.geometry(_WIN) win.resizable(False, False) win.update() self.w = win.winfo_width() self.h = win.winfo_height() #---------------------------------------------------------------------- # Create layout self.fig = plt.figure(figsize=(self.w * _FIG_W / 100, self.h * _FIG_H / 100), dpi=_DPI) self.ax = self.fig.add_subplot(1, 1, 1) self.canvas = FigureCanvasTkAgg(self.fig, master=win) # A tk.DrawingArea. self.canvas.draw() self.canvas.get_tk_widget().place(x=self.w * 0.0, y=self.h * 0.0) self.fig.canvas.callbacks.connect('button_press_event', self.on_click) #---------------------------------------------------------------------- # Axes buttons setup self.butAxeMap = tk.IntVar() for i, val in self.axes.items(): self.butA = tk.Radiobutton(win, text="{}".format(val), variable=self.butAxeMap, value=i, command=self.onButAxe) self.butA.place(x=self.w * _BTN_AXE_W, y=self.h * (_BTN_AXE_H + i * _BTN_DIS_H)) self.butA.select() self.butAxeMap.set(self.actAxe) #---------------------------------------------------------------------- # Value buttons X setup self.butValMapX = tk.IntVar() for i, val in self.values.items(): self.butX = tk.Radiobutton(win, text="{} [{}]".format( val, self.meta[val]['dim']), variable=self.butValMapX, value=i, command=self.onButValX) self.butX.place(x=self.w * _BTN_VAL_W, y=self.h * (_BTN_VAL_H + i * _BTN_DIS_H)) self.butX.select() self.butValMapX.set(self.actValX) #---------------------------------------------------------------------- # Value buttons Y setup self.butValMapY = tk.IntVar() for i, val in self.values.items(): self.butY = tk.Radiobutton(win, text="{} [{}]".format( val, self.meta[val]['dim']), variable=self.butValMapY, value=i, command=self.onButValY) self.butY.place(x=self.w * (_BTN_VAL_W + _BTN_DIS_W), y=self.h * (_BTN_VAL_H + i * _BTN_DIS_H)) self.butY.select() self.butValMapY.set(self.actValY) #---------------------------------------------------------------------- # Value buttons U setup self.butValMapU = tk.IntVar() for i, val in self.values.items(): self.butU = tk.Radiobutton(win, text="{} [{}]".format( val, self.meta[val]['dim']), variable=self.butValMapU, value=i, command=self.onButValU) self.butU.place(x=self.w * _BTN_VAL_W, y=self.h * (_BTN_VAL_H + (i + 15) * _BTN_DIS_H)) self.butU.select() self.butValMapU.set(self.actValU) #---------------------------------------------------------------------- # Value buttons V setup self.butValMapV = tk.IntVar() for i, val in self.values.items(): self.butV = tk.Radiobutton(win, text="{} [{}]".format( val, self.meta[val]['dim']), variable=self.butValMapV, value=i, command=self.onButValV) self.butV.place(x=self.w * (_BTN_VAL_W + _BTN_DIS_W), y=self.h * (_BTN_VAL_H + (i + 15) * _BTN_DIS_H)) self.butV.select() self.butValMapV.set(self.actValV) #---------------------------------------------------------------------- # Slider for slider axis Z setup sMin = self.space3M.shapeMin() sMax = self.space3M.shapeMax() self.sldS = tk.Scale(win, from_=sMin, to=sMax, resolution=1, orient=tk.HORIZONTAL, length=self.w * 0.18, command=self.onSlider, label="Dimension ") self.sldS.place(x=self.w * 0.81, y=self.h * 0.9) self.sVal = 0 self.sLabMap = tk.StringVar() self.sLab = tk.Label(win, textvariable=self.sLabMap) self.sLab.place(x=self.w * 0.86, y=self.h * 0.9) self.sLabMap.set("Test") #---------------------------------------------------------------------- # Initialisation self.show() # Initial drawing journal.O('Space3Mgui created for space {}'.format(self.title), 10) win.mainloop() # Start listening for events
def show(self): "Show Minkovski space according to given parameters" journal.I( 'Space3Mgui {} show {}'.format(self.title, self.axes[self.actAxe]), 10) # Odstranenie vsetkych axes while len(self.fig.axes) > 0: self.fig.axes[0].remove() # Rozhodnutie o slider dimezii self.setActValS() # Vytvorenie rezu udajov na zobrazenie (X, Y, U, V) = self.getDataSlice() # Priprava novych axes self.sliderShow() valX = self.values[self.actValX] valY = self.values[self.actValY] if self.actAxe == 1: # Scatter plot self.ax = self.fig.add_subplot(1, 1, 1) self.ax.set_title("{}: {}".format(self.axes[self.actAxe], self.title), fontsize=14) self.ax.grid(True) self.ax.set_xlabel(self.getDataLabel(valX)) self.ax.set_ylabel(self.getDataLabel(valY)) sctr = self.ax.scatter(x=X, y=Y, c=U, cmap='RdYlBu_r') self.fig.colorbar(sctr, ax=self.ax) elif self.actAxe == 2: # Quiver plot self.ax = self.fig.add_subplot(1, 1, 1) self.ax.set_title("{}: {}".format(self.axes[self.actAxe], self.title), fontsize=14) self.ax.grid(True) self.ax.set_xlabel(self.getDataLabel(valX)) self.ax.set_ylabel(self.getDataLabel(valY)) # Farebna skala podla fazy arr = np.c_[U, V] f = [] for c in arr: f.append(cm.phase(complex(c[0], c[1]))) C = np.array(f) # Vykreslenie axes quiv = self.ax.quiver(X, Y, U, V, C, cmap='RdYlBu_r') self.fig.colorbar(quiv, ax=self.ax) elif self.actAxe == 3: # 3D projection self.ax = self.fig.add_subplot(1, 1, 1, projection='3d') self.ax.set_title("{}: {}".format(self.axes[self.actAxe], self.title), fontsize=14) self.ax.grid(True) self.ax.set_xlabel(self.getDataLabel(valX)) self.ax.set_ylabel(self.getDataLabel(valY)) # Reduction z-axis a = U.min() b = U.max() dr = _SC_RED * (b - a) self.ax.set_zlim(a - dr, b + dr) # Vykreslenie axes surf = self.ax.plot_trisurf(X, Y, U, linewidth=0.2, cmap='RdYlBu_r', antialiased=False) self.fig.colorbar(surf, ax=self.ax) elif self.actAxe == 4: # Line plot self.ax = self.fig.add_subplot(1, 1, 1) self.ax.set_title("{}: {}".format(self.axes[self.actAxe], self.title), fontsize=14) self.ax.grid(True) self.ax.set_xlabel(self.getDataLabel(valX)) self.ax.set_ylabel(self.getDataLabel(valY)) self.ax.plot(X, Y) else: journal.M( 'Space3Mgui {} show error: Unknown axe {}'.format( self.title, self.actAxe), 10) # Vykreslenie noveho grafu self.fig.tight_layout() self.canvas.draw() journal.O('Space3Mgui {} show done'.format(self.title), 10)