Consult on writing .mwel code

Hey Chris,
I have some basic questions on writing .mwel code that I haven’t been able to answer by going through the docs. If you have the chance, could you point me in the right direction?

I would like to define a stimulus group using the paths of those images on the client machine, without relying on any particular naming convention. In Python, the desired pattern would look like this:

image_paths = ['images/image1.png', 'images/test/image_yellow.png', 'images/random/july/emblem.png']
stimulus_group1 = stimulus_group(image_paths)

My question is if .mwel supports creating these lists of strings, and how to correctly feed it into the stimulus_group keyword.

Our current setup in .mwel is the following, which requires a particular naming convention for the images on disk to work:

stimulus_group images_1 {
    range_replicator (
        from = 0
        to = 99
        step = 1
        variable = rr_index
        ) {
        image_file 'im{$rr_index}' (
            path = 'stimuli/OP_forward_training_pilot/A-B/train/group1/im${rr_index}.png'
            x_size = image_size
            y_size = image_size
            x_position = sample_image_pos_x
            y_position = sample_image_pos_y
            deferred = NO
            )
    }
}

When I am analyzing the data later, I have to remap the recorded sequence of images that were shown (encoded as positional indices of the stimuli) to the actual string paths of the images. I have so far done this by manually keeping track of the string prefixes for each .mwel file, but because we change images frequently, this becomes tedious and is prone to error.

So, I’m thinking it would be easier if we could simply encode the list of images explicitly in the definition of the .mwel file (which also frees us from naming conventions for the images), and we can directly extract this list of image paths from the .mwk file, and directly index into it during data analysis.

Any suggestions would be great! This is just one idea I had; maybe there is another mworks pattern that can solve this problem in an easier way.

Thanks,
Michael

Hi Michael,

Here’s a straightforward way to do what you want:

// Need to declare the "images" directory as a resource in order to use an expression
// for the image stimulus' "path" attribute
resource ('images')

var image_paths = ['images/letters/A.png', 'images/numbers/1-2/1.png', 'images/numbers/3-4/4.png']
var image_size = 10
var sample_image_pos_x = 0
var sample_image_pos_y = 0

var rr_index = 0 (scope = local)

stimulus_group images_1 {
    range_replicator (
        from = 0
        to = size(image_paths) - 1  // End point depends on size of "image_paths" list
        step = 1
        variable = rr_index
        ) {
        image_file 'im${rr_index}' (
            path = image_paths[$rr_index]  // Index in to "image_paths" list
            x_size = image_size
            x_position = sample_image_pos_x
            y_position = sample_image_pos_y
            )
    }
}

If you have any questions, please let me know.

Chris

Thanks Chris.
Michael