コード例 #1
0
def radial_average(image,
                   mask=None,
                   center=[1364, 1504],
                   threshold=0,
                   nx=300,
                   pixel_size=(1, 1),
                   min_x=-np.pi,
                   max_x=np.pi):
    '''
    Does the radial average over a given range, including threshold masking
    '''
    # - create angular grid
    phi_val = utils.angle_grid(center, image.shape,
                               pixel_size)  #*180./np.pi+180.
    # - create unitary mask (in case it's none)
    if mask is None:
        mask = np.ones(image.shape)

    # - bin values of image based on the angular coordinates
    bin_edges, sums, counts = utils.bin_1D(np.ravel(phi_val * mask),
                                           np.ravel(image * mask),
                                           nx,
                                           min_x=min_x,
                                           max_x=max_x)
    th_mask = counts > threshold
    phi_averages = np.array(sums[th_mask], dtype=float) / np.array(
        counts[th_mask], dtype=float)
    bin_centers = utils.bin_edges_to_centers(bin_edges)[th_mask]

    return bin_centers * 180 / np.pi + 180., phi_averages
コード例 #2
0
    def circular_average(calibrated_center,
                         threshold=0,
                         nx=100,
                         pixel_size=(1, 1),
                         min_x=None,
                         max_x=None):
        """Circular average of the the image data
	    The circular average is also known as the radial integration
	    (adapted from scikit-beam.roi)
	    Parameters
	    ----------
	    image : array
	        Image to compute the average as a function of radius
	    calibrated_center : tuple
	        The center of the image in pixel units
	        argument order should be (row, col)
	    mask  : arrayint, optional
	        Boolean array with 1s (and 0s) to be used (or not) in the average
	    threshold : int, optional
	        Ignore counts above `threshold`
	        default is zero
	    nx : int, optional
	        number of bins in x
	        defaults is 100 bins
	    pixel_size : tuple, optional
	        The size of a pixel (in a real unit, like mm).
	        argument order should be (pixel_height, pixel_width)
	        default is (1, 1)
	    min_x : float, optional number of pixels
	        Left edge of first bin defaults to minimum value of x
	    max_x : float, optional number of pixels
	        Right edge of last bin defaults to maximum value of x
	    Returns
	    -------
	    bin_centers : array
	        The center of each bin in R. shape is (nx, )
	    ring_averages : array
	        Radial average of the image. shape is (nx, ).
	    """
        # - create radial grid
        radial_val = utils.radial_grid(calibrated_center, self.data.shape,
                                       pixel_size)

        # - bin values of image based on the radial coordinates
        bin_edges, sums, counts = utils.bin_1D(np.ravel(radial_val *
                                                        self.mask),
                                               np.ravel(self.data * self.mask),
                                               nx,
                                               min_x=min_x,
                                               max_x=max_x)
        th_mask = counts > threshold
        ring_averages = sums[th_mask] / counts[th_mask]
        ring_averages = sums[th_mask] / counts[th_mask]

        bin_centers = utils.bin_edges_to_centers(bin_edges)[th_mask]

        return bin_centers, ring_averages
コード例 #3
0
	def radialAverage(calibrated_center, threshold=0, nx=100, pixel_size=(1, 1),  min_x=None, max_x=None):
		"""
		--------------------------------------------
        	Method: SpecklePattern.radialAverage
        	--------------------------------------------
		Radial average of the the image data
		The radial average is also known as the azimuthal integration
		(adapted from scikit-beam.roi)
        	--------------------------------------------
        	Usage: tracksToUse = mySpeckles.findTracksToUse(message)
        	--------------------------------------------
		Arguments:
    		image : array
    		    Image to compute the average as a function of radius
    		calibrated_center : tuple
    		    The center of the image in pixel units
    		    argument order should be (row, col)
    		mask  : arrayint, optional
    		    Boolean array with 1s (and 0s) to be used (or not) in the average
    		threshold : int, optional
    		    Ignore counts above `threshold`
    		    default is zero
    		nx : int, optional
    		    number of bins in x
    		    defaults is 100 bins
    		pixel_size : tuple, optional
    		    The size of a pixel (in a real unit, like mm).
    		    argument order should be (pixel_height, pixel_width)
    		    default is (1, 1)
    		min_x : float, optional number of pixels
    		    Left edge of first bin defaults to minimum value of x
    		max_x : float, optional number of pixels
    		    Right edge of last bin defaults to maximum value of x
		--------------------------------------------
		Returns:
    		bin_centers : array
    		    The center of each bin in R. shape is (nx, )
    		phi_averages : array
    		    Radial average of the image. shape is (nx, ).

		--------------------------------------------
		"""
		
    		# - create angular grid
    		phi_val = utils.angle_grid(calibrated_center, self.data.shape,pixel_size)#*180./np.pi+180.
    		
    		# - bin values of self.data based on the angular coordinates
    		bin_edges, sums, counts = utils.bin_1D(np.ravel(phi_val*self.mask),
    		                                       np.ravel(self.data*self.mask), nx,
    		                                       min_x=min_x,
    		                                       max_x=max_x)
    		th_mask = counts > threshold
    		phi_averages = sums[th_mask]/ counts[th_mask]
    		bin_centers = utils.bin_edges_to_centers(bin_edges)[th_mask]
    		
    		return bin_centers, phi_averages
コード例 #4
0
def test_bin_1D():
    # set up simple data
    x = np.linspace(0, 1, 100)
    y = np.arange(100)
    nx = 10
    # make call
    edges, val, count = core.bin_1D(x, y, nx)
    # check that values are as expected
    assert_array_almost_equal(edges, np.linspace(0, 1, nx + 1, endpoint=True))
    assert_array_almost_equal(val, np.sum(y.reshape(nx, -1), axis=1))
    assert_array_equal(count, np.ones(nx) * 10)
コード例 #5
0
ファイル: integrators.py プロジェクト: fperakis/XRD-tools
def angular_average(image, calibrated_center,mask,threshold=0, nx=100,
                     pixel_size=(1, 1),  min_x=None, max_x=None):
    """Circular average of the the image data
    The circular average is also known as the radial integration
    (adapted from scikit-beam.roi)
    Parameters
    ----------
    image : array
        Image to compute the average as a function of radius
    calibrated_center : tuple
        The center of the image in pixel units
        argument order should be (row, col)
    mask  : arrayint, optional
        Boolean array with 1s (and 0s) to be used (or not) in the average
    threshold : int, optional
        Ignore counts above `threshold`
        default is zero
    nx : int, optional
        number of bins in x
        defaults is 100 bins
    pixel_size : tuple, optional
        The size of a pixel (in a real unit, like mm).
        argument order should be (pixel_height, pixel_width)
        default is (1, 1)
    min_x : float, optional number of pixels
        Left edge of first bin defaults to minimum value of x
    max_x : float, optional number of pixels
        Right edge of last bin defaults to maximum value of x
    Returns
    -------
    bin_centers : array
        The center of each bin in R. shape is (nx, )
    ring_averages : array
        Radial average of the image. shape is (nx, ).
    """
    # - create radial grid
    radial_val = utils.radial_grid(calibrated_center, image.shape, pixel_size)

    # - create unitary mask (in case it's none)
    if mask is None:
        mask=np.ones(image.shape) 
  
    # - bin values of image based on the radial coordinates
    bin_edges, sums, counts = utils.bin_1D(np.ravel(radial_val*mask),
                                           np.ravel(image*mask), nx,
                                           min_x=min_x,
                                           max_x=max_x)
    th_mask = counts > threshold
    ring_averages = sums[th_mask] / counts[th_mask]
    ring_averages = sums[th_mask] / counts[th_mask]

    bin_centers = utils.bin_edges_to_centers(bin_edges)[th_mask]

    return bin_centers, ring_averages
コード例 #6
0
ファイル: test_utils.py プロジェクト: CJ-Wright/scikit-beam
def test_bin_1D():
    # set up simple data
    x = np.linspace(0, 1, 100)
    y = np.arange(100)
    nx = 10
    # make call
    edges, val, count = core.bin_1D(x, y, nx)
    # check that values are as expected
    assert_array_almost_equal(edges,
                              np.linspace(0, 1, nx + 1, endpoint=True))
    assert_array_almost_equal(val,
                              np.sum(y.reshape(nx, -1), axis=1))
    assert_array_equal(count,
                       np.ones(nx) * 10)
コード例 #7
0
def test_bin_1D_2():
    """
    Test for appropriate default value handling
    """
    # set up simple data
    x = np.linspace(0, 1, 100)
    y = np.arange(100)
    nx = core._defaults["bins"]
    min_x = None
    max_x = None
    # make call
    edges, val, count = core.bin_1D(x=x, y=y, nx=nx, min_x=min_x, max_x=max_x)
    # check that values are as expected
    assert_array_almost_equal(edges, np.linspace(0, 1, nx + 1, endpoint=True))
    assert_array_almost_equal(val, np.sum(y.reshape(nx, -1), axis=1))
    assert_array_equal(count, np.ones(nx))
コード例 #8
0
ファイル: test_utils.py プロジェクト: CJ-Wright/scikit-beam
def test_bin_1D_2():
    """
    Test for appropriate default value handling
    """
    # set up simple data
    x = np.linspace(0, 1, 100)
    y = np.arange(100)
    nx = core._defaults["bins"]
    min_x = None
    max_x = None
    # make call
    edges, val, count = core.bin_1D(x=x, y=y, nx=nx, min_x=min_x, max_x=max_x)
    # check that values are as expected
    assert_array_almost_equal(edges,
                              np.linspace(0, 1, nx + 1, endpoint=True))
    assert_array_almost_equal(val,
                              np.sum(y.reshape(nx, -1), axis=1))
    assert_array_equal(count,
                       np.ones(nx))
コード例 #9
0
    def radialAverage(calibrated_center,
                      threshold=0,
                      nx=100,
                      pixel_size=(1, 1),
                      min_x=None,
                      max_x=None):
        """
		--------------------------------------------
        	Method: SpecklePattern.radialAverage
        	--------------------------------------------
		Radial average of the the image data
		The radial average is also known as the azimuthal integration
		(adapted from scikit-beam.roi)
        	--------------------------------------------
        	Usage: tracksToUse = mySpeckles.findTracksToUse(message)
        	--------------------------------------------
		Arguments:
    		image : array
    		    Image to compute the average as a function of radius
    		calibrated_center : tuple
    		    The center of the image in pixel units
    		    argument order should be (row, col)
    		mask  : arrayint, optional
    		    Boolean array with 1s (and 0s) to be used (or not) in the average
    		threshold : int, optional
    		    Ignore counts above `threshold`
    		    default is zero
    		nx : int, optional
    		    number of bins in x
    		    defaults is 100 bins
    		pixel_size : tuple, optional
    		    The size of a pixel (in a real unit, like mm).
    		    argument order should be (pixel_height, pixel_width)
    		    default is (1, 1)
    		min_x : float, optional number of pixels
    		    Left edge of first bin defaults to minimum value of x
    		max_x : float, optional number of pixels
    		    Right edge of last bin defaults to maximum value of x
		--------------------------------------------
		Returns:
    		bin_centers : array
    		    The center of each bin in R. shape is (nx, )
    		phi_averages : array
    		    Radial average of the image. shape is (nx, ).

		--------------------------------------------
		"""

        # - create angular grid
        phi_val = utils.angle_grid(calibrated_center, self.data.shape,
                                   pixel_size)  #*180./np.pi+180.

        # - bin values of self.data based on the angular coordinates
        bin_edges, sums, counts = utils.bin_1D(np.ravel(phi_val * self.mask),
                                               np.ravel(self.data * self.mask),
                                               nx,
                                               min_x=min_x,
                                               max_x=max_x)
        th_mask = counts > threshold
        phi_averages = sums[th_mask] / counts[th_mask]
        bin_centers = utils.bin_edges_to_centers(bin_edges)[th_mask]

        return bin_centers, phi_averages