Implements Kuhl and Giardina method of computing the coefficients
An, Bn, Cn, Dn for a specified number of harmonics. This code is adapted
from the pyefd module. See the original paper for more detail:

Takes a filename and uses pyshp to load it, returning a list of
shapefile.ShapeRecord instances.

This list can be iterated over, passing the individual shape instances
to ProcessGeometry() one by one. There is no input handling if a
non-polygon shapefile is passed in, that will result in undefined behavior.

Parameters:

filename (string) – A filename with optional full path pointing to an
ESRI shapefile to be loaded by the pyshp module. The file extension
is optional.

Returns:

A list of shapefile._ShapeRecord objects representing each
polygon geometry in the shapefile.

Rescale the coordinates to values between 0 and 1 in both the x and y
directions. The normalizing is performed using x or y width of the minimum
bounding rectangle of the contour, whichever is largest. X and Y must have
the same dimensions.

Parameters:

X (list) – A list (or numpy array) of x coordinate values.

Y (list) – A list (or numpy array) of y coordinate values.

rawCentroid (tuple) – A tuple containing the x,y coordinates of the
centroid of the contour.

Returns:

A tuple containing a list of normalized x coordinates, a list of
normalized y coordinate and the normalized centroid.

Method to handle all the geometry processing that may be needed by the rest
of the EFD code.

Method which takes a single shape instance from a shapefile
eg shp.Reader(‘shapefile.shp’).shapeRecords()[n]
where n is the index of the shape within a multipart geometry. This results
in the contour, coordinate list and centroid data computed for the input
polygon being normalized and returned to the user.

Parameters:

shapefile._ShapeRecord – A shapefile object representing the geometry
and attributes of a single polygon from a multipart shapefile.

Returns:

A tuple containing a list of normalized x coordinates, a list of
normalized y coordinates, contour (a list of [x,y] coordinate pairs,
normalized about the shape’s centroid) and the normalized coordinate
centroid.

Method to handle all the geometry processing that may be needed by the rest
of the EFD code. This method normalizes the input data to allow spatially
distributed data to be plotted in the same cartesian space.

Method which takes a single shape instance from a shapefile
eg shp.Reader(‘shapefile.shp’).shapeRecords()[n]
where n is the index of the shape within a multipart geometry. This results
in the contour, coordinate list and centroid data computed for the input
polygon being normalized and returned to the user.

Parameters:

shapefile._ShapeRecord – A shapefile object representing the geometry
and attributes of a single polygon from a multipart shapefile.

Returns:

A tuple containing a list of normalized x coordinates, a list of
normalized y coordinates, contour (a list of [x,y] coordinate pairs,
normalized about the shape’s centroid) and the normalized coordinate
centroid.

Call this method to add a title identifying the harmonic being plotted, and
save the plot to a file. Note that harmonic is simply an int value to be
appended to the plot title, it does not select a harmonic to plot.

The figformat argumet can take any value which matplotlib understands,
which varies by system. To see a full list suitable for your matplotlib
instance, call plt.gcf().canvas.get_supported_filetypes().

Parameters:

ax (matplotlib.axes.Axes) – Matplotlib axis instance.

harmonic (int) – The harmonic which is being plotted.

filename (string) – A complete path and filename, without an extension,
for the saved plot.

figformat (string) – A string denoting the format to save the figure as.
Defaults to png.

Normalize the Elliptical Fourier Descriptor coefficients for a polygon.

Implements Kuhl and Giardina method of normalizing the coefficients
An, Bn, Cn, Dn. Performs 3 separate normalizations. First, it makes the
data location invariant by re-scaling the data to a common origin.
Secondly, the data is rotated with respect to the major axis. Thirdly,
the coefficients are normalized with regard to the absolute value of A_1.
This code is adapted from the pyefd module. See the original paper for
more detail:

coeffs (numpy.ndarray) – A numpy array of shape (n, 4) representing the
four coefficients for each harmonic computed.

size_invariant (bool) – Set to True (the default) to perform the third
normalization and false to return the data withot this processing
step. Set this to False when plotting a comparison between the
input data and the Fourier ellipse.

Returns:

A tuple consisting of a numpy.ndarray of shape (harmonics, 4)

representing the four coefficients for each harmonic computed and
the rotation in degrees applied to the normalized contour.

Write the data processed by writeGeometry into a shapefile generated by
generateShapefile().

If the filename of a shapfile is passed in as template, the spatial
projection of the template shapefile will be applied to the new shapefile.
Note that this does not carry out any coordinate transforms, it is merely
to apply the same spatial reference to the output data as was present in
the input data.

Parameters:

filename (string) – A complete path and filename, with or without the
.shp extenion, to write the final shapefile data to. Must be a path
which exists.

shape (shapefile.Writer) – A shapefile object representing the
geometry and attributes written by writeGeometry().

prj (string) – A complete path and filename, with or without the
.prj extenion, to the projection file from the shapefile that the
data was loaded from initially, Used to copy the spatial projection
information to the new file.

Warning

Code does not test if output paths exist, and if files exist they will
be overwritten.