Skip to content

Commit

Permalink
added centered stimulus
Browse files Browse the repository at this point in the history
  • Loading branch information
Vilim committed Dec 9, 2019
1 parent 3db0915 commit eeb1080
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
31 changes: 15 additions & 16 deletions stytra/stimulation/stimuli/closed_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ class Basic_CL_1D(BackgroundStimulus, InterpolatedStimulus, DynamicStimulus):
"""

def __init__(
self, *args,
base_vel=10,
swimming_threshold=-2,
max_fish_vel=40,
max_interbout_time=None,
**kwargs
self,
*args,
base_vel=10,
swimming_threshold=-2,
max_fish_vel=40,
max_interbout_time=None,
**kwargs
):
super().__init__(*args, **kwargs)
self.name = "general_cl1D"
Expand Down Expand Up @@ -93,7 +94,6 @@ def update(self):
)
self.abort_experiment()


self.get_fish_vel()

# If estimated velocity greater than threshold
Expand Down Expand Up @@ -152,11 +152,9 @@ class CalibratingClosedLoop1D(Basic_CL_1D):
(min, max) values for the final gain to be considered valid
"""

def __init__(self,
target_avg_fish_vel=-15,
calibrate_after=5,
min_bout_n=30,
**kwargs):
def __init__(
self, target_avg_fish_vel=-15, calibrate_after=5, min_bout_n=30, **kwargs
):
super().__init__(**kwargs)
self.name = "calibrating_cl1D"
self.dynamic_parameters.extend(["est_gain", "median_calib"])
Expand Down Expand Up @@ -203,9 +201,11 @@ def bout_ended(self):
self.bout_vel = []

def stop(self):
if len(self.bouts_vig_list) < self.min_bout_n or \
self.est_gain > self.valid_gain_range[1] or \
self.est_gain < self.valid_gain_range[0]:
if (
len(self.bouts_vig_list) < self.min_bout_n
or self.est_gain > self.valid_gain_range[1]
or self.est_gain < self.valid_gain_range[0]
):
self.abort_experiment()

self._experiment.logger.info(
Expand All @@ -214,7 +214,6 @@ def stop(self):
)
)


if len(self.bouts_vig_list) > self.calibrate_after:
self._experiment.logger.info(
"Calibrated! Calculated gain {} with {} bouts".format(
Expand Down
9 changes: 9 additions & 0 deletions stytra/stimulation/stimuli/visual.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,15 @@ def draw_block(self, p, point, w, h):
pass


class CenteredBackgroundStimulus(BackgroundStimulus):
def get_transform(self, w, h, x, y):
return (
QTransform().translate(-w / 2, -h / 2)
* super().get_transform(w, h, x, y)
* QTransform().translate(w / 2, h / 2)
)


class SeamlessImageStimulus(BackgroundStimulus):
""" Displays an image which should tile seamlessly.
Expand Down

0 comments on commit eeb1080

Please sign in to comment.