Skip to content

Wrap fitcircle - #1550

Closed
willschlitzer wants to merge 74 commits into
mainfrom
wrap/fitcircle
Closed

willschlitzer wants to merge 74 commits into
mainfrom
wrap/fitcircle

Conversation

@willschlitzer

@willschlitzer willschlitzer commented Sep 29, 2021

Copy link
Copy Markdown
Contributor

This pull request wraps the module fitcircle.

Preview at https://pygmt-dev--1550.org.readthedocs.build/en/1550/api/generated/pygmt.fitcircle.html

Reminders

  • Run make format and make check to make sure the code follows the style guide.
  • Add tests for new features or tests that would have caught the bug that you're fixing.
  • Add new public functions/methods/classes to doc/api/index.rst.
  • Write detailed docstrings for all functions/methods.
  • If adding new functionality, add an example to docstrings or tutorials.

Slash Commands

You can write slash commands (/command) in the first line of a comment to perform
specific operations. Supported slash commands are:

  • /format: automatically format and lint the code
  • /test-gmt-dev: run full tests on the latest GMT development version

@willschlitzer willschlitzer added the feature Brand new feature label Sep 29, 2021
@willschlitzer willschlitzer added this to the 0.5.0 milestone Sep 29, 2021
@willschlitzer willschlitzer self-assigned this Sep 29, 2021
@willschlitzer willschlitzer modified the milestones: 0.5.0, 0.6.0 Oct 7, 2021
@willschlitzer
willschlitzer marked this pull request as ready for review January 14, 2022 00:40
@weiji14 weiji14 removed this from the 0.6.0 milestone Mar 13, 2022
willschlitzer and others added 4 commits August 15, 2026 17:55
Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
Comment thread pygmt/helpers/caching.py Outdated
Comment thread pygmt/src/fitcircle.py Outdated
Comment thread pygmt/src/fitcircle.py Outdated
Comment thread pygmt/src/fitcircle.py
Comment thread pygmt/src/fitcircle.py Outdated
Comment on lines +26 to +54
Find mean position and great or small circle fit to points on sphere.

This method takes (longitude, latitude) values and converts them to Cartesian
three-vectors on the unit sphere. Then two locations are found: the mean
of the input positions, and the pole to the great circle which best fits
the input positions.

Setting ``norm`` to ``1`` (L1 norm) approximates the minimization of the
sum of absolute values of cosines of angular distances. This solution
finds the mean position as the Fisher average of the data, and the pole
position as the Fisher average of the cross-products between the mean
and the data. Averaging cross-products gives weight to points in
proportion to their distance from the mean, analogous to the "leverage"
of distant points in linear regression in the plane.

Setting ``norm`` to ``2`` (L2 norm) approximates the minimization of the
sum of squares of cosines of angular distances. It creates a 3 by 3
matrix of sums of squares of components of the data vectors. The
eigenvectors of this matrix give the mean and pole locations. This
method may be more subject to roundoff errors when there are thousands
of data. The pole is given by the eigenvector corresponding to the
smallest eigenvalue; it is the least-well represented factor in the data
and is not easily estimated by either method.

When the data are closely grouped along a great circle both solutions
are similar. If the data have large dispersion, the pole to the great
circle will be less well determined than the mean. Compare both
solutions as a qualitative check by calling :func:`pygmt.fitcircle`
twice, once for each ``norm``.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rewrap these lines to ~88 characters per line.

Comment thread pygmt/src/fitcircle.py Outdated
Comment thread pygmt/src/fitcircle.py
Comment thread pygmt/src/fitcircle.py Outdated
Comment thread pygmt/src/fitcircle.py Outdated
Comment thread pygmt/src/fitcircle.py Outdated
Comment thread pygmt/src/fitcircle.py Outdated
Comment thread pygmt/src/fitcircle.py Outdated
willschlitzer and others added 6 commits September 16, 2026 08:31
Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
Comment thread pygmt/src/fitcircle.py
Comment on lines +40 to +46
- ``norm=2`` (L2 norm) approximates the minimization of the sum of squares of
cosines of cosines of angular distances. It creates a 3 by 3 matrix of sums of
squares of components of the data vectors. The eigenvectors of this matrix give
the mean and pole locations. This method may be more subject to roundoff errors
when there are thousands of data. The pole is given by the eigenvector
corresponding to the smallest eigenvalue; it is the least-well represented factor
in the data and is not easily estimated by either method.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- ``norm=2`` (L2 norm) approximates the minimization of the sum of squares of
cosines of cosines of angular distances. It creates a 3 by 3 matrix of sums of
squares of components of the data vectors. The eigenvectors of this matrix give
the mean and pole locations. This method may be more subject to roundoff errors
when there are thousands of data. The pole is given by the eigenvector
corresponding to the smallest eigenvalue; it is the least-well represented factor
in the data and is not easily estimated by either method.
- ``norm=2`` (L2 norm) approximates the minimization of the sum of squares of
cosines of angular distances. It creates a 3 by 3 matrix of sums of squares of
components of the data vectors. The eigenvectors of this matrix give the mean and
pole locations. This method may be more subject to roundoff errors when there are
thousands of data. The pole is given by the eigenvector corresponding to the
smallest eigenvalue; it is the least-well represented factor in the data and is
not easily estimated by either method.

Comment thread pygmt/src/fitcircle.py
When the data are closely grouped along a great circle both solutions are similar.
If the data have large dispersion, the pole to the great circle will be less well
determined than the mean. Compare both solutions as a qualitative check by calling
:func:`pygmt.fitcircle`twice, once for each ``norm``.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
:func:`pygmt.fitcircle`twice, once for each ``norm``.
:func:`pygmt.fitcircle` twice, once for each ``norm``.

Comment thread pygmt/src/fitcircle.py
circle pole to the small circle (a ``float``, not a tuple)
"""
if norm not in {1, 2}:
raise GMTValueError(norm, description="norm", choices={1, 2})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
raise GMTValueError(norm, description="norm", choices={1, 2})
raise GMTValueError(norm, description="norm", choices=[1, 2])

Comment thread pygmt/src/fitcircle.py
Comment on lines +78 to +82
small_circle
Attempt to fit a small circle instead of a great circle. The pole will be
constrained to lie on the great circle connecting the pole of the best-fit great
circle and the mean location of the data. Optionally set the desired fixed
latitude of the small circle [Default will determine the optimal latitude].

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
small_circle
Attempt to fit a small circle instead of a great circle. The pole will be
constrained to lie on the great circle connecting the pole of the best-fit great
circle and the mean location of the data. Optionally set the desired fixed
latitude of the small circle [Default will determine the optimal latitude].
small_circle
Attempt to fit a small circle instead of a great circle. The pole will be
constrained to lie on the great circle connecting the pole of the best-fit great
circle and the mean location of the data. If ``True``, the latitude of the small
circle is determined automatically. Alternatively, pass a float to fix the
latitude of the small circle to that value. [Default is ``False``, i.e., fit a
great circle.]

Comment thread pygmt/src/fitcircle.py

- ``"small_circle_pole"``: the small circle pole
- ``"small_circle_distance"``: the colatitude/distance in degrees from the small
circle pole to the small circle (a ``float``, not a tuple)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add an inline example for it?

@willschlitzer

Copy link
Copy Markdown
Contributor Author

I'm guessing this branch is too old and out of date, given the length review process. Probably makes more sense for a fresh start.

@seisman

seisman commented Sep 18, 2026

Copy link
Copy Markdown
Member

I think this PR is very close to final. Starting a new PR doesn't help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Brand new feature needs review This PR has higher priority and needs review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants