Implemented more informative logging for behavioural test

This commit is contained in:
2019-12-12 12:46:03 +00:00
parent 27d412623d
commit c527f657dc
4 changed files with 32 additions and 19 deletions
+9 -7
View File
@@ -44,6 +44,7 @@ def find_participants(folder='./participant_data/'):
part_key = os.path.basename(path)
participants[part_key] = Participant(participant_dir=path)
participants[part_key].load('info')
participants[part_key].load('parameters')
return participants
def gen_participant_num(participants, N = 100):
@@ -215,13 +216,13 @@ def main():
np.random.shuffle(dtl_copy)
participant_params['decoder_test_lists'] = dtl_copy
# What order are the behavioral test stimuli presented?
participant_params['behavioral_train_lists'] = np.random.choice(
general_params['behavioral_train_lists'],
[general_params['behavioral_train_N']], replace=False)
participant_params['behavioral_test_lists'] = np.random.choice(
general_params['behavioral_test_lists'],
[general_params['behavioral_test_N']], replace=False)
# What order are the behavioural test stimuli presented?
participant_params['behavioural_train_lists'] = np.random.choice(
general_params['behavioural_train_lists'],
[general_params['behavioural_train_N']], replace=False)
participant_params['behavioural_test_lists'] = np.random.choice(
general_params['behavioural_test_lists'],
[general_params['behavioural_test_N']], replace=False)
# What order are the tone SNRs presented at?
n_tone_repeats = general_params['tone_repeats']
@@ -242,6 +243,7 @@ def main():
participants[key] = Participant(participant_dir="./participant_data/{}".format(key),
number=i, parameters=final_params, gen_time=nowtime)
participants[key].save("info")
participants[key].save("parameters")
# Log all parameters of the current participant
for key, val in participants[key].parameters.items():
+2
View File
@@ -14,6 +14,8 @@ socketio = config.socketio
server_lock = Lock()
logger = logging.getLogger(__name__)
logging.getLogger('matplotlib.font_manager').disabled = True
logging.getLogger('matplotlib').setLevel(logging.WARNING)
def url_ok(url, port):
+20 -12
View File
@@ -79,17 +79,18 @@ class MatTestThread(BaseThread):
self.listDir = listFolder
self.participant = participant
self.participant_parameters = self.participant.data['parameters']
if mode == "familiarisation":
self.inds = self.participant_parameters['behavioural_training_lists']
logger.info("Running participant_{self.participant.data['number']}, familiarisation")
elif mode == "testing":
self.participant_parameters = self.participant.parameters
if mode.lower() == "familiarisation":
self.inds = self.participant_parameters['behavioural_train_lists']
logger.info(f"Running participant_{self.participant.data['info']['number']}, familiarisation")
elif mode.lower() == "testing":
self.inds = self.participant_parameters['behavioural_test_lists']
logger.info("Running participant_{self.participant.data['number']}, testing")
logger.info(f"Running participant_{self.participant.data['info']['number']}, testing")
else:
raise ValueError(f"{mode} is not a valid mode value")
self.adaptiveTracks = [AdaptiveTrack(x, red_coef, cal_coef) for x in track_targets]
self.adaptiveTracks = [AdaptiveTrack(x, red_coef, cal_coef, snr=self.participant_parameters['behavioural_init_snr']) for x in track_targets]
logger.info(f"{len(self.adaptiveTracks)} adaptive tracks initialised with initial SNRs: {[x.snr for x in self.adaptiveTracks]}")
self.trackOrder = []
track_targets = np.array(self.participant.data['parameters']['behavioural_track_targets'])/100.
@@ -167,6 +168,7 @@ class MatTestThread(BaseThread):
self.displayInstructions()
self.waitForPartReady()
while not self.finishTest and not self._stopevent.isSet() and len(self.availableSentenceInds) and len(self.trackOrder):
# Plot SNR of current trial to the clinician screen
for at in self.adaptiveTracks:
@@ -184,6 +186,11 @@ class MatTestThread(BaseThread):
# Define words presented in the current trial
self.currentWords = self.listsString[0][currentSentenceInd]
logger.info("-"*78)
logger.info("{0:<25}".format("Current trial:") + f"{' '.join(self.currentWords)}")
logger.info("{0:<25}".format("Current track index:") + f"{self.adTrInd}")
logger.info("{0:<25}".format("Current trial number:") + f"{self.trialN}")
logger.info("{0:<25}".format("Current SNR:") + f"{self.adaptiveTracks[self.adTrInd].snr}")
self.playStimulus(self.y, self.fs)
self.waitForResponse()
self.checkSentencesAvailable()
@@ -191,14 +198,17 @@ class MatTestThread(BaseThread):
break
if self._stopevent.isSet():
return
logger.info("{0:<25}".format("N correct responses:") + f"{int(self.nCorrect*5)}")
self.adaptiveTracks[self.adTrInd].calcSNR(self.nCorrect)
self.checkSentencesAvailable()
self.saveState(out=self.backupFilepath)
self.trialN += 1
self.adaptiveTracks[self.adTrInd].incrementTrialN()
self.saveState(out=self.backupFilepath)
logger.info("-"*78)
if not self._stopevent.isSet():
self.unsetPageLoaded()
logger.info("Behavioural test complete")
self.socketio.emit('processing-complete', {'data': ''}, namespace='/main')
self.waitForPageLoad()
# Plot SNR of current trial to the clinician screen
@@ -375,8 +385,6 @@ class MatTestThread(BaseThread):
self.adaptiveTracks[ind].setNoise(noise, noise_rms)
def submitMatResponse(self, msg):
'''
Get and store participant response for current trial
@@ -434,15 +442,15 @@ class MatTestThread(BaseThread):
class AdaptiveTrack():
'''
'''
def __init__(self, target, red_coef, cal_coef):
def __init__(self, target, red_coef, cal_coef, snr=10.0):
'''
'''
self.snr = 10.0
self.snr = snr
self.direction = 0
# Record SNRs presented with each trial of the adaptive track
self.snrTrack = np.empty(180)
self.snrTrack[:] = np.nan
self.snrTrack[0] = 0.0
self.snrTrack[0] = self.snr
# Count number of presented trials
self.trialN = 1
self.reduction_coef = np.load(red_coef)*np.load(cal_coef)
+1
View File
@@ -147,6 +147,7 @@ class BaseThread(Thread):
this function correctly, self.partReady must be set to True via a socketio
handler in order to continue the test.
'''
logger.info("Waiting for participant to continue to test...")
while not self.partReady and not self._stopevent.isSet() and not self.finishTest:
self._stopevent.wait(0.5)
self.partReady = False