pointpats icon indicating copy to clipboard operation
pointpats copied to clipboard

Fix angle of rotation in ellipse

Open sjsrey opened this issue 10 months ago • 3 comments

This addresses #151.

I've tested it against the qgis plugin and we now replicate those results. Since that is GPL, I can't include that data in our test suite.

I have updated the tests to use data from Ebdon (1985).

sjsrey avatar Feb 27 '25 16:02 sjsrey

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 74.6%. Comparing base (c4203b6) to head (a7dea23). Report is 4 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##            main    #152     +/-   ##
=======================================
+ Coverage   74.5%   74.6%   +0.1%     
=======================================
  Files         12      12             
  Lines       1904    1912      +8     
=======================================
+ Hits        1419    1427      +8     
  Misses       485     485             
Files with missing lines Coverage Δ
pointpats/centrography.py 83.6% <100.0%> (+0.4%) :arrow_up:
:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov[bot] avatar Feb 27 '25 16:02 codecov[bot]

I note we're now flipping negative theta over the x axis. Just to confirm: was the issue the signed numpy.arctan/numpy.atan2?

We've gotta make sure this is remembered if it's bitten a few of us 😅

ljwolf avatar Feb 27 '25 17:02 ljwolf

I note we're now flipping negative theta over the x axis. Just to confirm: was the issue the signed numpy.arctan/numpy.atan2?

We've gotta make sure this is remembered if it's bitten a few of us 😅

There were two issues:

  • we had been returning the semi-major and semi-minor axes using Levine's arguments (correcting for dof - see below)
  • angle was signed incorrectly when $\tan{\theta} < 0$

So the changes here follow the discussion in Ebdon (1985) pgs 136-140. Specific part where more care had to be taken:

It is also important to note that the angle $\theta$ given by Equation 7.7 is the angle between the transposed y axis and the y axis of the ellipse. The angle is measured clockwise from the transposed y-axis, like a bearing from north on a map. Equation 7.7 can produce a negative value of $\tan{\theta}$. In this case the negative sign is ignored when looking up the angle in tables of tangents, but the angle found from the tables must be subtracted from $90^{\circ}$ in order to give the correct value of $\theta$.

In addition, we have to flip at the end of here: https://github.com/pysal/pointpats/blob/a7dea23ec92c4e586b4031cc61a2c2ac8f67262a/pointpats/centrography.py#L682
to get the right rotation here: https://github.com/pysal/pointpats/blob/a7dea23ec92c4e586b4031cc61a2c2ac8f67262a/pointpats/centrography.py#L691

I swapped in the Ebdon data for testing as for our original test data I couldn't find the source to check against.

We can add more details in the docs once we finalize how we want this implemented.

There are also a couple of extensions we could add to the ellipse:

  • weighted points
  • adjusting for degrees of freedom
  • handling arguments that Levine has made that the implementations of Ebdon and Cromley give axes that are too small by $\sqrt{2}$.
image image

I've added the WIP label so we can flesh all this out.

sjsrey avatar Feb 27 '25 18:02 sjsrey

The enhancements have been added in a new PR #156.

We can close this (unmerged) once that pr is reviewed, and if good, merged.

sjsrey avatar May 12 '25 23:05 sjsrey

This is now integrated into #156

sjsrey avatar May 19 '25 16:05 sjsrey