EEG-ExPy icon indicating copy to clipboard operation
EEG-ExPy copied to clipboard

Implement ExperimentSpec to reduce redundancy

Open ErikBjare opened this issue 5 years ago • 1 comments

A lot of the code/experiments needs access to static information such as:

  • device name
  • experiment name
  • subject id
  • session id
  • data directory
  • record duration

It would probably be a good idea to add a dataclass for this, that'll be easier to pass around without having to repeat the same set of arguments every time.

The idea would be that once you've constructed a ExperimentSpec, you can:

  • Run the experiment: expspec.run()
  • Get an EEG instance: expspec.device (generated from input arguments at initialization)
  • Generate a savefile: expspec.generate_output_file() (see #74)
  • Write new experiments by simply having their present functions accept the single argument spec which contains all metadata possibly needed by the experiment.

Essentially:

@dataclass
class ExperimentSpec:
    device_name: str
    experiment_name: str
    subject_id: int
    session_id: int
    device_options: dict = field(default_factory=dict, ...)

    def __post_init__(self):
        self.device = EEG(self.device_name, **self.device_options)

    def run() -> None:
        ...

    def get_output_file() -> Path: 
        ...

ErikBjare avatar Dec 23 '20 15:12 ErikBjare

This can maybe be implemented with a simple configuration files instead of starting a whole new dataclass but perhaps being able to do things like expspec.run() might be useful so I will play around with this.

JadinTredup avatar Mar 19 '21 14:03 JadinTredup