FLO-2DSoftware / qgis-flo-2d-plugin

A plugin for pre-processing/post-processing FLO-2D models
5 stars 7 forks source link

Pump Plot Issue #1350

Closed FLO-2DKaren closed 1 month ago

FLO-2DKaren commented 1 month ago
def create_pump_plot(self, name):
    self.plot.clear()
    if self.plot.plot.legend is not None:
        plot_scene = self.plot.plot.legend.scene()
        if plot_scene is not None:
            plot_scene.removeItem(self.plot.plot.legend)
    self.plot.plot.addLegend()

    self.plot_item_name = "Pump Curve:   " + name
    self.plot.plot.setTitle("Pump Curve:   " + name)

    currentPump = self.pump_curve_type_cbo.currentText()
    if currentPump == "Pump1" or currentPump == "Pump2":
        # Insert the (0, 0) and (0, d2[1]) points
        if self.d1 and self.d2:
            adjusted_d1 = [0] + self.d1
            adjusted_d2 = [0] + self.d2
            # Ensure adjusted_d1 has one more point than adjusted_d2
            adjusted_d1.append(adjusted_d1[-1])
            stepped_curve = pg.PlotDataItem(adjusted_d1, adjusted_d2, pen=QColor("#0018d4"), stepMode=True)
            self.plot.plot.addItem(stepped_curve)
    else:
        self.plot.add_item(self.plot_item_name, [self.d1, self.d2], col=QColor("#0018d4"))
FLO-2DKaren commented 1 month ago

I modified the code in Storm Drain Editor Widget to try and get a stepped plot. But my plot is off a little

https://github.com/FLO-2DSoftware/qgis-flo-2d-plugin/assets/20424460/6167c97e-8541-4473-9ba3-4227a59cb3a1

FLO-2DKaren commented 1 month ago

@FLO-2DJJ Hi JJ,

Any ideas on how to shift the plot? I tried to add an adjustment but I don't think it's working.

FLO-2DJJ commented 1 month ago

@FLO-2DKaren, Hi Keren, try this:

    def create_pump_plot(self, name):
        self.plot.clear()
        if self.plot.plot.legend is not None:
            plot_scene = self.plot.plot.legend.scene()
            if plot_scene is not None:
                plot_scene.removeItem(self.plot.plot.legend)
        self.plot.plot.addLegend()

        self.plot_item_name = "Pump Curve:   " + name
        self.plot.plot.setTitle("Pump Curve:   " + name)

        currentPump = self.pump_curve_type_cbo.currentText()
        if currentPump == "Pump1" or currentPump == "Pump2":
            # Insert the (0, 0) and (0, d2[1]) points
            if self.d1 and self.d2:
                adjusted_d1 = [0] + self.d1

                for index, d in enumerate(self.d2):
                    if index < len(self.d2) - 1:
                        self.d2[index] = self.d2[index + 1]

                adjusted_d2= [0] + self.d2  

                # Ensure adjusted_d1 has one more point than adjusted_d2
                adjusted_d1.append(adjusted_d1[1])
                stepped_curve = pg.PlotDataItem(adjusted_d1, adjusted_d2, pen=QColor("#0018d4"), stepMode=True)
                self.plot.plot.addItem(stepped_curve)
        else:
            self.plot.add_item(self.plot_item_name, [self.d1, self.d2], col=QColor("#0018d4"))

image

The only change is this:

                for index, d in enumerate(self.d2):
                    if index < len(self.d2) - 1:
                        self.d2[index] = self.d2[index + 1]

I'll look at the other issue (500 rows). The default for all plots is 500 rows.

FLO-2DKaren commented 1 month ago

@FLO-2DJJ

Oooh, that default is slowing processing down. I've noticed that the blue progress bar on QGIS window on the bottom is always processing for a long time after you click a new plot.
If you print what's trying to plot, you also get a bunch of nan in the console window.

We should look into that.

FLO-2DJJ commented 1 month ago

@FLO-2DKaren,

As a matter of interest, instead of

                for index, d in enumerate(self.d2):
                    if index < len(self.d2) - 1:
                        self.d2[index] = self.d2[index + 1]

you can use

self.d2 = self.d2[1:] + [self.d2[0]]

which is more Pythonic, faster, and readable.

FLO-2DKaren commented 1 month ago

@FLO-2DJJ

OK that looks more sensible to me. Can you implement this in the pump plot code and merge it. Once it is updated, I would like to replace some images that I have on the documentation.

FLO-2DJJ commented 1 month ago

@FLO-2DKaren,

Step plots for pumps of type1 and type2 merged into master with pull request #1352

FLO-2DKaren commented 1 month ago

Deprecation Warnings

@FLO-2DJJ

Hi JJ,

The new code has some deprecation warning that I missed. Can you sort these out.

FLO-2DKaren commented 1 month ago

2024-05-26T15:32:48 WARNING warning:C:\Users/User/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\flo2d\gui\storm_drain_editor_widget.py:5700: DeprecationWarning: stepMode=True is deprecated and will result in an error after October 2022. Use stepMode="center" instead. stepped_curve = pg.PlotDataItem(adjusted_d1, adjusted_d2, pen=QColor("#0018d4"), stepMode=True)

         traceback: File "C:\Users/User/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\flo2d\gui\storm_drain_editor_widget.py", line 5812, in update_pump_curve_data
          self.show_pump_curve_table_and_plot()
          File "C:\Users/User/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\flo2d\gui\storm_drain_editor_widget.py", line 5641, in show_pump_curve_table_and_plot
          self.create_pump_plot(curve_name)
          File "C:\Users/User/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\flo2d\gui\storm_drain_editor_widget.py", line 5700, in create_pump_plot
          stepped_curve = pg.PlotDataItem(adjusted_d1, adjusted_d2, pen=QColor("#0018d4"), stepMode=True)
          File "C:\Users\User\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\flo2d\deps\pyqtgraph-0.13.7-py3-none-any.whl\pyqtgraph\graphicsItems\PlotDataItem.py", line 375, in __init__
          self.setData(*args, **kargs)
          File "C:\Users\User\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\flo2d\deps\pyqtgraph-0.13.7-py3-none-any.whl\pyqtgraph\graphicsItems\PlotDataItem.py", line 690, in setData
          warnings.warn(

2024-05-26T15:32:48 WARNING warning:C:\Users\User\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\flo2d\deps\pyqtgraph-0.13.7-py3-none-any.whl\pyqtgraph\graphicsItems\PlotDataItem.py:905: DeprecationWarning: stepMode=True is deprecated and will result in an error after October 2022. Use stepMode="center" instead. self.curve.setData(x=x, y=y, **curveArgs)

         traceback: File "C:\Users/User/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\flo2d\gui\storm_drain_editor_widget.py", line 5812, in update_pump_curve_data
          self.show_pump_curve_table_and_plot()
          File "C:\Users/User/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\flo2d\gui\storm_drain_editor_widget.py", line 5641, in show_pump_curve_table_and_plot
          self.create_pump_plot(curve_name)
          File "C:\Users/User/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\flo2d\gui\storm_drain_editor_widget.py", line 5700, in create_pump_plot
          stepped_curve = pg.PlotDataItem(adjusted_d1, adjusted_d2, pen=QColor("#0018d4"), stepMode=True)
          File "C:\Users\User\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\flo2d\deps\pyqtgraph-0.13.7-py3-none-any.whl\pyqtgraph\graphicsItems\PlotDataItem.py", line 375, in __init__
          self.setData(*args, **kargs)
          File "C:\Users\User\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\flo2d\deps\pyqtgraph-0.13.7-py3-none-any.whl\pyqtgraph\graphicsItems\PlotDataItem.py", line 833, in setData
          self.updateItems( styleUpdate = self.property('styleWasChanged') )
          File "C:\Users\User\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\flo2d\deps\pyqtgraph-0.13.7-py3-none-any.whl\pyqtgraph\graphicsItems\PlotDataItem.py", line 905, in updateItems
          self.curve.setData(x=x, y=y, **curveArgs)
          File "C:\Users\User\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\flo2d\deps\pyqtgraph-0.13.7-py3-none-any.whl\pyqtgraph\graphicsItems\PlotCurveItem.py", line 479, in setData
          self.updateData(*args, **kargs)
          File "C:\Users\User\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\flo2d\deps\pyqtgraph-0.13.7-py3-none-any.whl\pyqtgraph\graphicsItems\PlotCurveItem.py", line 527, in updateData
          warnings.warn(

2024-05-26T15:32:48 WARNING warning:C:\Users\User\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\flo2d\deps\pyqtgraph-0.13.7-py3-none-any.whl\pyqtgraph\graphicsItems\PlotDataItem.py:905: DeprecationWarning: stepMode=True is deprecated and will result in an error after October 2022. Use stepMode="center" instead. self.curve.setData(x=x, y=y, **curveArgs)

         traceback: File "C:\Users/User/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\flo2d\gui\storm_drain_editor_widget.py", line 5812, in update_pump_curve_data
          self.show_pump_curve_table_and_plot()
          File "C:\Users/User/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\flo2d\gui\storm_drain_editor_widget.py", line 5675, in show_pump_curve_table_and_plot
          self.update_pump_plot()
          File "C:\Users/User/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\flo2d\gui\storm_drain_editor_widget.py", line 5713, in update_pump_plot
          self.plot.auto_range()
          File "C:\Users/User/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\flo2d\gui\plot_widget.py", line 139, in auto_range
          self.plot.autoRange()
          File "C:\Users\User\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\flo2d\deps\pyqtgraph-0.13.7-py3-none-any.whl\pyqtgraph\graphicsItems\PlotItem\PlotItem.py", line 275, in method
          return getattr(self.vb, name)(*args, **kwargs)
          File "C:\Users\User\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\flo2d\deps\pyqtgraph-0.13.7-py3-none-any.whl\pyqtgraph\graphicsItems\ViewBox\ViewBox.py", line 727, in autoRange
          self.setRange(bounds, padding=padding)
          File "C:\Users\User\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\flo2d\deps\pyqtgraph-0.13.7-py3-none-any.whl\pyqtgraph\graphicsItems\ViewBox\ViewBox.py", line 674, in setRange
          self.updateViewRange(lockX, lockY)
          File "C:\Users\User\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\flo2d\deps\pyqtgraph-0.13.7-py3-none-any.whl\pyqtgraph\graphicsItems\ViewBox\ViewBox.py", line 1683, in updateViewRange
          self.sigRangeChanged.emit(self, self.state['viewRange'], changed)
          File "C:\Users\User\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\flo2d\deps\pyqtgraph-0.13.7-py3-none-any.whl\pyqtgraph\graphicsItems\PlotDataItem.py", line 1209, in viewRangeChanged
          self.updateItems(styleUpdate=False)
          File "C:\Users\User\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\flo2d\deps\pyqtgraph-0.13.7-py3-none-any.whl\pyqtgraph\graphicsItems\PlotDataItem.py", line 905, in updateItems
          self.curve.setData(x=x, y=y, **curveArgs)
          File "C:\Users\User\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\flo2d\deps\pyqtgraph-0.13.7-py3-none-any.whl\pyqtgraph\graphicsItems\PlotCurveItem.py", line 479, in setData
          self.updateData(*args, **kargs)
          File "C:\Users\User\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\flo2d\deps\pyqtgraph-0.13.7-py3-none-any.whl\pyqtgraph\graphicsItems\PlotCurveItem.py", line 527, in updateData
          warnings.warn(
FLO-2DJJ commented 1 month ago

stepMode=True changed to stepMode="center". Merged to master with PR #1357

FLO-2DKaren commented 1 month ago

Tested