コード例 #1
0
ファイル: main.py プロジェクト: andythekid/Converter
 def plotCorrelationFi(self):
   """
   Построение графика корреляции левого и правого полушария по сегментам
   """
   # Если выделена не однастрока (4 поля)
   if len(self.ui.treExportProbes.selectedIndexes()) != 4:
     self.statusBar().showMessage(u'Пациент не выбран')
     return
   for index in self.ui.treExportProbes.selectedItems():
     # Получаем матрицы съема
     lMatr, rMatr = base.getMatrix(index.text(0), str(index.text(2)))
   # Получаем матрицу корреляции
   corrMtrx = MathFunc.CorrelationSegI(lMatr, rMatr)
   # подготавливаем холст
   gf.preparePlot(self.ui.qwtGraphPlot, u'Корреляция Seg(L,R)')
   gf.setAxis(self.ui.qwtGraphPlot)
   # markers (Вертикальны разделители)
   gf.plotVFuncMarkers(self.ui.qwtGraphPlot)
   # ось абцисс
   gf.plotAbciss(self.ui.qwtGraphPlot)
   # Построение графика правого полушария
   curve = Qwt.QwtPlotCurve(u'Корреляция Seg(L,R)')
   curve.attach(self.ui.qwtGraphPlot)
   curve.setRenderHint(Qwt.QwtPlotItem.RenderAntialiased)
   curve.setPen(Qt.QPen(Qt.Qt.black, 2))
   curve.setData(range(0, 35), corrMtrx)
   # Выводим график
   self.ui.qwtGraphPlot.replot()
コード例 #2
0
ファイル: main.py プロジェクト: andythekid/Converter
 def plotMaxMin(self):
   '''
   Постоение графика Max-min
   '''
   # Если выделена не однастрока (4 поля)
   if len(self.ui.treExportProbes.selectedIndexes()) != 4:
     self.statusBar().showMessage(u'Пациент не выбран')
     return
   for index in self.ui.treExportProbes.selectedItems():
     # Получаем матрицы съема
     lMatr, rMatr = base.getMatrix(index.text(0), str(index.text(2)))
   # Расчитываем MaxMin для каждого полушария
   lMaxMin = MathFunc.MaxMin(lMatr)
   rMaxMin = MathFunc.MaxMin(rMatr)
   # подготавливаем холст
   gf.preparePlot(self.ui.qwtGraphPlot, u'Max-Min')
   gf.setAxis(self.ui.qwtGraphPlot)
   # markers (Вертикальны разделители)
   gf.plotVFuncMarkers(self.ui.qwtGraphPlot)
   # Построение графика левого полушария
   curve = Qwt.QwtPlotCurve(u'Левое полушарие')
   curve.attach(self.ui.qwtGraphPlot)
   curve.setRenderHint(Qwt.QwtPlotItem.RenderAntialiased)
   curve.setPen(Qt.QPen(Qt.Qt.black, 2, Qt.Qt.DotLine))
   curve.setData(range(0, 35), lMaxMin)
   # Построение графика правого полушария
   curve = Qwt.QwtPlotCurve(u'Правое полушарие')
   curve.attach(self.ui.qwtGraphPlot)
   curve.setRenderHint(Qwt.QwtPlotItem.RenderAntialiased)
   curve.setPen(Qt.QPen(Qt.Qt.black, 2))
   curve.setData(range(0, 35), rMaxMin)
   # Выводим график
   self.ui.qwtGraphPlot.replot()
コード例 #3
0
ファイル: main.py プロジェクト: andythekid/Converter
  def plotSegment(self):
    """
    Построение по сегментам
    """
    cols = {'C1':Qt.Qt.black, 'C2-3':Qt.Qt.red, 'C4-5':Qt.Qt.blue,
            'C6':Qt.Qt.black, 'C7-8':Qt.Qt.red, 'Th1':Qt.Qt.blue,
            'Th2':Qt.Qt.black, 'Th3-4':Qt.Qt.red, 'Th5':Qt.Qt.blue,
            'Th6':Qt.Qt.black, 'Th7':Qt.Qt.red, 'Th8-9':Qt.Qt.blue,
            'Th10':Qt.Qt.black, 'Th11':Qt.Qt.red, 'Th12':Qt.Qt.blue,
            'L1':Qt.Qt.black, 'L2':Qt.Qt.red, 'L3':Qt.Qt.blue,
            'L4':Qt.Qt.black, 'L5':Qt.Qt.red, 'S1':Qt.Qt.blue,
            'S2':Qt.Qt.black, 'S3-4':Qt.Qt.red, 'K-S5':Qt.Qt.blue}

    # Если выделена не однастрока (4 поля)
    if len(self.ui.treExportProbes.selectedIndexes()) != 4:
      return
    # подготавливаем холст
    gf.preparePlot(self.ui.qwtSegPlot, u'Сегмент', leg = 'check')
    gf.setAxis(self.ui.qwtSegPlot)
    # markers (Вертикальны разделители)
    gf.plotVFuncMarkers(self.ui.qwtSegPlot)
    # Расчёт значений
    for index in self.ui.treExportProbes.selectedItems():
      # Получаем матрицы съема
      lMatr, rMatr = base.getMatrix(index.text(0), str(index.text(2)))
    # Получаем словарь сегментов для каждого полушария
    lSeg = MathFunc.Segment(lMatr)
    rSeg = MathFunc.Segment(rMatr)
    # Создаём словари curve
    curvL = {}
    curvR = {}
    # Строим графики по сементам
    for key in lSeg.keys():
      # Левое полушарие
      curvL[key] = Qwt.QwtPlotCurve(key)
      curvL[key].attach(self.ui.qwtSegPlot)
      curvL[key].setRenderHint(Qwt.QwtPlotItem.RenderAntialiased)
      curvL[key].setPen(Qt.QPen(cols[key], 2, Qt.Qt.DotLine))
      curvL[key].setData(range(len(lSeg[key])), lSeg[key])
      self.showCurve(curvL[key], False)
      # Правое полушарие
      curvR[key] = Qwt.QwtPlotCurve(key)
      curvR[key].attach(self.ui.qwtSegPlot)
      curvR[key].setRenderHint(Qwt.QwtPlotItem.RenderAntialiased)
      curvR[key].setPen(Qt.QPen(cols[key], 2))
      curvR[key].setData(range(len(rSeg[key])), rSeg[key])
      self.showCurve(curvR[key], False)
    # Выводим график
    self.showCurve(curvL['C1'], True)
    self.showCurve(curvR['C1'], True)
    self.ui.qwtSegPlot.replot()
コード例 #4
0
from DoublePendulum import DP #imports useful modules and double pendulum class from DoublePendulum.py
import json
import pandas as pd
import copy
from pathlib import Path
from matplotlib.animation import FuncAnimation 
import GraphFunc as func


Data = np.load(Path.cwd()/'Datafiles'/'datafile.npy', allow_pickle=True)
graphtitle = 'Total Energy over 500 seconds Euler-Cromer at dt = 0.01s'
graphname = 'graph.png'



kin1 = func.getKE1(Data)
kin2 = func.getKE2(Data)
pot1 = func.getPE1(Data)
pot2 = func.getPE2(Data)
Timelist = func.getTime(Data)
Elist = func.getE(Data)


plt.plot(Timelist, Elist, 'k-', lw = 1)
#plt.plot(Timelist, kin1, 'r-', lw = 1)
#plt.plot(Timelist, kin2, 'b-', lw = 1)
#plt.plot(Timelist, pot1, 'y-', lw = 1)
#plt.plot(Timelist, pot2, 'g-', lw = 1)

ymax = math.ceil( max([max(Elist),max(kin1),max(kin2),max(pot1),max(pot2)]) /10 ) * 10
ymin = min([min(Elist),min(kin1),min(kin2),min(pot1),min(pot2)])
コード例 #5
0
import numpy as np
import matplotlib.pyplot as plt
import math
from DoublePendulum import DP
import json
import pandas as pd
import copy
from pathlib import Path
from matplotlib.animation import FuncAnimation
import GraphFunc as func

Data = np.load(Path.cwd() / 'datafile.npy', allow_pickle=True)

time = func.getTime(Data)
xa = func.getx1(Data)
xb = func.getx2(Data)  #
ya = func.gety1(Data)  #
yb = func.gety2(Data)  #
timeInt = func.getInterval(Data)

fig = plt.figure()  #
ax = fig.add_subplot(111, autoscale_on=False, xlim=(-2, 2), ylim=(-2, 2))  #
ax.grid()
line, = ax.plot([], [], 'o-', lw=2, color='black', ms=8)
time_template = 'time = %.1fs'
time_text = ax.text(
    0.05,
    0.9,
    '',
    transform=ax.transAxes,
)
コード例 #6
0
ファイル: main.py プロジェクト: andythekid/Converter
 def plotVegetIndex(self):
   """
   Построение вегетативного индекса (ВИ)
   """
   if not self.ui.treExportProbes.selectedIndexes():
     return
   srcVI = []
   rezVI = []
   rezDat = []
   # Перебираем все выделенные item-ы
   for index in self.ui.treExportProbes.selectedItems():
     # Получаем матрицы съема
     lMatr, rMatr = base.getMatrix(index.text(0), str(index.text(2)))
     # Расчитываем MaxMin для каждого полушария
     lMaxMin = MathFunc.MaxMin(lMatr)
     rMaxMin = MathFunc.MaxMin(rMatr)
     # Расчитываем ВИ и заносим его в список исходных ВИ
     VI = MathFunc.VegetIndex(lMaxMin, rMaxMin)
     srcVI.append([index.text(2), VI]) #extend
   # Сортируем по дате
   srcVI.sort()
   # Если выставлена группировка индексов по времени и дате
   if self.groupVI:
     # Номер группы
     group = 0
     # Число индексов в группе
     div = 1
     # Предыдущий обрабатываемый ВИ
     oldVI = 0
     for i in xrange(len(srcVI)):
       # Если первый элемент в массиве
       # то добавляем его в первую группу
       if oldVI == 0:
         rezVI.append(srcVI[i][1])
         rezDat.append(srcVI[i][0])
       else:
         d1 = datetime.datetime.strptime(str(srcVI[i][0]), '%Y-%m-%d %H:%M:%S')
         d2 = datetime.datetime.strptime(str(oldVI[0]), '%Y-%m-%d %H:%M:%S')
         diff = d1 - d2
         # Если разница по времени между съемами >= 7 минут (3 мин на
         # съем и 3 на тупняк между съемами)
         if diff.seconds / 60 >= 7:
           # Делим уже сложенные ВИ на их количество
           rezVI[group] = rezVI[group] / div
           # Формируем красивую дату с числом индексов
           d1 = datetime.datetime.strptime(str(rezDat[group]), '%Y-%m-%d %H:%M:%S')
           rezDat[group] = d1.strftime('%d.%m.%y %H:%M ') + '(' + str(div) + ')'
           # Добавляем текущий индекс в новую группу
           group = group + 1
           rezVI.append(srcVI[i][1])
           rezDat.append(srcVI[i][0])
           div = 1
         # Иначе суммируем текущий индекс с существующей суммой
         else:
           rezVI[group] = rezVI[group] + srcVI[i][1]
           div = div + 1
       oldVI = srcVI[i]
     # Завершающий расчёт
     else:
       # Делим уже сложенные ВИ на их количество
       rezVI[group] = rezVI[group] / div
       # Формируем красивую дату с числом индексов
       d1 = datetime.datetime.strptime(str(rezDat[group]), '%Y-%m-%d %H:%M:%S')
       rezDat[group] = d1.strftime('%d.%m.%y %H:%M ') + '(' + str(div) + ')'
   # Если группировка не выставлена
   else:
     for i in xrange(len(srcVI)):
       rezVI.append(srcVI[i][1])
       d1 = datetime.datetime.strptime(str(srcVI[i][0]), '%Y-%m-%d %H:%M:%S')
       rezDat.append(d1.strftime('%d.%m.%y %H:%M '))
   # Расчёт среднего ВИ (отрисовывается отдельно)
   sum = 0
   for i in xrange(len(rezVI)):
     sum = sum + rezVI[i]
   mean = sum / float(len(rezVI))
   # Расчёт максимального ВИ + 20%(для масштабирования)
   maxVI = 0
   for i in rezVI:
     if i > maxVI:
       maxVI = i
   if maxVI < 2.5:
     maxVI = 2.5
   maxVI = maxVI + maxVI * 0.2
   # Построение графика ВИ
   # подготавливаем холст
   gf.preparePlot(self.ui.qwtGraphPlot, u'Вегетативный индекс', leg = 'no')
   gf.setAxis(self.ui.qwtGraphPlot, 'index', rezDat, rezVI, maxVI)
   # График ВИ
   curve = Qwt.QwtPlotCurve(u'ВИ')
   curve.attach(self.ui.qwtGraphPlot)
   curve.setPen(Qt.QPen(Qt.Qt.black, 20))
   curve.setData(range(len(rezVI)), rezVI)
   curve.setStyle(Qwt.Qwt.QwtPlotCurve.Sticks)
   # Построение границ нормы
   gf.plotNormBorders(self.ui.qwtGraphPlot, 2.5, 0.5, mean)
   # Выводим график
   self.ui.qwtGraphPlot.replot()