Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Celestial Navigation Plugin shows incorrect altitude (Hc) on FIND celestial body form #24

Open
rbossert149419 opened this issue Jan 17, 2025 · 19 comments

Comments

@rbossert149419
Copy link

Celestial Navigation Plugin shows Altitude of the Body on the Find celestial body form (as well as Azimuth). Altitude is known as Hc in the Nautical Almanac. The Altitude is wrong on the form. Attached 3 examples show a 3 to 6 minute error which resulted in 3-6 nm error in EP.

Steps to reproduce:
Drop a Mark to your DR location. "Move your Boat" to the Mark (as close as possible). Then enter a sight, select Sun, Planet, or a Star. Enter your sight data. Select the FIND (Find celestial body) button on the site tab. Altitude is incorrect and inconsistent to the Line of Position the plug in Plotted on the chart (Azimuth is correct). On the Celestial Navigation Sights form (shows all the sights), click on the View icon for that sight. The Line of Position plot which relies on Hc, Ho, Azimuth is shown. This plot is correct. The problem appears to be limited to the calculation of Hc using Law of Cosines formula on the FIND form. Attached are 3 examples that illustrate the Find Form Altitude value and the plugin's correct answer. In the examples, the error resulted in a 3-6 NM error in the EP or Fix. You can also confirm the error by Deducing Hc using the Open CPN measurement tool for the distance between the plotted LOP and DR mark (known as intercept). Intercept = Hc - Ho, thus Hc = Intercept + Ho.

Expected behavior
The Altitude should be within .1 minute of a degree compared to Commercial edition of Nautical Almanac using Sight Reduction formula pages 277-283 (attachment includes the Law of Cosines formula). Because of all of the combinations of sin, sin-1, cos, cos-1 going on in Law of Cosines equation, it has been recommended to use 5 decimal accuracy for LHA, DEC, and LAT to get .1 minute precision. Since inputs from Sextant (Hs), and Nautical Almanac daily page (GHA, Dec, SHA) are at 0.1 minute accuracy, Navigators don't expect Hc displayed beyond 0.1 minutes accuracy. Nautical Almanac examples shows Hc decimal degrees at 4 significant digits. I'd suggest 4 significant digits

Screen shots....

Open CPN Altitude calculation error PDF.pdf

OS: problem duplicated for macOS and Windows 10 (I've delayed my upgrade to 11). I believe all platforms have the problem..
plug in Version 2.4.41
Open CPN version 5.10.2

@rgleason
Copy link
Owner

rgleason commented Jan 17, 2025

If we find someone willing and able to fix this, are you available for testing?

This is a great example. thanks.

@rbossert149419
Copy link
Author

rbossert149419 commented Jan 17, 2025 via email

@rgleason
Copy link
Owner

Yes, indeed, please submit them. We need experts such as you! I hope that some old programming sailors who are passionate about sextants and accuracy will focus on improving this tool, as it could become a great resource.

Also if you have any suggestions or improvements to the manual, please advise.

How to get to the manuals from OpenCPN Wiki
https://opencpn.org/wiki/dokuwiki/doku.php?id=opencpn:manual_basic:plugins

Then https://opencpn-manuals.github.io/main/opencpn-plugins/index.html
Under Navigation pick Celestial_Navigation
https://opencpn-manuals.github.io/main/celestial_navigation/index.html

@rgleason
Copy link
Owner

@rbossert149419

Sean Patrick has offered to take a look at the code.
https://www.cruisersforum.com/forums/f134/celestial-navigation-plugin-redux-98748.html#post3967665
Sean Patrick:
If you have any questions about celestial navigation, ask me!
Celestial Navigation Spreadsheet
NavList Celestial Navigation Forum

Bob If you can create a zip file and upload to here it would be very useful!

@rbossert149419
Copy link
Author

rbossert149419 commented Jan 26, 2025 via email

@rgleason
Copy link
Owner

Bob, I sent you a PM on CruiserForum with my email.
I've asked David Burch if he would look at this too.

artisthos on CF has agreed to do testing.

@rgleason
Copy link
Owner

rgleason commented Feb 11, 2025

Bob, would you mind uploading to here the converted "numbers" and the excel spreadsheets that you refer too?

Also I am not so sure OpenCPN handles time in the way you think it might.
I may have to ask sebastien-rossert about that.

It appears that we need to:

  1. Follow the spreadsheet step by step. Spreadsheet mirrors Mees's algorithym
  2. We need to do the missing code for SD and HP.
  3. We also need greater accuracy for certain calcs.
  4. Change the forms to use Hc

I was confused by this first statement "I updated Github with the Code. I also updated the problem description
with some additional information. " Where is this?

@rbossert149419
Copy link
Author

rbossert149419 commented Feb 11, 2025 via email

@rgleason
Copy link
Owner

rgleason commented Feb 11, 2025

Bob, I think we better do that. I've written sebastien-rosset as he is in the process of implementing global time, and he'll probably have some thoughts about this. I will send him your note above. He may chime in here.

@sebastien-rosset

@rbossert149419
Copy link
Author

rbossert149419 commented Feb 11, 2025 via email

@rgleason

This comment has been minimized.

@rbossert149419

This comment has been minimized.

@rbossert149419

This comment has been minimized.

@sebastien-rosset
Copy link

I'm catching up on this thread. Wrt OpenCPN already calculates Julian Date, I'm assuming you meant the OpenCPN celestial navigation plugin. Because AFAIK, OpenCPN core does not deal with JD.

The celestial navigation plugin does work with JD, and it leverages the wxDateTime implementation to convert a timestamp to Julian calendar. For example, here:

double jdu = time.GetJulianDayNumber();

You also mention whether OpenCPN manages time calculations to 9+ significant digits, I would have to look into it, but again, it leverages the wxDateTime struct.

@rgleason
Copy link
Owner

Thank you Sebastien for the clarification. Below are the Hc files Bob has emailed:

Open.CPN.Altitude.calculation.error.Hc.pdf

Hc Altitude Computed rev 0.cpp.txt

Open CPN Intercept calculation.xlsx

@sebastien-rosset
Copy link

sebastien-rosset commented Feb 11, 2025

I was able to reproduce (mostly) the first example in this test: https://github.com/rgleason/celestial_navigation_pi/pull/33/files#diff-538ede6a0b5e101ab74abef50e6f6364e7015154d64c21821f8084e56fc490b5R49

In particular for the given input parameters, I can confirm I see:

Almanac OpenCPN
Ho 11° 30.6’ 11° 30.8’ (11.5131°)
GHA 128° 20.5', Dec: 18° 15.2' S -128° -20.5', Dec: 18° 15.2' S

For the GHA, I see the same results with a different sign.
Here is the test output:

 ctest -V
UpdateCTestConfiguration  from :/Users/serosset/git/celestial_navigation_pi/test/DartConfiguration.tcl
UpdateCTestConfiguration  from :/Users/serosset/git/celestial_navigation_pi/test/DartConfiguration.tcl
Test project /Users/serosset/git/celestial_navigation_pi/test
Constructing a list of tests
Updating test list for fixtures
Added 0 tests to meet fixture requirements
Checking test dependency graph...
Checking test dependency graph end
No tests were found!!!
SEROSSET-M-R8PT:test serosset$ cd bui
SEROSSET-M-R8PT:test serosset$ pwd
/Users/serosset/git/celestial_navigation_pi/test
SEROSSET-M-R8PT:test serosset$ cd ..
SEROSSET-M-R8PT:celestial_navigation_pi serosset$ cd build
SEROSSET-M-R8PT:build serosset$ ctest -V
UpdateCTestConfiguration  from :/Users/serosset/git/celestial_navigation_pi/build/DartConfiguration.tcl
UpdateCTestConfiguration  from :/Users/serosset/git/celestial_navigation_pi/build/DartConfiguration.tcl
Test project /Users/serosset/git/celestial_navigation_pi/build
Constructing a list of tests
Done constructing a list of tests
Updating test list for fixtures
Added 0 tests to meet fixture requirements
Checking test dependency graph...
Checking test dependency graph end
test 1
    Start 1: celestial_tests

1: Test command: /Users/serosset/git/celestial_navigation_pi/build/test/celestial_tests
1: Working Directory: /Users/serosset/git/celestial_navigation_pi/build/test
1: Test timeout computed to be: 10000000
1: Running main() from /tmp/googletest-20240731-4829-u2xmsk/googletest-1.15.2/googletest/src/gtest_main.cc
1: [==========] Running 1 test from 1 test suite.
1: [----------] Global test environment set-up.
1: [----------] 1 test from AltitudeTest
1: [ RUN      ] AltitudeTest.SunLowerLimbExample
1: Using plugin data directory: /Users/serosset/git/celestial_navigation_pi/test/testdata
1: Plugin data directory requested for celestial_navigation_pi, returning: /Users/serosset/git/celestial_navigation_pi/test/testdata
1: Plugin data directory requested for celestial_navigation_pi, returning: /Users/serosset/git/celestial_navigation_pi/test/testdata
1: Plugin data directory requested for celestial_navigation_pi, returning: /Users/serosset/git/celestial_navigation_pi/test/testdata
1: 
1: === Sun Lower Limb Example (Nov 13, 2024) ===
1: Main Correction Analysis:
1:   Almanac: 11.6'
1:   Actual : 5.78594'
1: /Users/serosset/git/celestial_navigation_pi/test/altitude_tests.cpp:95: Failure
1: The difference between actualCorrection and ALMANAC_MAIN_CORRECTION is 0.096901006898011816, which exceeds EPSILON_MIN, where
1: actualCorrection evaluates to 0.096432326435321514,
1: ALMANAC_MAIN_CORRECTION evaluates to 0.19333333333333333, and
1: EPSILON_MIN evaluates to 0.0016666666666666668.
1: Main correction differs from NA by -5.8140604138807088 minutes
1: 
1: 
1: Ho Analysis:
1:   Almanac: 11° 30.6'
1:   Actual : 11° 30.8'
1: /Users/serosset/git/celestial_navigation_pi/test/altitude_tests.cpp:105: Failure
1: The difference between sight.m_ObservedAltitude and ALMANAC_HO is 0.0030989931019878014, which exceeds EPSILON_MIN, where
1: sight.m_ObservedAltitude evaluates to 11.513098993101988,
1: ALMANAC_HO evaluates to 11.51, and
1: EPSILON_MIN evaluates to 0.0016666666666666668.
1: Ho differs from NA by 0.18593958611926809 minutes
1: 
1: Plugin data directory requested for celestial_navigation_pi, returning: /Users/serosset/git/celestial_navigation_pi/test/testdata
1: 
1: Body Position Analysis:
1:   Almanac GHA: 128° 20.5', Dec: 18° 15.2' S
1:   Actual GHA : -128° -20.5', Dec: 18° 15.2' S
1: /Users/serosset/git/celestial_navigation_pi/test/altitude_tests.cpp:121: Failure
1: The difference between gha and ALMANAC_GHA is 256.68261321350474, which exceeds EPSILON_MIN, where
1: gha evaluates to -128.3409465468381,
1: ALMANAC_GHA evaluates to 128.34166666666667, and
1: EPSILON_MIN evaluates to 0.0016666666666666668.
1: GHA differs from Almanac by -15400.956792810284 minutes
1: 
1: 
1: Detailed Calculation String:
1: Almanac Data For Sun
1: Geographical Position (lat, lon) = -18.2537 -128.3409
1: GHAAST = 357 52.4'
1: SHA = 130 28.1'
1: GHA = 128 20.5'
1: Dec = S 18 15.2'
1: SD = 16.2'
1: HP = 0.1'
1: 
1: Formulas used to calculate sight
1: 
1: Index Error is 0.0533 degrees
1: 
1: Eye Height is 2.4000 meters
1: Height Correction Degrees = 1.758*sqrt(2.4000) / 60.0
1: Height Correction Degrees = 0.0454
1: 
1: Apparent Altitude (Ha)
1: ApparentAltitude = Measurement - IndexCorrection - EyeHeightCorrection
1: ApparentAltitude = 11.4167 - 0.0533 - 0.0454
1: ApparentAltitude = 11.3179
1: 
1: Refraction Correction
1: x = tan(Pi/180*ApparentAltitude + 4.848e-2*(Pi/180) / (tan(Pi/180*ApparentAltitude) + .028))
1: x = tan(Pi/180*11.3179 + 4.848e-2*(Pi/180) / (tan(Pi/180*11.3179) + .028))
1: x = 0.2040
1: RefractionCorrection = .267 * Pressure / (x*(Temperature + 273.15)) / 60.0
1: RefractionCorrection = .267 * 1013.0000 / (x*(15.0000 + 273.15)) / 60.0
1: RefractionCorrection = 0.0767
1: 
1: Sun selected, Limb Correction
1: ra = 0.9894, lc = 0.266564/ra = 0.2694
1: Lower Limb
1: LimbCorrection = -0.2694
1: 
1: Corrected Altitude
1: CorrectedAltitude = ApparentAltitude - RefractionCorrection - LimbCorrection
1: CorrectedAltitude = 11.3179 - 0.0767 - -0.2694
1: CorrectedAltitude = 11.5107
1: 
1: Sun selected, parallax correction
1: rad = 0.9894, HP = 0.002442/rad = 0.0025
1: ParallaxCorrection = -180/Pi * asin( sin(Pi/180 * HP ) * cos(Pi/180 * CorrectedAltitude))
1: ParallaxCorrection = -180/Pi * asin( sin(Pi/180 * 0.0025 ) * cos(Pi/180 * 11.5107))
1: ParallaxCorrection = -0.0024
1: 
1: Observed Altitude (Ho)
1: ObservedAltitude = CorrectedAltitude - ParallaxCorrection
1: ObservedAltitude = 11.5107 - -0.0024
1: ObservedAltitude = 11.5131
1: 
1: [  FAILED  ] AltitudeTest.SunLowerLimbExample (145 ms)
1: [----------] 1 test from AltitudeTest (145 ms total)
1: 
1: [----------] Global test environment tear-down
1: [==========] 1 test from 1 test suite ran. (145 ms total)
1: [  PASSED  ] 0 tests.
1: [  FAILED  ] 1 test, listed below:
1: [  FAILED  ] AltitudeTest.SunLowerLimbExample
1: 
1:  1 FAILED TEST
1/1 Test #1: celestial_tests ..................***Failed    0.20 sec

@rgleason
Copy link
Owner

This is great. We will be able to quickly test the plugin as we make improvements. The plugin appears to be failing the standard set right now.

Incidentally, at the bottom of the Manual, I did a series of tests and left this note after hitting "Fix"

  1. Later added more sights and selected the 4 best ones and hit Fix and got about .6nm away.

The altitude & azimuth given with the “FIND” button is without the Parameter’s Tab corrections, so it will not be as accurate as an actual Sight.

@rbossert149419
Copy link
Author

rbossert149419 commented Feb 12, 2025 via email

@sebastien-rosset
Copy link

@rbossert149419 I would like to help you, though realistically I don't think I'll be able to do that in the next several weeks. I'm currently making improvements to the VDR plugin, GRIB plugin and have plans to improve the weather routing plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants