Changeset 5e903e8b in sasview for src/sas


Ignore:
Timestamp:
May 2, 2017 6:07:40 AM (7 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, 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, costrafo411, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
e123eb9
Parents:
b290a9e (diff), 658dd57 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into log_binning

Location:
src/sas
Files:
47 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/calculator/sas_gen.py

    r7432acb ra1b8fee  
    33SAS generic computation and sld file readers 
    44""" 
     5from __future__ import print_function 
     6 
    57import sas.sascalc.calculator.core.sld2i as mod 
    68from sas.sascalc.calculator.BaseComponent import BaseComponent 
     
    558560                            vol_pix = np.append(vol_pix, vol) 
    559561                        except: 
    560                             print "Error: set the sld of %s to zero"% atom_name 
     562                            print("Error: set the sld of %s to zero"% atom_name) 
    561563                            sld_n = np.append(sld_n, 0.0) 
    562564                        sld_mx = np.append(sld_mx, 0) 
     
    609611        Write 
    610612        """ 
    611         print "Not implemented... " 
     613        print("Not implemented... ") 
    612614 
    613615class SLDReader(object): 
     
    10441046    from mpl_toolkits.mplot3d import Axes3D 
    10451047    current_dir = os.path.abspath(os.path.curdir) 
    1046     print current_dir 
     1048    print(current_dir) 
    10471049    for i in range(6): 
    10481050        current_dir, _ = os.path.split(current_dir) 
  • src/sas/sascalc/data_util/calcthread.py

    r7432acb ra1b8fee  
    44#  \brief Abstract class for defining calculation threads. 
    55# 
     6from __future__ import print_function 
    67 
    78import thread 
     
    295296    """ 
    296297    def __init__(self, n=20000): 
    297         print thread.get_ident() 
     298        print(thread.get_ident()) 
    298299        self.starttime = clock() 
    299300        self.done = False 
     
    307308        self.work2.queue(n) 
    308309        self.work3.queue(n) 
    309         print "Expect updates from Main every second and from thread every 2.5 seconds" 
    310         print "" 
     310        print("Expect updates from Main every second and from thread every 2.5 seconds") 
     311        print("") 
    311312        self.work.ready(.5) 
    312313        while not self.done: 
    313314            sleep(1) 
    314             print "Main thread %d at %.2f" % (thread.get_ident(), 
    315                                               clock() - self.starttime) 
     315            print("Main thread %d at %.2f" % (thread.get_ident(), 
     316                                              clock() - self.starttime)) 
    316317 
    317318    def update(self, i=0): 
    318         print "Update i=%d from thread %d at %.2f" % (i, thread.get_ident(), 
    319                                                       clock() - self.starttime) 
     319        print("Update i=%d from thread %d at %.2f" % (i, thread.get_ident(), 
     320                                                      clock() - self.starttime)) 
    320321        self.work.ready(2.5) 
    321322 
    322323    def complete(self, total=0.0): 
    323         print "Complete total=%g from thread %d at %.2f" % (total, 
     324        print("Complete total=%g from thread %d at %.2f" % (total, 
    324325                                                    thread.get_ident(), 
    325                                                     clock() - self.starttime) 
     326                                                    clock() - self.starttime)) 
    326327        self.done = True 
  • src/sas/sascalc/data_util/formatnum.py

    r9a5097c ra1b8fee  
    3737formatter.compact flag. 
    3838""" 
    39 from __future__ import division 
     39from __future__ import division, print_function 
    4040 
    4141import math 
  • src/sas/sascalc/data_util/registry.py

    rb699768 ra1b8fee  
    66and registers the built-in file extensions. 
    77""" 
     8from __future__ import print_function 
    89 
    910import os.path 
  • src/sas/sascalc/dataloader/data_info.py

    r7432acb ra1b8fee  
    1616###################################################################### 
    1717 
     18from __future__ import print_function 
    1819 
    1920#TODO: Keep track of data manipulation in the 'process' data structure. 
  • src/sas/sascalc/dataloader/readers/IgorReader.py

    r959eb01 ra1b8fee  
    1212#copyright 2008, University of Tennessee 
    1313############################################################################# 
     14from __future__ import print_function 
     15 
    1416import os 
    1517 
  • src/sas/sascalc/dataloader/readers/associations.py

    r959eb01 ra1b8fee  
    1414#copyright 2009, University of Tennessee 
    1515############################################################################# 
     16from __future__ import print_function 
     17 
    1618import os 
    1719import sys 
     
    7173                    logger.error(msg) 
    7274    else: 
    73         print "Could not find reader association settings\n  %s [%s]" % (__file__, os.getcwd()) 
     75        print("Could not find reader association settings\n  %s [%s]" % (__file__, os.getcwd())) 
    7476          
    7577          
  • src/sas/sascalc/dataloader/readers/red2d_reader.py

    r959eb01 ra1b8fee  
    99#copyright 2008, University of Tennessee 
    1010###################################################################### 
     11from __future__ import print_function 
     12 
    1113import os 
    1214import numpy as np 
     
    8284        detector = Detector() 
    8385        if len(output.detector) > 0: 
    84             print str(output.detector[0]) 
     86            print(str(output.detector[0])) 
    8587        output.detector.append(detector) 
    8688                 
  • src/sas/sascalc/fit/AbstractFitEngine.py

    r7432acb ra1b8fee  
     1from __future__ import print_function 
    12 
    23import  copy 
     
    627628        """ 
    628629        """ 
    629         print str(self) 
     630        print(str(self)) 
  • src/sas/sascalc/fit/Loader.py

    rac07a3a ra1b8fee  
     1from __future__ import print_function 
     2 
    13# class Loader  to load any king of file 
    24#import wx 
     
    5456                    self.dx = np.zeros(len(self.x)) 
    5557                except: 
    56                     print "READ ERROR", line 
     58                    print("READ ERROR", line) 
    5759            # Sanity check 
    5860            if not len(self.x) == len(self.dx): 
     
    8082    load = Load() 
    8183    load.set_filename("testdata_line.txt") 
    82     print load.get_filename()  
     84    print(load.get_filename())  
    8385    load.set_values() 
    84     print load.get_values() 
     86    print(load.get_values()) 
    8587     
    8688             
  • src/sas/sascalc/fit/expression.py

    r9a5097c ra1b8fee  
    4343Ideally, this interface will change 
    4444""" 
     45from __future__ import print_function 
     46 
    4547import math 
    4648import re 
  • src/sas/sascalc/pr/fit/AbstractFitEngine.py

    r7432acb ra1b8fee  
     1from __future__ import print_function 
    12 
    23import  copy 
     
    630631        """ 
    631632        """ 
    632         print str(self) 
     633        print(str(self)) 
  • src/sas/sascalc/pr/fit/Loader.py

    rac07a3a ra1b8fee  
     1from __future__ import print_function 
     2 
    13# class Loader  to load any king of file 
    24#import wx 
     
    5456                    self.dx = np.zeros(len(self.x)) 
    5557                except: 
    56                     print "READ ERROR", line 
     58                    print("READ ERROR", line) 
    5759            # Sanity check 
    5860            if not len(self.x) == len(self.dx): 
     
    8082    load = Load() 
    8183    load.set_filename("testdata_line.txt") 
    82     print load.get_filename()  
     84    print(load.get_filename())  
    8385    load.set_values() 
    84     print load.get_values() 
     86    print(load.get_values()) 
    8587     
    8688             
  • src/sas/sascalc/pr/fit/expression.py

    r9a5097c ra1b8fee  
     1from __future__ import print_function 
     2 
    13# This program is public domain 
    24""" 
  • src/sas/sascalc/pr/num_term.py

    r7432acb ra1b8fee  
     1from __future__ import print_function 
     2 
    13import math 
    24import numpy as np 
     
    197199    # Testing estimator 
    198200    est = NTermEstimator(invert) 
    199     print est.num_terms() 
     201    print(est.num_terms()) 
  • src/sas/sascalc/simulation/analmodelpy/tests/signon.py

    rd85c194 r9c3d784  
    1717    from analmodelpy import analmodelpy as analmodelpymodule 
    1818 
    19     print "copyright information:" 
    20     print "   ", analmodelpy.copyright() 
    21     print "   ", analmodelpymodule.copyright() 
     19    print("copyright information:") 
     20    print("   ", analmodelpy.copyright()) 
     21    print("   ", analmodelpymodule.copyright()) 
    2222 
    23     print 
    24     print "module information:" 
    25     print "    file:", analmodelpymodule.__file__ 
    26     print "    doc:", analmodelpymodule.__doc__ 
    27     print "    contents:", dir(analmodelpymodule) 
     23    print() 
     24    print("module information:") 
     25    print("    file:", analmodelpymodule.__file__) 
     26    print("    doc:", analmodelpymodule.__doc__) 
     27    print("    contents:", dir(analmodelpymodule)) 
    2828 
    29     print 
    30     print analmodelpymodule.hello() 
     29    print() 
     30    print(analmodelpymodule.hello()) 
    3131 
    3232# version 
  • src/sas/sascalc/simulation/analmodelpy/tests/testanal_model.py

    rd85c194 ra1b8fee  
    1111#  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    1212#  
     13from __future__ import print_function 
     14 
    1315 
    1416if __name__ == "__main__": 
     
    1820    from SASsimulation import geoshapespy 
    1921 
    20     print "copyright information:" 
    21     print "   ", analmodelpymodule.copyright() 
     22    print("copyright information:") 
     23    print("   ", analmodelpymodule.copyright()) 
    2224 
    23     print 
    24     print "module information:" 
    25     print "    file:", analmodelpymodule.__file__ 
    26     print "    doc:", analmodelpymodule.__doc__ 
    27     print "    contents:", dir(analmodelpymodule) 
     25    print() 
     26    print("module information:") 
     27    print("    file:", analmodelpymodule.__file__) 
     28    print("    doc:", analmodelpymodule.__doc__) 
     29    print("    contents:", dir(analmodelpymodule)) 
    2830 
    2931    a = geoshapespy.new_sphere(1.0) 
  • src/sas/sascalc/simulation/geoshapespy/tests/testshapes.py

    rd85c194 ra1b8fee  
    1111#  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    1212#  
     13from __future__ import print_function 
     14 
    1315 
    1416if __name__ == "__main__": 
     
    1618    from SASsimulation import geoshapespy 
    1719 
    18     print 
    19     print "module information:" 
    20     print "    file:", geoshapespy.__file__ 
    21     print "    doc:", geoshapespy.__doc__ 
    22     print "    contents:", dir(geoshapespy) 
     20    print() 
     21    print("module information:") 
     22    print("    file:", geoshapespy.__file__) 
     23    print("    doc:", geoshapespy.__doc__) 
     24    print("    contents:", dir(geoshapespy)) 
    2325 
    2426    sp = geoshapespy.new_sphere(10) 
  • src/sas/sascalc/simulation/iqPy/tests/signon.py

    rd85c194 ra1b8fee  
    1111#  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    1212#  
     13from __future__ import print_function 
     14 
    1315 
    1416if __name__ == "__main__": 
     
    1719    from iqPy import iqPy as iqPymodule 
    1820 
    19     print "copyright information:" 
    20     print "   ", iqPy.copyright() 
    21     print "   ", iqPymodule.copyright() 
     21    print("copyright information:") 
     22    print("   ", iqPy.copyright()) 
     23    print("   ", iqPymodule.copyright()) 
    2224 
    23     print 
    24     print "module information:" 
    25     print "    file:", iqPymodule.__file__ 
    26     print "    doc:", iqPymodule.__doc__ 
    27     print "    contents:", dir(iqPymodule) 
     25    print() 
     26    print("module information:") 
     27    print("    file:", iqPymodule.__file__) 
     28    print("    doc:", iqPymodule.__doc__) 
     29    print("    contents:", dir(iqPymodule)) 
    2830 
    29     print 
     31    print() 
    3032 
    3133# version 
  • src/sas/sascalc/simulation/iqPy/tests/testiq.py

    rd85c194 r9c3d784  
    1717        iqPy.new_iq(10,0.01,0.4) 
    1818 
    19         print "pass." 
     19        print("pass.") 
    2020 
    2121# version 
  • src/sas/sascalc/simulation/pointsmodelpy/tests/signon.py

    rd85c194 ra1b8fee  
    1111#  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    1212#  
     13from __future__ import print_function 
     14 
    1315 
    1416if __name__ == "__main__": 
     
    1719    from pointsmodelpy import pointsmodelpy as pointsmodelpymodule 
    1820 
    19     print "copyright information:" 
    20     print "   ", pointsmodelpy.copyright() 
    21     print "   ", pointsmodelpymodule.copyright() 
     21    print("copyright information:") 
     22    print("   ", pointsmodelpy.copyright()) 
     23    print("   ", pointsmodelpymodule.copyright()) 
    2224 
    23     print 
    24     print "module information:" 
    25     print "    file:", pointsmodelpymodule.__file__ 
    26     print "    doc:", pointsmodelpymodule.__doc__ 
    27     print "    contents:", dir(pointsmodelpymodule) 
     25    print() 
     26    print("module information:") 
     27    print("    file:", pointsmodelpymodule.__file__) 
     28    print("    doc:", pointsmodelpymodule.__doc__) 
     29    print("    contents:", dir(pointsmodelpymodule)) 
    2830 
    29     print 
    30     print pointsmodelpymodule.hello() 
     31    print() 
     32    print(pointsmodelpymodule.hello()) 
    3133 
    3234# version 
  • src/sas/sascalc/simulation/pointsmodelpy/tests/test2dui.py

    r959eb01 ra1b8fee  
    77#  Imports: 
    88#-------------------------------------------------------------------------------- 
     9from __future__ import print_function 
    910 
    1011import wx 
     
    4647 
    4748        data = ImageData(value_grid, index_vals) 
    48         print value_grid, index_vals 
     49        print(value_grid, index_vals) 
    4950         
    5051        # Create the index axes 
  • src/sas/sascalc/simulation/pointsmodelpy/tests/testcomplexmodel.py

    r959eb01 ra1b8fee  
     1from __future__ import print_function 
     2 
    13from sasModeling.pointsmodelpy import pointsmodelpy 
    24from sasModeling.iqPy import iqPy 
    35from sasModeling.geoshapespy import geoshapespy 
     6 
    47 
    58#First testing: a normal case, a lores model holds a sphere 
     
    6164  iqPy.OutputIQ(iqcomplex,"testcomplex2.iq") 
    6265 
    63   print "p(r) is saved in testcomplex2.pr" 
    64   print "I(Q) is saved in testcomplex2.iq" 
    65   print "pass" 
     66  print("p(r) is saved in testcomplex2.pr") 
     67  print("I(Q) is saved in testcomplex2.iq") 
     68  print("pass") 
    6669 
    6770#testing 3, insert one empty pdbmodel and one loresmodel 
     
    8891  iqPy.OutputIQ(iqcomplex,"testcomplex3.iq") 
    8992 
    90   print "p(r) is saved in testcomplex3.pr" 
    91   print "I(Q) is saved in testcomplex3.iq" 
    92   print "pass" 
     93  print("p(r) is saved in testcomplex3.pr") 
     94  print("I(Q) is saved in testcomplex3.iq") 
     95  print("pass") 
    9396 
    9497# Test 2D complex model 
     
    106109    pointsmodelpy.get_complexpoints(complex,vpcomplex); 
    107110  
    108     print pointsmodelpy.get_complex_iq_2D(complex,vpcomplex,0.1,0.1); 
    109     print pointsmodelpy.get_complex_iq_2D(complex,vpcomplex,0.01,0.1); 
     111    print(pointsmodelpy.get_complex_iq_2D(complex,vpcomplex,0.1,0.1)); 
     112    print(pointsmodelpy.get_complex_iq_2D(complex,vpcomplex,0.01,0.1)); 
    110113 
    111114 
  • src/sas/sascalc/simulation/pointsmodelpy/tests/testlores.py

    r959eb01 ra1b8fee  
     1from __future__ import print_function 
     2 
     3 
    14if __name__ == "__main__": 
    25 
     
    1013#    print "   ", pointsmodelpymodule.copyright() 
    1114 
    12     print 
    13     print "module information:" 
    14     print "    file:", pointsmodelpy.__file__ 
    15     print "    doc:", pointsmodelpy.__doc__ 
    16     print "    contents:", dir(pointsmodelpy) 
    17     print "    contents:", dir(geoshapespy) 
     15    print() 
     16    print("module information:") 
     17    print("    file:", pointsmodelpy.__file__) 
     18    print("    doc:", pointsmodelpy.__doc__) 
     19    print("    contents:", dir(pointsmodelpy)) 
     20    print("    contents:", dir(geoshapespy)) 
    1821 
    1922#    a = geoshapespy.new_singlehelix(10,2,30,2) 
     
    4649    pointsmodelpy.outputPDB(lm,vp,"modelpy.pseudo.pdb") 
    4750 
    48     print "calculating distance distribution" 
     51    print("calculating distance distribution") 
    4952    rmax = pointsmodelpy.get_lores_pr(lm,vp) 
    50     print "finish calculating get_lores_pr, and rmax is:", rmax 
     53    print("finish calculating get_lores_pr, and rmax is:", rmax) 
    5154    pointsmodelpy.outputPR(lm,"testlores.pr") 
    5255    pointsmodelpy.get_lores_iq(lm,iq) 
     
    5457    iqPy.OutputIQ(iq, "testlores.iq") 
    5558 
    56     print "Testing get I from a single q" 
     59    print("Testing get I from a single q") 
    5760    result = pointsmodelpy.get_lores_i(lm,0.1) 
    58     print "The I(0.1) is: %s" % str(result)  
     61    print("The I(0.1) is: %s" % str(result))  
    5962 
    6063# version 
  • src/sas/sascalc/simulation/pointsmodelpy/tests/testlores2d.py

    r959eb01 ra1b8fee  
     1from __future__ import print_function 
     2 
     3 
    14def test_lores2d(phi): 
    25  from sasModeling.pointsmodelpy import pointsmodelpy  
     
    4548  value_grid = zeros((100,100),Float) 
    4649  width, height = value_grid.shape 
    47   print width,height 
     50  print(width,height) 
    4851 
    4952  I = pointsmodelpy.calculateI_Qxy(lm,0.00001,0.000002) 
    50   print I 
     53  print(I) 
    5154 
    5255  Imax = 0 
     
    8689  value_grid = zeros((100,100),Float) 
    8790  width, height = value_grid.shape 
    88   print width,height 
     91  print(width,height) 
    8992 
    9093  I = pointsmodelpy.calculateI_Qxy(lm,0.00001,0.000002) 
    91   print I 
     94  print(I) 
    9295 
    9396  Imax = 0 
     
    109112if __name__ == "__main__": 
    110113 
    111   print "start to test lores 2D" 
     114  print("start to test lores 2D") 
    112115#  test_lores2d(10) 
    113116  value_grid = get2d_2() 
    114   print value_grid 
    115   print "pass" 
     117  print(value_grid) 
     118  print("pass") 
  • src/sas/sasgui/guiframe/config.py

    rea45bfe ra1b8fee  
    22    Application settings 
    33""" 
     4from __future__ import print_function 
     5 
    46import time 
    57import os 
     
    150152        :TODO - Need method doc string 
    151153        """ 
    152         print "%g:  %s" % (time.clock(), message) 
     154        print("%g:  %s" % (time.clock(), message)) 
    153155 
    154156        if __EVT_DEBUG_2_FILE__: 
  • src/sas/sasgui/guiframe/data_panel.py

    r959eb01 ra1b8fee  
    1111This module provides Graphic interface for the data_manager module. 
    1212""" 
     13from __future__ import print_function 
     14 
    1315import wx 
    1416from wx.build import build_options 
     
    514516                self.parent.save_data2d(data, default_name) 
    515517            else: 
    516                 print "unable to save this type of data" 
     518                print("unable to save this type of data") 
    517519 
    518520    def layout_data_list(self): 
     
    14971499    except: 
    14981500        # raise 
    1499         print "error", sys.exc_value 
     1501        print("error", sys.exc_value) 
    15001502 
    15011503    app.MainLoop() 
  • src/sas/sasgui/guiframe/data_processor.py

    r7432acb ra1b8fee  
    1818 
    1919""" 
     20from __future__ import print_function 
     21 
    2022import os 
    2123import sys 
     
    20352037        frame.Show(True) 
    20362038    except: 
    2037         print sys.exc_value 
     2039        print(sys.exc_value) 
    20382040 
    20392041    app.MainLoop() 
  • src/sas/sasgui/guiframe/dummyapp.py

    r959eb01 ra1b8fee  
    33Allows the user to set an external data manager 
    44""" 
     5from __future__ import print_function 
     6 
    57import sas.sasgui.guiframe.gui_manager as gui_manager 
    68 
     
    3234        plug_menu.Append(id, '&Do something') 
    3335        def _on_do_something(event): 
    34             print "Do something" 
     36            print("Do something") 
    3537        wx.EVT_MENU(self.parent, id, _on_do_something) 
    3638     
  • src/sas/sasgui/guiframe/gui_style.py

    r959eb01 ra1b8fee  
    33Provide the style for guiframe 
    44""" 
     5from __future__ import print_function 
     6 
    57import wx 
    68import os 
     
    7981if __name__ == "__main__": 
    8082   
    81     print GUIFRAME.DEFAULT_STYLE 
    82     print GUIFRAME.FLOATING_PANEL 
    83     print GUIFRAME.SINGLE_APPLICATION 
     83    print(GUIFRAME.DEFAULT_STYLE) 
     84    print(GUIFRAME.FLOATING_PANEL) 
     85    print(GUIFRAME.SINGLE_APPLICATION) 
    8486    style = GUIFRAME.MULTIPLE_APPLICATIONS 
    8587    style &= GUIFRAME.PLOTTING_ON 
    86     print style == GUIFRAME.PLOTTING_ON 
     88    print(style == GUIFRAME.PLOTTING_ON) 
    8789    style1 = GUIFRAME.MULTIPLE_APPLICATIONS 
    8890    style1 &= (~GUIFRAME.MANAGER_ON) 
    89     print style1 == GUIFRAME.DEFAULT_STYLE 
    90     print style1 
     91    print(style1 == GUIFRAME.DEFAULT_STYLE) 
     92    print(style1) 
  • src/sas/sasgui/guiframe/proxy.py

    r463e7ffc ra1b8fee  
    11#!/usr/bin/env python 
    22# -*- coding: utf-8 -*- 
     3from __future__ import print_function 
     4 
    35import urllib2 
    46import sys 
     
    157159    response = c.connect() 
    158160    if response is not None: 
    159         print 50 * '-' 
     161        print(50 * '-') 
    160162        content = json.loads(response.read().strip()) 
    161163        pprint(content) 
  • src/sas/sasgui/perspectives/calculator/detector_editor.py

    r959eb01 ra1b8fee  
     1from __future__ import print_function 
    12 
    23import wx 
     
    3435            self.set_values() 
    3536        except: 
    36             print "error", sys.exc_value 
     37            print("error", sys.exc_value) 
    3738 
    3839    def _define_structure(self): 
  • src/sas/sasgui/perspectives/calculator/gen_scatter_panel.py

    r7432acb ra1b8fee  
    33This module relies on guiframe manager. 
    44""" 
     5from __future__ import print_function 
    56 
    67import wx 
     
    19981999            self.panel.set_volume_ctl_val(str(val)) 
    19992000        except: 
    2000             print "self.panel is not initialized yet" 
     2001            print("self.panel is not initialized yet") 
    20012002 
    20022003    def set_omfpanel_default_shap(self, shape): 
  • src/sas/sasgui/perspectives/calculator/image_viewer.py

    r7432acb ra1b8fee  
     1from __future__ import print_function 
     2 
    13import os 
    24import sys 
     
    7880                wx.PostEvent(parent, StatusEvent(status=err_msg, info="error")) 
    7981            else: 
    80                 print err_msg 
     82                print(err_msg) 
    8183 
    8284    def choose_data_file(self, location=None): 
     
    301303                                                    info="error")) 
    302304            else: 
    303                 print err_msg 
     305                print(err_msg) 
    304306        return flag 
    305307 
     
    332334                                                    info="error")) 
    333335            else: 
    334                 print err_msg 
     336                print(err_msg) 
    335337        return flag 
    336338 
     
    361363                                                    info="error")) 
    362364            else: 
    363                 print err_msg 
     365                print(err_msg) 
    364366 
    365367        self.OnClose(event) 
  • src/sas/sasgui/perspectives/calculator/model_editor.py

    r7432acb ra1b8fee  
    2323#copyright 2009, University of Tennessee 
    2424################################################################################ 
     25from __future__ import print_function 
     26 
    2527import wx 
    2628import sys 
     
    871873        # Put the cursor at appropriate position 
    872874        length = len(label) 
    873         print length 
     875        print(length) 
    874876        if label[length-1] == ')': 
    875877            length -= 1 
  • src/sas/sasgui/perspectives/fitting/basepage.py

    r9c0f3c17 ra1b8fee  
    22Base Page for fitting 
    33""" 
     4from __future__ import print_function 
     5 
    46import sys 
    57import os 
     
    657659        # It seems MAC needs wxCallAfter 
    658660        if event.GetId() == GUIFRAME_ID.COPYEX_ID: 
    659             print "copy excel" 
     661            print("copy excel") 
    660662            wx.CallAfter(self.get_copy_excel) 
    661663        elif event.GetId() == GUIFRAME_ID.COPYLAT_ID: 
    662             print "copy latex" 
     664            print("copy latex") 
    663665            wx.CallAfter(self.get_copy_latex) 
    664666        else: 
     
    33683370        except Exception: 
    33693371            logger.error(traceback.format_exc()) 
    3370             print "Error in BasePage._paste_poly_help: %s" % \ 
    3371                   sys.exc_info()[1] 
     3372            print("Error in BasePage._paste_poly_help: %s" % \ 
     3373                  sys.exc_info()[1]) 
    33723374 
    33733375    def _set_disp_cb(self, isarray, item): 
     
    33983400            Moveit; This method doesn't belong here 
    33993401        """ 
    3400         print "BasicPage.update_pinhole_smear was called: skipping" 
     3402        print("BasicPage.update_pinhole_smear was called: skipping") 
    34013403        return 
    34023404 
     
    35743576        # check model type to show sizer 
    35753577        if self.model is not None: 
    3576             print "_set_model_sizer_selection: disabled." 
     3578            print("_set_model_sizer_selection: disabled.") 
    35773579            # self._set_model_sizer_selection(self.model) 
    35783580 
  • src/sas/sasgui/perspectives/fitting/fitting.py

    r7432acb ra1b8fee  
    1111#copyright 2009, University of Tennessee 
    1212################################################################################ 
     13from __future__ import print_function 
     14 
    1315import re 
    1416import sys 
     
    12531255        """ 
    12541256        """ 
    1255         print "update_fit result", result 
     1257        print("update_fit result", result) 
    12561258 
    12571259    def _batch_fit_complete(self, result, pars, page_id, 
     
    20462048            res = (fn - gn) / en 
    20472049        except ValueError: 
    2048             print "Unmatch lengths %s, %s, %s" % (len(fn), len(gn), len(en)) 
     2050            print("Unmatch lengths %s, %s, %s" % (len(fn), len(gn), len(en))) 
    20492051            return 
    20502052 
  • src/sas/sasgui/perspectives/fitting/media/plugin.rst

    r984f3fc r72100ee  
    538538    sin, cos, tan, asin, acos, atan: 
    539539        Trigonometry functions and inverses, operating on radians. 
    540     sinh, cos, tanh, asinh, acosh, atanh: 
     540    sinh, cosh, tanh, asinh, acosh, atanh: 
    541541        Hyperbolic trigonometry functions. 
    542542    atan2(y,x): 
  • src/sas/sasgui/perspectives/fitting/models.py

    r463e7ffc ra1b8fee  
    22    Utilities to manage models 
    33""" 
     4from __future__ import print_function 
     5 
    46import traceback 
    57import os 
     
    141143        type, value, tb = sys.exc_info() 
    142144        if type is not None and issubclass(type, py_compile.PyCompileError): 
    143             print "Problem with", repr(value) 
     145            print("Problem with", repr(value)) 
    144146            raise type, value, tb 
    145147        return 1 
  • src/sas/sasgui/perspectives/pr/pr.py

    r7432acb ra1b8fee  
    1515# Make sure the option of saving each curve is available 
    1616# Use the I(q) curve as input and compare the output to P(r) 
     17from __future__ import print_function 
    1718 
    1819import sys 
     
    230231        out, cov = pr.pr_fit() 
    231232        for i in range(len(out)): 
    232             print "%g +- %g" % (out[i], math.sqrt(cov[i][i])) 
     233            print("%g +- %g" % (out[i], math.sqrt(cov[i][i]))) 
    233234 
    234235        # Show input P(r) 
     
    318319            except: 
    319320                err[i] = 1.0 
    320                 print "Error getting error", value, x[i] 
     321                print("Error getting error", value, x[i]) 
    321322 
    322323        new_plot = Data1D(x, y) 
  • src/sas/sasgui/perspectives/simulation/ShapeParameters.py

    rd85c194 ra1b8fee  
    88copyright 2009, University of Tennessee 
    99""" 
     10from __future__ import print_function 
     11 
    1012import wx 
    1113import sys 
     
    312314            self.parent.GetSizer().Layout() 
    313315        except: 
    314             print "TODO: move the Layout call of editShape up to the caller" 
     316            print("TODO: move the Layout call of editShape up to the caller") 
    315317 
    316318    def _readCtrlFloat(self, ctrl): 
     
    392394                    self.current_shape.params[item[0]] = tmp  
    393395        except: 
    394             print "Could not create" 
    395             print sys.exc_value 
     396            print("Could not create") 
     397            print(sys.exc_value) 
    396398                 
    397399    def _onCreate(self, evt): 
     
    485487        indices = self.shape_listbox.GetSelections() 
    486488        if len(indices)>0: 
    487             print "NOT YET IMPLMENTED" 
    488             print "renaming", self.shape_listbox.GetString(indices[0]) 
    489                  
     489            print("NOT YET IMPLMENTED") 
     490            print("renaming", self.shape_listbox.GetString(indices[0])) 
     491                 
  • src/sas/sasgui/plottools/PlotPanel.py

    r7432acb ra1b8fee  
    22    Plot panel. 
    33""" 
     4from __future__ import print_function 
     5 
    46import logging 
    57import traceback 
     
    3840def show_tree(obj, d=0): 
    3941    """Handy function for displaying a tree of graph objects""" 
    40     print "%s%s" % ("-"*d, obj.__class__.__name__) 
     42    print("%s%s" % ("-"*d, obj.__class__.__name__)) 
    4143    if 'get_children' in dir(obj): 
    4244        for a in obj.get_children(): show_tree(a, d + 1) 
     
    20142016            self.toolbar.copy_figure(self.canvas) 
    20152017        except: 
    2016             print "Error in copy Image" 
     2018            print("Error in copy Image") 
    20172019 
    20182020 
  • src/sas/sasgui/plottools/binder.py

    r463e7ffc ra1b8fee  
    22Extension to MPL to support the binding of artists to key/mouse events. 
    33""" 
     4from __future__ import print_function 
     5 
    46import sys 
    57import logging 
     
    6365            ] 
    6466        except: 
    65             print "bypassing scroll_event: wrong matplotlib version" 
     67            print("bypassing scroll_event: wrong matplotlib version") 
    6668            self._connections = [ 
    6769                canvas.mpl_connect('motion_notify_event', self._onMotion), 
  • src/sas/sasgui/plottools/convert_units.py

    r959eb01 ra1b8fee  
    33    This is a cleaned up version of unitConverter.py 
    44""" 
     5from __future__ import print_function 
     6 
    57import re 
    68import string 
     
    6870    unit8 = "m/s^{4}"  #         x^2               (m/s^{4})^{2} 
    6971 
    70     print "this unit1 %s ,its powerer %s , and value %s" % (unit1, 1, convert_unit(1, unit1)) 
    71     print "this unit2 %s ,its powerer %s , and value %s" % (unit2, 1, convert_unit(1, unit2)) 
    72     print "this unit3 %s ,its powerer %s , and value %s" % (unit3, 2, convert_unit(2, unit3)) 
    73     print "this unit4 %s ,its powerer %s , and value %s" % (unit4, -1, convert_unit(-1, unit4)) 
    74     print "this unit5 %s ,its powerer %s , and value %s" % (unit5, 2, convert_unit(2, unit5)) 
    75     print "this unit6 %s ,its powerer %s , and value %s" % (unit6, 2, convert_unit(2, unit6)) 
    76     print "this unit7 %s ,its powerer %s , and value %s" % (unit7, -1, convert_unit(-1, unit7)) 
    77     print "this unit8 %s ,its powerer %s , and value %s" % (unit8, 2, convert_unit(2, unit8)) 
    78     print "this unit9 %s ,its powerer %s , and value %s" % (unit9, 2, convert_unit(2, unit9)) 
     72    print("this unit1 %s ,its powerer %s , and value %s" % (unit1, 1, convert_unit(1, unit1))) 
     73    print("this unit2 %s ,its powerer %s , and value %s" % (unit2, 1, convert_unit(1, unit2))) 
     74    print("this unit3 %s ,its powerer %s , and value %s" % (unit3, 2, convert_unit(2, unit3))) 
     75    print("this unit4 %s ,its powerer %s , and value %s" % (unit4, -1, convert_unit(-1, unit4))) 
     76    print("this unit5 %s ,its powerer %s , and value %s" % (unit5, 2, convert_unit(2, unit5))) 
     77    print("this unit6 %s ,its powerer %s , and value %s" % (unit6, 2, convert_unit(2, unit6))) 
     78    print("this unit7 %s ,its powerer %s , and value %s" % (unit7, -1, convert_unit(-1, unit7))) 
     79    print("this unit8 %s ,its powerer %s , and value %s" % (unit8, 2, convert_unit(2, unit8))) 
     80    print("this unit9 %s ,its powerer %s , and value %s" % (unit9, 2, convert_unit(2, unit9))) 
  • src/sas/sasgui/plottools/fittings.py

    rac07a3a ra1b8fee  
    1414 
    1515""" 
     16from __future__ import print_function 
     17 
    1618from scipy import optimize 
    1719 
     
    106108    chisqr, out, cov = sasfit(line, [cstA, cstB], event.x, y, 0) 
    107109    # print "Output parameters:", out 
    108     print "The right answer is [70.0, 1.0]" 
    109     print chisqr, out, cov 
     110    print("The right answer is [70.0, 1.0]") 
     111    print(chisqr, out, cov) 
  • src/sas/sasgui/plottools/plottable_interactor.py

    r45dffa69 ra1b8fee  
    22    This module allows more interaction with the plot 
    33""" 
     4from __future__ import print_function 
     5 
    46from BaseInteractor import _BaseInteractor 
     7 
    58 
    69class PointInteractor(_BaseInteractor): 
     
    156159 
    157160    def clear(self): 
    158         print "plottable_interactor.clear()" 
     161        print("plottable_interactor.clear()") 
    159162 
    160163    def _on_click(self, evt): 
  • src/sas/sascalc/dataloader/manipulations.py

    r7432acb rb290a9e  
     1from __future__ import division 
    12""" 
    23Data manipulations for 2D data sets. 
    34Using the meta data information, various types of averaging 
    45are performed in Q-space 
     6 
     7To test this module use: 
     8``` 
     9cd test 
     10PYTHONPATH=../src/ python2  -m sasdataloader.test.utest_averaging DataInfoTests.test_sectorphi_quarter 
     11``` 
    512""" 
    613##################################################################### 
    7 #This software was developed by the University of Tennessee as part of the 
    8 #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 
    9 #project funded by the US National Science Foundation. 
    10 #See the license text in license.txt 
    11 #copyright 2008, University of Tennessee 
     14# This software was developed by the University of Tennessee as part of the 
     15# Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 
     16# project funded by the US National Science Foundation. 
     17# See the license text in license.txt 
     18# copyright 2008, University of Tennessee 
    1219###################################################################### 
    1320 
    14 #TODO: copy the meta data from the 2D object to the resulting 1D object 
     21 
     22# TODO: copy the meta data from the 2D object to the resulting 1D object 
    1523import math 
    16 import numpy 
     24import numpy as np 
     25import sys 
    1726 
    1827#from data_info import plottable_2D 
     
    7079    return phi_out 
    7180 
    72  
    73 def reader2D_converter(data2d=None): 
    74     """ 
    75     convert old 2d format opened by IhorReader or danse_reader 
    76     to new Data2D format 
    77  
    78     :param data2d: 2d array of Data2D object 
    79     :return: 1d arrays of Data2D object 
    80  
    81     """ 
    82     if data2d.data is None or data2d.x_bins is None or data2d.y_bins is None: 
    83         raise ValueError, "Can't convert this data: data=None..." 
    84     new_x = numpy.tile(data2d.x_bins, (len(data2d.y_bins), 1)) 
    85     new_y = numpy.tile(data2d.y_bins, (len(data2d.x_bins), 1)) 
    86     new_y = new_y.swapaxes(0, 1) 
    87  
    88     new_data = data2d.data.flatten() 
    89     qx_data = new_x.flatten() 
    90     qy_data = new_y.flatten() 
    91     q_data = numpy.sqrt(qx_data * qx_data + qy_data * qy_data) 
    92     if data2d.err_data is None or numpy.any(data2d.err_data <= 0): 
    93         new_err_data = numpy.sqrt(numpy.abs(new_data)) 
    94     else: 
    95         new_err_data = data2d.err_data.flatten() 
    96     mask = numpy.ones(len(new_data), dtype=bool) 
    97  
    98     #TODO: make sense of the following two lines... 
    99     #from sas.sascalc.dataloader.data_info import Data2D 
    100     #output = Data2D() 
    101     output = data2d 
    102     output.data = new_data 
    103     output.err_data = new_err_data 
    104     output.qx_data = qx_data 
    105     output.qy_data = qy_data 
    106     output.q_data = q_data 
    107     output.mask = mask 
    108  
    109     return output 
    110  
    111  
    112 class _Slab(object): 
    113     """ 
    114     Compute average I(Q) for a region of interest 
    115     """ 
    116     def __init__(self, x_min=0.0, x_max=0.0, y_min=0.0, 
    117                  y_max=0.0, bin_width=0.001): 
    118         # Minimum Qx value [A-1] 
    119         self.x_min = x_min 
    120         # Maximum Qx value [A-1] 
    121         self.x_max = x_max 
    122         # Minimum Qy value [A-1] 
    123         self.y_min = y_min 
    124         # Maximum Qy value [A-1] 
    125         self.y_max = y_max 
    126         # Bin width (step size) [A-1] 
    127         self.bin_width = bin_width 
    128         # If True, I(|Q|) will be return, otherwise, 
    129         # negative q-values are allowed 
    130         self.fold = False 
    131  
    132     def __call__(self, data2D): 
    133         return NotImplemented 
    134  
    135     def _avg(self, data2D, maj): 
    136         """ 
    137         Compute average I(Q_maj) for a region of interest. 
    138         The major axis is defined as the axis of Q_maj. 
    139         The minor axis is the axis that we average over. 
    140  
    141         :param data2D: Data2D object 
    142         :param maj_min: min value on the major axis 
    143         :return: Data1D object 
    144         """ 
    145         if len(data2D.detector) > 1: 
    146             msg = "_Slab._avg: invalid number of " 
    147             msg += " detectors: %g" % len(data2D.detector) 
    148             raise RuntimeError, msg 
    149  
    150         # Get data 
    151         data = data2D.data[numpy.isfinite(data2D.data)] 
    152         err_data = data2D.err_data[numpy.isfinite(data2D.data)] 
    153         qx_data = data2D.qx_data[numpy.isfinite(data2D.data)] 
    154         qy_data = data2D.qy_data[numpy.isfinite(data2D.data)] 
    155  
    156         # Build array of Q intervals 
    157         if maj == 'x': 
    158             if self.fold: 
    159                 x_min = 0 
    160             else: 
    161                 x_min = self.x_min 
    162             nbins = int(math.ceil((self.x_max - x_min) / self.bin_width)) 
    163         elif maj == 'y': 
    164             if self.fold: 
    165                 y_min = 0 
    166             else: 
    167                 y_min = self.y_min 
    168             nbins = int(math.ceil((self.y_max - y_min) / self.bin_width)) 
    169         else: 
    170             raise RuntimeError, "_Slab._avg: unrecognized axis %s" % str(maj) 
    171  
    172         x = numpy.zeros(nbins) 
    173         y = numpy.zeros(nbins) 
    174         err_y = numpy.zeros(nbins) 
    175         y_counts = numpy.zeros(nbins) 
    176  
    177         # Average pixelsize in q space 
    178         for npts in range(len(data)): 
    179             # default frac 
    180             frac_x = 0 
    181             frac_y = 0 
    182             # get ROI 
    183             if self.x_min <= qx_data[npts] and self.x_max > qx_data[npts]: 
    184                 frac_x = 1 
    185             if self.y_min <= qy_data[npts] and self.y_max > qy_data[npts]: 
    186                 frac_y = 1 
    187             frac = frac_x * frac_y 
    188  
    189             if frac == 0: 
    190                 continue 
    191             # binning: find axis of q 
    192             if maj == 'x': 
    193                 q_value = qx_data[npts] 
    194                 min_value = x_min 
    195             if maj == 'y': 
    196                 q_value = qy_data[npts] 
    197                 min_value = y_min 
    198             if self.fold and q_value < 0: 
    199                 q_value = -q_value 
    200             # bin 
    201             i_q = int(math.ceil((q_value - min_value) / self.bin_width)) - 1 
    202  
    203             # skip outside of max bins 
    204             if i_q < 0 or i_q >= nbins: 
    205                 continue 
    206  
    207             #TODO: find better definition of x[i_q] based on q_data 
    208             # min_value + (i_q + 1) * self.bin_width / 2.0 
    209             x[i_q] += frac * q_value 
    210             y[i_q] += frac * data[npts] 
    211  
    212             if err_data is None or err_data[npts] == 0.0: 
    213                 if data[npts] < 0: 
    214                     data[npts] = -data[npts] 
    215                 err_y[i_q] += frac * frac * data[npts] 
    216             else: 
    217                 err_y[i_q] += frac * frac * err_data[npts] * err_data[npts] 
    218             y_counts[i_q] += frac 
    219  
    220         # Average the sums 
    221         for n in range(nbins): 
    222             err_y[n] = math.sqrt(err_y[n]) 
    223  
    224         err_y = err_y / y_counts 
    225         y = y / y_counts 
    226         x = x / y_counts 
    227         idx = (numpy.isfinite(y) & numpy.isfinite(x)) 
    228  
    229         if not idx.any(): 
    230             msg = "Average Error: No points inside ROI to average..." 
    231             raise ValueError, msg 
    232         return Data1D(x=x[idx], y=y[idx], dy=err_y[idx]) 
    233  
    234  
    235 class SlabY(_Slab): 
    236     """ 
    237     Compute average I(Qy) for a region of interest 
    238     """ 
    239     def __call__(self, data2D): 
    240         """ 
    241         Compute average I(Qy) for a region of interest 
    242  
    243         :param data2D: Data2D object 
    244         :return: Data1D object 
    245         """ 
    246         return self._avg(data2D, 'y') 
    247  
    248  
    249 class SlabX(_Slab): 
    250     """ 
    251     Compute average I(Qx) for a region of interest 
    252     """ 
    253     def __call__(self, data2D): 
    254         """ 
    255         Compute average I(Qx) for a region of interest 
    256         :param data2D: Data2D object 
    257         :return: Data1D object 
    258         """ 
    259         return self._avg(data2D, 'x') 
    260  
    261  
    262 class Boxsum(object): 
    263     """ 
    264     Perform the sum of counts in a 2D region of interest. 
    265     """ 
    266     def __init__(self, x_min=0.0, x_max=0.0, y_min=0.0, y_max=0.0): 
    267         # Minimum Qx value [A-1] 
    268         self.x_min = x_min 
    269         # Maximum Qx value [A-1] 
    270         self.x_max = x_max 
    271         # Minimum Qy value [A-1] 
    272         self.y_min = y_min 
    273         # Maximum Qy value [A-1] 
    274         self.y_max = y_max 
    275  
    276     def __call__(self, data2D): 
    277         """ 
    278         Perform the sum in the region of interest 
    279  
    280         :param data2D: Data2D object 
    281         :return: number of counts, error on number of counts, 
    282             number of points summed 
    283         """ 
    284         y, err_y, y_counts = self._sum(data2D) 
    285  
    286         # Average the sums 
    287         counts = 0 if y_counts == 0 else y 
    288         error = 0 if y_counts == 0 else math.sqrt(err_y) 
    289  
    290         # Added y_counts to return, SMK & PDB, 04/03/2013 
    291         return counts, error, y_counts 
    292  
    293     def _sum(self, data2D): 
    294         """ 
    295         Perform the sum in the region of interest 
    296  
    297         :param data2D: Data2D object 
    298         :return: number of counts, 
    299             error on number of counts, number of entries summed 
    300         """ 
    301         if len(data2D.detector) > 1: 
    302             msg = "Circular averaging: invalid number " 
    303             msg += "of detectors: %g" % len(data2D.detector) 
    304             raise RuntimeError, msg 
    305         # Get data 
    306         data = data2D.data[numpy.isfinite(data2D.data)] 
    307         err_data = data2D.err_data[numpy.isfinite(data2D.data)] 
    308         qx_data = data2D.qx_data[numpy.isfinite(data2D.data)] 
    309         qy_data = data2D.qy_data[numpy.isfinite(data2D.data)] 
    310  
    311         y = 0.0 
    312         err_y = 0.0 
    313         y_counts = 0.0 
    314  
    315         # Average pixelsize in q space 
    316         for npts in range(len(data)): 
    317             # default frac 
    318             frac_x = 0 
    319             frac_y = 0 
    320  
    321             # get min and max at each points 
    322             qx = qx_data[npts] 
    323             qy = qy_data[npts] 
    324  
    325             # get the ROI 
    326             if self.x_min <= qx and self.x_max > qx: 
    327                 frac_x = 1 
    328             if self.y_min <= qy and self.y_max > qy: 
    329                 frac_y = 1 
    330             #Find the fraction along each directions 
    331             frac = frac_x * frac_y 
    332             if frac == 0: 
    333                 continue 
    334             y += frac * data[npts] 
    335             if err_data is None or err_data[npts] == 0.0: 
    336                 if data[npts] < 0: 
    337                     data[npts] = -data[npts] 
    338                 err_y += frac * frac * data[npts] 
    339             else: 
    340                 err_y += frac * frac * err_data[npts] * err_data[npts] 
    341             y_counts += frac 
    342         return y, err_y, y_counts 
    343  
    344  
    345 class Boxavg(Boxsum): 
    346     """ 
    347     Perform the average of counts in a 2D region of interest. 
    348     """ 
    349     def __init__(self, x_min=0.0, x_max=0.0, y_min=0.0, y_max=0.0): 
    350         super(Boxavg, self).__init__(x_min=x_min, x_max=x_max, 
    351                                      y_min=y_min, y_max=y_max) 
    352  
    353     def __call__(self, data2D): 
    354         """ 
    355         Perform the sum in the region of interest 
    356  
    357         :param data2D: Data2D object 
    358         :return: average counts, error on average counts 
    359  
    360         """ 
    361         y, err_y, y_counts = self._sum(data2D) 
    362  
    363         # Average the sums 
    364         counts = 0 if y_counts == 0 else y / y_counts 
    365         error = 0 if y_counts == 0 else math.sqrt(err_y) / y_counts 
    366  
    367         return counts, error 
    368  
    369  
    37081def get_pixel_fraction_square(x, xmin, xmax): 
    37182    """ 
     
    390101        return 1.0 
    391102 
    392  
    393 class CircularAverage(object): 
    394     """ 
    395     Perform circular averaging on 2D data 
    396  
    397     The data returned is the distribution of counts 
    398     as a function of Q 
    399     """ 
    400     def __init__(self, r_min=0.0, r_max=0.0, bin_width=0.0005): 
    401         # Minimum radius included in the average [A-1] 
    402         self.r_min = r_min 
    403         # Maximum radius included in the average [A-1] 
    404         self.r_max = r_max 
    405         # Bin width (step size) [A-1] 
    406         self.bin_width = bin_width 
    407  
    408     def __call__(self, data2D, ismask=False): 
    409         """ 
    410         Perform circular averaging on the data 
    411  
    412         :param data2D: Data2D object 
    413         :return: Data1D object 
    414         """ 
    415         # Get data W/ finite values 
    416         data = data2D.data[numpy.isfinite(data2D.data)] 
    417         q_data = data2D.q_data[numpy.isfinite(data2D.data)] 
    418         err_data = data2D.err_data[numpy.isfinite(data2D.data)] 
    419         mask_data = data2D.mask[numpy.isfinite(data2D.data)] 
    420  
    421         dq_data = None 
    422  
    423         # Get the dq for resolution averaging 
    424         if data2D.dqx_data is not None and data2D.dqy_data is not None: 
    425             # The pinholes and det. pix contribution present 
    426             # in both direction of the 2D which must be subtracted when 
    427             # converting to 1D: dq_overlap should calculated ideally at 
    428             # q = 0. Note This method works on only pinhole geometry. 
    429             # Extrapolate dqx(r) and dqy(phi) at q = 0, and take an average. 
    430             z_max = max(data2D.q_data) 
    431             z_min = min(data2D.q_data) 
    432             x_max = data2D.dqx_data[data2D.q_data[z_max]] 
    433             x_min = data2D.dqx_data[data2D.q_data[z_min]] 
    434             y_max = data2D.dqy_data[data2D.q_data[z_max]] 
    435             y_min = data2D.dqy_data[data2D.q_data[z_min]] 
    436             # Find qdx at q = 0 
    437             dq_overlap_x = (x_min * z_max - x_max * z_min) / (z_max - z_min) 
    438             # when extrapolation goes wrong 
    439             if dq_overlap_x > min(data2D.dqx_data): 
    440                 dq_overlap_x = min(data2D.dqx_data) 
    441             dq_overlap_x *= dq_overlap_x 
    442             # Find qdx at q = 0 
    443             dq_overlap_y = (y_min * z_max - y_max * z_min) / (z_max - z_min) 
    444             # when extrapolation goes wrong 
    445             if dq_overlap_y > min(data2D.dqy_data): 
    446                 dq_overlap_y = min(data2D.dqy_data) 
    447             # get dq at q=0. 
    448             dq_overlap_y *= dq_overlap_y 
    449  
    450             dq_overlap = numpy.sqrt((dq_overlap_x + dq_overlap_y) / 2.0) 
    451             # Final protection of dq 
    452             if dq_overlap < 0: 
    453                 dq_overlap = y_min 
    454             dqx_data = data2D.dqx_data[numpy.isfinite(data2D.data)] 
    455             dqy_data = data2D.dqy_data[numpy.isfinite(data2D.data)] - dq_overlap 
    456             # def; dqx_data = dq_r dqy_data = dq_phi 
    457             # Convert dq 2D to 1D here 
    458             dqx = dqx_data * dqx_data 
    459             dqy = dqy_data * dqy_data 
    460             dq_data = numpy.add(dqx, dqy) 
    461             dq_data = numpy.sqrt(dq_data) 
    462  
    463         #q_data_max = numpy.max(q_data) 
    464         if len(data2D.q_data) is None: 
    465             msg = "Circular averaging: invalid q_data: %g" % data2D.q_data 
    466             raise RuntimeError, msg 
    467  
    468         # Build array of Q intervals 
    469         nbins = int(math.ceil((self.r_max - self.r_min) / self.bin_width)) 
    470  
    471         x = numpy.zeros(nbins) 
    472         y = numpy.zeros(nbins) 
    473         err_y = numpy.zeros(nbins) 
    474         err_x = numpy.zeros(nbins) 
    475         y_counts = numpy.zeros(nbins) 
    476  
    477         for npt in range(len(data)): 
    478  
    479             if ismask and not mask_data[npt]: 
    480                 continue 
    481  
    482             frac = 0 
    483  
    484             # q-value at the pixel (j,i) 
    485             q_value = q_data[npt] 
    486             data_n = data[npt] 
    487  
    488             ## No need to calculate the frac when all data are within range 
    489             if self.r_min >= self.r_max: 
    490                 raise ValueError, "Limit Error: min > max" 
    491  
    492             if self.r_min <= q_value and q_value <= self.r_max: 
    493                 frac = 1 
    494             if frac == 0: 
    495                 continue 
    496             i_q = int(math.floor((q_value - self.r_min) / self.bin_width)) 
    497  
    498             # Take care of the edge case at phi = 2pi. 
    499             if i_q == nbins: 
    500                 i_q = nbins - 1 
    501             y[i_q] += frac * data_n 
    502             # Take dqs from data to get the q_average 
    503             x[i_q] += frac * q_value 
    504             if err_data is None or err_data[npt] == 0.0: 
    505                 if data_n < 0: 
    506                     data_n = -data_n 
    507                 err_y[i_q] += frac * frac * data_n 
    508             else: 
    509                 err_y[i_q] += frac * frac * err_data[npt] * err_data[npt] 
    510             if dq_data is not None: 
    511                 # To be consistent with dq calculation in 1d reduction, 
    512                 # we need just the averages (not quadratures) because 
    513                 # it should not depend on the number of the q points 
    514                 # in the qr bins. 
    515                 err_x[i_q] += frac * dq_data[npt] 
    516             else: 
    517                 err_x = None 
    518             y_counts[i_q] += frac 
    519  
    520         # Average the sums 
    521         for n in range(nbins): 
    522             if err_y[n] < 0: 
    523                 err_y[n] = -err_y[n] 
    524             err_y[n] = math.sqrt(err_y[n]) 
    525             #if err_x is not None: 
    526             #    err_x[n] = math.sqrt(err_x[n]) 
    527  
    528         err_y = err_y / y_counts 
    529         err_y[err_y == 0] = numpy.average(err_y) 
    530         y = y / y_counts 
    531         x = x / y_counts 
    532         idx = (numpy.isfinite(y)) & (numpy.isfinite(x)) 
    533  
    534         if err_x is not None: 
    535             d_x = err_x[idx] / y_counts[idx] 
    536         else: 
    537             d_x = None 
    538  
    539         if not idx.any(): 
    540             msg = "Average Error: No points inside ROI to average..." 
    541             raise ValueError, msg 
    542  
    543         return Data1D(x=x[idx], y=y[idx], dy=err_y[idx], dx=d_x) 
    544  
    545  
    546 class Ring(object): 
    547     """ 
    548     Defines a ring on a 2D data set. 
    549     The ring is defined by r_min, r_max, and 
    550     the position of the center of the ring. 
    551  
    552     The data returned is the distribution of counts 
    553     around the ring as a function of phi. 
    554  
    555     Phi_min and phi_max should be defined between 0 and 2*pi 
    556     in anti-clockwise starting from the x- axis on the left-hand side 
    557     """ 
    558     #Todo: remove center. 
    559     def __init__(self, r_min=0, r_max=0, center_x=0, center_y=0, nbins=36): 
    560         # Minimum radius 
    561         self.r_min = r_min 
    562         # Maximum radius 
    563         self.r_max = r_max 
    564         # Center of the ring in x 
    565         self.center_x = center_x 
    566         # Center of the ring in y 
    567         self.center_y = center_y 
    568         # Number of angular bins 
    569         self.nbins_phi = nbins 
    570  
    571  
    572     def __call__(self, data2D): 
    573         """ 
    574         Apply the ring to the data set. 
    575         Returns the angular distribution for a given q range 
    576  
    577         :param data2D: Data2D object 
    578  
    579         :return: Data1D object 
    580         """ 
    581         if data2D.__class__.__name__ not in ["Data2D", "plottable_2D"]: 
    582             raise RuntimeError, "Ring averaging only take plottable_2D objects" 
    583  
    584         Pi = math.pi 
    585  
    586         # Get data 
    587         data = data2D.data[numpy.isfinite(data2D.data)] 
    588         q_data = data2D.q_data[numpy.isfinite(data2D.data)] 
    589         err_data = data2D.err_data[numpy.isfinite(data2D.data)] 
    590         qx_data = data2D.qx_data[numpy.isfinite(data2D.data)] 
    591         qy_data = data2D.qy_data[numpy.isfinite(data2D.data)] 
    592  
    593         # Set space for 1d outputs 
    594         phi_bins = numpy.zeros(self.nbins_phi) 
    595         phi_counts = numpy.zeros(self.nbins_phi) 
    596         phi_values = numpy.zeros(self.nbins_phi) 
    597         phi_err = numpy.zeros(self.nbins_phi) 
    598  
    599         # Shift to apply to calculated phi values in order 
    600         # to center first bin at zero 
    601         phi_shift = Pi / self.nbins_phi 
    602  
    603         for npt in range(len(data)): 
    604             frac = 0 
    605             # q-value at the point (npt) 
    606             q_value = q_data[npt] 
    607             data_n = data[npt] 
    608  
    609             # phi-value at the point (npt) 
    610             phi_value = math.atan2(qy_data[npt], qx_data[npt]) + Pi 
    611  
    612             if self.r_min <= q_value and q_value <= self.r_max: 
    613                 frac = 1 
    614             if frac == 0: 
    615                 continue 
    616             # binning 
    617             i_phi = int(math.floor((self.nbins_phi) * \ 
    618                                    (phi_value + phi_shift) / (2 * Pi))) 
    619  
    620             # Take care of the edge case at phi = 2pi. 
    621             if i_phi >= self.nbins_phi: 
    622                 i_phi = 0 
    623             phi_bins[i_phi] += frac * data[npt] 
    624  
    625             if err_data is None or err_data[npt] == 0.0: 
    626                 if data_n < 0: 
    627                     data_n = -data_n 
    628                 phi_err[i_phi] += frac * frac * math.fabs(data_n) 
    629             else: 
    630                 phi_err[i_phi] += frac * frac * err_data[npt] * err_data[npt] 
    631             phi_counts[i_phi] += frac 
    632  
    633         for i in range(self.nbins_phi): 
    634             phi_bins[i] = phi_bins[i] / phi_counts[i] 
    635             phi_err[i] = math.sqrt(phi_err[i]) / phi_counts[i] 
    636             phi_values[i] = 2.0 * math.pi / self.nbins_phi * (1.0 * i) 
    637  
    638         idx = (numpy.isfinite(phi_bins)) 
    639  
    640         if not idx.any(): 
    641             msg = "Average Error: No points inside ROI to average..." 
    642             raise ValueError, msg 
    643         #elif len(phi_bins[idx])!= self.nbins_phi: 
    644         #    print "resulted",self.nbins_phi- len(phi_bins[idx]) 
    645         #,"empty bin(s) due to tight binning..." 
    646         return Data1D(x=phi_values[idx], y=phi_bins[idx], dy=phi_err[idx]) 
    647  
     103def get_intercept(q, q_0, q_1): 
     104    """ 
     105    Returns the fraction of the side at which the 
     106    q-value intercept the pixel, None otherwise. 
     107    The values returned is the fraction ON THE SIDE 
     108    OF THE LOWEST Q. :: 
     109 
     110            A           B 
     111        +-----------+--------+    <--- pixel size 
     112        0                    1 
     113        Q_0 -------- Q ----- Q_1   <--- equivalent Q range 
     114        if Q_1 > Q_0, A is returned 
     115        if Q_1 < Q_0, B is returned 
     116        if Q is outside the range of [Q_0, Q_1], None is returned 
     117 
     118    """ 
     119    if q_1 > q_0: 
     120        if q > q_0 and q <= q_1: 
     121            return (q - q_0) / (q_1 - q_0) 
     122    else: 
     123        if q > q_1 and q <= q_0: 
     124            return (q - q_1) / (q_0 - q_1) 
     125    return None 
    648126 
    649127def get_pixel_fraction(qmax, q_00, q_01, q_10, q_11): 
     
    710188    return frac_max 
    711189 
    712  
    713 def get_intercept(q, q_0, q_1): 
    714     """ 
    715     Returns the fraction of the side at which the 
    716     q-value intercept the pixel, None otherwise. 
    717     The values returned is the fraction ON THE SIDE 
    718     OF THE LOWEST Q. :: 
    719  
    720             A           B 
    721         +-----------+--------+    <--- pixel size 
    722         0                    1 
    723         Q_0 -------- Q ----- Q_1   <--- equivalent Q range 
    724         if Q_1 > Q_0, A is returned 
    725         if Q_1 < Q_0, B is returned 
    726         if Q is outside the range of [Q_0, Q_1], None is returned 
    727  
    728     """ 
    729     if q_1 > q_0: 
    730         if q > q_0 and q <= q_1: 
    731             return (q - q_0) / (q_1 - q_0) 
     190def get_dq_data(data2D): 
     191    ''' 
     192    Get the dq for resolution averaging 
     193    The pinholes and det. pix contribution present 
     194    in both direction of the 2D which must be subtracted when 
     195    converting to 1D: dq_overlap should calculated ideally at 
     196    q = 0. Note This method works on only pinhole geometry. 
     197    Extrapolate dqx(r) and dqy(phi) at q = 0, and take an average. 
     198    ''' 
     199    z_max = max(data2D.q_data) 
     200    z_min = min(data2D.q_data) 
     201    x_max = data2D.dqx_data[data2D.q_data[z_max]] 
     202    x_min = data2D.dqx_data[data2D.q_data[z_min]] 
     203    y_max = data2D.dqy_data[data2D.q_data[z_max]] 
     204    y_min = data2D.dqy_data[data2D.q_data[z_min]] 
     205    # Find qdx at q = 0 
     206    dq_overlap_x = (x_min * z_max - x_max * z_min) / (z_max - z_min) 
     207    # when extrapolation goes wrong 
     208    if dq_overlap_x > min(data2D.dqx_data): 
     209        dq_overlap_x = min(data2D.dqx_data) 
     210    dq_overlap_x *= dq_overlap_x 
     211    # Find qdx at q = 0 
     212    dq_overlap_y = (y_min * z_max - y_max * z_min) / (z_max - z_min) 
     213    # when extrapolation goes wrong 
     214    if dq_overlap_y > min(data2D.dqy_data): 
     215        dq_overlap_y = min(data2D.dqy_data) 
     216    # get dq at q=0. 
     217    dq_overlap_y *= dq_overlap_y 
     218 
     219    dq_overlap = np.sqrt((dq_overlap_x + dq_overlap_y) / 2.0) 
     220    # Final protection of dq 
     221    if dq_overlap < 0: 
     222        dq_overlap = y_min 
     223    dqx_data = data2D.dqx_data[np.isfinite(data2D.data)] 
     224    dqy_data = data2D.dqy_data[np.isfinite( 
     225        data2D.data)] - dq_overlap 
     226    # def; dqx_data = dq_r dqy_data = dq_phi 
     227    # Convert dq 2D to 1D here 
     228    dq_data = np.sqrt(dqx_data**2 + dqx_data**2) 
     229    return dq_data 
     230 
     231################################################################################ 
     232 
     233def reader2D_converter(data2d=None): 
     234    """ 
     235    convert old 2d format opened by IhorReader or danse_reader 
     236    to new Data2D format 
     237    This is mainly used by the Readers 
     238 
     239    :param data2d: 2d array of Data2D object 
     240    :return: 1d arrays of Data2D object 
     241 
     242    """ 
     243    if data2d.data is None or data2d.x_bins is None or data2d.y_bins is None: 
     244        raise ValueError("Can't convert this data: data=None...") 
     245    new_x = np.tile(data2d.x_bins, (len(data2d.y_bins), 1)) 
     246    new_y = np.tile(data2d.y_bins, (len(data2d.x_bins), 1)) 
     247    new_y = new_y.swapaxes(0, 1) 
     248 
     249    new_data = data2d.data.flatten() 
     250    qx_data = new_x.flatten() 
     251    qy_data = new_y.flatten() 
     252    q_data = np.sqrt(qx_data * qx_data + qy_data * qy_data) 
     253    if data2d.err_data is None or np.any(data2d.err_data <= 0): 
     254        new_err_data = np.sqrt(np.abs(new_data)) 
    732255    else: 
    733         if q > q_1 and q <= q_0: 
    734             return (q - q_1) / (q_0 - q_1) 
    735     return None 
    736  
     256        new_err_data = data2d.err_data.flatten() 
     257    mask = np.ones(len(new_data), dtype=bool) 
     258 
     259    # TODO: make sense of the following two lines... 
     260    #from sas.sascalc.dataloader.data_info import Data2D 
     261    #output = Data2D() 
     262    output = data2d 
     263    output.data = new_data 
     264    output.err_data = new_err_data 
     265    output.qx_data = qx_data 
     266    output.qy_data = qy_data 
     267    output.q_data = q_data 
     268    output.mask = mask 
     269 
     270    return output 
     271 
     272################################################################################ 
     273 
     274class Binning(object): 
     275    ''' 
     276    This class just creates a binning object 
     277    either linear or log 
     278    ''' 
     279 
     280    def __init__(self, min_value, max_value, n_bins, base=None): 
     281        ''' 
     282        if base is None: Linear binning 
     283        ''' 
     284        self.min = min_value if min_value > 0 else 0.0001 
     285        self.max = max_value 
     286        self.n_bins = n_bins 
     287        self.base = base 
     288 
     289    def get_bin_index(self, value): 
     290        ''' 
     291        The general formula logarithm binning is: 
     292        bin = floor(N * (log(x) - log(min)) / (log(max) - log(min))) 
     293        ''' 
     294        if self.base: 
     295            temp_x = self.n_bins * (math.log(value, self.base) - math.log(self.min, self.base)) 
     296            temp_y = math.log(self.max, self.base) - math.log(self.min, self.base) 
     297        else: 
     298            temp_x = self.n_bins * (value - self.min) 
     299            temp_y = self.max - self.min 
     300        # Bin index calulation 
     301        return int(math.floor(temp_x / temp_y)) 
     302 
     303 
     304################################################################################ 
     305 
     306class _Slab(object): 
     307    """ 
     308    Compute average I(Q) for a region of interest 
     309    """ 
     310 
     311    def __init__(self, x_min=0.0, x_max=0.0, y_min=0.0, 
     312                 y_max=0.0, bin_width=0.001): 
     313        # Minimum Qx value [A-1] 
     314        self.x_min = x_min 
     315        # Maximum Qx value [A-1] 
     316        self.x_max = x_max 
     317        # Minimum Qy value [A-1] 
     318        self.y_min = y_min 
     319        # Maximum Qy value [A-1] 
     320        self.y_max = y_max 
     321        # Bin width (step size) [A-1] 
     322        self.bin_width = bin_width 
     323        # If True, I(|Q|) will be return, otherwise, 
     324        # negative q-values are allowed 
     325        self.fold = False 
     326 
     327    def __call__(self, data2D): 
     328        return NotImplemented 
     329 
     330    def _avg(self, data2D, maj): 
     331        """ 
     332        Compute average I(Q_maj) for a region of interest. 
     333        The major axis is defined as the axis of Q_maj. 
     334        The minor axis is the axis that we average over. 
     335 
     336        :param data2D: Data2D object 
     337        :param maj_min: min value on the major axis 
     338        :return: Data1D object 
     339        """ 
     340        if len(data2D.detector) > 1: 
     341            msg = "_Slab._avg: invalid number of " 
     342            msg += " detectors: %g" % len(data2D.detector) 
     343            raise RuntimeError(msg) 
     344 
     345        # Get data 
     346        data = data2D.data[np.isfinite(data2D.data)] 
     347        err_data = data2D.err_data[np.isfinite(data2D.data)] 
     348        qx_data = data2D.qx_data[np.isfinite(data2D.data)] 
     349        qy_data = data2D.qy_data[np.isfinite(data2D.data)] 
     350 
     351        # Build array of Q intervals 
     352        if maj == 'x': 
     353            if self.fold: 
     354                x_min = 0 
     355            else: 
     356                x_min = self.x_min 
     357            nbins = int(math.ceil((self.x_max - x_min) / self.bin_width)) 
     358        elif maj == 'y': 
     359            if self.fold: 
     360                y_min = 0 
     361            else: 
     362                y_min = self.y_min 
     363            nbins = int(math.ceil((self.y_max - y_min) / self.bin_width)) 
     364        else: 
     365            raise RuntimeError("_Slab._avg: unrecognized axis %s" % str(maj)) 
     366 
     367        x = np.zeros(nbins) 
     368        y = np.zeros(nbins) 
     369        err_y = np.zeros(nbins) 
     370        y_counts = np.zeros(nbins) 
     371 
     372        # Average pixelsize in q space 
     373        for npts in range(len(data)): 
     374            # default frac 
     375            frac_x = 0 
     376            frac_y = 0 
     377            # get ROI 
     378            if self.x_min <= qx_data[npts] and self.x_max > qx_data[npts]: 
     379                frac_x = 1 
     380            if self.y_min <= qy_data[npts] and self.y_max > qy_data[npts]: 
     381                frac_y = 1 
     382            frac = frac_x * frac_y 
     383 
     384            if frac == 0: 
     385                continue 
     386            # binning: find axis of q 
     387            if maj == 'x': 
     388                q_value = qx_data[npts] 
     389                min_value = x_min 
     390            if maj == 'y': 
     391                q_value = qy_data[npts] 
     392                min_value = y_min 
     393            if self.fold and q_value < 0: 
     394                q_value = -q_value 
     395            # bin 
     396            i_q = int(math.ceil((q_value - min_value) / self.bin_width)) - 1 
     397 
     398            # skip outside of max bins 
     399            if i_q < 0 or i_q >= nbins: 
     400                continue 
     401 
     402            # TODO: find better definition of x[i_q] based on q_data 
     403            # min_value + (i_q + 1) * self.bin_width / 2.0 
     404            x[i_q] += frac * q_value 
     405            y[i_q] += frac * data[npts] 
     406 
     407            if err_data is None or err_data[npts] == 0.0: 
     408                if data[npts] < 0: 
     409                    data[npts] = -data[npts] 
     410                err_y[i_q] += frac * frac * data[npts] 
     411            else: 
     412                err_y[i_q] += frac * frac * err_data[npts] * err_data[npts] 
     413            y_counts[i_q] += frac 
     414 
     415        # Average the sums 
     416        for n in range(nbins): 
     417            err_y[n] = math.sqrt(err_y[n]) 
     418 
     419        err_y = err_y / y_counts 
     420        y = y / y_counts 
     421        x = x / y_counts 
     422        idx = (np.isfinite(y) & np.isfinite(x)) 
     423 
     424        if not idx.any(): 
     425            msg = "Average Error: No points inside ROI to average..." 
     426            raise ValueError(msg) 
     427        return Data1D(x=x[idx], y=y[idx], dy=err_y[idx]) 
     428 
     429 
     430class SlabY(_Slab): 
     431    """ 
     432    Compute average I(Qy) for a region of interest 
     433    """ 
     434 
     435    def __call__(self, data2D): 
     436        """ 
     437        Compute average I(Qy) for a region of interest 
     438 
     439        :param data2D: Data2D object 
     440        :return: Data1D object 
     441        """ 
     442        return self._avg(data2D, 'y') 
     443 
     444 
     445class SlabX(_Slab): 
     446    """ 
     447    Compute average I(Qx) for a region of interest 
     448    """ 
     449 
     450    def __call__(self, data2D): 
     451        """ 
     452        Compute average I(Qx) for a region of interest 
     453        :param data2D: Data2D object 
     454        :return: Data1D object 
     455        """ 
     456        return self._avg(data2D, 'x') 
     457 
     458################################################################################ 
     459 
     460class Boxsum(object): 
     461    """ 
     462    Perform the sum of counts in a 2D region of interest. 
     463    """ 
     464 
     465    def __init__(self, x_min=0.0, x_max=0.0, y_min=0.0, y_max=0.0): 
     466        # Minimum Qx value [A-1] 
     467        self.x_min = x_min 
     468        # Maximum Qx value [A-1] 
     469        self.x_max = x_max 
     470        # Minimum Qy value [A-1] 
     471        self.y_min = y_min 
     472        # Maximum Qy value [A-1] 
     473        self.y_max = y_max 
     474 
     475    def __call__(self, data2D): 
     476        """ 
     477        Perform the sum in the region of interest 
     478 
     479        :param data2D: Data2D object 
     480        :return: number of counts, error on number of counts, 
     481            number of points summed 
     482        """ 
     483        y, err_y, y_counts = self._sum(data2D) 
     484 
     485        # Average the sums 
     486        counts = 0 if y_counts == 0 else y 
     487        error = 0 if y_counts == 0 else math.sqrt(err_y) 
     488 
     489        # Added y_counts to return, SMK & PDB, 04/03/2013 
     490        return counts, error, y_counts 
     491 
     492    def _sum(self, data2D): 
     493        """ 
     494        Perform the sum in the region of interest 
     495 
     496        :param data2D: Data2D object 
     497        :return: number of counts, 
     498            error on number of counts, number of entries summed 
     499        """ 
     500        if len(data2D.detector) > 1: 
     501            msg = "Circular averaging: invalid number " 
     502            msg += "of detectors: %g" % len(data2D.detector) 
     503            raise RuntimeError(msg) 
     504        # Get data 
     505        data = data2D.data[np.isfinite(data2D.data)] 
     506        err_data = data2D.err_data[np.isfinite(data2D.data)] 
     507        qx_data = data2D.qx_data[np.isfinite(data2D.data)] 
     508        qy_data = data2D.qy_data[np.isfinite(data2D.data)] 
     509 
     510        y = 0.0 
     511        err_y = 0.0 
     512        y_counts = 0.0 
     513 
     514        # Average pixelsize in q space 
     515        for npts in range(len(data)): 
     516            # default frac 
     517            frac_x = 0 
     518            frac_y = 0 
     519 
     520            # get min and max at each points 
     521            qx = qx_data[npts] 
     522            qy = qy_data[npts] 
     523 
     524            # get the ROI 
     525            if self.x_min <= qx and self.x_max > qx: 
     526                frac_x = 1 
     527            if self.y_min <= qy and self.y_max > qy: 
     528                frac_y = 1 
     529            # Find the fraction along each directions 
     530            frac = frac_x * frac_y 
     531            if frac == 0: 
     532                continue 
     533            y += frac * data[npts] 
     534            if err_data is None or err_data[npts] == 0.0: 
     535                if data[npts] < 0: 
     536                    data[npts] = -data[npts] 
     537                err_y += frac * frac * data[npts] 
     538            else: 
     539                err_y += frac * frac * err_data[npts] * err_data[npts] 
     540            y_counts += frac 
     541        return y, err_y, y_counts 
     542 
     543 
     544class Boxavg(Boxsum): 
     545    """ 
     546    Perform the average of counts in a 2D region of interest. 
     547    """ 
     548 
     549    def __init__(self, x_min=0.0, x_max=0.0, y_min=0.0, y_max=0.0): 
     550        super(Boxavg, self).__init__(x_min=x_min, x_max=x_max, 
     551                                     y_min=y_min, y_max=y_max) 
     552 
     553    def __call__(self, data2D): 
     554        """ 
     555        Perform the sum in the region of interest 
     556 
     557        :param data2D: Data2D object 
     558        :return: average counts, error on average counts 
     559 
     560        """ 
     561        y, err_y, y_counts = self._sum(data2D) 
     562 
     563        # Average the sums 
     564        counts = 0 if y_counts == 0 else y / y_counts 
     565        error = 0 if y_counts == 0 else math.sqrt(err_y) / y_counts 
     566 
     567        return counts, error 
     568 
     569################################################################################ 
     570 
     571class CircularAverage(object): 
     572    """ 
     573    Perform circular averaging on 2D data 
     574 
     575    The data returned is the distribution of counts 
     576    as a function of Q 
     577    """ 
     578 
     579    def __init__(self, r_min=0.0, r_max=0.0, bin_width=0.0005): 
     580        # Minimum radius included in the average [A-1] 
     581        self.r_min = r_min 
     582        # Maximum radius included in the average [A-1] 
     583        self.r_max = r_max 
     584        # Bin width (step size) [A-1] 
     585        self.bin_width = bin_width 
     586 
     587    def __call__(self, data2D, ismask=False): 
     588        """ 
     589        Perform circular averaging on the data 
     590 
     591        :param data2D: Data2D object 
     592        :return: Data1D object 
     593        """ 
     594        # Get data W/ finite values 
     595        data = data2D.data[np.isfinite(data2D.data)] 
     596        q_data = data2D.q_data[np.isfinite(data2D.data)] 
     597        err_data = data2D.err_data[np.isfinite(data2D.data)] 
     598        mask_data = data2D.mask[np.isfinite(data2D.data)] 
     599 
     600        dq_data = None 
     601        if data2D.dqx_data is not None and data2D.dqy_data is not None: 
     602            dq_data = get_dq_data(data2D) 
     603 
     604        if len(q_data) == 0: 
     605            msg = "Circular averaging: invalid q_data: %g" % data2D.q_data 
     606            raise RuntimeError(msg) 
     607 
     608        # Build array of Q intervals 
     609        nbins = int(math.ceil((self.r_max - self.r_min) / self.bin_width)) 
     610 
     611        x = np.zeros(nbins) 
     612        y = np.zeros(nbins) 
     613        err_y = np.zeros(nbins) 
     614        err_x = np.zeros(nbins) 
     615        y_counts = np.zeros(nbins) 
     616 
     617        for npt in range(len(data)): 
     618 
     619            if ismask and not mask_data[npt]: 
     620                continue 
     621 
     622            frac = 0 
     623 
     624            # q-value at the pixel (j,i) 
     625            q_value = q_data[npt] 
     626            data_n = data[npt] 
     627 
     628            # No need to calculate the frac when all data are within range 
     629            if self.r_min >= self.r_max: 
     630                raise ValueError("Limit Error: min > max") 
     631 
     632            if self.r_min <= q_value and q_value <= self.r_max: 
     633                frac = 1 
     634            if frac == 0: 
     635                continue 
     636            i_q = int(math.floor((q_value - self.r_min) / self.bin_width)) 
     637 
     638            # Take care of the edge case at phi = 2pi. 
     639            if i_q == nbins: 
     640                i_q = nbins - 1 
     641            y[i_q] += frac * data_n 
     642            # Take dqs from data to get the q_average 
     643            x[i_q] += frac * q_value 
     644            if err_data is None or err_data[npt] == 0.0: 
     645                if data_n < 0: 
     646                    data_n = -data_n 
     647                err_y[i_q] += frac * frac * data_n 
     648            else: 
     649                err_y[i_q] += frac * frac * err_data[npt] * err_data[npt] 
     650            if dq_data is not None: 
     651                # To be consistent with dq calculation in 1d reduction, 
     652                # we need just the averages (not quadratures) because 
     653                # it should not depend on the number of the q points 
     654                # in the qr bins. 
     655                err_x[i_q] += frac * dq_data[npt] 
     656            else: 
     657                err_x = None 
     658            y_counts[i_q] += frac 
     659 
     660        # Average the sums 
     661        for n in range(nbins): 
     662            if err_y[n] < 0: 
     663                err_y[n] = -err_y[n] 
     664            err_y[n] = math.sqrt(err_y[n]) 
     665            # if err_x is not None: 
     666            #    err_x[n] = math.sqrt(err_x[n]) 
     667 
     668        err_y = err_y / y_counts 
     669        err_y[err_y == 0] = np.average(err_y) 
     670        y = y / y_counts 
     671        x = x / y_counts 
     672        idx = (np.isfinite(y)) & (np.isfinite(x)) 
     673 
     674        if err_x is not None: 
     675            d_x = err_x[idx] / y_counts[idx] 
     676        else: 
     677            d_x = None 
     678 
     679        if not idx.any(): 
     680            msg = "Average Error: No points inside ROI to average..." 
     681            raise ValueError(msg) 
     682 
     683        return Data1D(x=x[idx], y=y[idx], dy=err_y[idx], dx=d_x) 
     684 
     685################################################################################ 
     686 
     687class Ring(object): 
     688    """ 
     689    Defines a ring on a 2D data set. 
     690    The ring is defined by r_min, r_max, and 
     691    the position of the center of the ring. 
     692 
     693    The data returned is the distribution of counts 
     694    around the ring as a function of phi. 
     695 
     696    Phi_min and phi_max should be defined between 0 and 2*pi 
     697    in anti-clockwise starting from the x- axis on the left-hand side 
     698    """ 
     699    # Todo: remove center. 
     700 
     701    def __init__(self, r_min=0, r_max=0, center_x=0, center_y=0, nbins=36): 
     702        # Minimum radius 
     703        self.r_min = r_min 
     704        # Maximum radius 
     705        self.r_max = r_max 
     706        # Center of the ring in x 
     707        self.center_x = center_x 
     708        # Center of the ring in y 
     709        self.center_y = center_y 
     710        # Number of angular bins 
     711        self.nbins_phi = nbins 
     712 
     713    def __call__(self, data2D): 
     714        """ 
     715        Apply the ring to the data set. 
     716        Returns the angular distribution for a given q range 
     717 
     718        :param data2D: Data2D object 
     719 
     720        :return: Data1D object 
     721        """ 
     722        if data2D.__class__.__name__ not in ["Data2D", "plottable_2D"]: 
     723            raise RuntimeError("Ring averaging only take plottable_2D objects") 
     724 
     725        Pi = math.pi 
     726 
     727        # Get data 
     728        data = data2D.data[np.isfinite(data2D.data)] 
     729        q_data = data2D.q_data[np.isfinite(data2D.data)] 
     730        err_data = data2D.err_data[np.isfinite(data2D.data)] 
     731        qx_data = data2D.qx_data[np.isfinite(data2D.data)] 
     732        qy_data = data2D.qy_data[np.isfinite(data2D.data)] 
     733 
     734        # Set space for 1d outputs 
     735        phi_bins = np.zeros(self.nbins_phi) 
     736        phi_counts = np.zeros(self.nbins_phi) 
     737        phi_values = np.zeros(self.nbins_phi) 
     738        phi_err = np.zeros(self.nbins_phi) 
     739 
     740        # Shift to apply to calculated phi values in order 
     741        # to center first bin at zero 
     742        phi_shift = Pi / self.nbins_phi 
     743 
     744        for npt in range(len(data)): 
     745            frac = 0 
     746            # q-value at the point (npt) 
     747            q_value = q_data[npt] 
     748            data_n = data[npt] 
     749 
     750            # phi-value at the point (npt) 
     751            phi_value = math.atan2(qy_data[npt], qx_data[npt]) + Pi 
     752 
     753            if self.r_min <= q_value and q_value <= self.r_max: 
     754                frac = 1 
     755            if frac == 0: 
     756                continue 
     757            # binning 
     758            i_phi = int(math.floor((self.nbins_phi) * 
     759                                   (phi_value + phi_shift) / (2 * Pi))) 
     760 
     761            # Take care of the edge case at phi = 2pi. 
     762            if i_phi >= self.nbins_phi: 
     763                i_phi = 0 
     764            phi_bins[i_phi] += frac * data[npt] 
     765 
     766            if err_data is None or err_data[npt] == 0.0: 
     767                if data_n < 0: 
     768                    data_n = -data_n 
     769                phi_err[i_phi] += frac * frac * math.fabs(data_n) 
     770            else: 
     771                phi_err[i_phi] += frac * frac * err_data[npt] * err_data[npt] 
     772            phi_counts[i_phi] += frac 
     773 
     774        for i in range(self.nbins_phi): 
     775            phi_bins[i] = phi_bins[i] / phi_counts[i] 
     776            phi_err[i] = math.sqrt(phi_err[i]) / phi_counts[i] 
     777            phi_values[i] = 2.0 * math.pi / self.nbins_phi * (1.0 * i) 
     778 
     779        idx = (np.isfinite(phi_bins)) 
     780 
     781        if not idx.any(): 
     782            msg = "Average Error: No points inside ROI to average..." 
     783            raise ValueError(msg) 
     784        # elif len(phi_bins[idx])!= self.nbins_phi: 
     785        #    print "resulted",self.nbins_phi- len(phi_bins[idx]) 
     786        #,"empty bin(s) due to tight binning..." 
     787        return Data1D(x=phi_values[idx], y=phi_bins[idx], dy=phi_err[idx]) 
     788 
     789################################################################################ 
    737790 
    738791class _Sector(object): 
     
    748801    starting from the x- axis on the left-hand side 
    749802    """ 
    750     def __init__(self, r_min, r_max, phi_min=0, phi_max=2 * math.pi, nbins=20): 
     803 
     804    def __init__(self, r_min, r_max, phi_min=0, phi_max=2 * math.pi, nbins=20, base = None): 
    751805        self.r_min = r_min 
    752806        self.r_max = r_max 
     
    754808        self.phi_max = phi_max 
    755809        self.nbins = nbins 
     810        self.base = base 
    756811 
    757812    def _agv(self, data2D, run='phi'): 
     
    765820        """ 
    766821        if data2D.__class__.__name__ not in ["Data2D", "plottable_2D"]: 
    767             raise RuntimeError, "Ring averaging only take plottable_2D objects" 
    768         Pi = math.pi 
     822            raise RuntimeError("Ring averaging only take plottable_2D objects") 
    769823 
    770824        # Get the all data & info 
    771         data = data2D.data[numpy.isfinite(data2D.data)] 
    772         q_data = data2D.q_data[numpy.isfinite(data2D.data)] 
    773         err_data = data2D.err_data[numpy.isfinite(data2D.data)] 
    774         qx_data = data2D.qx_data[numpy.isfinite(data2D.data)] 
    775         qy_data = data2D.qy_data[numpy.isfinite(data2D.data)] 
     825        data = data2D.data[np.isfinite(data2D.data)] 
     826        q_data = data2D.q_data[np.isfinite(data2D.data)] 
     827        err_data = data2D.err_data[np.isfinite(data2D.data)] 
     828        qx_data = data2D.qx_data[np.isfinite(data2D.data)] 
     829        qy_data = data2D.qy_data[np.isfinite(data2D.data)] 
     830 
    776831        dq_data = None 
    777  
    778         # Get the dq for resolution averaging 
    779832        if data2D.dqx_data is not None and data2D.dqy_data is not None: 
    780             # The pinholes and det. pix contribution present 
    781             # in both direction of the 2D which must be subtracted when 
    782             # converting to 1D: dq_overlap should calculated ideally at 
    783             # q = 0. 
    784             # Extrapolate dqy(perp) at q = 0 
    785             z_max = max(data2D.q_data) 
    786             z_min = min(data2D.q_data) 
    787             x_max = data2D.dqx_data[data2D.q_data[z_max]] 
    788             x_min = data2D.dqx_data[data2D.q_data[z_min]] 
    789             y_max = data2D.dqy_data[data2D.q_data[z_max]] 
    790             y_min = data2D.dqy_data[data2D.q_data[z_min]] 
    791             # Find qdx at q = 0 
    792             dq_overlap_x = (x_min * z_max - x_max * z_min) / (z_max - z_min) 
    793             # when extrapolation goes wrong 
    794             if dq_overlap_x > min(data2D.dqx_data): 
    795                 dq_overlap_x = min(data2D.dqx_data) 
    796             dq_overlap_x *= dq_overlap_x 
    797             # Find qdx at q = 0 
    798             dq_overlap_y = (y_min * z_max - y_max * z_min) / (z_max - z_min) 
    799             # when extrapolation goes wrong 
    800             if dq_overlap_y > min(data2D.dqy_data): 
    801                 dq_overlap_y = min(data2D.dqy_data) 
    802             # get dq at q=0. 
    803             dq_overlap_y *= dq_overlap_y 
    804  
    805             dq_overlap = numpy.sqrt((dq_overlap_x + dq_overlap_y) / 2.0) 
    806             if dq_overlap < 0: 
    807                 dq_overlap = y_min 
    808             dqx_data = data2D.dqx_data[numpy.isfinite(data2D.data)] 
    809             dqy_data = data2D.dqy_data[numpy.isfinite(data2D.data)] - dq_overlap 
    810             # def; dqx_data = dq_r dqy_data = dq_phi 
    811             # Convert dq 2D to 1D here 
    812             dqx = dqx_data * dqx_data 
    813             dqy = dqy_data * dqy_data 
    814             dq_data = numpy.add(dqx, dqy) 
    815             dq_data = numpy.sqrt(dq_data) 
    816  
    817         #set space for 1d outputs 
    818         x = numpy.zeros(self.nbins) 
    819         y = numpy.zeros(self.nbins) 
    820         y_err = numpy.zeros(self.nbins) 
    821         x_err = numpy.zeros(self.nbins) 
    822         y_counts = numpy.zeros(self.nbins) 
     833            dq_data = get_dq_data(data2D) 
     834 
     835        # set space for 1d outputs 
     836        x = np.zeros(self.nbins) 
     837        y = np.zeros(self.nbins) 
     838        y_err = np.zeros(self.nbins) 
     839        x_err = np.zeros(self.nbins) 
     840        y_counts = np.zeros(self.nbins) # Cycle counts (for the mean) 
    823841 
    824842        # Get the min and max into the region: 0 <= phi < 2Pi 
     
    826844        phi_max = flip_phi(self.phi_max) 
    827845 
     846        #  binning object 
     847        if run.lower() == 'phi': 
     848            binning = Binning(self.phi_min, self.phi_max, self.nbins, self.base) 
     849        else: 
     850            binning = Binning(self.r_min, self.r_max, self.nbins, self.base) 
     851 
    828852        for n in range(len(data)): 
    829             frac = 0 
    830853 
    831854            # q-value at the pixel (j,i) 
     
    837860 
    838861            # phi-value of the pixel (j,i) 
    839             phi_value = math.atan2(qy_data[n], qx_data[n]) + Pi 
    840  
    841             ## No need to calculate the frac when all data are within range 
    842             if self.r_min <= q_value and q_value <= self.r_max: 
    843                 frac = 1 
    844             if frac == 0: 
     862            phi_value = math.atan2(qy_data[n], qx_data[n]) + math.pi 
     863 
     864            # No need to calculate: data outside of the radius 
     865            if self.r_min > q_value or q_value > self.r_max: 
    845866                continue 
    846             #In case of two ROIs (symmetric major and minor regions)(for 'q2') 
     867 
     868            # In case of two ROIs (symmetric major and minor regions)(for 'q2') 
    847869            if run.lower() == 'q2': 
    848                 ## For minor sector wing 
     870                # For minor sector wing 
    849871                # Calculate the minor wing phis 
    850                 phi_min_minor = flip_phi(phi_min - Pi) 
    851                 phi_max_minor = flip_phi(phi_max - Pi) 
     872                phi_min_minor = flip_phi(phi_min - math.pi) 
     873                phi_max_minor = flip_phi(phi_max - math.pi) 
    852874                # Check if phis of the minor ring is within 0 to 2pi 
    853875                if phi_min_minor > phi_max_minor: 
    854                     is_in = (phi_value > phi_min_minor or \ 
    855                               phi_value < phi_max_minor) 
     876                    is_in = (phi_value > phi_min_minor or 
     877                             phi_value < phi_max_minor) 
    856878                else: 
    857                     is_in = (phi_value > phi_min_minor and \ 
    858                               phi_value < phi_max_minor) 
    859  
    860             #For all cases(i.e.,for 'q', 'q2', and 'phi') 
    861             #Find pixels within ROI 
     879                    is_in = (phi_value > phi_min_minor and 
     880                             phi_value < phi_max_minor) 
     881 
     882            # For all cases(i.e.,for 'q', 'q2', and 'phi') 
     883            # Find pixels within ROI 
    862884            if phi_min > phi_max: 
    863                 is_in = is_in or (phi_value > phi_min or \ 
    864                                    phi_value < phi_max) 
     885                is_in = is_in or (phi_value > phi_min or 
     886                                  phi_value < phi_max) 
    865887            else: 
    866                 is_in = is_in or (phi_value >= phi_min  and \ 
    867                                     phi_value < phi_max) 
    868  
     888                is_in = is_in or (phi_value >= phi_min and 
     889                                  phi_value < phi_max) 
     890 
     891            # data oustide of the phi range 
    869892            if not is_in: 
    870                 frac = 0 
    871             if frac == 0: 
    872893                continue 
    873             # Check which type of averaging we need 
     894 
     895            # Get the binning index 
    874896            if run.lower() == 'phi': 
    875                 temp_x = (self.nbins) * (phi_value - self.phi_min) 
    876                 temp_y = (self.phi_max - self.phi_min) 
    877                 i_bin = int(math.floor(temp_x / temp_y)) 
     897                i_bin = binning.get_bin_index(phi_value) 
    878898            else: 
    879                 temp_x = (self.nbins) * (q_value - self.r_min) 
    880                 temp_y = (self.r_max - self.r_min) 
    881                 i_bin = int(math.floor(temp_x / temp_y)) 
     899                i_bin = binning.get_bin_index(q_value) 
    882900 
    883901            # Take care of the edge case at phi = 2pi. 
     
    885903                i_bin = self.nbins - 1 
    886904 
    887             ## Get the total y 
    888             y[i_bin] += frac * data_n 
    889             x[i_bin] += frac * q_value 
     905            # Get the total y 
     906            y[i_bin] += data_n 
     907            x[i_bin] += q_value 
    890908            if err_data[n] is None or err_data[n] == 0.0: 
    891909                if data_n < 0: 
    892910                    data_n = -data_n 
    893                 y_err[i_bin] += frac * frac * data_n 
     911                y_err[i_bin] += data_n 
    894912            else: 
    895                 y_err[i_bin] += frac * frac * err_data[n] * err_data[n] 
     913                y_err[i_bin] += err_data[n]**2 
    896914 
    897915            if dq_data is not None: 
     
    900918                # it should not depend on the number of the q points 
    901919                # in the qr bins. 
    902                 x_err[i_bin] += frac * dq_data[n] 
     920                x_err[i_bin] += dq_data[n] 
    903921            else: 
    904922                x_err = None 
    905             y_counts[i_bin] += frac 
     923            y_counts[i_bin] += 1 
    906924 
    907925        # Organize the results 
     
    923941                #x[i] = math.sqrt((r_inner * r_inner + r_outer * r_outer) / 2) 
    924942                x[i] = x[i] / y_counts[i] 
    925         y_err[y_err == 0] = numpy.average(y_err) 
    926         idx = (numpy.isfinite(y) & numpy.isfinite(y_err)) 
     943        y_err[y_err == 0] = np.average(y_err) 
     944        idx = (np.isfinite(y) & np.isfinite(y_err)) 
    927945        if x_err is not None: 
    928946            d_x = x_err[idx] / y_counts[idx] 
     
    931949        if not idx.any(): 
    932950            msg = "Average Error: No points inside sector of ROI to average..." 
    933             raise ValueError, msg 
    934         #elif len(y[idx])!= self.nbins: 
     951            raise ValueError(msg) 
     952        # elif len(y[idx])!= self.nbins: 
    935953        #    print "resulted",self.nbins- len(y[idx]), 
    936954        #"empty bin(s) due to tight binning..." 
     
    946964    The number of bin in phi also has to be defined. 
    947965    """ 
     966 
    948967    def __call__(self, data2D): 
    949968        """ 
     
    965984    The number of bin in Q also has to be defined. 
    966985    """ 
     986 
    967987    def __call__(self, data2D): 
    968988        """ 
     
    975995        return self._agv(data2D, 'q2') 
    976996 
     997################################################################################ 
    977998 
    978999class Ringcut(object): 
     
    9871008    in anti-clockwise starting from the x- axis on the left-hand side 
    9881009    """ 
     1010 
    9891011    def __init__(self, r_min=0, r_max=0, center_x=0, center_y=0): 
    9901012        # Minimum radius 
     
    10071029        """ 
    10081030        if data2D.__class__.__name__ not in ["Data2D", "plottable_2D"]: 
    1009             raise RuntimeError, "Ring cut only take plottable_2D objects" 
     1031            raise RuntimeError("Ring cut only take plottable_2D objects") 
    10101032 
    10111033        # Get data 
    10121034        qx_data = data2D.qx_data 
    10131035        qy_data = data2D.qy_data 
    1014         q_data = numpy.sqrt(qx_data * qx_data + qy_data * qy_data) 
     1036        q_data = np.sqrt(qx_data * qx_data + qy_data * qy_data) 
    10151037 
    10161038        # check whether or not the data point is inside ROI 
     
    10181040        return out 
    10191041 
     1042################################################################################ 
    10201043 
    10211044class Boxcut(object): 
     
    10231046    Find a rectangular 2D region of interest. 
    10241047    """ 
     1048 
    10251049    def __init__(self, x_min=0.0, x_max=0.0, y_min=0.0, y_max=0.0): 
    10261050        # Minimum Qx value [A-1] 
     
    10551079        """ 
    10561080        if data2D.__class__.__name__ not in ["Data2D", "plottable_2D"]: 
    1057             raise RuntimeError, "Boxcut take only plottable_2D objects" 
     1081            raise RuntimeError("Boxcut take only plottable_2D objects") 
    10581082        # Get qx_ and qy_data 
    10591083        qx_data = data2D.qx_data 
     
    10661090        return outx & outy 
    10671091 
     1092################################################################################ 
    10681093 
    10691094class Sectorcut(object): 
     
    10771102    and (phi_max-phi_min) should not be larger than pi 
    10781103    """ 
     1104 
    10791105    def __init__(self, phi_min=0, phi_max=math.pi): 
    10801106        self.phi_min = phi_min 
     
    11061132        """ 
    11071133        if data2D.__class__.__name__ not in ["Data2D", "plottable_2D"]: 
    1108             raise RuntimeError, "Sectorcut take only plottable_2D objects" 
     1134            raise RuntimeError("Sectorcut take only plottable_2D objects") 
    11091135        Pi = math.pi 
    11101136        # Get data 
     
    11131139 
    11141140        # get phi from data 
    1115         phi_data = numpy.arctan2(qy_data, qx_data) 
     1141        phi_data = np.arctan2(qy_data, qx_data) 
    11161142 
    11171143        # Get the min and max into the region: -pi <= phi < Pi 
     
    11201146        # check for major sector 
    11211147        if phi_min_major > phi_max_major: 
    1122             out_major = (phi_min_major <= phi_data) + (phi_max_major > phi_data) 
     1148            out_major = (phi_min_major <= phi_data) + \ 
     1149                (phi_max_major > phi_data) 
    11231150        else: 
    1124             out_major = (phi_min_major <= phi_data) & (phi_max_major > phi_data) 
     1151            out_major = (phi_min_major <= phi_data) & ( 
     1152                phi_max_major > phi_data) 
    11251153 
    11261154        # minor sector 
     
    11321160        if phi_min_minor > phi_max_minor: 
    11331161            out_minor = (phi_min_minor <= phi_data) + \ 
    1134                             (phi_max_minor >= phi_data) 
     1162                (phi_max_minor >= phi_data) 
    11351163        else: 
    11361164            out_minor = (phi_min_minor <= phi_data) & \ 
    1137                             (phi_max_minor >= phi_data) 
     1165                (phi_max_minor >= phi_data) 
    11381166        out = out_major + out_minor 
    11391167 
Note: See TracChangeset for help on using the changeset viewer.