コード例 #1
0
ファイル: space3Mgui.py プロジェクト: duhovyoblak/IUniverse
    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)
コード例 #2
0
ファイル: space3Mgui.py プロジェクト: duhovyoblak/IUniverse
    def setActValS(self):
        "Choose hidden variable for slider axis for given actX and actY"

        self.actValS = 2

        lst = [1, 2, 4]

        try:
            lst.remove(self.actValX)
        except:
            pass

        try:
            lst.remove(self.actValY)
        except:
            pass

        try:
            lst.remove(self.actValU)
        except:
            pass

        self.actValS = lst[0]

        journal.M(
            'Space3Mgui {} setActValS choose for X={}, Y={}, U={} slider value S = {}'
            .format(self.title, self.actValX, self.actValY, self.actValU,
                    self.actValS), 10)
コード例 #3
0
ファイル: space3Mgui.py プロジェクト: duhovyoblak/IUniverse
    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)
コード例 #4
0
ファイル: partCommon.py プロジェクト: duhovyoblak/IUniverse
    def getJson(self):
        "Create and return Json record for particle"

        json = {'name': self.name, 'type': self.type, 'eV': self.eV}

        journal.M('PartCommon {} getJson created'.format(self.name), 10)

        return json
コード例 #5
0
ファイル: partMassLess.py プロジェクト: duhovyoblak/IUniverse
    def getJson(self):
        "Create and return Json record for particle"

        json = super().getJson()

        journal.M('PartMassLess {} getJson created'.format(self.name), 10)

        return json
コード例 #6
0
    def getMassR(self):
        "Return relativistic mass of particle in [eV/c2], mr = m / sqrt(1 - (v2/c2)) "

        try:
            if self.massLess: return self.getMass()
            else: return self.getMass() / sqrt(1 - self.getAbsV2() / _C2)
        except:
            journal.M(
                'Particle3M {} getMassR is not defined'.format(self.name), 9)
            return _ERR
コード例 #7
0
    def getJson(self):
        "Create and return Json record"

        json = {
            'name': self.name,
            'type': self.type,
            'm': self.m,
            'v': self.v,
            ' pos': self.pos
        }

        journal.M('Particle3M {} getJson created'.format(self.name), 10)

        return json
コード例 #8
0
ファイル: space3Mgui.py プロジェクト: duhovyoblak/IUniverse
    def onSlider(self, new_val):
        "Resolve change in Slider's value for given dimension"

        key = self.values[self.actValS]
        newS = self.sldS.get()

        # Check if new slider's value is applicable
        if newS < self.space3M.shapeMin(key) or newS >= self.space3M.shapeMax(
                key):

            journal.M(
                'Space3Mgui {} onSlider: {} is outside grid for dim {}'.format(
                    self.title, newS, key), 10)
            self.sldS.set(self.sVal)

        else:
            self.sVal = self.sldS.get()
            self.show()
コード例 #9
0
ファイル: partCommon.py プロジェクト: duhovyoblak/IUniverse
    def clear(self):
        "Clear all data content and set default transformation parameters"

        journal.M('PartCommon {} ALL cleared'.format(self.name), 10)
コード例 #10
0
ファイル: space3Mgui.py プロジェクト: duhovyoblak/IUniverse
    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)