# Mapping image files from MWorks to BrainIO

**URL:** <https://mworks.discourse.group/t/mapping-image-files-from-mworks-to-brainio/826>\
**Category:** Support\
**Created:** [September 1, 2022, 9:49pm UTC](https://mworks.discourse.group/t/mapping-image-files-from-mworks-to-brainio/826 "2022-09-01T21:49:30Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jjpr-mit](https://avatars.discourse-cdn.com/v4/letter/j/e5b9ba/32.png) [@jjpr-mit](https://mworks.discourse.group/u/jjpr-mit)\
**Post date:** [September 1, 2022, 9:49pm UTC](https://mworks.discourse.group/t/mapping-image-files-from-mworks-to-brainio/826/1 "2022-09-01T21:49:30Z")

</div>

Hi Chris,

I’m automating the process by which we translate spike times to PSTH and package them as BrainIO Data Assemblies. I need to label each stimulus presentation event with the stimulus ID of the image file within the associated BrainIO Stimulus Set. I’ve already got a mapping from presentation event to “stimulus\_presented” from the .mwk2 file, so all I need to figure out now is how to map from “stimulus\_presented” in the .mwk2 to “stimulus\_id” in the BrainIO Stimulus Set.

I’m able to use the mwel Python package from the MWorks repo to parse a .mwel file and get an AST, so that’s convenient.

I’m looking at a few example experiments, trying to write something that will work on any of them. In the Oasis900 experiment, I’ve found the “stimulus\_group” in the associated .mwel file. It contains a “range\_replicator” which contains an “image\_file” which acts as a template for the group. To get each file name, it does substitution of a variable called “RSVP\_stim\_counter” which is the counter defined by the range\_replicator. If the counter defined by the range\_replicator corresponds to stimulus\_presented in the .mwk2 file, this is pretty straightforward, because the file names match the ones in the Oasis900 BrainIO Stimulus Set and that completes the mapping.

However, in the Objectome experiment, the file names used in the Stimulus Set don’t match the ones in the .mwel. So using RSVP\_stim\_counter doesn’t generalize.

Do you know how “stimulus\_presented” in the .mwk2 file gets populated? Is that done by the MWorks application, or does it come from user input?

Thanks,

JJPR

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [September 6, 2022, 2:10pm UTC](https://mworks.discourse.group/t/mapping-image-files-from-mworks-to-brainio/826/2 "2022-09-06T14:10:54Z")

</div>



---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [September 6, 2022, 2:43pm UTC](https://mworks.discourse.group/t/mapping-image-files-from-mworks-to-brainio/826/3 "2022-09-06T14:43:21Z")

</div>

Hi Jon,

There’s no built-in variable named “stimulus\_presented”. That must be defined by the particular experiment(s) you’re looking at, so I can’t say when and how it’s being set.

The usual way to get info about stimulus presentations is to extract the variable [#stimDisplayUpdate](https://mworks.github.io/documentation/latest/reference/sysvars.html#stimdisplayupdate) from the event file. The value of that variable is a list of dictionaries, where each dictionary contains the tag and properties of a stimulus that was on screen during that display update. For image file stimuli, the dictionary contains a `filename` key, whose value is the full path of the image file loaded by MWorks, and a `file_hash` key, whose value is the SHA-1 hash of the image file ([more info](https://mworks.discourse.group/t/using-the-file-hash-to-verify-an-image-stimulus/49)). If the filenames used when running the experiment don’t match those in your database, the file hash should provide a way to create a mapping between the two.

Does that answer your question? Apologies if I misunderstood: This is my first day back at work after three weeks of vacation, and my brain isn’t back up to speed yet 🙂

Cheers,  
Chris

---

<div class="post-metadata">

**Author:** ![jjpr-mit](https://avatars.discourse-cdn.com/v4/letter/j/e5b9ba/32.png) [@jjpr-mit](https://mworks.discourse.group/u/jjpr-mit)\
**Post date:** [September 6, 2022, 5:20pm UTC](https://mworks.discourse.group/t/mapping-image-files-from-mworks-to-brainio/826/4 "2022-09-06T17:20:42Z")

</div>

OMG that is fantastic! I’ve got code for extracting info from MWorks .mwk2 files here:

[https://github.com/dicarlolab/brainio-dicarlo/blob/main/brainio\_dicarlo/pipeline/utils/mworks.py](https://github.com/dicarlolab/brainio-dicarlo/blob/main/brainio_dicarlo/pipeline/utils/mworks.py)

It’s mostly based on Sachi’s code and the example code you provided in the doc. It includes the slightly modified version of the MWK2Reader class I told you about. Knowing this, I can extract much more information to attach as metadata on our packaged data assemblies. Having the SHA-1 alone will make things feasible that haven’t been.

Thanks!

JJPR

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [September 7, 2022, 12:43pm UTC](https://mworks.discourse.group/t/mapping-image-files-from-mworks-to-brainio/826/5 "2022-09-07T12:43:43Z")

</div>

> [@Jonathan\_Prescott-Ro](#):
>
> I’ve got code for extracting info from MWorks .mwk2 files here

Thanks, I’ll check it out!

Chris

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [September 12, 2022, 1:36pm UTC](https://mworks.discourse.group/t/mapping-image-files-from-mworks-to-brainio/826/6 "2022-09-12T13:36:41Z")

</div>



---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [September 12, 2022, 1:37pm UTC](https://mworks.discourse.group/t/mapping-image-files-from-mworks-to-brainio/826/7 "2022-09-12T13:37:00Z")

</div>


