binning
This module contains functions for binning 3D scalar fields.
Module Contents
Functions
If arr.shape is 3D, make it 2D. |
|
If arr.shape is 2D, make it 1D. |
|
Works out the shape of the finite differences grid and returns it. |
|
Works out the shape of the finite differences grid that we’re going to need to store data with this start, stop and step. |
|
This is an alias to the native C function _weighted_bin_3d, which adds a useful protective layer. A lot of explicit type conversions are carried out, which prevents segfaults on the C side. |
|
Entirely analogous to weighted_bin_3d, but histograms in only 1 dimension. This is useful for re-histogramming for e.g. 2-theta and |Q| projections. |
API
- binning.fix_delta_q_geometry(arr: numpy.ndarray) numpy.ndarray
If arr.shape is 3D, make it 2D.
- binning.fix_intensity_geometry(arr: numpy.ndarray) numpy.ndarray
If arr.shape is 2D, make it 1D.
- binning.finite_diff_grid(start: numpy.ndarray, stop: numpy.ndarray, step: numpy.ndarray)
Works out the shape of the finite differences grid and returns it.
- binning.finite_diff_shape(start: numpy.ndarray, stop: numpy.ndarray, step: numpy.ndarray)
Works out the shape of the finite differences grid that we’re going to need to store data with this start, stop and step.
- binning.typecheckdict(float_dict, type)
- binning.weighted_bin_3d(coords: numpy.ndarray, weights: numpy.ndarray, out: numpy.ndarray, count: numpy.ndarray, start: numpy.ndarray, stop: numpy.ndarray, step: numpy.ndarray, min_intensity=None) numpy.ndarray
This is an alias to the native C function _weighted_bin_3d, which adds a useful protective layer. A lot of explicit type conversions are carried out, which prevents segfaults on the C side.
- Args:
- coords:
A numpy array of the coordinates we’re going to bin. Should be the output of Image.q_vectors.
- weights:
The intensities measured at each of the q_vectors stored in coords. Should be the output of Image.data
- out:
The current state of the binned reciprocal space map.
- count:
The number of times each voxel in out has been binned to so far.
- start:
A numpy array that looks like [qx_min, qy_min, qz_min].
- stop:
A numpy array that looks like [qx_max, qy_max, qz_max]. Together with start, these arrays specify the bounds of the region of reciprocal space that we’re binning to.
- step:
The side-length of each reciprocal space voxel.
- min_intensity:
Any intensities recorded below this intensity should be completely ignored. This is used for masking. Defaults to None (i.e. no masking). This is not the same thing as background subtraction.
- binning.weighted_bin_1d(coords: numpy.ndarray, weights: numpy.ndarray, out: numpy.ndarray, count: numpy.ndarray, start: float, stop: float, step: float)
Entirely analogous to weighted_bin_3d, but histograms in only 1 dimension. This is useful for re-histogramming for e.g. 2-theta and |Q| projections.
- Args:
- coords:
A numpy array of the coordinates we’re going to bin. Should be a numpy array with shape (N,).
- weights:
The intensities measured at each of the q_vectors stored in coords. Should be a numpy array with shape (N,)
- out:
If the results of this binning are to be appended to another histogram, out should be the histogram to which the results will be appended. Otherwise, np.zeros() please. This should have the shape of your desired output. So, if you’re binning into 1000 equally spaced bines, it should have shape (1000,)
- count:
Same shape as out. This array just counts how many times you bin into each bin. This is needed for normalisation.
- start:
The minimum coordinate that we want to bin to. Any coordinate smaller than this value will be thrown away.
- stop:
The maximum coordinate we want to bin to. Any coordinate larger than this value will be thrown away.
- step:
The side-length of each bin voxel.