def getPeakSymmetry(shape, px, py, fillValue=0):

"""Build the operator to symmetrize a the intensities for a single row

"""

center = (np.array(shape)1)/2.0

# If the peak is centered at the middle of the footprint,

# make the entire footprint symmetric

if px==center[1] and py==center[0]:

return scipy.sparse.coo_matrix(np.fliplr(np.eye(shape[0]*shape[1])))


# Otherwise, find the bounding box that contains the minimum number of pixels needed to symmetrize

if py<(shape[0]1)/2.:

ymin = 0

ymax = 2*py+1

elif py>(shape[0]1)/2.:

ymin = 2*pyshape[0]+1

ymax = shape[0]

else:

ymin = 0

ymax = shape[0]

if px<(shape[1]1)/2.:

xmin = 0

xmax = 2*px+1

elif px>(shape[1]1)/2.:

xmin = 2*pxshape[1]+1

xmax = shape[1]

else:

xmin = 0

xmax = shape[1]


fpHeight, fpWidth = shape

fpSize = fpWidth*fpHeight

tWidth = xmaxxmin

tHeight = ymaxymin

extraWidth = fpWidthtWidth

pixels = (tHeight1)*fpWidth+tWidth


# This is the block of the matrix that symmetrizes intensities at the peak position

subOp = np.eye(pixels, pixels)

for i in range(0,tHeight1):

for j in range(extraWidth):

idx = (i+1)*tWidth+(i*extraWidth)+j

subOp[idx, idx] = fillValue

subOp = np.fliplr(subOp)


smin = ymin*fpWidth+xmin

smax = (ymax1)*fpWidth+xmax

if fillValue!=0:

symmetryOp = np.identity(fpSize)*fillValue

else:

symmetryOp = np.zeros((fpSize, fpSize))

symmetryOp[smin:smax,smin:smax] = subOp


# Return a sparse matrix, which greatly speeds up the processing

return scipy.sparse.coo_matrix(symmetryOp)


def getPeakSymmetryOp(shape, px, py, fillValue=0):

"""Operator to calculate the difference from the symmetric intensities

"""

symOp = getPeakSymmetry(shape, px, py, fillValue)

diffOp = scipy.sparse.identity(symOp.shape[0])symOp

# In cases where the symmetry operator is very small (eg. a small isolated source)

# scipy doesn't return a sparse matrix, so we test whether or not the matrix is sparse

# and if it is, use a sparse matrix that works best with the proximal operators.

if hasattr(diffOp, "tocoo"):

diffOp = diffOp.tocoo()

return diffOp

For simplicity this work is not being done on a separate branch, but instead will be included in
DM9172. The code for the new symmetry operator appears below:"""
"""