diff --git a/jplephem/exceptions.py b/jplephem/exceptions.py new file mode 100644 index 0000000..68073dc --- /dev/null +++ b/jplephem/exceptions.py @@ -0,0 +1,20 @@ +"""A set of special exceptions that can be thrown by the jplephem library""" + +class OutOfRangeTimestampError(ValueError): + """ + This exception is thrown if any input times are out of the range of + times jplephem can compute ephemeris for. + It has for properties: + + - `message` is a string explaining what happened, + - `min_timestamp` and `max_timestamp` are floats giving the minimum and + maximum supported times, + - `out_of_range_times` is an array of booleans where `True` means the + corresponding date in the input array is out of range and `False` means + it is correct. + """ + def __init__(self, message, min_timestamp, max_timestamp, out_of_range_times): + self.message = message + self.min_timestamp = min_timestamp + self.max_timestamp = max_timestamp + self.out_of_range_times = out_of_range_times diff --git a/jplephem/spk.py b/jplephem/spk.py index 4a635a3..8d27040 100644 --- a/jplephem/spk.py +++ b/jplephem/spk.py @@ -6,6 +6,7 @@ http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/FORTRAN/req/spk.html from numpy import array, empty, empty_like, interp, rollaxis from .daf import DAF from .descriptorlib import reify +from .exceptions import OutOfRangeTimestampError from .names import target_names T0 = 2451545.0 @@ -227,8 +228,13 @@ class Segment(BaseSegment): if (index < 0).any() or (index > n).any(): final_epoch = init + intlen * n - raise ValueError('segment only covers dates %.1f through %.1f' - % (init, final_epoch)) + raise OutOfRangeTimestampError( + 'segment only covers dates %.1f through %.1f' % (init, + final_epoch), + min_timestamp=init, + max_timestamp=final_epoch, + out_of_range_times=[True if i < 0 or i > n else False + for i in index]) omegas = (index == n) index[omegas] -= 1