Repository navigation
Add optional time field to Saver - #352
Open
physicalfleet-dev-team wants to merge 1 commit into
Open
physicalfleet-dev-team wants to merge 1 commit into
physicalfleet-dev-team wants to merge 1 commit into
Conversation
Saver can now record the time of every saved state in `t`: * save(t) stores the given time. * Saver(kf, dt=...) advances the time by dt on every save(), starting at t0 (the time of the state saved by save_current). An explicit save(t) resets the clock. Without either, nothing changes. Mixing timed and untimed saves, or a filter attribute named 't', raises a ValueError instead of producing a `t` list that does not line up with the other attributes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Hi Roger! 👋
This adds the optional time field to
Saverthat you sketched in #231, so a saved history can be plotted or analyzed against time without keeping a parallel list by hand.How to use it
Details
save(t)storestas given.Saver(kf, dt=..., t0=0.)advances the time bydton eachsave().t0is the time of the state saved bysave_current=True, so withsave_currentthe times aret0, t0+dt, .... An explicitsave(t)resets the clock, and latersave()calls continue from it (handy after a gap in the measurements).saver.t/saver['t']like any other saved attribute, andto_array()converts them too.tnordt, nothing changes: notkey is added. I deliberately didn't pick up the filter's owndtautomatically. Otherwise every existingSaverof a g-h, fading-memory or ensemble filter would suddenly grow atentry.taligned with the other lists, mixing timed and untimed saves raises aValueError. So does saving a time from an object that already has an attribute namedt(the message suggestsignore=['t']). Both checks run before anything is appended, so the Saver stays consistent.dtandt0are keyword-only, so the existing positional signature is unchanged. The Saver's own bookkeeping attributes are named_time_step/_last_timerather than_dt, becausesave()copies the filter's attributes (e.g. the UKF's_dt) into the Saver's__dict__.Tests
New tests in
filterpy/common/tests/test_helpers.py: no time by default, explicit times,dtwith and withoutsave_current/t0, a UKF withdt(its_dtis still saved), an explicit time resetting thedtclock, the consistency errors, and thetname clash. Six of them fail on master, sincesave()takes no argument there.On an M1 Mac, Python 3.12, numpy 2,
uv pip install -e . pytest scipy matplotlib:The one failure,
kalman/tests/test_kf.py::test_steadystate(ValueError: math domain error), also fails on master here.pylint --rcfile=.pylintrc filterpy/common/helpers.pyreports no new messages compared to master.Heads-up: #346 also touches
Saver.save()(the property loop). The two changes are in different parts of the method, so a rebase should be easy whichever lands first.Thanks for filterpy and the book, they taught a lot of us Kalman filtering! 🚀