Changeset 092a3d9 in sasview


Ignore:
Timestamp:
Jan 20, 2017 6:26:35 AM (7 years ago)
Author:
Piotr Rozyczko <rozyczko@…>
Branches:
ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
Children:
03c372d
Parents:
0f3c22d
Message:

Color Map control for 2D charts. Initial commit - SASVIEW-391

Location:
src/sas
Files:
3 added
9 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/GUITests.py

    r87cc73a r092a3d9  
    2323from UnitTesting import PlotPropertiesTest 
    2424from UnitTesting import PlotUtilitiesTest 
     25from UnitTesting import ColorMapTest 
    2526 
    2627def suite(): 
     
    4849        unittest.makeSuite(PlotPropertiesTest.PlotPropertiesTest, 'test'), 
    4950        unittest.makeSuite(PlotUtilitiesTest.PlotUtilitiesTest, 'test'), 
     51        unittest.makeSuite(ColorMapTest.ColorMapTest, 'test'), 
    5052    ) 
    5153    return unittest.TestSuite(suites) 
  • src/sas/qtgui/Plotter.py

    r0f3c22d r092a3d9  
    2828        self.plot_dict = {} 
    2929 
    30         # Simple window for data display 
    31         self.txt_widget = QtGui.QTextEdit(None) 
    3230        # Window for text add 
    3331        self.addText = AddText(self) 
     
    336334            self.canvas.draw_idle() 
    337335 
    338     def onDataInfo(self, plot_data): 
    339         """ 
    340         Displays data info text window for the selected plot 
    341         """ 
    342         text_to_show = GuiUtils.retrieveData1d(plot_data) 
    343         # Hardcoded sizes to enable full width rendering with default font 
    344         self.txt_widget.resize(420,600) 
    345  
    346         self.txt_widget.setReadOnly(True) 
    347         self.txt_widget.setWindowFlags(QtCore.Qt.Window) 
    348         self.txt_widget.setWindowIcon(QtGui.QIcon(":/res/ball.ico")) 
    349         self.txt_widget.setWindowTitle("Data Info: %s" % plot_data.filename) 
    350         self.txt_widget.insertPlainText(text_to_show) 
    351  
    352         self.txt_widget.show() 
    353         # Move the slider all the way up, if present 
    354         vertical_scroll_bar = self.txt_widget.verticalScrollBar() 
    355         vertical_scroll_bar.triggerAction(QtGui.QScrollBar.SliderToMinimum) 
    356  
    357     def onSavePoints(self, plot_data): 
    358         """ 
    359         Saves plot data to a file 
    360         """ 
    361         GuiUtils.saveData1D(plot_data) 
    362  
    363336    def onLinearFit(self, id): 
    364337        """ 
  • src/sas/qtgui/Plotter2D.py

    rb46f285 r092a3d9  
    22import numpy 
    33import pylab 
     4import functools 
    45 
    56from PyQt4 import QtGui 
     7from PyQt4 import QtCore 
    68 
    79DEFAULT_CMAP = pylab.cm.jet 
     
    1012import sas.qtgui.PlotUtilities as PlotUtilities 
    1113from sas.qtgui.PlotterBase import PlotterBase 
     14from sas.qtgui.ColorMap import ColorMap 
    1215from sas.sasgui.guiframe.dataFitting import Data2D 
    1316 
     
    2225        self.dimension = dimension 
    2326        super(Plotter2DWidget, self).__init__(parent, manager=manager, quickplot=quickplot) 
     27 
     28        self.cmap = DEFAULT_CMAP.name 
     29        # Default scale 
     30        self.scale = 'log_{10}' 
    2431 
    2532    @property 
     
    5562 
    5663        # Toggle the scale 
    57         zmin_2D_temp = self.zmin 
    58         zmax_2D_temp = self.zmax 
    59         # self.scale predefined in the baseclass 
    60         if self.scale == 'log_{10}': 
    61             self.scale = 'linear' 
    62             if not self.zmin is None: 
    63                 zmin_2D_temp = numpy.power(10, self.zmin) 
    64             if not self.zmax is None: 
    65                 zmax_2D_temp = numpy.power(10, self.zmax) 
    66         else: 
    67             self.scale = 'log_{10}' 
    68             if not self.zmin is None: 
    69                 # min log value: no log(negative) 
    70                 if self.zmin <= 0: 
    71                     zmin_2D_temp = MIN_Z 
    72                 else: 
    73                     zmin_2D_temp = numpy.log10(self.zmin) 
    74             if not self.zmax is None: 
    75                 zmax_2D_temp = numpy.log10(self.zmax) 
     64        zmin_2D_temp, zmax_2D_temp = self.calculateDepth() 
    7665 
    7766        # Prepare and show the plot 
     
    8574                      zmax=zmax_2D_temp) 
    8675 
     76    def calculateDepth(self): 
     77        """ 
     78        Re-calculate the plot depth parameters depending on the scale 
     79        """ 
     80        # Toggle the scale 
     81        zmin_temp = self.zmin 
     82        zmax_temp = self.zmax 
     83        # self.scale predefined in the baseclass 
     84        if self.scale == 'log_{10}': 
     85            if self.zmin is not None: 
     86                zmin_temp = numpy.power(10, self.zmin) 
     87            if self.zmax is not None: 
     88                zmax_temp = numpy.power(10, self.zmax) 
     89        else: 
     90            if self.zmin is not None: 
     91                # min log value: no log(negative) 
     92                zmin_temp = MIN_Z if self.zmin <= 0 else numpy.log10(self.zmin) 
     93            if self.zmax is not None: 
     94                zmax_temp = numpy.log10(self.zmax) 
     95 
     96        return (zmin_temp, zmax_temp) 
     97 
     98 
    8799    def createContextMenu(self): 
    88100        """ 
     
    90102        """ 
    91103        self.defaultContextMenu() 
     104 
     105        self.contextMenu.addSeparator() 
     106        self.actionDataInfo = self.contextMenu.addAction("&DataInfo") 
     107        self.actionDataInfo.triggered.connect( 
     108                              functools.partial(self.onDataInfo, self.data)) 
     109 
     110        self.actionSavePointsAsFile = self.contextMenu.addAction("&Save Points as a File") 
     111        self.actionSavePointsAsFile.triggered.connect( 
     112                                functools.partial(self.onSavePoints, self.data)) 
     113        self.contextMenu.addSeparator() 
     114 
     115        self.actionCircularAverage = self.contextMenu.addAction("&Perform Circular Average") 
     116        self.actionCircularAverage.triggered.connect(self.onCircularAverage) 
     117 
     118        self.actionSectorView = self.contextMenu.addAction("&Sector [Q View]") 
     119        self.actionSectorView.triggered.connect(self.onSectorView) 
     120        self.actionAnnulusView = self.contextMenu.addAction("&Annulus [Phi View]") 
     121        self.actionAnnulusView.triggered.connect(self.onAnnulusView) 
     122        self.actionBoxSum = self.contextMenu.addAction("&Box Sum") 
     123        self.actionBoxSum.triggered.connect(self.onBoxSum) 
     124        self.actionBoxAveragingX = self.contextMenu.addAction("&Box Averaging in Qx") 
     125        self.actionBoxAveragingX.triggered.connect(self.onBoxAveragingX) 
     126        self.actionBoxAveragingY = self.contextMenu.addAction("&Box Averaging in Qy") 
     127        self.actionBoxAveragingY.triggered.connect(self.onBoxAveragingY) 
     128        self.contextMenu.addSeparator() 
     129        self.actionEditGraphLabel = self.contextMenu.addAction("&Edit Graph Label") 
     130        self.actionEditGraphLabel.triggered.connect(self.onEditgraphLabel) 
     131        self.contextMenu.addSeparator() 
     132        self.actionColorMap = self.contextMenu.addAction("&2D Color Map") 
     133        self.actionColorMap.triggered.connect(self.onColorMap) 
     134        self.contextMenu.addSeparator() 
     135        self.actionChangeScale = self.contextMenu.addAction("Toggle Linear/Log Scale") 
     136        self.actionChangeScale.triggered.connect(self.onToggleScale) 
    92137 
    93138    def createContextMenuQuick(self): 
     
    111156        Toggle axis and replot image 
    112157        """ 
     158        # self.scale predefined in the baseclass 
     159        if self.scale == 'log_{10}': 
     160            self.scale = 'linear' 
     161        else: 
     162            self.scale = 'log_{10}' 
     163 
    113164        self.plot() 
     165 
     166    def onCircularAverage(self): 
     167        """ 
     168        """ 
     169        pass 
     170 
     171    def onSectorView(self): 
     172        """ 
     173        """ 
     174        pass 
     175 
     176    def onAnnulusView(self): 
     177        """ 
     178        """ 
     179        pass 
     180 
     181    def onBoxSum(self): 
     182        """ 
     183        """ 
     184        pass 
     185 
     186    def onBoxAveragingX(self): 
     187        """ 
     188        """ 
     189        pass 
     190 
     191    def onBoxAveragingY(self): 
     192        """ 
     193        """ 
     194        pass 
     195 
     196    def onEditgraphLabel(self): 
     197        """ 
     198        """ 
     199        pass 
     200 
     201    def onColorMap(self): 
     202        """ 
     203        Display the color map dialog and modify the plot's map accordingly 
     204        """ 
     205        color_map_dialog = ColorMap(self, cmap=self.cmap, 
     206                                    zmin=self.vmin, 
     207                                    zmax=self.vmax, 
     208                                    data=self.data) 
     209 
     210        if color_map_dialog.exec_() == QtGui.QDialog.Accepted: 
     211            self.cmap = color_map_dialog.cmap() 
     212            self.vmin, self.vmax = color_map_dialog.norm() 
     213            # Redraw the chart with new cmap 
     214            self.plot() 
     215        pass 
    114216 
    115217    def showPlot(self, data, qx_data, qy_data, xmin, xmax, ymin, ymax, 
     
    140242            try: 
    141243                if  self.zmin <= 0  and len(output[output > 0]) > 0: 
    142                     zmin_temp = self.zmin_2D 
     244                    zmin_temp = self.zmin 
    143245                    output[output > 0] = numpy.log10(output[output > 0]) 
    144246                elif self.zmin <= 0: 
     
    185287            cb.set_label('$' + self.scale + '$') 
    186288 
     289            self.vmin = cb.vmin 
     290            self.vmax = cb.vmax 
     291 
    187292        else: 
    188293            # clear the previous 2D from memory 
  • src/sas/qtgui/PlotterBase.py

    rb46f285 r092a3d9  
    33 
    44from PyQt4 import QtGui 
     5from PyQt4 import QtCore 
    56 
    67# TODO: Replace the qt4agg calls below with qt5 equivalent. 
     
    1617from sas.sasgui.plottools.binder import BindArtist 
    1718 
     19import sas.qtgui.GuiUtils as GuiUtils 
     20from sas.sasgui.guiframe.dataFitting import Data1D, Data2D 
    1821from sas.qtgui.ScaleProperties import ScaleProperties 
    1922from sas.qtgui.WindowTitle import WindowTitle 
     
    3740        # ... and the toolbar with all the default MPL buttons 
    3841        self.toolbar = NavigationToolbar(self.canvas, self) 
     42 
     43        # Simple window for data display 
     44        self.txt_widget = QtGui.QTextEdit(None) 
    3945 
    4046        # Set the layout and place the canvas widget in it. 
     
    474480            if self._scale_yhi is not None and self._scale_ylo is not None: 
    475481                ax.set_ylim(self._scale_ylo, self._scale_yhi) 
     482 
     483    def onDataInfo(self, plot_data): 
     484        """ 
     485        Displays data info text window for the selected plot 
     486        """ 
     487        if isinstance(plot_data, Data1D): 
     488            text_to_show = GuiUtils.retrieveData1d(plot_data) 
     489        else: 
     490            text_to_show = GuiUtils.retrieveData2d(plot_data) 
     491        # Hardcoded sizes to enable full width rendering with default font 
     492        self.txt_widget.resize(420,600) 
     493 
     494        self.txt_widget.setReadOnly(True) 
     495        self.txt_widget.setWindowFlags(QtCore.Qt.Window) 
     496        self.txt_widget.setWindowIcon(QtGui.QIcon(":/res/ball.ico")) 
     497        self.txt_widget.setWindowTitle("Data Info: %s" % plot_data.filename) 
     498        self.txt_widget.insertPlainText(text_to_show) 
     499 
     500        self.txt_widget.show() 
     501        # Move the slider all the way up, if present 
     502        vertical_scroll_bar = self.txt_widget.verticalScrollBar() 
     503        vertical_scroll_bar.triggerAction(QtGui.QScrollBar.SliderToMinimum) 
     504 
     505    def onSavePoints(self, plot_data): 
     506        """ 
     507        Saves plot data to a file 
     508        """ 
     509        if isinstance(plot_data, Data1D): 
     510            GuiUtils.saveData1D(plot_data) 
     511        else: 
     512            GuiUtils.saveData2D(plot_data) 
  • src/sas/qtgui/UnitTesting/Plotter2DTest.py

    rb46f285 r092a3d9  
    1313from sas.sasgui.guiframe.dataFitting import Data1D 
    1414from sas.sasgui.guiframe.dataFitting import Data2D 
     15from UnitTesting.TestUtils import WarningTestNotImplemented 
    1516 
    1617# Tested module 
     
    6061 
    6162        self.assertTrue(FigureCanvas.draw_idle.called) 
     63 
     64    def testCalculateDepth(self): 
     65        ''' Test the depth calculator ''' 
     66        WarningTestNotImplemented() 
     67 
     68    def testOnColorMap(self): 
     69        ''' Respond to the color map event ''' 
     70        WarningTestNotImplemented() 
    6271 
    6372    def testOnToggleScale(self): 
  • src/sas/qtgui/run_tests.bat

    r87cc73a r092a3d9  
    2222python -m UnitTesting.PlotPropertiesTest 
    2323python -m UnitTesting.PlotUtilitiesTest 
     24python -m UnitTesting.ColorMapTest 
  • src/sas/qtgui/run_tests.sh

    r87cc73a r092a3d9  
    2121python -m UnitTesting.PlotPropertiesTest 
    2222python -m UnitTesting.PlotUtilitiesTest 
     23python -m UnitTesting.ColorMapTest 
  • src/sas/sasgui/plottools/config.py

    r239214f r092a3d9  
    6464 
    6565# this should happen after initial matplotlib configuration 
    66 from .toolbar import NavigationToolBar 
    67 from matplotlib.backends import backend_wxagg 
    68 backend_wxagg.NavigationToolbar2WxAgg = NavigationToolBar 
     66#from .toolbar import NavigationToolBar 
     67#from matplotlib.backends import backend_wxagg 
     68#backend_wxagg.NavigationToolbar2WxAgg = NavigationToolBar 
    6969 
    7070# CRUFT: bumps 0.7.5.6 and older uses wrong toolbar 
    71 backend_wxagg.NavigationToolbar2Wx = NavigationToolBar 
     71#backend_wxagg.NavigationToolbar2Wx = NavigationToolBar 
  • src/sas/sasgui/plottools/toolbar.py

    rd7bb526 r092a3d9  
    3535 
    3636    # CRUFT: mpl 1.1 uses save rather than save_figure 
    37     try: save_figure = NavigationToolbar2WxAgg.save 
    38     except AttributeError: pass 
     37    #try: save_figure = NavigationToolbar2WxAgg.save 
     38    #except AttributeError: pass 
    3939     
    4040    def _init_toolbar(self): 
Note: See TracChangeset for help on using the changeset viewer.