skyfielders / python-skyfield

Elegant astronomy for Python
MIT License
1.41k stars 211 forks source link

Topocentric coordinates does not working as in example #254

Closed DonSelester closed 5 years ago

DonSelester commented 5 years ago

I was tried to do calculates based on topocentric coordinates, but example code: boston = earth + Topos('42.3583 N', '71.0636 W') throws an error "TypeError: please provide either latitude_degrees= or latitude= with north being positive"

So I decided to put float coordinates: place = earth + Topos(latitude_degrees=42.3583, longitude_degrees=71.0636) and It works but I think It gives me an incorrectly calculated Altitude degrees, or maybe I checking wrong ones

brandon-rhodes commented 5 years ago

To address a problem with Altitude, I would need a small Python script that produces the output that concerns you, and a suggestion as to what the script should be printing instead; then I'll have something to investigate.

Interestingly, I can't reproduce your TypeError. That line of code works fine if run on my computer. What version of Skyfield are you using — maybe that could be a difference?

DonSelester commented 5 years ago

To address a problem with Altitude, I would need a small Python script that produces the output that concerns you, and a suggestion as to what the script should be printing instead; then I'll have something to investigate.

Interestingly, I can't reproduce your TypeError. That line of code works fine if run on my computer. What version of Skyfield are you using — maybe that could be a difference?

First of all, I'm using Python 2.7. Skyfield 1.10 and Django 1.11.20. And here is my function:

ts = api.load.timescale() e = api.load('de421.bsp') def planets_pos():     t = ts.now()     earth = e['earth']     boston = earth + Topos('42.3583 N', '71.0636 W') # Not working     #boston = earth + Topos(latitude_degrees=42.3583, longitude_degrees=71.0636) # Works     od = {'sun': e['sun'], 'moon': e['moon'], 'mercury': e['mercury'], 'venus': e['venus'], 'mars': e['MARS BARYCENTER']}     info = {}     i = 0     for key, value in od.iteritems():         astronometric = boston.at(t).observe(value)         ra, dec, distance = astronometric.apparent().radec()         alt, az, d = astronometric.apparent().altaz()         info[i] = { 'name': key, 'alt': alt.dstr(), 'az': az.dstr(), 'd': d, 'ra': ra, 'dec': dec, }         i = i + 1

Interesting thing is when I tried to run same code in Interpreter, It didn't gave me an error. Maybe it's Django problem...

DonSelester commented 5 years ago

And here is a site where I was checking computed result: https://www.astro.com/horoscope

brandon-rhodes commented 5 years ago

Thanks for providing some code! Reducing your script to a simplest possible case (and adding in an "import" that I think got left out of your cut and paste), I get no error when I run:

from skyfield import api
api.Topos('42.3583 N', '71.0636 W')

I'm not sure how Django would affect Skyfield's interface either way. If this little two-line script gives you an error, I'd be interested in seeing the full traceback so that I could try to figure out how your copy of Python ran into a problem with it.

To address the altitude question, I'll need something a bit more specific than a link to a web site: I'll need a script that prints a number — try using a specific time, not now() since a script that uses now() will give a different number each time it's run — and an idea of what number you wished it had printed. Only that way will I know exactly what you're seeing on your screen, and exactly what value you want instead. Otherwise I would have to guess at how you're using the web site and what number you saw when you did — so I've learned over the years to ask for exactly the number you want, to make sure my answer addresses exactly what you're seeing. Thanks!

DonSelester commented 5 years ago

Thanks for reply. Here is the traceback: Traceback:

File "D:\DjangoEnv's\hrvin\lib\site-packages\django\core\handlers\exception.py" in inner 41. response = get_response(request)

File "D:\DjangoEnv's\hrvin\lib\site-packages\django\core\handlers\base.py" in _legacy_get_response 249. response = self._get_response(request)

File "D:\DjangoEnv's\hrvin\lib\site-packages\django\core\handlers\base.py" in _get_response 187. response = self.process_exception_by_middleware(e, request)

File "D:\DjangoEnv's\hrvin\lib\site-packages\django\core\handlers\base.py" in _get_response 185. response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "C:\Users\user\Projects\hrvin\accounts\views.py" in skyfield_test 549. info, time, earth = planets_pos(latitude, longitude)

File "C:\Users\user\Projects\hrvin\accounts\calculates.py" in planets_pos 693. boston = earth + Topos('42.3583 N', '71.0636 W')

File "D:\DjangoEnv's\hrvin\lib\site-packages\skyfield\toposlib.py" in __init__ 36. raise TypeError('please provide either latitude_degrees=<float>'

Exception Type: TypeError at /skyfield_test/ Exception Value: please provide either latitude_degrees=<float> or latitude=<skyfield.units.Angle object> with north being positive

And I've remake code and bound it to a specific time:

from skyfield import api from skyfield.api import Topos from skyfield.api import utc from datetime import datetime

ts = api.load.timescale() e = api.load('de421.bsp') day = datetime(2019, 1, 1, 10, 0, tzinfo=utc) t = ts.utc(day) earth = e['earth'] #boston = earth + Topos('42.3583 N', '71.0636 W') boston = earth + Topos(latitude_degrees=42.3583, longitude_degrees=-71.0636) astronometric = boston.at(t).observe(e['MARS BARYCENTER']) alt, az, d = astronometric.apparent().altaz()

I'm waiting for something like this on a given date 0°21′34″ but in altitude It gives me -47deg 49' 07.9". So I don't know or I looking for some other argument or I doing something wrong. And one more thing, I ran this code in a python command line with this: boston = earth + Topos('42.3583 N', '71.0636 W') and computed altitude was -47deg 49' similar to what I get in django with this: boston = earth + Topos(latitude_degrees=42.3583, longitude_degrees=-71.0636)

Maybe I need other argument? I don't clearly know what is this 0°21′34″ but I need to get it. In general, I need to find the position of the planet, depending on the location, so I thought Altitude is what I need. Thanks!

brandon-rhodes commented 5 years ago

Thank you, this working script with stable output is perfect!

The exception is befuddling. The test right above it in the code is isinstance(latitude, (str, float, tuple)) which I would have thought would have returned True for a str object like '42.3583 N'. The only thing I can think of you trying is editing your copy of Skyfield — edit toposlib.py and add a new line as the first line of __init__(): print(type(latitude)). That should show us what the type of latitude is, since it must not be str?

I am not sure what 0°21′34″ is either, and I am not sure how to tell what value that is. It's clearly an angle, and a fairly small one (less than one degree?), but I'm not sure how to go about guessing what coordinate it could be — how does the web site you're using describe it?

DonSelester commented 5 years ago

Thanks for response! Since the results is correct I think I don't need to make changes in a lib, I'll use float values instead of string.

According to web sites I'm using, I guess I need to find in what constellation is the planet and its transit coordinates at a specific moment. Is there a way to make it? Thanks.

GammaSagittarii commented 5 years ago

@DonSelester what you need for astrology is ecliptic longitude, please change alt, az, d = astronometric.apparent().altaz() to: lat, lon, d = astronometric.apparent().ecliptic_latlon(epoch='date') What you need will be lon. Obviously you will have to do more work to get "signs" because skyfield is astronomy library not an astrology one.

DonSelester commented 5 years ago

@GammaSagittarii Thank you for help, ecliptic longitude is really seems like what I need. According to web sites where I'm checking, the coordinates is right but degrees is not. They are looks too big up to 360 degrees, but I guess they should be up to ~ 30 degrees. What it can be? Thanks!

GammaSagittarii commented 5 years ago

@DonSelester This an astronomy library issue tracker. Its purpose is reporting issues, with the library itself. This is not an astronomy or astrology forum. You are obviously trying to do some sort of website clone of astro.com but at the same time are too lazy to learn just the basics pertaining to the subject. Flying blind and being a help vampire will get you nowhere.

@brandon-rhodes Maybe we should add some sort of basics in the docs for astrology because we keep getting these "serious" issue reports, but on the other hand if we do that - than we will get even more questions and feature requests. I think it is better to add something along the line "WARNING for wannabe astrology software makers please learn the basics of astronomy and astrology coordinate systems before reporting issues".

There is a great video on the subject of too good docs https://www.youtube.com/watch?v=imrBnf94E78

DonSelester commented 5 years ago

@GammaSagittarii Yes, I am a little lost the main goal of the problem. Now I know that Topos gives the correct result, so I can continue work. Anyway I appreciate your help, thanks for paying attention!