sasdata.data_util.manipulations module¶
Data manipulations for 2D data sets. Using the meta data information, various types of averaging are performed in Q-space
To test this module use:
`
cd test
PYTHONPATH=../src/ python2 -m sasmanipulations.test.utest_averaging DataInfoTests.test_sectorphi_quarter
`
- class sasdata.data_util.manipulations.Binning(min_value, max_value, n_bins, base=None)¶
Bases:
objectThis class just creates a binning object either linear or log
- __dict__ = mappingproxy({'__module__': 'sasdata.data_util.manipulations', '__firstlineno__': 281, '__doc__': '\nThis class just creates a binning object\neither linear or log\n', '__init__': <function Binning.__init__>, 'get_bin_index': <function Binning.get_bin_index>, '__static_attributes__': ('base', 'max', 'min', 'n_bins'), '__dict__': <attribute '__dict__' of 'Binning' objects>, '__weakref__': <attribute '__weakref__' of 'Binning' objects>, '__annotations__': {}})¶
- __doc__ = '\nThis class just creates a binning object\neither linear or log\n'¶
- __firstlineno__ = 281¶
- __init__(min_value, max_value, n_bins, base=None)¶
- Parameters:
min_value – the value defining the start of the binning interval.
max_value – the value defining the end of the binning interval.
n_bins – the number of bins.
base – the base used for log, linear binning if None.
Beware that min_value should always be numerically smaller than max_value. Take particular care when binning angles across the 2pi to 0 discontinuity.
- __module__ = 'sasdata.data_util.manipulations'¶
- __static_attributes__ = ('base', 'max', 'min', 'n_bins')¶
- __weakref__¶
list of weak references to the object
- get_bin_index(value)¶
- Parameters:
value – the value in the binning interval whose bin index should be returned. Must be between min_value and max_value.
The general formula logarithm binning is: bin = floor(N * (log(x) - log(min)) / (log(max) - log(min)))
- class sasdata.data_util.manipulations.Boxavg(x_min=0.0, x_max=0.0, y_min=0.0, y_max=0.0)¶
Bases:
Boxavg- __annotations__ = {}¶
- __doc__ = None¶
- __firstlineno__ = 381¶
- __init__(x_min=0.0, x_max=0.0, y_min=0.0, y_max=0.0)¶
Set up the Region of Interest and its boundaries.
The units of these parameters are A^-1 :param qx_range: Bounds of the ROI along the Q_x direction. :param qy_range: Bounds of the ROI along the Q_y direction.
- __module__ = 'sasdata.data_util.manipulations'¶
- __static_attributes__ = ()¶
- class sasdata.data_util.manipulations.Boxcut(x_min=0.0, x_max=0.0, y_min=0.0, y_max=0.0)¶
Bases:
Boxcut- __annotations__ = {}¶
- __doc__ = None¶
- __firstlineno__ = 833¶
- __init__(x_min=0.0, x_max=0.0, y_min=0.0, y_max=0.0)¶
Assign the variables used to label the properties of the Data2D object. Also establish the upper and lower bounds defining the ROI.
The units of these parameters are A^-1 :param qx_range: Bounds of the ROI along the Q_x direction. :param qy_range: Bounds of the ROI along the Q_y direction.
- __module__ = 'sasdata.data_util.manipulations'¶
- __static_attributes__ = ()¶
- class sasdata.data_util.manipulations.Boxsum(x_min=0.0, x_max=0.0, y_min=0.0, y_max=0.0)¶
Bases:
Boxsum- __annotations__ = {}¶
- __doc__ = None¶
- __firstlineno__ = 375¶
- __init__(x_min=0.0, x_max=0.0, y_min=0.0, y_max=0.0)¶
Set up the Region of Interest and its boundaries.
The units of these parameters are A^-1 :param qx_range: Bounds of the ROI along the Q_x direction. :param qy_range: Bounds of the ROI along the Q_y direction.
- __module__ = 'sasdata.data_util.manipulations'¶
- __static_attributes__ = ()¶
- class sasdata.data_util.manipulations.CircularAverage(r_min=0.0, r_max=0.0, bin_width=0.0005)¶
Bases:
objectPerform circular averaging on 2D data
The data returned is the distribution of counts as a function of Q
- __call__(data2D, ismask=False)¶
Perform circular averaging on the data
- Parameters:
data2D – Data2D object
- Returns:
Data1D object
- __dict__ = mappingproxy({'__module__': 'sasdata.data_util.manipulations', '__firstlineno__': 388, '__doc__': '\nPerform circular averaging on 2D data\n\nThe data returned is the distribution of counts\nas a function of Q\n', '__init__': <function CircularAverage.__init__>, '__call__': <function CircularAverage.__call__>, '__static_attributes__': ('bin_width', 'r_max', 'r_min'), '__dict__': <attribute '__dict__' of 'CircularAverage' objects>, '__weakref__': <attribute '__weakref__' of 'CircularAverage' objects>, '__annotations__': {}})¶
- __doc__ = '\nPerform circular averaging on 2D data\n\nThe data returned is the distribution of counts\nas a function of Q\n'¶
- __firstlineno__ = 388¶
- __init__(r_min=0.0, r_max=0.0, bin_width=0.0005)¶
- __module__ = 'sasdata.data_util.manipulations'¶
- __static_attributes__ = ('bin_width', 'r_max', 'r_min')¶
- __weakref__¶
list of weak references to the object
- class sasdata.data_util.manipulations.Ring(r_min=0.0, r_max=0.0, center_x=0.0, center_y=0.0, nbins=36)¶
Bases:
RingWrapper for new Ring.
- __annotations__ = {}¶
- __doc__ = '\nWrapper for new Ring.\n'¶
- __firstlineno__ = 508¶
- __init__(r_min=0.0, r_max=0.0, center_x=0.0, center_y=0.0, nbins=36)¶
Set up the lower and upper radial limits as well as the number of bins.
The units are A^-1 for the radial parameters. :param r_min: Lower limit for |Q| values to use during averaging. :param r_max: Upper limit for |Q| values to use during averaging. :param nbins: The number of bins data is sorted into along Phi the axis
- __module__ = 'sasdata.data_util.manipulations'¶
- __static_attributes__ = ('nbins',)¶
- property nbins_phi¶
- class sasdata.data_util.manipulations.Ringcut(r_min=0.0, r_max=0.0, center_x=0.0, center_y=0.0)¶
Bases:
Ringcut- __annotations__ = {}¶
- __doc__ = None¶
- __firstlineno__ = 820¶
- __init__(r_min=0.0, r_max=0.0, center_x=0.0, center_y=0.0)¶
Assign the variables used to label the properties of the Data2D object. Also establish the upper and lower bounds defining the ROI.
The units are A^-1 for radial parameters, and radians for anglar ones. :param r_range: Tuple (r_min, r_max) defining limits for |Q| values to use during averaging. :param phi_range: Tuple (phi_min, phi_max) defining limits for φ in radians (in the ROI).
Note that Phi is measured anti-clockwise from the positive x-axis.
- __module__ = 'sasdata.data_util.manipulations'¶
- __static_attributes__ = ()¶
- class sasdata.data_util.manipulations.SectorPhi(r_min, r_max, phi_min=0, phi_max=6.283185307179586, nbins=20, base=None)¶
Bases:
_SectorSector average as a function of phi. I(phi) is return and the data is averaged over Q.
A sector is defined by r_min, r_max, phi_min, phi_max. The number of bin in phi also has to be defined.
- __call__(data2D)¶
Perform sector average and return I(phi).
- Parameters:
data2D – Data2D object
- Returns:
Data1D object
- __doc__ = '\nSector average as a function of phi.\nI(phi) is return and the data is averaged over Q.\n\nA sector is defined by r_min, r_max, phi_min, phi_max.\nThe number of bin in phi also has to be defined.\n'¶
- __firstlineno__ = 748¶
- __module__ = 'sasdata.data_util.manipulations'¶
- __static_attributes__ = ()¶
- class sasdata.data_util.manipulations.SectorQ(r_min, r_max, phi_min=0, phi_max=6.283185307179586, nbins=20, base=None)¶
Bases:
_SectorSector average as a function of Q for both wings. setting the _Sector.fold attribute determines whether or not the two sectors are averaged together (folded over) or separate. In the case of separate (not folded), the qs for the “minor wing” are arbitrarily set to a negative value. I(Q) is returned and the data is averaged over phi.
A sector is defined by r_min, r_max, phi_min, phi_max. where r_min, r_max, phi_min, phi_max >0. The number of bin in Q also has to be defined.
- __annotations__ = {}¶
- __call__(data2D)¶
Perform sector average and return I(Q).
- Parameters:
data2D – Data2D object
- Returns:
Data1D object
- __doc__ = '\nSector average as a function of Q for both wings. setting the _Sector.fold\nattribute determines whether or not the two sectors are averaged together\n(folded over) or separate. In the case of separate (not folded), the\nqs for the "minor wing" are arbitrarily set to a negative value.\nI(Q) is returned and the data is averaged over phi.\n\nA sector is defined by r_min, r_max, phi_min, phi_max.\nwhere r_min, r_max, phi_min, phi_max >0.\nThe number of bin in Q also has to be defined.\n'¶
- __firstlineno__ = 767¶
- __module__ = 'sasdata.data_util.manipulations'¶
- __static_attributes__ = ()¶
- class sasdata.data_util.manipulations.Sectorcut(phi_min=0.0, phi_max=3.141592653589793, center_x=0.0, center_y=0.0)¶
Bases:
Sectorcut- __annotations__ = {}¶
- __doc__ = None¶
- __firstlineno__ = 840¶
- __init__(phi_min=0.0, phi_max=3.141592653589793, center_x=0.0, center_y=0.0)¶
Assign the variables used to label the properties of the Data2D object. Also establish the upper and lower bounds defining the ROI.
The units are A^-1 for radial parameters, and radians for anglar ones. :param r_range: Tuple (r_min, r_max) defining limits for |Q| values to use during averaging. :param phi_range: Tuple (phi_min, phi_max) defining limits for φ in radians (in the ROI).
Note that Phi is measured anti-clockwise from the positive x-axis.
- __module__ = 'sasdata.data_util.manipulations'¶
- __static_attributes__ = ()¶
- class sasdata.data_util.manipulations.SlabX(x_min=0.0, x_max=0.0, y_min=0.0, y_max=0.0, bin_width=0.001, fold=False)¶
Bases:
SlabXWrapper for new SlabX.
- Old signature:
SlabX(x_min=0, x_max=0, y_min=0, y_max=0, bin_width=0.001, fold=False)
New signature uses nbins; translate bin_width -> nbins using ceil(range/bin_width)
- __annotations__ = {}¶
- __doc__ = '\nWrapper for new SlabX.\n\nOld signature:\n SlabX(x_min=0, x_max=0, y_min=0, y_max=0, bin_width=0.001, fold=False)\nNew signature uses nbins; translate bin_width -> nbins using ceil(range/bin_width)\n'¶
- __firstlineno__ = 320¶
- __init__(x_min=0.0, x_max=0.0, y_min=0.0, y_max=0.0, bin_width=0.001, fold=False)¶
Set up the ROI boundaries, the binning of the output 1D data, and fold.
The units of these parameters are A^-1 :param qx_range: Bounds of the ROI along the Q_x direction. :param qy_range: Bounds of the ROI along the Q_y direction. :param nbins: The number of bins data is sorted into along Q_x. :param fold: Whether the two halves of the ROI along Q_x should be
folded together during averaging.
- __module__ = 'sasdata.data_util.manipulations'¶
- __static_attributes__ = ('nbins',)¶
- class sasdata.data_util.manipulations.SlabY(x_min=0.0, x_max=0.0, y_min=0.0, y_max=0.0, bin_width=0.001, fold=False)¶
Bases:
SlabYWrapper for new SlabY. Same bin_width -> nbins translation as SlabX.
- __annotations__ = {}¶
- __doc__ = '\nWrapper for new SlabY. Same bin_width -> nbins translation as SlabX.\n'¶
- __firstlineno__ = 348¶
- __init__(x_min=0.0, x_max=0.0, y_min=0.0, y_max=0.0, bin_width=0.001, fold=False)¶
Set up the ROI boundaries, the binning of the output 1D data, and fold.
The units of these parameters are A^-1 :param qx_range: Bounds of the ROI along the Q_x direction. :param qy_range: Bounds of the ROI along the Q_y direction. :param qy_max: Upper bound of the ROI along the Q_y direction. :param nbins: The number of bins data is sorted into along Q_y. :param fold: Whether the two halves of the ROI along Q_y should be
folded together during averaging.
- __module__ = 'sasdata.data_util.manipulations'¶
- __static_attributes__ = ('nbins',)¶
- class sasdata.data_util.manipulations.WedgePhi(r_min, r_max, phi_min=0, phi_max=6.283185307179586, center_x=0.0, center_y=0.0, nbins=10)¶
Bases:
WedgePhiWrapper for new WedgePhi (behaviour matches legacy WedgePhi expectations).
- __annotations__ = {}¶
- __doc__ = '\nWrapper for new WedgePhi (behaviour matches legacy WedgePhi expectations).\n'¶
- __firstlineno__ = 791¶
- __init__(r_min, r_max, phi_min=0, phi_max=6.283185307179586, center_x=0.0, center_y=0.0, nbins=10)¶
Set up the ROI boundaries, and the binning of the output 1D data.
The units are A^-1 for radial parameters, and radians for anglar ones. :param r_range: Tuple (r_min, r_max) defining limits for |Q| values to use during averaging. :param phi_range: Tuple (phi_min, phi_max) defining angular bounds in radians.
Defaults to full circle (0, 2*pi).
- Parameters:
nbins – The number of bins data is sorted into along the φ axis.
- __module__ = 'sasdata.data_util.manipulations'¶
- __static_attributes__ = ()¶
- class sasdata.data_util.manipulations.WedgeQ(r_min, r_max, phi_min=0, phi_max=6.283185307179586, center_x=0.0, center_y=0.0, nbins=10)¶
Bases:
WedgeQWrapper for new WedgeQ (behaviour matches legacy WedgeQ expectations).
- __annotations__ = {}¶
- __doc__ = '\nWrapper for new WedgeQ (behaviour matches legacy WedgeQ expectations).\n'¶
- __firstlineno__ = 804¶
- __init__(r_min, r_max, phi_min=0, phi_max=6.283185307179586, center_x=0.0, center_y=0.0, nbins=10)¶
Set up the ROI boundaries, and the binning of the output 1D data.
The units are A^-1 for radial parameters, and radians for anglar ones. :param r_range: Tuple (r_min, r_max) defining limits for |Q| values to use during averaging. :param phi_range: Tuple (phi_min, phi_max) defining limits for φ in radians (in the primary ROI). :Defaults to full circle (0, 2*pi). :param nbins: The number of bins data is sorted into along the |Q| axis
- __module__ = 'sasdata.data_util.manipulations'¶
- __static_attributes__ = ()¶
- class sasdata.data_util.manipulations._Sector(r_min, r_max, phi_min=0, phi_max=6.283185307179586, nbins=20, base=None)¶
Bases:
objectDefines a sector region on a 2D data set. The sector is defined by r_min, r_max, phi_min and phi_max. phi_min and phi_max are defined by the right and left lines wrt a central line such that phi_max could be less than phi_min if they straddle the discontinuity from 2pi to 0.
Phi is defined between 0 and 2*pi in anti-clockwise starting from the negative x-axis.
- __annotations__ = {}¶
- __dict__ = mappingproxy({'__module__': 'sasdata.data_util.manipulations', '__firstlineno__': 530, '__doc__': '\nDefines a sector region on a 2D data set.\nThe sector is defined by r_min, r_max, phi_min and phi_max.\nphi_min and phi_max are defined by the right and left lines wrt a central\nline such that phi_max could be less than phi_min if they straddle the\ndiscontinuity from 2pi to 0.\n\nPhi is defined between 0 and 2*pi in anti-clockwise\nstarting from the negative x-axis.\n', '__init__': <function _Sector.__init__>, '_agv': <function _Sector._agv>, '__static_attributes__': ('base', 'fold', 'nbins', 'phi_max', 'phi_min', 'r_max', 'r_min'), '__dict__': <attribute '__dict__' of '_Sector' objects>, '__weakref__': <attribute '__weakref__' of '_Sector' objects>, '__annotations__': {}})¶
- __doc__ = '\nDefines a sector region on a 2D data set.\nThe sector is defined by r_min, r_max, phi_min and phi_max.\nphi_min and phi_max are defined by the right and left lines wrt a central\nline such that phi_max could be less than phi_min if they straddle the\ndiscontinuity from 2pi to 0.\n\nPhi is defined between 0 and 2*pi in anti-clockwise\nstarting from the negative x-axis.\n'¶
- __firstlineno__ = 530¶
- __init__(r_min, r_max, phi_min=0, phi_max=6.283185307179586, nbins=20, base=None)¶
- Parameters:
base – must be a valid base for an algorithm, i.e.,
a positive number
- __module__ = 'sasdata.data_util.manipulations'¶
- __static_attributes__ = ('base', 'fold', 'nbins', 'phi_max', 'phi_min', 'r_max', 'r_min')¶
- __weakref__¶
list of weak references to the object
- _agv(data2D, run='phi')¶
Perform sector averaging.
- Parameters:
data2D – Data2D object
run – define the varying parameter (‘phi’ , or ‘sector’)
- Returns:
Data1D object
- sasdata.data_util.manipulations.flip_phi(phi: float) float¶
Force phi to be within the 0 <= to <= 2pi range by adding or subtracting 2pi as necessary
- Returns:
phi in >=0 and <=2Pi
- sasdata.data_util.manipulations.get_dq_data(data2d: Data2D) array¶
Get the dq for resolution averaging The pinholes and det. pix contribution present in both direction of the 2D which must be subtracted when converting to 1D: dq_overlap should be calculated ideally at q = 0. Note This method works on only pinhole geometry. Extrapolate dqx(r) and dqy(phi) at q = 0, and take an average.
- sasdata.data_util.manipulations.get_intercept(q: float, q_0: float, q_1: float) float | None¶
Returns the fraction of the side at which the q-value intercept the pixel, None otherwise. The values returned is the fraction ON THE SIDE OF THE LOWEST Q.
A B +-----------+--------+ <--- pixel size 0 1 Q_0 -------- Q ----- Q_1 <--- equivalent Q range if Q_1 > Q_0, A is returned if Q_1 < Q_0, B is returned if Q is outside the range of [Q_0, Q_1], None is returned
- sasdata.data_util.manipulations.get_pixel_fraction(q_max: float, q_00: float, q_01: float, q_10: float, q_11: float) float¶
Returns the fraction of the pixel defined by the four corners (q_00, q_01, q_10, q_11) that has q < q_max.:
q_01 q_11 y=1 +--------------+ | | | | | | y=0 +--------------+ q_00 q_10 x=0 x=1
- sasdata.data_util.manipulations.get_pixel_fraction_square(x: float, x_min: float, x_max: float) float¶
Return the fraction of the length from xmin to x.:
A B +-----------+---------+ xmin x xmax
- Parameters:
x – x-value
x_min – minimum x for the length considered
x_max – minimum x for the length considered
- Returns:
(x-xmin)/(xmax-xmin) when xmin < x < xmax
- sasdata.data_util.manipulations.get_q_compo(dx: float, dy: float, detector_distance: float, wavelength: float, compo: str | None = None) float¶
This reduces tiny error at very large q. Implementation of this func is not started yet.<–ToDo
- sasdata.data_util.manipulations.position_and_wavelength_to_q(dx: float, dy: float, detector_distance: float, wavelength: float) float¶
- Parameters:
dx – x-distance from beam center [mm]
dy – y-distance from beam center [mm]
detector_distance – sample to detector distance [mm]
wavelength – neutron wavelength [nm]
- Returns:
q-value at the given position