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

rise/transit/set times calculation #140

Closed
valeriy-sokoloff opened this issue Mar 8, 2025 · 8 comments · Fixed by #141 or #142
Closed

rise/transit/set times calculation #140

valeriy-sokoloff opened this issue Mar 8, 2025 · 8 comments · Fixed by #141 or #142
Assignees
Labels
bug Something isn't working
Milestone

Comments

@valeriy-sokoloff
Copy link

Hi! I'm trying to compute the Moon and Sun rise, transit, and set times for a given date and location: example-riseset.c

$ ./example-riseset -0.833 SUN
'SUN' observed from lon = -73.920, lat = 40.730:
 will rise above  -0.8 degrees at  : 2025-08-20T10:16:48.868Z
 will transit at                   : 2025-08-20T17:04:33.411Z
 will set below  -0.8 degrees at   : 2025-08-20T23:51:36.179Z
$ ./example-riseset -0.833 MOON
'MOON' observed from lon = -73.920, lat = 40.730:
 will rise above  -0.8 degrees at  : 2025-08-20T06:58:31.859Z
 will transit at                   : 2025-08-20T14:56:18.920Z
 will set below  -0.8 degrees at   : 2025-08-20T22:43:35.827Z

At first glance, the results look good. However, when I compared them with data from USNO and imcee.fr - used as "sources of trust" - I noticed a discrepancy:

example usno imcee
sun rise 10:16:48 10:11 10:12
sun transit 17:04:33 16:59 16:59
sun set 23:51:36 23:46 23:45
moon rise 06:58:31 06:53 06:55
moon transit 14:56:18 14:51 14:51
moon set 22:43:35 22:38 22:37

The produced output appears to be about 5 minutes later than USNO/imcee.

I also tested different locations and dates, with and without built-in refraction calculations, using custom refraction calculations, and with dynamic elevation angle calculations. The discrepancy remains, up to +7 minutes.

It seems like there might be an underlying bug in supernovas.
Could you please check and confirm this, or let me know if I’m just missing something?

SuperNOVAS v.1.3.0-rc4
CSPICE V.N0067
@attipaci attipaci added the bug Something isn't working label Mar 8, 2025
@attipaci attipaci linked a pull request Mar 8, 2025 that will close this issue
@attipaci
Copy link
Collaborator

attipaci commented Mar 8, 2025

Hi @valeriy-sokoloff,

Thanks for your bug report. I'm embarrassed to say, but indeed, I did not check the calculation carefully enough myself, since as you said, it looked good at first glance. So, thanks for doing a more careful check to uncover a real issue. :-)

I did find a badly placed bracket, which seems to be the culprit. I checked the Sun with DE440s (calceph) after the fix, and the transit times now match USNO. The rise/set times also match for -0.833 deg elevation. Please check PR #141 yourself, and let me know if it looks good to you too, or if there is more to it still...

I'm really glad you caught this bug in the development stage, before the 1.3 release.

cheers,

-- Attila

@attipaci
Copy link
Collaborator

attipaci commented Mar 8, 2025

PS. I also noticed that I made a mistake of using the refraction (degrees) with the wrong unit (arcseconds), which effectively meant that the refraction did not factor in much in the calculation. Also corrected in PR #141.

Now the -0.8 degrees makes more sense also. The standard optical refraction is 0.585 deg on the horizon, and if you define 'rise' for the Sun when the first light from the disk (0.26 deg radius) becomes visible, then the center of the unrefracted Sun is actually 0.845 deg below horizon. After the fixes, you should therefore check for -0.26 deg elevation to compare with USNO if using the standard refraction or -0.845 degrees if not using refraction...

@attipaci attipaci added this to the 1.3.0 milestone Mar 8, 2025
@attipaci attipaci self-assigned this Mar 8, 2025
@attipaci
Copy link
Collaborator

attipaci commented Mar 8, 2025

The modified example-rise-set.c for the Sun with DE440s and calceph:

 ./example-rise-set -0.26
'SUN' observed from lon = 7.098, lat = 50.737:
 will rise above  -0.3 degrees at  : 2025-03-09T05:57:53.936Z
 will transit at                   : 2025-03-09T11:42:02.549Z
 will set below  -0.3 degrees at   : 2025-03-09T17:27:06.470Z

And from USNO for same date and location:

      Date         Begin      Rise  Az.   Transit Alt.    Set  Az.     End
     (Zone)        Civil                                              Civil  
                  Twilight                                           Twilight
                     h  m     h  m   °      h  m  °       h  m   °      h  m
2025 Mar 09 (Sun)   05:26    05:58  96     11:42 35S     17:27 264     17:59      

I think this confirms both fixes (the misplaced bracket, and the poorly applied refraction)...

@attipaci attipaci pinned this issue Mar 8, 2025
@valeriy-sokoloff
Copy link
Author

Super, thank you! The same results for example-rise-set.c with de440s and cspice.

However, if you change the observation date slightly into the future,

novas_set_time(NOVAS_UTC, novas_date("2025-08-19T00:00:00Z"), LEAP_SECONDS, DUT1, &obs_time)

the result is:

'SUN' observed from lon = 7.098, lat = 50.737:
 will rise above  -0.3 degrees at  : 2025-08-19T04:29:06.319Z
 will transit at                   : 2025-08-19T11:39:07.920Z
 will set below  -0.3 degrees at   : 2025-08-19T18:48:05.965Z

And from USNO for same date and location:

      Date         Begin      Rise  Az.   Transit Alt.    Set  Az.     End
     (Zone)        Civil                                              Civil  
                  Twilight                                           Twilight
                     h  m     h  m   °      h  m  °       h  m   °      h  m
2025 Aug 19 (Tue)   03:50    04:26  69     11:35 52S     18:44 291     19:20      

@valeriy-sokoloff
Copy link
Author

valeriy-sokoloff commented Mar 8, 2025

Also, if you change the body to the Moon and the location, it now fails to calculate some events when using novas_standard_refraction:

make_planet(NOVAS_MOON, &source)
make_observer_on_surface(40.73, -73.92, 60.0, 0.0, 0.0, &ob
novas_set_time(NOVAS_UTC, novas_date("2025-08-20T00:00:00Z"), LEAP_SECONDS, DUT1, &obs_time)
./example-rise-set -0.26
'MOON' observed from lon = -73.920, lat = 40.730:
 will rise above  -0.3 degrees at  : 2025-08-20T06:56:47.049Z
 will transit at                   : 2025-08-20T14:54:59.436Z

  ERROR! novas_cross_el_time: failed to converge [=> 0]
       @ novas_sets_below [=> NAN]
 will not set below  -0.3 degrees

even though it theoretically should:

      Date               Rise  Az.       Transit Alt.       Set  Az.
     (Zone)  
                          h  m   °         h  m  °          h  m   °                 
2025 Aug 20 (Wed)        06:53  54        14:51 74S        22:38 302                           

@attipaci
Copy link
Collaborator

attipaci commented Mar 8, 2025

Yes, that's not good. I'll keep looking into it until we sort it out properly...

@attipaci attipaci reopened this Mar 8, 2025
@attipaci
Copy link
Collaborator

attipaci commented Mar 8, 2025

All right. It looks like the iterative approach for Solar-system bodies was a bit misconstrued also. I think it's fixed in PR #142. For your date and location it gives:

./example-rise-set -0.26
'SUN' observed from lon = -73.920, lat = 40.730:
 will rise above  -0.3 degrees at  : 2025-08-20T10:11:11.835Z
 will transit at                   : 2025-08-20T16:58:58.265Z
 will set below  -0.3 degrees at   : 2025-08-20T23:46:02.893Z

vs USNO's:

              Location:  W 73°55'12.0", N40°43'48.0",     0m               
                 (Longitude referred to Greenwich meridian)                  
     
                            Time Zone: Greenwich                             
     
      Date         Begin      Rise  Az.   Transit Alt.    Set  Az.     End
     (Zone)        Civil                                              Civil  
                  Twilight                                           Twilight
                     h  m     h  m   °      h  m  °       h  m   °      h  m
2025 Aug 20 (Wed)   09:42    10:11  73     16:59 61S     23:46 287     00:16    

@attipaci attipaci linked a pull request Mar 8, 2025 that will close this issue
attipaci added a commit that referenced this issue Mar 9, 2025
attipaci added a commit that referenced this issue Mar 9, 2025
* Fix iterative method for Solar-system rise/set/transit

* Update CHANGELOG for fixed issue #140

* Edits to inline comments

* Additional API doc notes for rise/set times
@attipaci
Copy link
Collaborator

attipaci commented Mar 9, 2025

Hi @valeriy-sokoloff. I merged #142. Thanks again for your efforts.

attipaci added a commit that referenced this issue Mar 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants