Repository navigation
Description
Describe the new feature or enhancement
Currently, there is no dedicated way to store details about eye tracking related annotations. Several properties of saccades (e.g., peak velocity, start+end position, ...) and fixations (e.g., avg position) are useful information downstream. (This info can/will hopefully in future be generated by a [to be implemented] ET analysis module or [for now] be read from the Eyelink output file.)
Atm, annotations only allow to store onset, duration, description, (and orig_time) as they need to be generic. So extending Annotations with additional (eye tracking specific) fields is not an option.
For reference: EYE-EEG stores {'latency', 'duration', 'sac_vmax', 'sac_amplitude', 'sac_angle', 'epoch', 'sac_startpos_x', 'sac_startpos_y', 'sac_endpos_x', 'sac_endpos_y'} for saccades and {'latency', 'duration', 'fix_avgpos_x', 'fix_avgpos_y', 'epoch', 'sac_vmax', 'sac_amplitude', 'sac_angle', 'sac_startpos_x', 'sac_startpos_y', 'sac_endpos_x', 'sac_endpos_y'} for fixations (Code).
Describe your proposed implementation
[1] With @dominikwelke, @mscheltienne , @sappelhoff we discussed having a separate structure (probably a dict) that holds the according info and can be indexed with a unique identifier linked to a given annotation object. This identifier could be a hash formed by combining onset, duration, and description.
[2] Ideally, the information can still be linked once the annotations are transferred into events. I guess, the event_dict route could be extended accordingly but have not thought this through or discussed with others.
Describe possible alternatives
As discussed above, extending the Annotation class does not seem a viable alternative.
Alternatively, we can leave it to the user as the metrics can theoretically be calculated from the gaze data on the fly. This, however, seems to be tedious and non-trivial (esp., for parameters like peak velocity).
Additional context
@scott-huberty (and @larsoner ): do you have ideas/opinions regarding this? As you have implemented the bulk of the existing functionality regarding eye tracking data and probably already thought about similar questions. Thx!
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
eioe commentedon Nov 14, 2023
@drammock , just FYI: I'm working on this in the context of the sprint but I don't think I can label it accordingly myself.
agramfort commentedon Nov 14, 2023
eioe commentedon Nov 14, 2023
👍 ahja nice, metadata (which I haven't worked with yet) sound like a viable round for [2] (ie., more detailled info on events).
challenge for raw data remains.
mscheltienne commentedon Nov 14, 2023
In the eyetracking analysis module, I would have functions which computes a given metric for an eyetracking event, e.g.
which takes in input a
Rawobject with the annotations on which the metric must be computed and returns a mapping between the annotation and the metric.And then we can have higher level function/method/objects which will use those metric-computation function automatically and fill e.g. the epochs metadata.
eioe commentedon Nov 14, 2023
looks nice. thx @mscheltienne. However, don't we "waste energy" this way? Normal procedure is that whatever determines where a saccades is, at the same time returns the saccade parameters.
If I understand your approach correctly, we would "recalculate" the parameters for an already determined annotation. Or am I misreading you?
How about an approach like:
which annotates
rawand returns adict[Annotation, SaccParams]?mscheltienne commentedon Nov 14, 2023
I was applying this sentence, implementing analysis functions which compute those metrics, regardless of the eyetracking device.
eioe commentedon Nov 14, 2023
yes, but is in your scenario the
rawwhich is passed tocompute_saccade_velocity()already annotated with gaze events?mscheltienne commentedon Nov 14, 2023
Yes, the events should be present in the
raw, in the form of annotations. Did I misunderstood something here?IMO, those events can come from 2 sources: the reader or from
compute_functionwhich take in input aRawwitheyegazeorpupilchannels.drammock commentedon Nov 14, 2023
Let's try to solve one problem at a time.
I think it is possible to solve (1) first and independently of (2), as long as we bear in mind that the values included in
.edffiles may not be the full set of values we care about. In other words, once we have a storage plan, we can then later decide how we populate that storage in cases where the values aren't coming from the data file.As noted above, metadata dataframes are at present only supported for Epochs objects, and Annotations objects only have 4 fields (onset, duration, description, and channels). So logical options are:
add ability to attach metadata dataframe to Raw. This seems not too bad to implement; I'm imagining some subset of the following columns: [onset_sample/onset_time, n_samples/duration, measure, value], where "measure" would take values like
sacc_peak_velorsacc_onset_angleand "value" is the corresponding numeric value. This would be "long format" data so if each saccade has 3 associated measures then there would be 3 rows for that saccade. The downside to long-format is thatvaluemust either always be float, or be an object-dtype column (which gets messy)... wide-format may be better if we leverage pandas' nullable dtypes for any string or integer columns). The big question in my mind is: if you assume that the metadata dataframe exists as just described, how you envision using that dataframe? Do you need additional helper functions? Does it need to persist when converting Raw to Epochs? Or do you just grab a copy of it and use pandas or seaborn to do whatever derivative computations you want, alongside (but separate from) the raw -> epochs -> evoked analyses?allow Annotations to have arbitrary extra fields. A basic choice is whether we allow top-level extra fields or whether we hide them all one level deep in something like
Annotations.userdataor something like that. This feels like easiest to implement, but harder to use than the metadata dataframe. This plus a helper function likemake_dataframe_from_annotation_userdatamight be good enough, depending on the answers to the intended-usage questions in (1) above.shoe-horn the derived values into the existing Annotation description. This is bad because it requires storing name-value pairs as strings and then parsing them later to get at the numeric values. It also requires either multiple coincident annotations (one for each derived measure) --- which while maybe tractable in code, will be a nightmare to visualize during
raw.plot()--- or a single annotation whose description contains multiple key-value pairs that need to be parsed from strings. This feels both fragile and also a possible security concern if we do the parsing carelessly.scott-huberty commentedon Nov 15, 2023
I think
read_raw_eyelinkdoes parse the aforementioned saccadic metadata from file and stores it in a dataframe, but we only end up extracting the onset and duration for the annotations. Once we figure out(b), we could refactor this code to store that saccadic metadata in the right place.As for
(b)I'm slightly partial to the metadata dataframe proposal. I think if I were to try to use this metadata in an analysis, this method would be a lot easier to work with (for example I could merge my stimulus onset info into the dataframe, and look at amplitude of saccades within 1-second of stimulus onset).My other thought is that annotations have a visualization component, and I don't know how we would visualize a
userdatafield, making the field kind of hidden?Happy to hear others thoughts.
eioe commentedon Nov 15, 2023
@drammock , great summary/battle plan. Thx! 🙏
As @scott-huberty mentioned and as far as I have seen, at present the reading (for
.ascfiles) is already implemented, so we're mostly missing the storage part.Regarding (b):
I agree.
I have not worked much enough with annotations (esp. their visualization) to have a strong opinion here. But I see your concerns. Also, I find
Annotation.userdata.peak_velocitynot very intuitive, tbh, asuserdatacould be anything.tbh, I have some concerns also here:
a) Long format breaks with the logic of 1 row per epoch/event in a metadata DF which is in-place for metadata on
Epochsatm. sure, metadata onRawmay behave differently as there are no epochs, but we can interpret saccades/fixations as events and each of these would immediately have multiple rows in the metadata. At latest when epoching, we'd need to convert metadata to a different (wide) shape to adhere to the existing rule.b) Related to a), I interpret the matter in a way that a saccade/fixation has a series of properties which define (
onset_time,duration) and characterize (e.g.,peak_velocity,pos_start_x, ...) it. This structure would be represented in the long format DF i a way as well, as the "grouping"/indexing would be done via [onset_time,duration]. However, would we want to add the information which kind of event it is (saccade or fixation)? Or is it good enough that this can be inferred from the types of values present (i.e., it's a fixation iffix_avgpos_x) is present?Let me sketch the use cases which I have in mind:
[1] Fixation related potentials (FRP) dependent on fixation target:
I want to epoch my data to fixation onsets and then compare ERPs in epochs in which a
facewas fixated vs fixations on acar. The data stems from a free viewing experiment in which people were exploring a given scene. Positions of faces and cars in the scene are given as (x,y) tuples (same coord system as my ET data). So I'd want to filter my Annotations for those with.description == "fixation"and then further identify those for whichany([dist(('fix_avgpos_x', 'fix_avgpos_y'), loc] < size_face for loc in face_locations]. Likewise for cars. Then I can easily convert these into events and use these for epoching.[2] Plot FRP as a function of the size of the incoming saccade:
I'd want to epoch using all events/annotations with
.description == "fixation"and then somehow be able to access for each of these epochssac_amplitude(which, in the logic of EYE-EEG, see above) refers to the previous saccade.[3] use gaze event properties to discard independetly epoched data:
I epoch my data using stimulus onset events, and then want to discard all trials for which there was a saccade with an amplitude larger than
sacc_thresholdwithin the first second. (I think, this is somewhat close to what @scott-huberty described). If I do the epoching first (and somehow the gaze event data is passed along), there could now also be multiple saccade "events" within my epoch.Just putting this out for thought.
I'm digging a bit deeper into the existing functionality/logic of
metadatafor now, to have a better grasp how much it could be of help for these scenarios.eioe commentedon Nov 15, 2023
update:
after discussing this with @britta-wstnr and @mscheltienne , here's the current state of affairs:
[for the sake of simplicity, I will just write about saccades, but the same ofc applies to fixations and potentially blinks and other events maybe even unrelated to eye data.]
If saccade info lives in
raw.metadataor even in a separate object it is challenging to make sure that it stays linked/synced with the according annotation object (i.e., in case of resampling, data rejection, ...). This challenge does not exist, when the data lives on the annotation object which needs to be handled/updated by MNE anyways.We therefore converged towards option "2." as of in @drammock 's post above, that is to store the data in a custom structure, hidden under
.userdata(or so) on the annotations object.This structure
when epoching the data (either by using saccade events or other events) the saccade info can be passed along to the Epochs by making use of the existing functionalities for
metadata. For this, however, we will have to make sure how to pass along the info fromannotation.userdatato the event based logic.Any input/opinions from @drammock or @larsoner are welcome.
@britta-wstnr & @mscheltienne pls feel free to comment if I forgot or misunderstood something from our discussion.
I'm off for lunch now and would afterwards start working on a PR suggesting the introduction of
.userdataon annotations.Sidenote: @mscheltienne mentioned that we should introduce a "locking" feature/flag for annotations which makes sure that these annotations cannot be (accidentally) moved manually be the user. This also applies to saccade annotations which should never be moved manually. Definitely a separate issue though.
7 remaining items
eioe commentedon Nov 15, 2023
Thx @drammock for the summary of our discussion earlier today. I've just seen this now (🙈) after we talked and slightly changed plans again.
Here's roughly the new idea:
Some thoughts:
eioe commentedon Nov 16, 2023
@hoechenberger
I think, one reason that speaks against this is that different annotations may have different fields in their metadata (or no metadata at all) which would make
Annotations._dfa pretty sparse DF.eioe commentedon Nov 16, 2023
ok, here's another update.
After a loooong discussion with @britta-wstnr and @wmvanvliet , we decided (? ehehe) that adding
._metadatato annotations might at the end not be the route to go. (Mostly bc of concerns that users will get tempted to start stuffing other things into this field which will lead to bad things esp bc annotations are written to.fif.)The new idea is to use a private
._idattribute on each annotation which has a unique identifier that can be used to link the annotation to metadata which lives in a separate object.Here's an examplary workflow:
(for this to work, you need to checkout my latest changes made in #12213 811d387
which implements the
._idattribute.)Output:
eioe commentedon Nov 16, 2023
@drammock uf you have a sec to give this a look, that'd be great. Esp if the
._idroute is something that you can envision and is something worth pursuing tomorrow. Thx!drammock commentedon Nov 16, 2023
@eioe and I just had another chat about this. Here's my position after that:
sacc_peak_velin order to end up with only saccade rows.Annotationsinstance that assigns new (numeric?) identifiers to each annotation "span" that gets added to it.Things to think about:
please feel free to raise objections or point out problems that I'm missing.
eioe commentedon Nov 17, 2023
thx @drammock
as discussed, aesthetically unpleasant, but fine for me. Will also reduce redundancy in code (which might be more important then a densly filled DF). On it.
However, I plead for a different name than
metadataas this is used in BIDS already for other info (BIDS metadata). IMO, consistency withEpochs.metadatadoes not justify inconsistency with BIDS. Open for opinions.How do people feel about
EyeEvents?Agree. That's why I suggested
uuid, which is independent of the other attributes.That's also true for the
uuidthough. Enough of a reason to reject it?Yea, I thought about that and also @britta-wstnr had suggested that, as the numbers are smaller.
Downsides that I see:
Annotationsobjects hand out the same identifier to different spans. The link between a specificmetadataobject and anAnnotationobject does not need to be exclusive. MultipleAnnotationsinstances could point to the samemetadata. Then, however, they need to use different_ids. (Also in the case where an annotation is created which does not have anymetadata. Or shall it not get an._idthen?) How do they know about each other? Possible, but a bit cumbersome.annotationsobjects: withuuids we can just append their_idattributes. With numeric_ids we need to implement logic which makes sure that there are no duplicates and handle the according cases. Does that then mean also to update one of the associatedmetadataobjects? Do we always need to check whether anAnnotationobject has associated metadata when merging it with another one?_ids truely outweigh its challenges in comparison touuidss?eioe commentedon Nov 17, 2023
I did now skim read the according PR. And I do not think that is something we need to worry much in the context which we are discussing here. The kind of
metadatawe have in mind for now (saccade, fixation properties, ...) would either count asderivativesorsourcedatain the BIDS language and therefore not underlie the conventiones of the BEP/new standard. Therefore, there also doe not seem to be (much/any) talk about how to name the properties. I think this is nothing that should restrict us here. Also confirmed by @sappelhoff .Yea, this will be controversial. I think this boils down to how much the object that we are talking about is
metadatawhich is clearly associated with a givenRaw(or derivedEpochs) or how much it is its own entity which can be linked (in parts) to other objects but also has a meaning on its own. To be fair though, the only use case that comes to my mind at the moment: One might want to calculate/plot the main sequence (or other saccadic/fixational behavioral properties) also from data which has been rejected for EEG analyses. I do not have a hard opinion on this point. Just, if we want to keep annotations and metadata in sync, this needs to be realized and there is no obvious way in sight for this as the Annotations do not have a pointer to the metadata (if we are doing this via._id). In this regard in bring us back to questions in my last post.hoechenberger commentedon Nov 17, 2023
Hi, I'm for consistency within MNE, and here "metadata" (which is a super generic term anyway) has a different meaning than in BIDS. If we were talking about MNE-BIDS I would support your proposal for choosing a different name, but for MNE, "metadata" is the logical choice in my opinion
mscheltienne commentedon Nov 17, 2023
+1 for
metadataas well.eioe commentedon Nov 17, 2023
ok, another lively discussion and pivot. 🤭 Main participants this time @britta-wstnr @drammock @larsoner .
Conclusions:
Annotationsdict(orNone), each with keys of kindstrand values of kindstr,float, orNone(enforced as this makes sure we do not have problems writting it to disk)annotation_data_to_dataframe()function which allows to extract these data in an easy fashionOpen questions:
dataas it is shorter thanmetadataand its content actually is not very "meta". As of writing this, I started to likedetailsa bit more (which only came to my mind afterwards) as I think it's a better description of what it is.@propertyand we're using a setter? And/or aset_data(dict)method?Noneor{}?Opinions on any of the points welcome. Otherwise, I'll make a decision and take opinions on the PR.
scott-huberty commentedon Nov 17, 2023
We should probably use
Nonebecasue{}is mutable, which can cause hard to debug.. bugs!drammock commentedon Nov 17, 2023
@propertywon't be enough here to enforce key and value restrictions:Upon init of the Annotations object we can validate whatever is passed in
Annotations(..., data=list_of_dicts)but once it exists we can't stop users from adding whatever keys/values they want. So at minimum we will need aset_data()method and to document that users shouldn't directly modify it. But I worry that they'll notice it's a dict and just do it anyway. So that means either:dictthat overrides__setitem__to first do key/value validation and only then set the value, orI just briefly chatted with @larsoner and we're both OK with either approach. I slightly prefer approach 1.
eioe commentedon Nov 17, 2023
Thx for pointing this out. If I was to build an authoritarian regime I would not want to do it using python.
Option 1. sounds good.