def __init__(self, rt_list_three_values_csv, i_list_csv): if rt_list_three_values_csv != 'NA': rt_list = map( float, peaks.rt_three_values_to_full_list_string( rt_list_three_values_csv).split(',')) i_list = map(float, i_list_csv.split(',')) # i_list_smoothed = smooth_chromatogram_using_Savitzky_Golay(i_list) self.rt_list = rt_list self.i_list = i_list # self.i_list_smoothed = i_list_smoothed max_peaks, __ = peaks.peakdetect(i_list, rt_list, 2.0, 0.3) # max_peaks_smoothed, __ = peaks.peakdetect(i_list_smoothed, rt_list, 6.0, 0.3) if len(max_peaks) > 0: # max_peaks_smoothed = filter_smoothed_peaks_based_on_raw_peaks(max_peaks, max_peaks_smoothed) max_peaks_all = filter_peaks_based_on_peak_shape( max_peaks, i_list, rt_list) self.peak_apex_rt_list = [rt for (rt, i) in max_peaks_all] self.peak_apex_i_list = [i for (rt, i) in max_peaks_all] else: # if no peak found. Most likely there is no signal. Use looser criteria to detect peaks max_peaks, __ = peaks.peakdetect(i_list, rt_list, 1.0, 0.3) # max_peaks_smoothed, __ = peaks.peakdetect(i_list_smoothed, rt_list, 1.0, 0.3) # max_peaks_smoothed = filter_smoothed_peaks_based_on_raw_peaks(max_peaks, max_peaks_smoothed) max_peaks_all = filter_peaks_based_on_peak_shape( max_peaks, i_list, rt_list) if len(max_peaks) > 0: self.peak_apex_rt_list = [rt for (rt, i) in max_peaks_all] self.peak_apex_i_list = [i for (rt, i) in max_peaks_all] else: # if still no peak found, most likely it is an empty chrom. # use the point in the median value as peak self.peak_apex_rt_list = [np.median(np.array(rt_list))] self.peak_apex_i_list = [np.median(np.array(i_list))] else: self.rt_list = 'NA' self.i_list = 'NA' self.peak_apex_rt_list = 'NA' self.peak_apex_i_list = 'NA'
def __init__(self, rt_list_three_values_csv, i_list_csv): if rt_list_three_values_csv != 'NA': rt_list = map(float, peaks.rt_three_values_to_full_list_string(rt_list_three_values_csv).split(',')) i_list = map(float, i_list_csv.split(',')) # i_list_smoothed = smooth_chromatogram_using_Savitzky_Golay(i_list) self.rt_list = rt_list self.i_list = i_list # self.i_list_smoothed = i_list_smoothed max_peaks, __ = peaks.peakdetect(i_list, rt_list, 2.0, 0.3) # max_peaks_smoothed, __ = peaks.peakdetect(i_list_smoothed, rt_list, 6.0, 0.3) if len(max_peaks) > 0: # max_peaks_smoothed = filter_smoothed_peaks_based_on_raw_peaks(max_peaks, max_peaks_smoothed) max_peaks_all = filter_peaks_based_on_peak_shape(max_peaks, i_list, rt_list) self.peak_apex_rt_list = [rt for (rt, i) in max_peaks_all] self.peak_apex_i_list = [i for (rt, i) in max_peaks_all] else: # if no peak found. Most likely there is no signal. Use looser criteria to detect peaks max_peaks, __ = peaks.peakdetect(i_list, rt_list, 1.0, 0.3) # max_peaks_smoothed, __ = peaks.peakdetect(i_list_smoothed, rt_list, 1.0, 0.3) # max_peaks_smoothed = filter_smoothed_peaks_based_on_raw_peaks(max_peaks, max_peaks_smoothed) max_peaks_all = filter_peaks_based_on_peak_shape(max_peaks, i_list, rt_list) if len(max_peaks) > 0: self.peak_apex_rt_list = [rt for (rt, i) in max_peaks_all] self.peak_apex_i_list = [i for (rt, i) in max_peaks_all] else: # if still no peak found, most likely it is an empty chrom. # use the point in the median value as peak self.peak_apex_rt_list = [np.median(np.array(rt_list))] self.peak_apex_i_list = [np.median(np.array(i_list))] else: self.rt_list = 'NA' self.i_list = 'NA' self.peak_apex_rt_list = 'NA' self.peak_apex_i_list = 'NA'
def jcamp2wav(fh, wavenme=None, rate=44100, secs=5): ' convert a fh to a .dx file to a .wav file' def sound_func(amp, hz, t): # sound generation return amp * sin(hz * t) def mean(l): return sum(l) / len(l) dct = jcamp.jcamp_read(fh) x, y = dct['x'], dct['y'] dif = (y.max() - y.min()) pk = peakdetect(y, x, lookahead=1, delta=dif / 10) max_peaks = pk[0] # [ [x0,y0] , ...., [xn,yn] ] waves = [[(_y - y.min()) / dif, MusicFreq.freq2octave(_x, 0)] for _x, _y in max_peaks] # amp(0..1), freq oct '0' waves.sort(reverse=True) # get <= 10 most powerful waves = waves[:10] pi2 = pi * 2 # -> evaluate waves average for each sample data = np.asarray([ mean([sound_func(amp, hz, t) for amp, hz in waves]) for t in np.arange(0, secs * pi2, pi2 / rate) ], dtype=np.float32) if wavenme is None or not wavenme: wavenme = fh.name.replace('.dx', '.wav') wav_write(wavenme, rate, data)
def star_sound(fnme, wavenme=None, rate=44100, secs=5): # from data[1] def sound_func(amp, hz, t): # sound generation return amp * sin(hz * t) * sin(MusicFreq.freq2octave(hz, -7) * t) def mean(l): return sum(l) / len(l) irms, lrms, header, data = read_dat(fnme) y = data.T[1] x = data.T[0] dif = (y.max() - y.min()) pk = peakdetect(y, x, lookahead=1, delta=dif / 10) max_peaks = pk[0] # [ [x0,y0] , ...., [xn,yn] ] waves = [[(_y - y.min()) / dif, MusicFreq.freq2octave(_x, 0)] for _x, _y in max_peaks] # amp(0..1), freq oct '0' waves.sort(reverse=True) # get <= 10 most powerful waves = waves[:10] pi2 = pi * 2 # -> evaluate waves average for each sample datawav = np.asarray( [mean([sound_func(amp, hz, t) for amp, hz in waves]) for t in np.arange(0, secs * pi2, pi2 / rate)], dtype=np.float32) if wavenme is None or not wavenme: wavenme = fnme.replace('.dat', '.wav') wav_write(wavenme, rate, datawav)
def find_peaks(y_axis, x_axis=None, lookahead=200, delta=0): r1, r2 = pks.peakdetect(y_axis, x_axis=None, lookahead=200, delta=0) return np.array(r1), np.array(r2)