Ignore:
Timestamp:
Feb 9, 2017 6:07:05 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:
9a05a8d5
Parents:
bda1faa7
Message:

Code review changes for Slicer Parameter Editor

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sasgui/guiframe/local_perspectives/plotting/SectorSlicer.py

    r3bdbfcc r57b7ee2  
    22    Sector interactor 
    33""" 
    4 import math 
     4import numpy 
    55from PyQt4 import QtGui 
    66from PyQt4 import QtCore 
     
    1111from sas.qtgui.SlicerModel import SlicerModel 
    1212 
     13MIN_PHI = 0.05 
    1314 
    1415class SectorInteractor(_BaseInteractor, SlicerModel): 
     
    2829 
    2930        # Compute qmax limit to reset the graph 
    30         x = math.pow(max(self.base.data.xmax, 
    31                          math.fabs(self.base.data.xmin)), 2) 
    32         y = math.pow(max(self.base.data.ymax, 
    33                          math.fabs(self.base.data.ymin)), 2) 
    34         self.qmax = math.sqrt(x + y) 
     31        x = numpy.power(max(self.base.data.xmax, 
     32                         numpy.fabs(self.base.data.xmin)), 2) 
     33        y = numpy.power(max(self.base.data.ymax, 
     34                         numpy.fabs(self.base.data.ymin)), 2) 
     35        self.qmax = numpy.sqrt(x + y) 
    3536        # Number of points on the plot 
    3637        self.nbins = 20 
    3738        # Angle of the middle line 
    38         self.theta2 = math.pi / 3 
     39        self.theta2 = numpy.pi / 3 
    3940        # Absolute value of the Angle between the middle line and any side line 
    40         self.phi = math.pi / 12 
     41        self.phi = numpy.pi / 12 
    4142        # Middle line 
    4243        self.main_line = LineInteractor(self, self.axes, color='blue', 
     
    135136            nbins = 20 
    136137        sect = SectorQ(r_min=0.0, r_max=radius, 
    137                        phi_min=phimin + math.pi, 
    138                        phi_max=phimax + math.pi, nbins=nbins) 
     138                       phi_min=phimin + numpy.pi, 
     139                       phi_max=phimax + numpy.pi, nbins=nbins) 
    139140 
    140141        sector = sect(self.base.data) 
     
    209210        # Always make sure that the left and the right line are at phi 
    210211        # angle of the middle line 
    211         if math.fabs(self.left_line.phi) != math.fabs(self.right_line.phi): 
     212        if numpy.fabs(self.left_line.phi) != numpy.fabs(self.right_line.phi): 
    212213            msg = "Phi left and phi right are different" 
    213214            msg += " %f, %f" % (self.left_line.phi, self.right_line.phi) 
    214215            raise ValueError, msg 
    215         params["Phi [deg]"] = self.main_line.theta * 180 / math.pi 
    216         params["Delta_Phi [deg]"] = math.fabs(self.left_line.phi * 180 / math.pi) 
     216        params["Phi [deg]"] = self.main_line.theta * 180 / numpy.pi 
     217        params["Delta_Phi [deg]"] = numpy.fabs(self.left_line.phi * 180 / numpy.pi) 
    217218        params["nbins"] = self.nbins 
    218219        return params 
     
    226227            values the user assigned to the slicer. 
    227228        """ 
    228         main = params["Phi [deg]"] * math.pi / 180 
    229         phi = math.fabs(params["Delta_Phi [deg]"] * math.pi / 180) 
     229        main = params["Phi [deg]"] * numpy.pi / 180 
     230        phi = numpy.fabs(params["Delta_Phi [deg]"] * numpy.pi / 180) 
     231 
     232        # phi should not be too close. 
     233        if numpy.fabs(phi) < MIN_PHI: 
     234            phi = MIN_PHI 
     235            params["Delta_Phi [deg]"] = MIN_PHI 
     236 
    230237        self.nbins = int(params["nbins"]) 
    231238        self.main_line.theta = main 
     
    241248    def draw(self): 
    242249        """ 
     250        Redraw canvas 
    243251        """ 
    244252        self.base.draw() 
     
    254262    """ 
    255263    def __init__(self, base, axes, color='black', zorder=5, r=1.0, 
    256                  phi=math.pi / 4, theta2=math.pi / 3): 
     264                 phi=numpy.pi / 4, theta2=numpy.pi / 3): 
    257265        """ 
    258266        """ 
     
    272280        self.phi = phi 
    273281        # End points polar coordinates 
    274         x1 = self.radius * math.cos(self.theta) 
    275         y1 = self.radius * math.sin(self.theta) 
    276         x2 = -1 * self.radius * math.cos(self.theta) 
    277         y2 = -1 * self.radius * math.sin(self.theta) 
     282        x1 = self.radius * numpy.cos(self.theta) 
     283        y1 = self.radius * numpy.sin(self.theta) 
     284        x2 = -1 * self.radius * numpy.cos(self.theta) 
     285        y2 = -1 * self.radius * numpy.sin(self.theta) 
    278286        # Defining a new marker 
    279287        self.inner_marker = self.axes.plot([x1 / 2.5], [y1 / 2.5], linestyle='', 
     
    331339            delta = 0 
    332340        if  right: 
    333             self.phi = -1 * math.fabs(self.phi) 
     341            self.phi = -1 * numpy.fabs(self.phi) 
    334342            #delta=-delta 
    335343        else: 
    336             self.phi = math.fabs(self.phi) 
     344            self.phi = numpy.fabs(self.phi) 
    337345        if side: 
    338346            self.theta = mline.theta + self.phi 
     
    347355        else: 
    348356            theta3 = self.theta2 + delta 
    349         x1 = self.radius * math.cos(theta3) 
    350         y1 = self.radius * math.sin(theta3) 
    351         x2 = -1 * self.radius * math.cos(theta3) 
    352         y2 = -1 * self.radius * math.sin(theta3) 
     357        x1 = self.radius * numpy.cos(theta3) 
     358        y1 = self.radius * numpy.sin(theta3) 
     359        x2 = -1 * self.radius * numpy.cos(theta3) 
     360        y2 = -1 * self.radius * numpy.sin(theta3) 
    353361        self.inner_marker.set(xdata=[x1 / 2.5], ydata=[y1 / 2.5]) 
    354362        self.line.set(xdata=[x1, x2], ydata=[y1, y2]) 
     
    377385        Process move to a new position, making sure that the move is allowed. 
    378386        """ 
    379         self.theta = math.atan2(y, x) 
     387        self.theta = numpy.arctan2(y, x) 
    380388        self.has_move = True 
    381389        if not self.left_moving: 
     
    388396                return 
    389397            elif  self.theta2 < 0 and self.theta > 0 and \ 
    390                 (self.theta2 + 2 * math.pi - self.theta) >= math.pi / 2: 
     398                (self.theta2 + 2 * numpy.pi - self.theta) >= numpy.pi / 2: 
    391399                self.restore() 
    392400                return 
    393401            elif  self.theta2 < 0 and self.theta < 0 and \ 
    394                 (self.theta2 - self.theta) >= math.pi / 2: 
    395                 self.restore() 
    396                 return 
    397             elif self.theta2 > 0 and (self.theta2 - self.theta >= math.pi / 2 or \ 
    398                 (self.theta2 - self.theta >= math.pi / 2)): 
     402                (self.theta2 - self.theta) >= numpy.pi / 2: 
     403                self.restore() 
     404                return 
     405            elif self.theta2 > 0 and (self.theta2 - self.theta >= numpy.pi / 2 or \ 
     406                (self.theta2 - self.theta >= numpy.pi / 2)): 
    399407                self.restore() 
    400408                return 
    401409        else: 
    402             if  self.theta < 0 and (self.theta + math.pi * 2 - self.theta2) <= 0: 
     410            if  self.theta < 0 and (self.theta + numpy.pi * 2 - self.theta2) <= 0: 
    403411                self.restore() 
    404412                return 
     
    409417                self.restore() 
    410418                return 
    411             elif self.theta - self.theta2 >= math.pi / 2 or  \ 
    412                 ((self.theta + math.pi * 2 - self.theta2) >= math.pi / 2 and \ 
     419            elif self.theta - self.theta2 >= numpy.pi / 2 or  \ 
     420                ((self.theta + numpy.pi * 2 - self.theta2) >= numpy.pi / 2 and \ 
    413421                 self.theta < 0 and self.theta2 > 0): 
    414422                self.restore() 
    415423                return 
    416424 
    417         self.phi = math.fabs(self.theta2 - self.theta) 
    418         if self.phi > math.pi: 
    419             self.phi = 2 * math.pi - math.fabs(self.theta2 - self.theta) 
     425        self.phi = numpy.fabs(self.theta2 - self.theta) 
     426        if self.phi > numpy.pi: 
     427            self.phi = 2 * numpy.pi - numpy.fabs(self.theta2 - self.theta) 
    420428        self.base.base.update() 
    421429 
     
    446454    """ 
    447455    def __init__(self, base, axes, color='black', 
    448                  zorder=5, r=1.0, theta=math.pi / 4): 
     456                 zorder=5, r=1.0, theta=numpy.pi / 4): 
    449457        """ 
    450458        """ 
     
    458466        self.scale = 10.0 
    459467        # Inner circle 
    460         x1 = self.radius * math.cos(self.theta) 
    461         y1 = self.radius * math.sin(self.theta) 
    462         x2 = -1 * self.radius * math.cos(self.theta) 
    463         y2 = -1 * self.radius * math.sin(self.theta) 
     468        x1 = self.radius * numpy.cos(self.theta) 
     469        y1 = self.radius * numpy.sin(self.theta) 
     470        x2 = -1 * self.radius * numpy.cos(self.theta) 
     471        y2 = -1 * self.radius * numpy.sin(self.theta) 
    464472        # Inner circle marker 
    465473        self.inner_marker = self.axes.plot([x1 / 2.5], [y1 / 2.5], linestyle='', 
     
    502510        if theta != None: 
    503511            self.theta = theta 
    504         x1 = self.radius * math.cos(self.theta) 
    505         y1 = self.radius * math.sin(self.theta) 
    506         x2 = -1 * self.radius * math.cos(self.theta) 
    507         y2 = -1 * self.radius * math.sin(self.theta) 
     512        x1 = self.radius * numpy.cos(self.theta) 
     513        y1 = self.radius * numpy.sin(self.theta) 
     514        x2 = -1 * self.radius * numpy.cos(self.theta) 
     515        y2 = -1 * self.radius * numpy.sin(self.theta) 
    508516 
    509517        self.inner_marker.set(xdata=[x1 / 2.5], ydata=[y1 / 2.5]) 
     
    533541        Process move to a new position, making sure that the move is allowed. 
    534542        """ 
    535         self.theta = math.atan2(y, x) 
     543        self.theta = numpy.arctan2(y, x) 
    536544        self.has_move = True 
    537545        self.base.base.update() 
Note: See TracChangeset for help on using the changeset viewer.