Changeset 092a3d9 in sasview for src/sas/qtgui/Plotter2D.py


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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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 
Note: See TracChangeset for help on using the changeset viewer.