def motograms_from_file(file_name, wav_file_dir): hf = h5py.File(file_name, 'r') motograms = list() for md5, stim_group in hf['motograms'].iteritems(): wav_file_name = os.path.join(wav_file_dir, '%s.wav' % md5) if not os.path.exists(wav_file_name): print 'No such file: %s' % wav_file_name continue intercept = stim_group.attrs['intercept'] slope = stim_group.attrs['slope'] wf = WavFile(wav_file_name, log_spectrogram=False) wf.analyze(min_freq=300, max_freq=8000, spec_sample_rate=1000.0, freq_spacing=125.0) for split_name, split_group in stim_group.iteritems(): mgram = np.array(split_group['motogram']) time = mgram[:, 0] alpha = mgram[:, 1] beta = -1.0 * ( slope * alpha + intercept ) # sign inversion from difference between Hedi's and Mike's models mu = mgram[:, 2] sigma1 = mgram[:, 3] sigma2 = mgram[:, 4] fitvals = mgram[:, 5] motogram = Motogram() motogram.alpha = alpha motogram.beta = beta motogram.mu = mu motogram.sigma1 = sigma1 motogram.sigma2 = sigma2 motogram.fitvals = fitvals motogram.hedi_spectrogram = np.array(split_group['spectrogram']) motogram.hedi_spectrogram_freq = np.array( split_group['frequencies']) motogram.start_time = split_group.attrs['start_time'] / 1000.0 motogram.end_time = split_group.attrs['end_time'] / 1000.0 motogram.md5 = md5 motogram.wav_file = wf motogram.wav_file_name = wav_file_name motograms.append(motogram) hf.close() return motograms
def __init__(self, output, duration, dt): self.output = output self.duration = duration self.dt = dt wf = WavFile() wf.sample_rate = 1.0 / dt wf.data = self.output[:, 0] wf.analyze() self.wav_file = wf
def motograms_from_file(file_name, wav_file_dir): hf = h5py.File(file_name, 'r') motograms = list() for md5,stim_group in hf['motograms'].iteritems(): wav_file_name = os.path.join(wav_file_dir, '%s.wav' % md5) if not os.path.exists(wav_file_name): print 'No such file: %s' % wav_file_name continue intercept = stim_group.attrs['intercept'] slope = stim_group.attrs['slope'] wf = WavFile(wav_file_name, log_spectrogram=False) wf.analyze(min_freq=300, max_freq=8000, spec_sample_rate=1000.0, freq_spacing=125.0) for split_name,split_group in stim_group.iteritems(): mgram = np.array(split_group['motogram']) time = mgram[:, 0] alpha = mgram[:, 1] beta = -1.0 * (slope*alpha + intercept) # sign inversion from difference between Hedi's and Mike's models mu = mgram[:, 2] sigma1 = mgram[:, 3] sigma2 = mgram[:, 4] fitvals = mgram[:, 5] motogram = Motogram() motogram.alpha = alpha motogram.beta = beta motogram.mu = mu motogram.sigma1 = sigma1 motogram.sigma2 = sigma2 motogram.fitvals = fitvals motogram.hedi_spectrogram = np.array(split_group['spectrogram']) motogram.hedi_spectrogram_freq = np.array(split_group['frequencies']) motogram.start_time = split_group.attrs['start_time'] / 1000.0 motogram.end_time = split_group.attrs['end_time'] / 1000.0 motogram.md5 = md5 motogram.wav_file = wf motogram.wav_file_name = wav_file_name motograms.append(motogram) hf.close() return motograms