skyfielders / python-skyfield

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

Unable to import most .bsp files from NAIF without full url #147

Closed JoshPaterson closed 6 years ago

JoshPaterson commented 6 years ago

The NAIF has many ephemerides available for natural satellites of other planets:

https://naif.jpl.nasa.gov/pub/naif/generic_kernels/spk/satellites/

However the loader is unable to find most of them, for example:

load('nep086.bsp')

gives this error:

OSError: cannot get ftp://ssd.jpl.nasa.gov/pub/eph/planets/bsp/nep086.bsp because <urlopen error 
ftp error: URLError("ftp error: error_perm('550 Failed to change directory.',)",)>

This is because nep086.bsp does not exist at the JPL site, and load should be looking for it at the NAIF site instead. I believe the only file from NAIF that loads properly is jup310.bsp, due to these lines:

https://github.com/skyfielders/python-skyfield/blob/b9b346572127e8473f5fbf838325a3f0de91d613/skyfield/iokit.py#L93-L95

It is possible to get around this by using the full url like this:

load(r'https://naif.jpl.nasa.gov/pub/naif/generic_kernels/spk/satellites/nep086.bsp')

I also noticed there's no mention of these ephemerides in the documentation. If you're interested I can add a description of these to the docs and make a pull request.

ghost commented 6 years ago

Oddly, ftp://ssd.jpl.nasa.gov/pub/eph/satellites/bsp/ (which is not the same as the 'planets' URL above) has ephemerides for some satellites for some planets, but not all. I vaguely remember an earlier issue (perhaps not skyfield specifically) re NASA being inconsistent w/ where they keep BSP files, and removing them and moving them around sometimes.

There was even talk of creating a mirror to help with this issue and also to allow access from proxies (see https://github.com/skyfielders/python-skyfield/issues/94 for a similar, but different, issue)

brandon-rhodes commented 6 years ago

@JoshPaterson I think going ahead and using the Skyfield documentation as a master list of .bsp sources sounds good, since I've not found another page anywhere that seems to catalog them all (though both of you, please feel free to Google around in case one exists) — so, I'll welcome a pull request!

I'm not sure, though, whether we should be expanding iokit.py to automatically know the URL of every bsp file out there, like nep086.bsp, or whether instead we should be encouraging users to use full URLs. What do y'all think?

JoshPaterson commented 6 years ago

I'll put together a pull request then!

I think encouraging the use of more full URL's is a good idea, but I also think it would be good to keep automatic loading of the most common files. A clean place to draw the line would be to only automatically load files from ftp://ssd.jpl.nasa.gov/pub/eph/planets/bsp/, which are all of the de*.bsp files. The fact that issue #145 is only coming up now implies that planetary satellite ephemerides and other ephemerides available from elsewhere are not very commonly used.

If someone were to request a file that couldn't be found a good error message would then be: "only files from ftp://ssd.jpl.nasa.gov/pub/eph/planets/bsp/ can be automatically found, use a full url instead, see the documentation for information about sources"

EricDuminil commented 6 years ago

Hello! What should be modified? The code, the documentation, both? I could write a pull request if it's clear what should be done. The code in the first paragraph of README doesn't work anymore, which is too bad because it is the first contact many devs will have with the project.

brandon-rhodes commented 6 years ago

@EricDuminil I'd love to fix the code in the README! Could you paste in the error that you're getting? Starting in a directory without the bsp file present, it gives then when I run it:

[#################################] 100% de421.bsp
20h 09m 16.99s
-22deg 09' 14.8"
0.725472 au

I'll be interested to see what error you're encountering instead, thanks!

EricDuminil commented 6 years ago

I'm really sorry about this false alarm. Somehow, many NASA links are blocked by proxy at work (why???). The error was: OSError: cannot get ftp://ssd.jpl.nasa.gov/pub/eph/planets/bsp/de421.bsp because <urlopen error ftp error: ConnectionRefusedError(111, 'Connection refused')> but it worked fine in other networks. Thanks for this useful project!

brandon-rhodes commented 6 years ago

Interesting, I wonder why your work dislikes FTP so much! Thanks for digging a bit deeper.