question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Handling EphemerisRangeError when observing a minor planet with missing data

See original GitHub issue

On running the test below:

#!/usr/bin/env python3

import datetime, io, skyfield.api, skyfield.constants, skyfield.data.mpc

print( "Skyfield:", skyfield.__version__ )

# Download and save  
# https://minorplanetcenter.net/iau/Ephemerides/Distant/Soft00Distant.txt
# and adjust the date to the download date.
now = datetime.datetime.strptime( "2020-09-16", "%Y-%m-%d" )

latitude = -33
longitude = 151
timeScale = skyfield.api.load.timescale( builtin = True )
t = timeScale.utc( now.year, now.month, now.day, now.hour, now.minute, now.second )
topos = skyfield.api.Topos( latitude_degrees = latitude, longitude_degrees = longitude )
ephemeris = skyfield.api.load( "de421.bsp" )
sun = ephemeris[ "sun" ]
earth = ephemeris[ "earth" ]
with open( "Soft00Distant.txt" ) as f:
   for line in f:
       with io.BytesIO( line.encode() ) as f:
           dataframe = skyfield.data.mpc.load_mpcorb_dataframe( f ).set_index( "designation", drop = False )
           name = line[ 166 : 194 ].strip()
           if "2012 DR30" in name:
               body = sun + skyfield.data.mpc.mpcorb_orbit( dataframe.loc[ name ], timeScale, skyfield.constants.GM_SUN_Pitjeva_2005_km3_s2 )
               ra, dec, sunBodyDistance = sun.at( t ).observe( body ).radec()
               ra, dec, earthBodyDistance = ( earth + topos ).at( t ).observe( body ).radec()

I get the following:

skyfield.errors.EphemerisRangeError: ephemeris segment only covers dates 1899-07-28 23:59:18Z through 2053-10-08 23:58:51Z UT

which occurs during both the sun and earth observation.

On looking at the downloaded data, there is a piece of data missing from one field when compared to lines before/after. I presume this missing field is causing the exception. Is this is something that should/could be handled within Skyfield, or rather I just wrap a try/except around the code?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Bernmeistercommented, Sep 17, 2020

I didn’t realise that the file could be loaded into a dataframe in one go. Yes, I’ve found that comets and minor planets run an order of magnitude or two slower than PyEphem (and was going to post about a little later on). My use case is in two parts: first I download the MPC data files (one for comets and four for minor planets). For each file, I remove a comet/minor planet if it exceeds (apparent) magnitude of 15. I then write out a binary blob file containing what’s left. Secondly I use the binary blob on each update of my software loop to read in this much smaller subset.

I presume what you have written above in the code sample (open the text file and load into dataframe) is what you refer to speeding things up, then I’ll have a go at using that. Much appreciated!

0reactions
brandon-rhodescommented, Nov 21, 2020

@Bernmeister — Thanks for following up! I have updated the docs to describe filtering the dataframe to remove invalid orbits, and hopefully any users who miss that advice will be led here or to the docs when they search for the exception name.

Oh, and, for the record, I believe that this line — which is missing its semimajor axis — was the culprit from Soft00Distant.txt:

K12D30R  7.1   0.15 K194R   0.04515  195.57163  341.47709   77.98645  0.9909325  0.00001530                MPO434970   209   8 2000-2014 0.26 M-v 38h MPC        0000         2012 DR30
Read more comments on GitHub >

github_iconTop Results From Across the Web

Ephemerides for numbered minor planets - Astrometrica
The ephemerides supplied are unperturbed. Ephemerides from perturbed orbit solutions are generated from elements at the nearest 200-day epoch. The accuracy of ...
Read more >
Getting started - Astroquery - Read the Docs
This is an Astroquery wrapper for querying services at the IAU Minor Planet Center (MPC). Three services are available: Minor Planet Center Web...
Read more >
ephemerides: Topics by WorldWideScience.org
We present here examples of ephemerides for the Sun, the Moon, planets and ... for data evaluation in real-time and post-processing the method...
Read more >
Untitled
The EPHEMERIS kernel type (SPK) contains spacecraft and planet, satellite or other target body ephemeris data that provide position and velocity of a ......
Read more >
Accuracy of positional CCD observations of numbered minor ...
-Petersburg. They are receiving these data for an improving of orbital asteroid system published in their annual book “Ephemerides of Minor Planets”. Our ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found