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 sasdataloader.test.utest_averaging DataInfoTests.test_sectorphi_quarter `

class sasdata.data_util.manipulations.Binning(min_value, max_value, n_bins, base=None)

Bases: object

This class just creates a binning object either linear or log

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: Boxsum

Perform the average of counts in a 2D region of interest.

class sasdata.data_util.manipulations.Boxcut(x_min=0.0, x_max=0.0, y_min=0.0, y_max=0.0)

Bases: object

Find a rectangular 2D region of interest.

class sasdata.data_util.manipulations.Boxsum(x_min=0.0, x_max=0.0, y_min=0.0, y_max=0.0)

Bases: object

Perform the sum of counts in a 2D region of interest.

class sasdata.data_util.manipulations.CircularAverage(r_min=0.0, r_max=0.0, bin_width=0.0005)

Bases: object

Perform circular averaging on 2D data

The data returned is the distribution of counts as a function of Q

class sasdata.data_util.manipulations.Ring(r_min=0, r_max=0, center_x=0, center_y=0, nbins=36)

Bases: object

Defines a ring on a 2D data set. The ring is defined by r_min, r_max, and the position of the center of the ring.

The data returned is the distribution of counts around the ring as a function of phi.

Phi_min and phi_max should be defined between 0 and 2*pi in anti-clockwise starting from the x- axis on the left-hand side

class sasdata.data_util.manipulations.Ringcut(r_min=0, r_max=0, center_x=0, center_y=0)

Bases: object

Defines a ring on a 2D data set. The ring is defined by r_min, r_max, and the position of the center of the ring.

The data returned is the region inside the ring

Phi_min and phi_max should be defined between 0 and 2*pi in anti-clockwise starting from the x- axis on the left-hand side

class sasdata.data_util.manipulations.SectorPhi(r_min, r_max, phi_min=0, phi_max=6.283185307179586, nbins=20, base=None)

Bases: _Sector

Sector 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.

class sasdata.data_util.manipulations.SectorQ(r_min, r_max, phi_min=0, phi_max=6.283185307179586, nbins=20, base=None)

Bases: _Sector

Sector 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.

class sasdata.data_util.manipulations.Sectorcut(phi_min=0, phi_max=3.141592653589793)

Bases: object

Defines a sector (major + minor) region on a 2D data set. The sector is defined by phi_min, phi_max, where phi_min and phi_max are defined by the right and left lines wrt central line.

Phi_min and phi_max are given in units of radian and (phi_max-phi_min) should not be larger than pi

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: _Slab

Compute average I(Qx) for a region of interest

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: _Slab

Compute average I(Qy) for a region of interest

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 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

sasdata.data_util.manipulations.reader2D_converter(data2d: Data2D | None = None) Data2D

convert old 2d format opened by IhorReader or danse_reader to new Data2D format This is mainly used by the Readers

Parameters:

data2d – 2d array of Data2D object

Returns:

1d arrays of Data2D object