Beispiel #1
0
def mkrphibinstat(shape,
                  origin,
                  r_map=None,
                  mask=None,
                  statistic='mean',
                  bins=(800, 300)):
    ''' Make the radial phi binned statistic. Allow for an rmap to be supplied
    '''
    if origin is None:
        origin = (shape[0] - 1) / 2., (shape[1] - 1) / 2.

    if r_map is None:
        r_map = radial_grid(origin, shape)

    phi_map = angle_grid(origin, shape)

    shape = tuple(shape)
    if mask is not None:
        if mask.shape != shape:
            raise ValueError('"mask" has incorrect shape. '
                             ' Expected: ' + str(shape) + ' Received: ' +
                             str(mask.shape))
        mask = mask.reshape(-1)

    rphibinstat = BinnedStatistic2D(r_map.reshape(-1),
                                    phi_map.reshape(-1),
                                    statistic,
                                    bins=bins,
                                    mask=mask)
    return rphibinstat
Beispiel #2
0
def convert_Qmap(img,
                 qx_map,
                 qy_map=None,
                 bins=None,
                 rangeq=None,
                 origin=None,
                 mask=None,
                 statistic='mean'):
    """Y.G. Nov 3@CHX 
    Convert a scattering image to a qmap by giving qx_map and qy_map
    Return converted qmap, x-coordinates and y-coordinates
    """
    if qy_map is not None:
        if rangeq is None:
            qx_min, qx_max = qx_map.min(), qx_map.max()
            qy_min, qy_max = qy_map.min(), qy_map.max()
            rangeq = [[qx_min, qx_max], [qy_min, qy_max]]
            #rangeq =  [qx_min,qx_max ,  qy_min,qy_max]
        if bins is None:
            bins = qx_map.shape

        if mask is not None:
            m = mask.ravel()
        else:
            m = None

        b2d = BinnedStatistic2D(qx_map.ravel(),
                                qy_map.ravel(),
                                statistic=statistic,
                                bins=bins,
                                mask=m,
                                range=rangeq)
        remesh_data, xbins, ybins = b2d(
            img.ravel()), b2d.bin_centers[0], b2d.bin_centers[1]

    else:
        if rangeq is None:
            qx_min, qx_max = qx_map.min(), qx_map.max()
            rangeq = [qx_min, qx_max]
        if bins is None:
            bins = [qx_map.size]
        #print( rangeq, bins )
        if mask is not None:
            m = mask.ravel()
        else:
            m = None
        b1d = BinnedStatistic1D(qx_map.ravel(), bins=bins, mask=m)

        remesh_data = b1d(img.ravel())
        #print('Here')
        xbins = b1d.bin_centers
        ybins = None

    return remesh_data, xbins, ybins
Beispiel #3
0
def qphiavg(image,
            q_map=None,
            phi_map=None,
            mask=None,
            bins=None,
            origin=None,
            range=None,
            statistic='mean'):
    ''' Octo 20, 2017 Yugang According to Julien's Suggestion
        Get from https://github.com/CFN-softbio/SciStreams/blob/master/SciStreams/processing/qphiavg.py
        With a small revision --> return three array rather than dict
    
        quick qphi average calculator.
        ignores bins for now
    '''
    # TODO : replace with method that takes qphi maps
    # TODO : also return q and phi of this...
    # print("In qphi average stream")
    shape = image.shape
    if bins is None:
        bins = shape
        #print(bins)
    if origin is None:
        origin = (shape[0] - 1) / 2., (shape[1] - 1) / 2.

    from skbeam.core.utils import radial_grid, angle_grid

    if q_map is None:
        q_map = radial_grid(origin, shape)
    if phi_map is None:
        phi_map = angle_grid(origin, shape)

    expected_shape = tuple(shape)
    if mask is not None:
        if mask.shape != expected_shape:
            raise ValueError('"mask" has incorrect shape. '
                             ' Expected: ' + str(expected_shape) +
                             ' Received: ' + str(mask.shape))
        mask = mask.reshape(-1)

    rphibinstat = BinnedStatistic2D(q_map.reshape(-1),
                                    phi_map.reshape(-1),
                                    statistic=statistic,
                                    bins=bins,
                                    mask=mask,
                                    range=range)

    sqphi = rphibinstat(image.ravel())
    qs = rphibinstat.bin_centers[0]
    phis = rphibinstat.bin_centers[1]
    return sqphi, qs, phis
Beispiel #4
0
def qphiavg(image,
            q_map=None,
            phi_map=None,
            mask=None,
            bins=None,
            origin=None,
            range=None,
            statistic='mean'):
    ''' quick qphi average calculator.
        ignores bins for now
    '''
    # TODO : replace with method that takes qphi maps
    # TODO : also return q and phi of this...
    # print("In qphi average stream")
    shape = image.shape
    if bins is None:
        bins = shape
        #print(bins)
    if origin is None:
        origin = (shape[0] - 1) / 2., (shape[1] - 1) / 2.

    from skbeam.core.utils import radial_grid, angle_grid

    if q_map is None:
        q_map = radial_grid(origin, shape)
    if phi_map is None:
        phi_map = angle_grid(origin, shape)

    expected_shape = tuple(shape)
    if mask is not None:
        if mask.shape != expected_shape:
            raise ValueError('"mask" has incorrect shape. '
                             ' Expected: ' + str(expected_shape) +
                             ' Received: ' + str(mask.shape))
        mask = mask.reshape(-1)

    rphibinstat = BinnedStatistic2D(q_map.reshape(-1),
                                    phi_map.reshape(-1),
                                    statistic=statistic,
                                    bins=bins,
                                    mask=mask,
                                    range=range)

    sqphi = rphibinstat(image.ravel())
    qs = rphibinstat.bin_centers[0]
    phis = rphibinstat.bin_centers[1]
    return sqphi, qs, phis