Skip to content

Commit

Permalink
Merge branch 'CSNG-MFF:master' into new_Arkheia_export
Browse files Browse the repository at this point in the history
  • Loading branch information
rozsatib authored Sep 12, 2024
2 parents 3181735 + 94263f7 commit 6cd138b
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 2 deletions.
56 changes: 56 additions & 0 deletions mozaik/experiments/vision.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from mozaik.experiments import Experiment
from parameters import ParameterSet
import mozaik.stimuli.vision.topographica_based as topo
import mozaik.stimuli.vision.visual_stimulus as vs
import numpy
from mozaik.stimuli import InternalStimulus
from mozaik.tools.distribution_parametrization import ParameterWithUnitsAndPeriod, MozaikExtendedParameterSet
Expand Down Expand Up @@ -2179,3 +2180,58 @@ def __init__(self, model, parameters):

def do_analysis(self, data_store):
pass


class MeasurePixelMovieFromFile(VisualExperiment):
"""
Present a sequence of images loaded from a directory, in alphabetical order of
image filenames, interleaved by blank stimulation.
Parameters
----------
model : Model
The model on which to execute the experiment.
Other parameters
----------------
duration : float
The duration of single presentation of the stimulus.
movie_path : str
Path to the directory containing the images.
movie_name : str
Name of the directory containing the images.
num_trials : int
Number of trials each each stimulus is shown.
"""

required_parameters = ParameterSet(
{
"duration": float,
"movie_path": str,
"movie_name": str,
"num_trials": int,
}
)
def generate_stimuli(self):
for k in range(0, self.parameters.num_trials):
self.stimuli.append(
vs.PixelMovieFromFile(
frame_duration=self.frame_duration,
movie_path=self.parameters.movie_path,
movie_name=self.parameters.movie_name,
duration=self.parameters.duration,
size_x=self.model.visual_field.size_x,
size_y=self.model.visual_field.size_y,
location_x=0.0,
location_y=0.0,
background_luminance=self.background_luminance,
density=self.density,
trial=k
)
)

def do_analysis(self, data_store):
pass
34 changes: 33 additions & 1 deletion mozaik/stimuli/vision/visual_stimulus.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
from mozaik.tools.units import lux
from scipy.ndimage import interpolation
from collections import OrderedDict

from mozaik.tools.mozaik_parametrized import SNumber, SString, SParameterSet
from mozaik.tools.distribution_parametrization import MozaikExtendedParameterSet
from quantities import Hz, rad, degrees, ms, dimensionless

logger = mozaik.getMozaikLogger()

Expand Down Expand Up @@ -185,3 +187,33 @@ def next_frame(self):
"""For creating movies"""
self.update()
return [self.img]

class PixelMovieFromFile(VisualStimulus):
"""
A visual stimulus that consists of a movie that is loaded from a file, where it is stored as a 3D numpy matrix (npy),
with the first axis the time, and 2nd and 3rd axis the visual field. The individual frames are presented one by one
for the self.frame_duration. The stimulus is assumed to have pixel values in the interval [0,1].
"""

size = SNumber(
degrees, doc="The length of the longer axis of the image in visual degrees"
)

movie_path = SString(doc="Path to the image file.")
movie_name = SString(doc="Name of the image file.")
duration = SNumber(ms, doc="Image + blank screen display duration.")

def __init__(self, **params):
VisualStimulus.__init__(self, **params)

import os
with open(os.path.join(self.movie_path,self.movie_name), 'rb') as f:
self.mc = numpy.load(f)
assert self.mc.shape[1] == self.mc.shape[2], ("The spatial shape of the pixel movie has to be square")
assert ( self.duration == self.frame_duration * len(self.mc)), ("The duration of the total stimulus has to be the number of frames in the movie times the frame duration.")
#assert ( self.mc.shape[1] == self.size_x), ("The size of the image has to match the resolution and size of the simulated visual field [%d vs %d] ." % (self.mc.shape[1],self.size_x))


def frames(self):
for i in range(len(self.mc)):
yield (self.mc[i] * 2 * self.background_luminance, [i])
2 changes: 1 addition & 1 deletion mozaik/visualization/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,7 @@ def __init__(self, datastore, parameters, plot_file_name=None, fig_param=None, f
self.length = None
# currently there is no way to check whether the sensory input is retinal
self.retinal_input = datastore.get_sensory_stimulus()
self.st = datastore.sensory_stimulus.keys()
self.st = list(datastore.sensory_stimulus.keys())

# remove internal stimuli from the list
self.retinal_input = [self.retinal_input[i] for i in range(0,len(self.st)) if MozaikParametrized.idd(self.st[i]).name != 'InternalStimulus']
Expand Down

0 comments on commit 6cd138b

Please sign in to comment.