Repository navigation
Make coordinates.solar_system_ephemeris accept local ephemeris file - #8767
Conversation
|
Thanks! Need to add test(s) and a change log. |
Codecov Report
@@ Coverage Diff @@
## master #8767 +/- ##
==========================================
- Coverage 86.96% 86.95% -0.01%
==========================================
Files 400 400
Lines 59448 59451 +3
Branches 1100 1100
==========================================
+ Hits 51697 51698 +1
- Misses 7110 7112 +2
Partials 641 641
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #8767 +/- ##
==========================================
+ Coverage 86.96% 86.97% +0.01%
==========================================
Files 400 400
Lines 59454 59456 +2
Branches 1100 1100
==========================================
+ Hits 51703 51714 +11
+ Misses 7110 7101 -9
Partials 641 641
Continue to review full report at Codecov.
|
|
Also before merge, the commits need to be squashed to get rid of the "merge commit" message. Please do not use |
I must admit I have no idea about how to do this... Running those two commands doesn't seem to change anything...??? |
|
@rhandberg , I apologize for the confusion. Full commands are documented at http://docs.astropy.org/en/latest/development/workflow/development_workflow.html#how-to-rebase |
|
@rhandberg - once you have done the merge commit, the rebase keeps it in place, but one could get rid of it by doing |
|
@rhandberg - the actual PR looks good! But we do need a test! (in Ideally, the test would use a tiny ephemeris file, but I don't know if such a thing exists (or is easy to create). Alternatively, since we download Easier, but no less importantly, could you add an entry in I wondered about adding something to the general documentation, but think that is not necessary: people should just look at the docstring you already changed. That said, for reasons I'm not sure about, |
Would astropy.utils.data.get_cached_urls help? Or theoretically astropy.utils.data.download_file will grab the cached version, if available. astropy/astropy/coordinates/solar_system.py Lines 155 to 157 in de39336 astropy/astropy/coordinates/solar_system.py Line 172 in de39336 So, to clarify further, theoretically, you could do this (unless >>> from astropy.utils.data import download_file, get_cached_urls
>>> # The URL is just example, replace with the URL you desire
>>> get_cached_urls()
['http://data.astropy.org/l1448/l1448_13co.fits', ...]
>>> # No actual download would happen in this line below
>>> file_path = download_file('http://data.astropy.org/l1448/l1448_13co.fits', cache=True)
>>> file_path
'C:\\Users\\...\\.astropy\\cache\\download\\py3\\somehashvalue' |
Have to use os.path.isfile, because urlparse does not fail on Windows paths
|
What do you think of the following test? It should test the loading of ephemeris using URLs and file paths and that they give the same result. @pytest.mark.remote_data
@pytest.mark.skipif('not HAS_JPLEPHEM')
@pytest.mark.parametrize('time', (Time('1960-01-12 00:00'),
Time('1980-03-25 00:00'),
Time('2010-10-13 00:00')))
def test_url_or_file_ephemeris(time):
# URL for ephemeris de432s used for testing:
url = 'http://naif.jpl.nasa.gov/pub/naif/generic_kernels/spk/planets/de432s.bsp'
# Pass the ephemeris directly as a URL.
coord_by_url = get_body('earth', time, ephemeris=url)
# Translate the URL to the cached location on the filesystem.
# Since we just used the url above, it should already have been downloaded.
filepath = download_file(url, cache=True)
# Get the coordinates using the file path directly:
coord_by_filepath = get_body('earth', time, ephemeris=filepath)
# Using the URL or filepath should give exactly the same results:
assert_quantity_allclose(coord_by_url.ra, coord_by_filepath.ra)
assert_quantity_allclose(coord_by_url.dec, coord_by_filepath.dec)
assert_quantity_allclose(coord_by_url.distance, coord_by_filepath.distance)Maybe a separate test is needed to check that it throws and error if you provide a non-existing file or URL? |
|
@pllim - thanks, that's just the thing! @rhandberg - test looks excellent! And agreed that a test with a non-existing file would be good to add - given your code, this will also check the bad url path (which of course we know works from your initial issue!). Maybe also a test with an existing file that is not an ephemeris file. |
|
Great! What do you think about this for the second test where we are testing for non-existing URL and file path as well as a file that is not an ephemeris file... Actually I'm just passing the current Python file... @pytest.mark.remote_data
@pytest.mark.skipif('not HAS_JPLEPHEM')
def test_url_or_file_ephemeris_wrong_input():
time = Time('1960-01-12 00:00')
# Try loading a non-existing URL:
with pytest.raises(HTTPError):
get_body('earth', time, ephemeris='http://data.astropy.org/path/to/nonexisting/file.bsp')
# Try loading a non-existing file:
with pytest.raises(ValueError):
get_body('earth', time, ephemeris='/path/to/nonexisting/file.bsp')
# Try loading a file that does exist, but is not an ephemeris file:
with pytest.raises(ValueError):
get_body('earth', time, ephemeris=__file__) |
|
FWIW # Try loading a non-existing URL:
with pytest.raises(HTTPError):
get_body('earth', time, ephemeris='http://data.astropy.org/path/to/nonexisting/file.bsp')can be in its own test function decorated with |
|
@pllim - Very good point! I will split that test into two. |
|
Tests have now been added, but codecov seems to still fail... Looks like it is because the whole |
mhvk
left a comment
There was a problem hiding this comment.
Looks all OK modulo two small items.
| ^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| - Changed ``coordinates.solar_system_ephemeris`` to also accept local files | ||
| as input. The ephemeris can not be selected by either keyword (e.g. 'jpl', |
| value = DEFAULT_JPL_EPHEMERIS | ||
|
|
||
| if value.lower() in ('de430', 'de432s'): | ||
| elif value.lower() in ('de430', 'de432s'): |
There was a problem hiding this comment.
This should remain an if - since DEFAULT_JPL_EPHEMERIS = 'de430'
I guess I never added a test since I didn't want to download an enormous file for every test run...
|
@mhvk - Good catches! Those two issues have been fixed now. |
Make
coordinates.solar_system_ephemerisaccept local ephemeris file as input.New dependency of
os.pathis needed, because tests revealed that standard Windows paths would pass throughurlparsewithout throwing an error. I therefore switched to useos.path.isfileto test if the input was a file path.Fixes #8750