-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
MRG, ENH: Use datetime objects for meas_date #7124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
This is on its way to passing because the bug was already fixed in #7036. I'll re-title and eventually make this into a PR to use datetime objects with meas_date (hopefully). |
Codecov Report
@@ Coverage Diff @@
## master #7124 +/- ##
==========================================
+ Coverage 89.7% 89.71% +0.01%
==========================================
Files 444 444
Lines 78997 79091 +94
Branches 12674 12689 +15
==========================================
+ Hits 70863 70956 +93
- Misses 5320 5322 +2
+ Partials 2814 2813 -1 |
|
FYI I found a bug in Does something bad to the annotation: It's fixed in this PR. And then I noticed that this same code does not produce an annotation in the same place when |
|
Tests pass locally, this is ready for review/merge from my end |
| raw = _raw_annot(None, None) | ||
| assert raw.annotations.orig_time is None | ||
| assert raw.annotations.onset[0] == 0.5 | ||
| assert raw.annotations.onset[0] == 1.5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@agramfort this is the line that should match above
| emit_warning=emit_warning) | ||
| new_annotations.onset -= ( | ||
| meas_date - new_annotations.orig_time).total_seconds() | ||
| new_annotations._orig_time = meas_date |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hopefully simpler
| assert two is not None | ||
| shift = one_n_samples / sfreq # to the right by the number of samples | ||
| shift += one_first_samp / sfreq # to the right by the offset | ||
| shift -= two_first_samp / sfreq # undo its offset |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hopefully simpler
| """Test load brainvision annotations and parse them to events.""" | ||
| sfreq = 1000.0 | ||
| expected_orig_time = 1384359243.794231 | ||
| expected_orig_time = _stamp_to_dt((1384359243, 794232)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do you have all these changes by 1uS ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in principle it should be more accurate now, as it uses round rather than int cast. These values I'm assuming were taken from what was produced by the old code, not necessarily what was most correct.
| events, _ = events_from_annotations(raw) | ||
| latencies = np.sort(events[:, 0]) | ||
| assert_array_equal(latencies, EXPECTED_LATENCIES) | ||
| assert_allclose(latencies, EXPECTED_LATENCIES, atol=1e-6) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above I think, we were operating at the precision limit before. Rather than change all values in EXPECTED_LATENCIES I just made it tolerant of a 1 μs error.
mne/tests/test_annotations.py
Outdated
| assert_allclose(raw.annotations.duration, duration) | ||
| assert_allclose(raw_concat.annotations.duration, duration) | ||
| assert_allclose(raw.annotations.duration, duration, atol=1e-6) | ||
| assert_allclose(raw_concat.annotations.duration, duration, atol=1e-6) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this necessary? do we have a loss of precision with this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one I can push a little fix for
agramfort
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thx @larsoner
feel free to merge when CIs come back green
* TST: Add test for another meas_date * ENH: Use datetime instead of float * FIX: Fwd * FIX: Simplifications * ENH: Add set_meas_date * FIX: Unify treatment of first_samp * FIX: Ref * FIX: Ref * FIX: Closer * FIX: Replicate and fix * Update test_annotations.py * FIX: Tweak duration
* TST: Add test for another meas_date * ENH: Use datetime instead of float * FIX: Fwd * FIX: Simplifications * ENH: Add set_meas_date * FIX: Unify treatment of first_samp * FIX: Ref * FIX: Ref * FIX: Closer * FIX: Replicate and fix * Update test_annotations.py * FIX: Tweak duration


Closes #7116.First step, replicate the failure (hopefully). It passes locally on Linux but hopefully Azure shows the issue.datetime | Noneobjects forinfo['meas_date'].datetime | Noneforraw.annotations.orig_timeset_meas_datethat takes care of annotations and such. The anonymization code can use this / be refactored to use it. It only takesdatetime | Noneas an argument.Extend set_meas_date and/or anonymize functions to kill some of these other dates (such asmeas_id)raw._first_timefromtimestamp)