diff --git a/pyqt/stabwindow.ui b/pyqt/stabwindow.ui index afe0d9dbf17e562ad14e9a2758cc2fb7d3e2d8ed..3fdda7266f2aea691e67bd0495c3726abeb192fb 100644 --- a/pyqt/stabwindow.ui +++ b/pyqt/stabwindow.ui @@ -7,7 +7,7 @@ <x>0</x> <y>0</y> <width>1338</width> - <height>713</height> + <height>760</height> </rect> </property> <property name="windowTitle"> @@ -61,7 +61,7 @@ <property name="geometry"> <rect> <x>10</x> - <y>50</y> + <y>90</y> <width>1321</width> <height>651</height> </rect> @@ -70,8 +70,8 @@ <widget class="QWidget" name="horizontalLayoutWidget_2"> <property name="geometry"> <rect> - <x>610</x> - <y>10</y> + <x>10</x> + <y>50</y> <width>721</width> <height>31</height> </rect> @@ -89,6 +89,98 @@ <property name="toolTip"> <string><html><head/><body><p>Tab-separated boundaries of the two regions (blue and green area).</p><p>Can be directly copy-pasted in Excel/Calc.</p></body></html></string> </property> + <property name="readOnly"> + <bool>true</bool> + </property> + </widget> + </item> + </layout> + </widget> + <widget class="QWidget" name="gridLayoutWidget"> + <property name="geometry"> + <rect> + <x>1110</x> + <y>10</y> + <width>213</width> + <height>71</height> + </rect> + </property> + <layout class="QGridLayout" name="gridLayout"> + <item row="1" column="0"> + <widget class="QLabel" name="stab_label_blue"> + <property name="text"> + <string>Blue</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QLabel" name="stab_label_mean"> + <property name="text"> + <string>Mean</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QLineEdit" name="stab_lineedit_left_mean"> + <property name="readOnly"> + <bool>true</bool> + </property> + </widget> + </item> + <item row="2" column="0"> + <widget class="QLabel" name="stab_label_green"> + <property name="text"> + <string>Green</string> + </property> + </widget> + </item> + <item row="0" column="2"> + <widget class="QLabel" name="stab_label_sd"> + <property name="text"> + <string>Std dev</string> + </property> + </widget> + </item> + <item row="0" column="3"> + <widget class="QLabel" name="stab_label_time"> + <property name="text"> + <string>Time span (s)</string> + </property> + </widget> + </item> + <item row="2" column="1"> + <widget class="QLineEdit" name="stab_lineedit_right_mean"> + <property name="readOnly"> + <bool>true</bool> + </property> + </widget> + </item> + <item row="1" column="2"> + <widget class="QLineEdit" name="stab_lineedit_left_sd"> + <property name="readOnly"> + <bool>true</bool> + </property> + </widget> + </item> + <item row="2" column="2"> + <widget class="QLineEdit" name="stab_lineedit_right_sd"> + <property name="readOnly"> + <bool>true</bool> + </property> + </widget> + </item> + <item row="1" column="3"> + <widget class="QLineEdit" name="stab_lineedit_left_time"> + <property name="readOnly"> + <bool>true</bool> + </property> + </widget> + </item> + <item row="2" column="3"> + <widget class="QLineEdit" name="stab_lineedit_right_time"> + <property name="readOnly"> + <bool>true</bool> + </property> </widget> </item> </layout> diff --git a/src/gui/uistabwindow.py b/src/gui/uistabwindow.py index 1908ca22edde252173aeea165309f5ae62ffcbbe..d0aaa050d2c17d3140597299d3464150d83e02fb 100644 --- a/src/gui/uistabwindow.py +++ b/src/gui/uistabwindow.py @@ -11,7 +11,7 @@ from PyQt5 import QtCore, QtGui, QtWidgets class Ui_StabWindow(object): def setupUi(self, StabWindow): StabWindow.setObjectName("StabWindow") - StabWindow.resize(1338, 713) + StabWindow.resize(1338, 760) self.horizontalLayoutWidget = QtWidgets.QWidget(StabWindow) self.horizontalLayoutWidget.setGeometry(QtCore.QRect(10, 10, 461, 31)) self.horizontalLayoutWidget.setObjectName("horizontalLayoutWidget") @@ -33,10 +33,10 @@ class Ui_StabWindow(object): self.stab_combobox_variable.setObjectName("stab_combobox_variable") self.horizontalLayout.addWidget(self.stab_combobox_variable) self.stab_graphicsview = PlotWidget(StabWindow) - self.stab_graphicsview.setGeometry(QtCore.QRect(10, 50, 1321, 651)) + self.stab_graphicsview.setGeometry(QtCore.QRect(10, 90, 1321, 651)) self.stab_graphicsview.setObjectName("stab_graphicsview") self.horizontalLayoutWidget_2 = QtWidgets.QWidget(StabWindow) - self.horizontalLayoutWidget_2.setGeometry(QtCore.QRect(610, 10, 721, 31)) + self.horizontalLayoutWidget_2.setGeometry(QtCore.QRect(10, 50, 721, 31)) self.horizontalLayoutWidget_2.setObjectName("horizontalLayoutWidget_2") self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget_2) self.horizontalLayout_2.setContentsMargins(0, 0, 0, 0) @@ -45,8 +45,54 @@ class Ui_StabWindow(object): self.stab_label_timeranges.setObjectName("stab_label_timeranges") self.horizontalLayout_2.addWidget(self.stab_label_timeranges) self.stab_lineedit_timeranges = QtWidgets.QLineEdit(self.horizontalLayoutWidget_2) + self.stab_lineedit_timeranges.setReadOnly(True) self.stab_lineedit_timeranges.setObjectName("stab_lineedit_timeranges") self.horizontalLayout_2.addWidget(self.stab_lineedit_timeranges) + self.gridLayoutWidget = QtWidgets.QWidget(StabWindow) + self.gridLayoutWidget.setGeometry(QtCore.QRect(1110, 10, 213, 71)) + self.gridLayoutWidget.setObjectName("gridLayoutWidget") + self.gridLayout = QtWidgets.QGridLayout(self.gridLayoutWidget) + self.gridLayout.setContentsMargins(0, 0, 0, 0) + self.gridLayout.setObjectName("gridLayout") + self.stab_label_blue = QtWidgets.QLabel(self.gridLayoutWidget) + self.stab_label_blue.setObjectName("stab_label_blue") + self.gridLayout.addWidget(self.stab_label_blue, 1, 0, 1, 1) + self.stab_label_mean = QtWidgets.QLabel(self.gridLayoutWidget) + self.stab_label_mean.setObjectName("stab_label_mean") + self.gridLayout.addWidget(self.stab_label_mean, 0, 1, 1, 1) + self.stab_lineedit_left_mean = QtWidgets.QLineEdit(self.gridLayoutWidget) + self.stab_lineedit_left_mean.setReadOnly(True) + self.stab_lineedit_left_mean.setObjectName("stab_lineedit_left_mean") + self.gridLayout.addWidget(self.stab_lineedit_left_mean, 1, 1, 1, 1) + self.stab_label_green = QtWidgets.QLabel(self.gridLayoutWidget) + self.stab_label_green.setObjectName("stab_label_green") + self.gridLayout.addWidget(self.stab_label_green, 2, 0, 1, 1) + self.stab_label_sd = QtWidgets.QLabel(self.gridLayoutWidget) + self.stab_label_sd.setObjectName("stab_label_sd") + self.gridLayout.addWidget(self.stab_label_sd, 0, 2, 1, 1) + self.stab_label_time = QtWidgets.QLabel(self.gridLayoutWidget) + self.stab_label_time.setObjectName("stab_label_time") + self.gridLayout.addWidget(self.stab_label_time, 0, 3, 1, 1) + self.stab_lineedit_right_mean = QtWidgets.QLineEdit(self.gridLayoutWidget) + self.stab_lineedit_right_mean.setReadOnly(True) + self.stab_lineedit_right_mean.setObjectName("stab_lineedit_right_mean") + self.gridLayout.addWidget(self.stab_lineedit_right_mean, 2, 1, 1, 1) + self.stab_lineedit_left_sd = QtWidgets.QLineEdit(self.gridLayoutWidget) + self.stab_lineedit_left_sd.setReadOnly(True) + self.stab_lineedit_left_sd.setObjectName("stab_lineedit_left_sd") + self.gridLayout.addWidget(self.stab_lineedit_left_sd, 1, 2, 1, 1) + self.stab_lineedit_right_sd = QtWidgets.QLineEdit(self.gridLayoutWidget) + self.stab_lineedit_right_sd.setReadOnly(True) + self.stab_lineedit_right_sd.setObjectName("stab_lineedit_right_sd") + self.gridLayout.addWidget(self.stab_lineedit_right_sd, 2, 2, 1, 1) + self.stab_lineedit_left_time = QtWidgets.QLineEdit(self.gridLayoutWidget) + self.stab_lineedit_left_time.setReadOnly(True) + self.stab_lineedit_left_time.setObjectName("stab_lineedit_left_time") + self.gridLayout.addWidget(self.stab_lineedit_left_time, 1, 3, 1, 1) + self.stab_lineedit_right_time = QtWidgets.QLineEdit(self.gridLayoutWidget) + self.stab_lineedit_right_time.setReadOnly(True) + self.stab_lineedit_right_time.setObjectName("stab_lineedit_right_time") + self.gridLayout.addWidget(self.stab_lineedit_right_time, 2, 3, 1, 1) self.retranslateUi(StabWindow) QtCore.QMetaObject.connectSlotsByName(StabWindow) @@ -58,5 +104,10 @@ class Ui_StabWindow(object): self.stab_label_variable.setText(_translate("StabWindow", " Variable:")) self.stab_label_timeranges.setText(_translate("StabWindow", "Time ranges:")) self.stab_lineedit_timeranges.setToolTip(_translate("StabWindow", "<html><head/><body><p>Tab-separated boundaries of the two regions (blue and green area).</p><p>Can be directly copy-pasted in Excel/Calc.</p></body></html>")) + self.stab_label_blue.setText(_translate("StabWindow", "Blue")) + self.stab_label_mean.setText(_translate("StabWindow", "Mean")) + self.stab_label_green.setText(_translate("StabWindow", "Green")) + self.stab_label_sd.setText(_translate("StabWindow", "Std dev")) + self.stab_label_time.setText(_translate("StabWindow", "Time span (s)")) from pyqtgraph import PlotWidget diff --git a/src/uim/explouim.py b/src/uim/explouim.py index 6786dfba3a6832e1b78518b3543008dc4871cb44..1d2d35e9976dc8d6e200450f92b28483a2a383e9 100644 --- a/src/uim/explouim.py +++ b/src/uim/explouim.py @@ -566,7 +566,7 @@ class ExploUim: self.stab_region_left = pg.LinearRegionItem(brush=pg.mkBrush(color=[0, 0, 255, 40])) self.stab_region_left.setZValue(10) self.stab_plot_item.addItem(self.stab_region_left, ignoreBounds=True) - self.stab_region_left.sigRegionChanged.connect(lambda region: self.__update_stab_mean__(region, "left")) + self.stab_region_left.sigRegionChanged.connect(lambda region: self.__update_region_characteristics__(region, "left")) self.stab_region_left.sigRegionChanged.connect(self.__update_time_ranges__) self.stab_left_mean = 0.0 self.stab_left_mean_line = pg.InfiniteLine(pen=pg.mkPen(color=[0, 0, 255]), angle=0) @@ -576,7 +576,7 @@ class ExploUim: self.stab_region_right = pg.LinearRegionItem(brush=pg.mkBrush(color=[0, 255, 0, 40])) self.stab_region_right.setZValue(10) self.stab_plot_item.addItem(self.stab_region_right, ignoreBounds=True) - self.stab_region_right.sigRegionChanged.connect(lambda region: self.__update_stab_mean__(region, "right")) + self.stab_region_right.sigRegionChanged.connect(lambda region: self.__update_region_characteristics__(region, "right")) self.stab_region_right.sigRegionChanged.connect(self.__update_time_ranges__) self.stab_right_mean = 0.0 self.stab_right_mean_line = pg.InfiniteLine(pen=pg.mkPen(color=[0, 255, 0]), angle=0) @@ -635,26 +635,35 @@ class ExploUim: self.stab_region_right.setRegion([x_2_third, x_max]) # Re-calculate the position of the left/right means - self.__update_stab_mean__(self.stab_region_left, "left") - self.__update_stab_mean__(self.stab_region_right, "right") + self.__update_region_characteristics__(self.stab_region_left, "left") + self.__update_region_characteristics__(self.stab_region_right, "right") # X range is the same as main window's plot X range self.stab_plot_item.getViewBox().setRange(xRange=(main_range[0][0], main_range[0][1]), yRange=(main_range[1][0], main_range[1][1]), padding=0) - def __update_stab_mean__(self, region: pg.LinearRegionItem, side: str): + def __update_region_characteristics__(self, region: pg.LinearRegionItem, side: str): df = self.stab_timeseries.copy() # Get the selected region's boundaries xmin = region.getRegion()[0] xmax = region.getRegion()[1] - # Compute x_value's average over the selected region. - mean = df[(df["datetime"] >= xmin) & (df["datetime"] <= xmax)]["value"].mean() + # Get data inside region's boundaries + inside_values = df[(df["datetime"] >= xmin) & (df["datetime"] <= xmax)]["value"] + + # Compute x_value's average and standard deviation over the selected region. + mean = inside_values.mean() + sd = inside_values.std() if math.isnan(mean): return + # Update UI's text zones + getattr(self.stab_window.ui, "stab_lineedit_"+side+"_mean").setText("{:.2f}".format(mean)) + getattr(self.stab_window.ui, "stab_lineedit_"+side+"_sd").setText("{:.2f}".format(sd)) + getattr(self.stab_window.ui, "stab_lineedit_"+side+"_time").setText("{:.2f}".format(xmax-xmin)) + # Update global "mean" variable setattr(self, "stab_" + side + "_mean", mean)