Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update octagon.py #320

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions aeon/schema/octagon.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ def draw_background(pattern):
def gratings_slice_onset(pattern):
return {"GratingsSliceOnset": _reader.Harp(f"{pattern}_12_*", columns=["wall_id"])}

@staticmethod
def checkerboard_slice_onset(pattern):
return {"CheckerboardSliceOnset": _reader.Harp(f"{pattern}_14_*", columns=["wall_id"])}
Comment on lines +130 to +132
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

The new method checkerboard_slice_onset is almost identical to the existing method gratings_slice_onset. This violates the DRY (Don't Repeat Yourself) principle. You can refactor these methods into a single method that takes an additional parameter for the stimulus type. Here's a suggested change:

-    @staticmethod
-    def gratings_slice_onset(pattern):
-        return {"GratingsSliceOnset": _reader.Harp(f"{pattern}_12_*", columns=["wall_id"])}
-
-    @staticmethod
-    def checkerboard_slice_onset(pattern):
-        return {"CheckerboardSliceOnset": _reader.Harp(f"{pattern}_14_*", columns=["wall_id"])}

+    @staticmethod
+    def slice_onset(stimulus_type, pattern):
+        if stimulus_type == "Gratings":
+            return {f"{stimulus_type}SliceOnset": _reader.Harp(f"{pattern}_12_*", columns=["wall_id"])}
+        elif stimulus_type == "Checkerboard":
+            return {f"{stimulus_type}SliceOnset": _reader.Harp(f"{pattern}_14_*", columns=["wall_id"])}
+        else:
+            raise ValueError("Invalid stimulus type")

This way, you can add more stimulus types in the future without adding more methods.



class Wall:
@staticmethod
Expand Down
Loading