brandon-rhodes / pyephem

Scientific-grade astronomy routines for Python
Other
766 stars 121 forks source link

Rise/set times not taking account of observer elevation #102

Closed mattiaverga closed 8 years ago

mattiaverga commented 8 years ago

I'm experiencing with Python and PyEphem, while playing I wrote this simple script:

import ephem

citta = ephem.Observer()
sole = ephem.Sun()
citta.temp = 20
citta.pressure = 1013
citta.lat = "46:00.0"
citta.lon = "09:09.0"
citta.elevation = 0

citta.date = "2016/2/13"

print(citta)
for giorno in range(1,10):
    alba = citta.next_rising(sole)
    mezzogiorno = citta.next_transit(sole)
    tramonto = citta.next_setting(sole)
    print('%s %s %s' % (alba, mezzogiorno, tramonto))
    citta.date += 1

While comparing results with other softwares I realized that changing citta.elevation value doesn't change rise and set times.

brandon-rhodes commented 8 years ago

Please provide the values for rise and set times that the other software is providing when you change elevation there, and also the values that PyEphem is providing — otherwise, we cannot guess what difference you are seeing or where it might come from.

mattiaverga commented 8 years ago

Here are the results of pyephem script I wrote at two different altitudes for the same observer. As you can notice, changing the altitude doesn't change rise/set times:

$ python2 altezza.py 
<ephem.Observer date='2016/2/13 00:00:00' epoch='2000/1/1 12:00:00' lon=9:09:00.0 lat=46:00:00.0 elevation=0.0m horizon=0:00:00.0 temp=20.0C pressure=1013.0mBar>
2016/2/13 06:29:56 2016/2/13 11:37:36 2016/2/13 16:45:55
2016/2/14 06:28:25 2016/2/14 11:37:35 2016/2/14 16:47:23
2016/2/15 06:26:52 2016/2/15 11:37:33 2016/2/15 16:48:52
2016/2/16 06:25:18 2016/2/16 11:37:29 2016/2/16 16:50:20
2016/2/17 06:23:43 2016/2/17 11:37:26 2016/2/17 16:51:49
2016/2/18 06:22:06 2016/2/18 11:37:21 2016/2/18 16:53:17
2016/2/19 06:20:29 2016/2/19 11:37:16 2016/2/19 16:54:44
2016/2/20 06:18:50 2016/2/20 11:37:10 2016/2/20 16:56:12
2016/2/21 06:17:10 2016/2/21 11:37:04 2016/2/21 16:57:39

$ python2 altezza.py 
<ephem.Observer date='2016/2/13 00:00:00' epoch='2000/1/1 12:00:00' lon=9:09:00.0 lat=46:00:00.0 elevation=1000.0m horizon=0:00:00.0 temp=20.0C pressure=1013.0mBar>
2016/2/13 06:29:56 2016/2/13 11:37:36 2016/2/13 16:45:55
2016/2/14 06:28:25 2016/2/14 11:37:35 2016/2/14 16:47:23
2016/2/15 06:26:52 2016/2/15 11:37:33 2016/2/15 16:48:52
2016/2/16 06:25:18 2016/2/16 11:37:29 2016/2/16 16:50:20
2016/2/17 06:23:43 2016/2/17 11:37:26 2016/2/17 16:51:49
2016/2/18 06:22:06 2016/2/18 11:37:21 2016/2/18 16:53:17
2016/2/19 06:20:29 2016/2/19 11:37:16 2016/2/19 16:54:44
2016/2/20 06:18:50 2016/2/20 11:37:10 2016/2/20 16:56:12
2016/2/21 06:17:10 2016/2/21 11:37:04 2016/2/21 16:57:39

These are the results from Skychart for the same observer settings (with times in local time). They are slightly different also because Skychart takes into account umidity and temperature decay in the troposphere, but as you can notice, changing altitude also change rise/set times:

0mt;"Longitudine=09°09'00""Est";"Latitudine=+46°00'00""";Fuso Orario=CET
Sole;Data Coord.;;
8h46m UT;Sorge;Transito;Tramonta
2016-02-13;07h30m40s;12h37m38s;17h45m13s
2016-02-14;07h29m09s;12h37m36s;17h46m42s
2016-02-15;07h27m36s;12h37m34s;17h48m11s
2016-02-16;07h26m02s;12h37m31s;17h49m40s
2016-02-17;07h24m27s;12h37m27s;17h51m08s
2016-02-18;07h22m50s;12h37m23s;17h52m36s
2016-02-19;07h21m12s;12h37m18s;17h54m04s

1000mt;"Longitudine=09°09'00""Est";"Latitudine=+46°00'00""";Fuso Orario=CET
Sole;Data Coord.;;
8h47m UT;Sorge;Transito;Tramonta
2016-02-14;07h23m08s;12h37m36s;17h52m44s
2016-02-15;07h21m36s;12h37m34s;17h54m12s
2016-02-16;07h20m03s;12h37m31s;17h55m39s
2016-02-17;07h18m28s;12h37m27s;17h57m07s
2016-02-18;07h16m53s;12h37m23s;17h58m34s
2016-02-19;07h15m16s;12h37m18s;18h00m01s
``
ghost commented 8 years ago

As noted in https://github.com/brandon-rhodes/pyephem/issues/33 correcting for altitude may actually be a bad idea, unless we're talking about altitude above surrounding terrain (which is something else entirely). I am "working on" (as in doing nothing on) a project re how the derivative of altitude (local terrain altitude changes) affect sunrise/sunset: https://github.com/barrycarter/bcapps/tree/master/DEM

brandon-rhodes commented 8 years ago

Since the purpose of PyEphem is to allow Python scripts to get at the same numbers and results as users of the XEphem graphical astronomy program, and since XEphem does not appear to change its rise and set results with elevation, I am not planning on changing PyEphem in this particular instance to match results that you might be getting from other astronomy libraries — because it would be at the expense of PyEphem’s central claim that it provides Python script access to the same results people get with XEphem.

If you are interested in a library that does not operate under that constraint, please check out Skyfield, and feel free to open an issue at its GitHub repository about any poor behaviors that you find:

https://github.com/skyfielders/python-skyfield

Since it is rewritten from the ground up in Python, and does not claim to give the same exact results as any other particular product, I have the freedom over there to implement separate behaviors from those that XEphem users have gotten used to over the years.

Thanks again for the additional comment that helped me understand the results you were seeing!