Pre-move to big mac commit

This commit is contained in:
2019-01-22 11:36:16 +00:00
parent 41f1348484
commit 2b6be43232
8 changed files with 41 additions and 16 deletions
+7 -3
View File
@@ -9,13 +9,16 @@ import pdb
import matplotlib.pyplot as plt
from pathops import dir_must_exist
from signalops import gen_trigger
import resampy
def gen_da_stim(n, outpath):
da_file = './BioMAP_da-40ms.wav'
da_stim, fs, enc, fmt = sndio.read(da_file, return_format=True)
prestim_size = 0.0158
full_stim_size = 0.09174311926605504
da_size = 0.04
# Repetition rate in Hz
repetition_rate = 10.9
full_stim_size = 1./repetition_rate
da_size = da_stim.size / fs
prestim = np.zeros(int(fs*prestim_size))
poststim = np.zeros(int(fs*((full_stim_size-prestim_size)-da_size)))
y_part = np.concatenate([prestim, da_stim, poststim])
@@ -30,7 +33,8 @@ def gen_da_stim(n, outpath):
trigger = gen_trigger(idx, 2., 0.01, fs)
y = np.vstack((y_l, y_r, trigger))
sndio.write(outpath, y.T, rate = fs, format = fmt, enc=enc)
y = resampy.resample(y, fs, 44100).T
sndio.write(outpath, y, rate = 44100, format = fmt, enc=enc)
return outpath
+8 -5
View File
@@ -13,7 +13,7 @@ from shutil import copy2
from test_base import BaseThread
from matrix_test.helper_modules.signalops import play_wav, block_mix_wavs
from pathops import dir_must_exist
from pathops import dir_must_exist, delete_if_exists
from scipy.special import logit
from config import socketio
import csv
@@ -59,7 +59,8 @@ class DaTestThread(BaseThread):
self.nTrials = nTrials
self.trial_ind = 0
self._stopevent = Event()
self.si = np.array([20.0, 35.0, 50.0, 65.0, 80.0, 90.0])
# (Completely clean stimulus added by default later)
self.si = np.array([19.0, 50.0, 81.0, 90.0])
super(DaTestThread, self).__init__(self.test_name,
sessionFilepath=sessionFilepath,
@@ -132,20 +133,23 @@ class DaTestThread(BaseThread):
x = logit(self.si * 0.01)
snrs = (x/(4*s_50))+srt_50
snrs = np.append(snrs, np.inf)
self.si = np.append(self.si, np.inf)
self.snr_fs = 10**(-snrs/20)
self.snr_fs[self.snr_fs == np.inf] = 0.
if (self.snr_fs == -np.inf).any():
raise ValueError("Noise infinitely louder than signal for an SNR (SNRs: {})".format(self.snr_fs))
wavs = globDir(self.stim_folder, "3000_da.wav") * len(self.si)
rms_files = globDir(self.stim_folder, "overall_da_rms.npy") * len(self.si)
wavs = globDir(self.stim_folder, "3000_da.wav") * len(snrs)
rms_files = globDir(self.stim_folder, "overall_da_rms.npy") * len(snrs)
self.socketio.emit('test_stim_load', namespace='/main')
# Add noise to audio files at set SNRs and write to participant
# directory
self.data_path = self.participant.data_paths[self.test_name]
out_dir = os.path.join(self.data_path, "stimulus")
delete_if_exists(out_dir)
out_info = os.path.join(out_dir, "stim_info.csv")
dir_must_exist(out_dir)
@@ -157,7 +161,6 @@ class DaTestThread(BaseThread):
out_wavpath = os.path.join(out_dir, fp)
stim_rms = np.load(rms)
match_ratio = stim_rms/self.noise_rms
set_trace()
block_mix_wavs(wav, self.noise_path, out_wavpath,
1.*self.reduction_coef,
snr_fs*match_ratio*self.reduction_coef,
@@ -54,10 +54,12 @@ def logisticFuncLiklihood(args):
with np.errstate(divide='raise'):
try:
a = np.concatenate(res)
a[a == 0] = a.max()
a[a == 0] = np.finfo(float).eps
out = -np.sum(np.log(a))
except:
set_trace()
if out == 0.:
pdb.set_trace()
return out
@@ -69,6 +71,7 @@ def fitLogistic():
wordsCorrect = wordsCorrect[:trialN].astype(float)
trackSNR = snrTrack[:trialN]
res = minimize(logisticFuncLiklihood, np.array([np.mean(trackSNR),1.0]))
pdb.set_trace()
percent_correct = (np.sum(wordsCorrect, axis=1)/wordsCorrect.shape[1])*100.
sortedSNRind = np.argsort(-trackSNR)
sortedSNR = trackSNR[sortedSNRind]
+2 -3
View File
@@ -136,7 +136,7 @@ class MatTestThread(BaseThread):
Main loop for iteratively finding the SRT
'''
self.waitForPageLoad()
while not self.finishTest and not self._stopevent.isSet():
while not self.finishTest and not self._stopevent.isSet() and len(self.availableSentenceInds):
self.plotSNR()
self.y = self.generateTrial(self.snr)
self.playStimulus(self.y, self.fs)
@@ -205,7 +205,7 @@ class MatTestThread(BaseThread):
with np.errstate(divide='raise'):
try:
a = np.concatenate(res)
a[a == 0] = a.max()
a[a == 0] = np.finfo(float).eps
out = -np.sum(np.log(a))
except:
set_trace()
@@ -402,7 +402,6 @@ class MatTestThread(BaseThread):
y = x_noise
# Set speech to start 500ms after the noise, scaled to the desired SNR
sigStart = round(self.fs/2.)
set_trace()
y[sigStart:sigStart+x.size] += x*snr_fs
y *= self.reduction_coef
return y
+11 -1
View File
@@ -2,9 +2,19 @@ from pathops import dir_must_exist
import os
import dill
import numpy as np
import pdb
from config import server, socketio, participants
def set_trace():
import logging
log = logging.getLogger('werkzeug')
log.setLevel(logging.ERROR)
log = logging.getLogger('engineio')
log.setLevel(logging.ERROR)
pdb.set_trace()
def find_participants(folder='./participant_data/'):
'''
Returns a tuple of (participant number, participant filepath) for every
@@ -25,7 +35,7 @@ def gen_participant_num(participants, N = 100):
taken_nums = []
for part_key in participants.keys():
participant = participants[part_key]
taken_nums.append(participant['info']['number'])
taken_nums.append(int(participant['info']['number'][0]))
n = 0
num_found = False
while not num_found:
+7
View File
@@ -108,6 +108,13 @@ def create_participant_page():
part_num = gen_participant_num(participants)
return render_template("create_participant.html", num=part_num)
def set_trace():
import logging
log = logging.getLogger('werkzeug')
log.setLevel(logging.ERROR)
log = logging.getLogger('engineio')
log.setLevel(logging.ERROR)
pdb.set_trace()
@server.route('/participant/create/submit', methods=["POST"])
def create_participant_submit():
data = request.form
+2 -2
View File
@@ -48,7 +48,7 @@
<body class = "body">
<nav id="main-nav" class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="home">BPLabs v0.1</a>
<a class="navbar-brand" href="/home">BPLabs v0.1</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
@@ -56,7 +56,7 @@
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="home">Home<span class="sr-only">(current)</span></a>
<a class="nav-link" href="/home">Home<span class="sr-only">(current)</span></a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
-1
View File
@@ -265,7 +265,6 @@ class BaseThread(Thread):
Restore thread state from a saved session filepath
'''
with open(filepath, 'rb') as f:
set_trace()
self.__dict__.update(dill.load(f))