2. Point operations module (symmetrize.pointops)

@author: R. Patrick Xian

symmetrize.pointops.arm(Aold, Anew)[source]

Calculate the area retainment measure (ARM).

Parameters:
Aold, Anewnumeric/numeric

The area before (old) and after (new) symmetrization.

Return:
snumeric

The value of the ARM.

symmetrize.pointops.cart2homo(points, dtyp='float32')[source]

Transform points from Cartesian to homogeneous coordinates.

Parameter:
pointstuple/list/array

Pixel coordinates of the points in Cartesian coordinates, (x, y).

Return:
pts_homo2D array

Pixel coordinates of the points (pts) in homogeneous coordinates, (x, y, 1).

symmetrize.pointops.csm(pcent, pvert, rotsym=None, type='rotation')[source]

Computation of the continuous (a)symmetry measure (CSM) for a set of polygon vertices exhibiting a degree of rotational symmetry. The value is bounded within [0, 1].

When csm = 0, the point set is completely symmetric.

When csm = 1, the point set is completely asymmetric.

Parameters:
pcenttuple/list

Pixel coordinates of the center position.

pvertnumpy array

Pixel coordinates of the vertices.

rotsymint | None

Order of rotational symmetry.

typestr | ‘rotation’

The type of the symmetry operation.

Return:
sfloat

Calculated continuous (a)symmetry measure.

symmetrize.pointops.cvdist(verts, center)[source]

Calculate the center-vertex distance.

Parameters:
vertstuple/list

Pixel coordinates of the vertices.

centertuple/list

Pixel coordinates of the center.

symmetrize.pointops.gridplot(xgrid, ygrid, ax=None, subsamp=5, **kwds)[source]

Plotting transform grid with downsampling. Adapted from the StackOverflow post, https://stackoverflow.com/questions/47295473/how-to-plot-using-matplotlib-python-colahs-deformed-grid

Parameters:
xgrid, ygrid2D array, 2D array

Coordinate grids along the x and y directions.

axAxesObject

Axes object to anchor the plot.

subsampint | 5

Subsampling portion.

**kwdskeyword arguments

Plotting keywords.

symmetrize.pointops.homo2cart(points)[source]

Transform points from homogeneous to Cartesian coordinates.

Parameter:
pointstuple/list/array

Pixel coordinates of the points in homogeneous coordinates, (x, y, 1).

Return:
pts_cartarray

Pixel coordinates of the points (pts) in Cartesian coordinates, (x, y).

symmetrize.pointops.peakdetect2d(img, method='daofind', **kwds)[source]

Peak detection in 2D image.

Parameters:
img2D array

Image matrix.

methodstr | ‘daofind’

Detection method (‘daofind’ or ‘maxlist’).

**kwdskeyword arguments

Additional arguments passed to the specific methods chosen.

'daofind' See astropy.stats.sigma_clipped_stats()

and photutils.detection.DAOStarFinder().

'maxlist' See skimage.feature.peak_local_max().

Return:
pks2D array

Pixel coordinates of detected peaks, in (column, row) ordering.

symmetrize.pointops.pointset_center(pset, method='centroidnn', ret='cnc')[source]

Determine the center position of a point set and separate it from the rest.

Parameters:
pset2D array

Pixel coordinates of the point set.

methodstr | ‘centroidnn’ (the nearest neighbor of centroid)

Method to determine the point set center.

'centroidnn' Use the point with the minimal distance to the centroid as the center.

'centroid' Use the centroid as the center.

retstr | ‘cnc’

Condition to extract the center position.

'cnc' Return the pixel positions of the center (c) and the non-center (nc) points.

'all' Return the pixel positions of the center, the non-center points and the centroid.

symmetrize.pointops.pointset_locate(image, method='daofind', center='detected', centermethod='centroidnn', direction='ccw', **kwds)[source]

A combination of detecting, sorting and ordering peaks from a 2D image.

Parameters:
image2D array

2D image for locating the point feature positions.

methodstr | ‘daofind’

Method for detecting peaks (‘daofind’ or ‘maxlist’).

centerstr/tuple/list

Center position in (row, column) form.

centermethod : str | ‘centroidnn’ direction : str | ‘ccw’

Direction of the ordering of the vertices (‘cw’ for clockwise, or ‘ccw’ for counterclockwise).

**kwdskeyword arguments

Extra arguments for the feature detection algorithms.

symmetrize.pointops.pointset_order(pset, center=None, direction='ccw')[source]

Order a point set around a center in a clockwise or counterclockwise way.

Parameters:
pset2D array

Pixel coordinates of the point set.

centerlist/tuple/1D array | None

Pixel coordinates of the putative shape center.

directionstr | ‘ccw’

Direction of the ordering (‘cw’ or ‘ccw’).

Return:
pset_ordered2D array

Sorted pixel coordinates of the point set.

symmetrize.pointops.polyarea(x=[], y=[], coords=[], coord_order='rc')[source]

Calculate the area of a convex polygon area from its vertex coordinates, using the surveyor’s formula (also called the shoelace formula). The vertices are ordered in a clockwise or counterclockwise fashions.

Parameters:
x, ytuple/list/1D array | [], []

Collection of vertex coordinates along the x and y coordinates.

coordslist/2D array | []

Vertex coordinates.

coord_orderstr | ‘rc’

The ordering of coordinates in the coords array, choose from ‘rc’ or ‘yx’, ‘cr’ or ‘xy’. Here r = row (y), c = column (x).

Return:
Anumeric

The area of the convex polygon bounded by the given vertices.

symmetrize.pointops.reorder(points, itemid, axis=0)[source]

Reorder a point set along an axis.

Parameters:
pointstuple/list

Collection of the pixel coordinates of points.

itemidint

Index of the entry to be placed at the start.

axisint | 1

The axis to apply the shift.

Return:
pts_rolledtuple/list

The points’ pixel coordinates after position shift.

symmetrize.pointops.rotmat(theta, to_rad=True, coordsys='cartesian')[source]

Rotation matrix in 2D in different coordinate systems.

Parameters:
thetanumeric

Rotation angle.

to_radbool | True

Specify the option to convert the angle to radians.

coordsysstr | ‘cartesian’

Coordinate system specification (‘cartesian’ or ‘homogen’).

symmetrize.pointops.vvdist(verts, neighbor=1)[source]

Calculate the neighboring vertex-vertex distance.

Parameters:
vertstuple/list

Pixel coordinates of the vertices.

neighborint | 1

Neighbor index (1 = nearest).