Fix trajectory_predict_skypos mutating input array #790
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
trajectory_predict_skypos
is meant to predict the positions of a KBMOD trajectory along a list or array of observation times, however it mutates the observation times if they are provided as a numpy array rather than a list.It calls
dt = np.asarray(times)
which creates a new numpy array iftimes
is a list or is a no-op if it is an array. We then subtract out the starting timestamp so all times are offset from 0, and we use the in-place operation ofdt -= dt[0]
to preserve memory. However iftimes
is an array, the original object passed to the array has been mutated to now be offset by 0.As quickly illustrated in a python repl:
This PR fixes this by choosing not to do the in-place subtraction.
To add better testing for this, we a) use tests with non-zero observation times to actually test the subtraction and b) test both lists and numpy arrays as inputs.
Note that this was showing up as an issue with the
KnownObjMatcher
having its numpy array of observation times mutated by the call totrajectory_predict_skypos
. Then when it tries to compare the observation times against times from an ephemeris, a match cannot be made due to the temporal subtraction.