Skip to content

Commit

Permalink
Changed the manipulations to new_manipulations to test the rewrite ou…
Browse files Browse the repository at this point in the history
…t, and changed variable names to new versions. Also removed the angle transformation, as new_manipulations uses the same -pi to pi interval as the slicers.
  • Loading branch information
ehewins committed Sep 7, 2023
1 parent 55b1e9f commit 0a74773
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 75 deletions.
6 changes: 2 additions & 4 deletions src/sas/qtgui/Plotting/Plotter2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from mpl_toolkits.mplot3d import Axes3D

from sasdata.data_util.manipulations import CircularAverage
from sasdata.data_util.new_manipulations import CircularAverage

from sas.qtgui.Plotting.PlotterData import Data1D
from sas.qtgui.Plotting.PlotterData import Data2D
Expand Down Expand Up @@ -307,10 +307,8 @@ def circularAverage(self):
self.ymax = max(numpy.fabs(self.data0.ymax),
numpy.fabs(self.data0.ymin))
self.radius = numpy.sqrt(numpy.power(self.qmax, 2) + numpy.power(self.ymax, 2))
#Compute beam width
bin_width = (self.qmax + self.qmax) / npt
# Create data1D circular average of data2D
circle = CircularAverage(r_min=0, r_max=self.radius, bin_width=bin_width)
circle = CircularAverage(r_min=0, r_max=self.radius, nbins=npt)
circ = circle(self.data0)
dxl = circ.dxl if hasattr(circ, "dxl") else None
dxw = circ.dxw if hasattr(circ, "dxw") else None
Expand Down
17 changes: 8 additions & 9 deletions src/sas/qtgui/Plotting/Slicers/AnnulusSlicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,27 +101,26 @@ def _post_data(self, nbins=None):
if data is None:
return

from sasdata.data_util.manipulations import Ring
from sasdata.data_util.new_manipulations import Ring
rmin = min(numpy.fabs(self.inner_circle.get_radius()),
numpy.fabs(self.outer_circle.get_radius()))
rmax = max(numpy.fabs(self.inner_circle.get_radius()),
numpy.fabs(self.outer_circle.get_radius()))
if nbins is not None:
self.nbins = nbins
# Create the data1D Q average of data2D
sect = Ring(r_min=rmin, r_max=rmax, nbins=self.nbins)
sector = sect(self.data)
ring_object = Ring(r_min=rmin, r_max=rmax, nbins=self.nbins)
ring = ring_object(self.data)

if hasattr(sector, "dxl"):
dxl = sector.dxl
if hasattr(ring, "dxl"):
dxl = ring.dxl
else:
dxl = None
if hasattr(sector, "dxw"):
dxw = sector.dxw
if hasattr(ring, "dxw"):
dxw = ring.dxw
else:
dxw = None
new_plot = Data1D(x=(sector.x - numpy.pi) * 180 / numpy.pi,
y=sector.y, dy=sector.dy)
new_plot = Data1D(x=ring.x * 180 / numpy.pi, y=ring.y, dy=ring.dy)
new_plot.dxl = dxl
new_plot.dxw = dxw
new_plot.name = "AnnulusPhi" + "(" + self.data.name + ")"
Expand Down
32 changes: 10 additions & 22 deletions src/sas/qtgui/Plotting/Slicers/BoxSlicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ def _post_data(self, new_slab=None, nbins=None, direction=None):
if self.direction is None:
self.direction = direction

x_min = -1 * numpy.fabs(self.vertical_lines.x)
x_max = numpy.fabs(self.vertical_lines.x)
y_min = -1 * numpy.fabs(self.horizontal_lines.y)
y_max = numpy.fabs(self.horizontal_lines.y)
qx_min = -1 * numpy.fabs(self.vertical_lines.x)
qx_max = numpy.fabs(self.vertical_lines.x)
qy_min = -1 * numpy.fabs(self.horizontal_lines.y)
qy_max = numpy.fabs(self.horizontal_lines.y)

if nbins is not None:
self.nbins = nbins
Expand All @@ -142,24 +142,12 @@ def _post_data(self, new_slab=None, nbins=None, direction=None):
msg = "post data:cannot average , averager is empty"
raise ValueError(msg)
self.averager = new_slab
if self.direction == "X":
if self.fold:
x_low = 0
else:
x_low = numpy.fabs(x_min)
bin_width = (x_max + x_low) / self.nbins
elif self.direction == "Y":
if self.fold:
y_low = 0
else:
y_low = numpy.fabs(y_min)
bin_width = (y_max + y_low) / self.nbins
else:
if self.direction not in ["X", "Y"]:
msg = "post data:no Box Average direction was supplied"
raise ValueError(msg)
# # Average data2D given Qx or Qy
box = self.averager(x_min=x_min, x_max=x_max, y_min=y_min, y_max=y_max,
bin_width=bin_width)
box = self.averager(qx_min=qx_min, qx_max=qx_max, qy_min=qy_min,
qy_max=qy_max, nbins=self.nbins)
box.fold = self.fold
boxavg = box(self.data)
# 3 Create Data1D to plot
Expand Down Expand Up @@ -250,7 +238,7 @@ def setParams(self, params):
values the user assigned to the slicer.
"""
self.x = float(numpy.fabs(params["x_max"]))
self.y = float(numpy.fabs(params["y_max"]))
self.y = float(numpy.fabs(params["qy_max"]))
self.nbins = params["nbins"]
self.fold = params["fold"]

Expand Down Expand Up @@ -502,7 +490,7 @@ def _post_data(self):
"""
Post data creating by averaging in Qx direction
"""
from sasdata.data_util.manipulations import SlabX
from sasdata.data_util.new_manipulations import SlabX
super()._post_data(SlabX, direction="X")

def validate(self, param_name, param_value):
Expand Down Expand Up @@ -535,7 +523,7 @@ def _post_data(self):
"""
Post data creating by averaging in Qy direction
"""
from sasdata.data_util.manipulations import SlabY
from sasdata.data_util.new_manipulations import SlabY
super()._post_data(SlabY, direction="Y")

def validate(self, param_name, param_value):
Expand Down
16 changes: 9 additions & 7 deletions src/sas/qtgui/Plotting/Slicers/BoxSum.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from sas.qtgui.Utilities.GuiUtils import formatNumber, toDouble

from sas.qtgui.Plotting.Slicers.BaseInteractor import BaseInteractor
from sasdata.data_util.manipulations import Boxavg, Boxsum
from sasdata.data_util.new_manipulations import Boxavg, Boxsum

from sas.qtgui.Plotting.SlicerModel import SlicerModel

Expand Down Expand Up @@ -218,15 +218,17 @@ def postData(self):
contained in that region and the error on that sum
"""
# the region of the summation
x_min = self.horizontal_lines.x2
x_max = self.horizontal_lines.x1
y_min = self.vertical_lines.y2
y_max = self.vertical_lines.y1
qx_min = self.horizontal_lines.x2
qx_max = self.horizontal_lines.x1
qy_min = self.vertical_lines.y2
qy_max = self.vertical_lines.y1
#computation of the sum and its error
box = Boxavg(x_min=x_min, x_max=x_max, y_min=y_min, y_max=y_max)
box = Boxavg(qx_min=qx_min, qx_max=qx_max,
qy_min=qy_min, qy_max=qy_max)
self.count, self.error = box(self.data)
# Dig out number of points summed, SMK & PDB, 04/03/2013
boxtotal = Boxsum(x_min=x_min, x_max=x_max, y_min=y_min, y_max=y_max)
boxtotal = Boxsum(qx_min=qx_min, qx_max=qx_max,
qy_min=qy_min, qy_max=qy_max)
self.total, self.totalerror, self.points = boxtotal(self.data)
if self.update_model:
self.setModelFromParams()
Expand Down
5 changes: 2 additions & 3 deletions src/sas/qtgui/Plotting/Slicers/SectorSlicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,14 @@ def _post_data(self, nbins=None):
if data is None:
return
# Averaging
from sasdata.data_util.manipulations import SectorQ
from sasdata.data_util.new_manipulations import SectorQ
radius = self.qmax
phimin = -self.left_line.phi + self.main_line.theta
phimax = self.left_line.phi + self.main_line.theta
if nbins is None:
nbins = self.nbins
sect = SectorQ(r_min=0.0, r_max=radius,
phi_min=phimin + numpy.pi,
phi_max=phimax + numpy.pi, nbins=nbins)
phi_min=phimin, phi_max=phimax, nbins=nbins)

sector = sect(self.data)
# Create 1D data resulting from average
Expand Down
55 changes: 25 additions & 30 deletions src/sas/qtgui/Plotting/Slicers/WedgeSlicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ class WedgeInteractor(BaseInteractor, SlicerModel):
edges of the wedge (similar to the sector), and two rings at Q1 and Q2
(similar to the annulus). The wedge is centred on the line defined by
LineInteractor, which the radial lines move symmetrically around.
This class is itself subclassed by SectorInteractorPhi and
SectorInteractorQ which define the direction of the averaging.
SectorInteractorPhi averages all Q points at constant Phi (as for the
AnnulusSlicer) and SectorInteractorQ averages all phi points at constant Q
This class is itself subclassed by WedgeInteractorPhi and
WedgeInteractorQ which define the direction of the averaging.
WedgeInteractorPhi averages all Q points at constant Phi (as for the
AnnulusSlicer) and WedgeInteractorQ averages all phi points at constant Q
(as for the SectorSlicer).
"""
def __init__(self, base, axes, item=None, color='black', zorder=3):
Expand Down Expand Up @@ -132,11 +132,11 @@ def save(self, ev):
self.radial_lines.save(ev)
self.central_line.save(ev)

def _post_data(self, new_sector=None, nbins=None):
def _post_data(self, wedge_type=None, nbins=None):
"""
post 1D data averagin in Q or Phi given new_sector type
post 1D data averagin in Q or Phi given wedge_type type
:param new_sector: slicer used for directional averaging in Q or Phi
:param wedge_type: slicer used for directional averaging in Q or Phi
:param nbins: the number of point plotted when averaging
:TODO - Unlike other slicers, the two sector types are sufficiently
different that this method contains three instances of If (check class name) do x.
Expand All @@ -162,32 +162,27 @@ def _post_data(self, new_sector=None, nbins=None):
if nbins is not None:
self.nbins = nbins
if self.averager is None:
if new_sector is None:
if wedge_type is None:
msg = "post data:cannot average , averager is empty"
raise ValueError(msg)
self.averager = new_sector
self.averager = wedge_type

# Add pi to the angles before invoking sector averaging to transform angular
# range from python default of -pi,pi to 0,2pi suitable for manipulations
sect = self.averager(r_min=rmin, r_max=rmax, phi_min=phimin + np.pi,
phi_max=phimax + np.pi, nbins=self.nbins)
sect.fold = False
sector = sect(self.data)
wedge_object = self.averager(r_min=rmin, r_max=rmax, phi_min=phimin,
phi_max=phimax, nbins=self.nbins)
wedge = wedge_object(self.data)

if hasattr(sector, "dxl"):
dxl = sector.dxl
if hasattr(wedge, "dxl"):
dxl = wedge.dxl
else:
dxl = None
if hasattr(sector, "dxw"):
dxw = sector.dxw
if hasattr(wedge, "dxw"):
dxw = wedge.dxw
else:
dxw = None
if self.averager.__name__ == 'SectorPhi':
# And here subtract pi when getting angular data back from wedge averaging in
# phi in manipulations to get back in the -pi,pi range. Also convert from
# radians to degrees for nicer display.
sector.x = (sector.x - np.pi) * 180 / np.pi
new_plot = Data1D(x=sector.x, y=sector.y, dy=sector.dy, dx=sector.dx)
if self.averager.__name__ == 'WedgePhi':
# Convert from radians to degrees for nicer display.
wedge.x = wedge.x * 180 / np.pi
new_plot = Data1D(x=wedge.x, y=wedge.y, dy=wedge.dy, dx=wedge.dx)
new_plot.dxl = dxl
new_plot.dxw = dxw
new_plot.name = str(self.averager.__name__) + \
Expand All @@ -196,7 +191,7 @@ def _post_data(self, new_sector=None, nbins=None):
new_plot.interactive = True
new_plot.detector = self.data.detector
# If the data file does not tell us what the axes are, just assume...
if self.averager.__name__ == 'SectorPhi':
if self.averager.__name__ == 'WedgePhi':
# angular plots usually require a linear x scale and better with
# a linear y scale as well.
new_plot.xaxis("\\rm{\phi}", "degrees")
Expand Down Expand Up @@ -339,8 +334,8 @@ def __init__(self, base, axes, item=None, color='black', zorder=3):
self._post_data()

def _post_data(self):
from sasdata.data_util.manipulations import SectorQ
super()._post_data(SectorQ)
from sasdata.data_util.new_manipulations import WedgeQ
super()._post_data(WedgeQ)


class WedgeInteractorPhi(WedgeInteractor):
Expand All @@ -355,6 +350,6 @@ def __init__(self, base, axes, item=None, color='black', zorder=3):
self._post_data()

def _post_data(self):
from sasdata.data_util.manipulations import SectorPhi
super()._post_data(SectorPhi)
from sasdata.data_util.new_manipulations import WedgePhi
super()._post_data(WedgePhi)

0 comments on commit 0a74773

Please sign in to comment.