Trial
Description
Default class defining a trial, which can contain a Sequence instance, and an Audio or AudioDerivative instance.
Initialisation
- class krajjat.classes.trial.Trial(trial_id=None, condition=None, sequence=None, audio=None)
Creates a Trial instance, which can contain a motion sequence and an audio clip.
New in version 2.0.
- Parameters:
trial_id (str|int|None, optional) – The identifier for the trial, which can be a string, an integer or None. If set on None, the initialisation function will try to set the trial ID on the name on the name of the Sequence instance or the name of the Audio instance, in that order. If no sequence nor audio attribute are set, the function will return an Exception, as a trial must have an ID.
condition (str|int|None, optional) – The condition for the Trial instance.
sequence (Sequence|None, optional) – The motion sequence from this trial.
audio (Audio|AudioDerivative|None, optional) – The audio clip (or an AudioDerivative) from this trial.
- trial_id
The identifier of the trial.
- Type:
str|int
- condition
The condition of the trial.
- Type:
str|int|None
- audio
The audio (or an AudioDerivative) of the trial.
- Type:
Audio|AudioDerivative|None
Examples
>>> trial = Trial() >>> sequence = Sequence("sequence_01.xlsx") >>> audio = Audio("audio_01.wav") >>> trial = Trial("001", sequence=sequence, audio=audio)
Magic method
- class krajjat.classes.trial.Trial.__eq__(self, other)
Returns True if the trial IDs, sequence and audio attributes are the same.
New in version 2.0.
- Parameters:
other (Trial) – Another Trial instance.
- Returns:
Whether the Trial instances are equal.
- Return type:
bool
Example
>>> trial_1 = Trial(1, "English", Sequence("sequence_01.mat"), Audio("audio_01.wav")) >>> trial_2 = Trial(1, "English", Sequence("sequence_01.mat"), Audio("audio_01.wav")) >>> trial_1 == trial_2 True >>> trial_3 = Trial(1, "Spanish", Sequence("sequence_01.mat"), Audio("audio_01.wav")) >>> trial_1 == trial_3 True >>> trial_4 = Trial(2, "English", Sequence("sequence_01.mat"), Audio("audio_01.wav")) >>> trial_1 == trial_4 False
Setter functions
- class krajjat.classes.trial.Trial.set_trial_id(self, trial_id)
Ses the identifier of the trial.
New in version 2.0.
Parameter
- trial_id: int|str
A code to identify the trial.
Example
>>> trial = Trial() >>> trial.set_trial_id("R001")
- class krajjat.classes.trial.Trial.set_condition(self, condition)
Sets the condition of the trial.
New in version 2.0.
- Parameters:
condition (str or int) – The condition of the trial.
Example
>>> trial = Trial() >>> trial.set_condition("English")
- class krajjat.classes.trial.Trial.set_sequence(self, sequence)
Sets a Sequence instance in the trial.
New in version 2.0.
- Parameters:
sequence (Sequence) – A Sequence instance.
Example
>>> trial = Trial() >>> trial.set_sequence(Sequence("sequence_01.mat"))
- class krajjat.classes.trial.Trial.set_audio(self, audio)
Sets an Audio instance in the trial.
New in version 2.0.
- Parameters:
audio (Audio|AudioDerivative) – An Audio or AudioDerivative instance.
Example
>>> trial = Trial() >>> trial.set_audio(Audio("audio_01.wav"))
Getter functions
- class krajjat.classes.trial.Trial.get_trial_id(self)
Returns the identifier of the trial.
New in version 2.0.
- Returns:
The value of the
trial_idof the Trial instance.- Return type:
str or int
Examples
>>> trial = Trial(42) >>> trial.get_trial_id() 42 >>> sequence = Sequence(name="trial_01") >>> trial = Trial(sequence=sequence) >>> trial.get_trial_id() trial_01
- class krajjat.classes.trial.Trial.get_condition(self)
Returns the condition of the trial.
New in version 2.0.
- Returns:
The condition of the trial
- Return type:
str, int or None
Examples
>>> trial = Trial() >>> trial.get_condition() None >>> trial = Trial(1, condition="Swedish") >>> trial.get_condition() Swedish
- class krajjat.classes.trial.Trial.get_sequence(self)
Returns the Sequence instance from the trial.
New in version 2.0.
- Returns:
The sequence of the trial.
- Return type:
Example
>>> trial = Trial("108", None, Sequence("sequence_01.xlsx")) >>> trial.get_sequence()
- class krajjat.classes.trial.Trial.get_audio(self)
Returns the Audio instance from the trial.
New in version 2.0.
- Returns:
The audio of the trial.
- Return type:
Example
>>> trial = Trial(audio=Audio("audio_01.wav")) >>> trial.get_audio()
- class krajjat.classes.trial.Trial.get_audio_kind(self)
Returns the attribute
AudioDerivative.kindof theaudioattribute.New in version 2.0.
- Returns:
The kind of the AudioDerivative, either
"Audio","Envelope","Pitch","Intensity", or"Formant"- orNoneif no audio is set.- Return type:
str|None
Examples
>>> trial = Trial(audio=Envelope("envelope.tsv")) >>> trial.get_audio_kind() Envelope >>> trial.set_audio(Intensity("intensity.csv")) >>> trial.get_audio_kind() Intensity
Predicate functions
- class krajjat.classes.trial.Trial.has_sequence(self)
Returns True if a Sequence has been set for the Trial instance.
New in version 2.0.
- Returns:
False if
Trial.sequenceis set on None, True otherwise.- Return type:
bool
Examples
>>> trial = Trial(1) >>> trial.has_sequence() False >>> trial.set_sequence(Sequence("sequence_01.json")) >>> trial.has_sequence() True
- class krajjat.classes.trial.Trial.has_audio(self)
Returns True if an Audio has been set for the Trial instance.
New in version 2.0.
- Returns:
False if
Trial.audiois set on None, True otherwise.- Return type:
bool
Examples
>>> trial = Trial(1) >>> trial.has_audio() False >>> trial.set_audio(audio("audio_01.json")) >>> trial.has_audio() True
- class krajjat.classes.trial.Trial.are_timestamps_equal(self)
Returns True if there are as many data points between the Sequence and the Audio objects, and if their timestamps are the same.
New in version 2.0.
- Returns:
True if the timestamps are the same for the Sequence and the Audio objects.
- Return type:
bool
Example
>>> sequence = Sequence("sequence_01.mat") >>> audio = Audio("audio_01.wav") >>> trial = Trial(1, sequence=sequence, audio=audio) >>> trial.are_timestamps_equal() True