SasView / sasdata

Package for loading and handling SAS data
BSD 3-Clause "New" or "Revised" License
1 stars 2 forks source link

SectorPhi class throws errors (bin index out of range) when phi range includes 0 (or 2Pi) #40

Closed ehewins closed 1 year ago

ehewins commented 1 year ago

Describe the bug The title describes how the bug appears to the user. The source of the problem is the method Binning.get_bin_index() in sasdata/data_util/manipulations.py. If used for angular coordinates, it is possible for the bin index it returns to be greater than the total number of bins, as the subtraction operation doesn't account for the cyclic nature of angles. An error is later thrown when this bad bin index is used, causing the "Wedge Averaging in Phi" slicer to break (this is the only slicer to use the SectorPhi class).

To Reproduce Steps to reproduce the behavior:

  1. In SasView, Compute/Plot any 2D data from example_data/2d_data, using any model.
  2. Right click the plot and select 'Wedge Averaging in Phi'
  3. Drag and drop the central line so that the wedge region passes over the negative x-axis.
  4. See that the slicer cannot be placed here, as it continues to move with the mouse cursor. Also note the error shown in the terminal.

Expected behavior The slicer should cease to move when the mouse button is released, and there should be no error thrown.

butlerpd commented 1 year ago

I would argue that the problem is NOT the Binning.get_bin_index() method, the problem is that it it the _avg method in the _Sector class (which inherits from the SectorPhi class) that is sending the wrong information to binning ... for the reasons described (cyclic nature of angles) IMO.