Skip to content

Commit

Permalink
various minor bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jjuod committed Aug 9, 2018
1 parent 47f89e1 commit 8a03bf0
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 158 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# ignore compiled C objects
*.so

# vim swap files
*.swp

# ignore temp files produced during analysis
Sound Files/Noise examples/Noise_10s/*.xlsx
Sound Files/Noise examples/Noise_10s/*.data
Expand Down
164 changes: 81 additions & 83 deletions AviaNZ.py

Large diffs are not rendered by default.

61 changes: 23 additions & 38 deletions Dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,10 @@
# Since most of them just get user selections, they are mostly just a mess of UI things
import sys,os

try:
from PyQt4.QtCore import *
pyqt4 = True
except ImportError as e:
pyqt4 = False

if pyqt4:
from PyQt4.QtCore import *
from PyQt4.QtGui import *
#import PyQt4.phonon as phonon
else:
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *

#from PyQt4.QtCore import *
#from PyQt4.QtGui import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *

import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
import pyqtgraph.functions as fn
Expand Down Expand Up @@ -247,7 +234,7 @@ def __init__(self, maxv, parent=None):
self.algs = QComboBox()
#self.algs.addItems(["Amplitude","Energy Curve","Harma","Median Clipping","Wavelets"])
self.algs.addItems(["Default","Median Clipping","Fundamental Frequency","FIR","Wavelets","Harma","Power","Cross-Correlation"])
self.algs.currentIndexChanged[QString].connect(self.changeBoxes)
self.algs.currentIndexChanged[str].connect(self.changeBoxes)
self.prevAlg = "Default"
self.undo = QPushButton("Undo")
self.resLabel = QLabel("Output Resolution (secs)")
Expand Down Expand Up @@ -526,7 +513,7 @@ def __init__(self, parent=None,DOC=True,sampleRate=None):
self.algs.addItems(["Wavelets", "Bandpass", "Butterworth Bandpass", "Median Filter"])
else:
self.algs.addItems(["Wavelets", "Bandpass", "Butterworth Bandpass"])
self.algs.currentIndexChanged[QString].connect(self.changeBoxes)
self.algs.currentIndexChanged[str].connect(self.changeBoxes)
self.prevAlg = "Wavelets"

# Wavelet: Depth of tree, threshold type, threshold multiplier, wavelet
Expand Down Expand Up @@ -856,7 +843,6 @@ def __init__(self, sg, audiodata, sampleRate, label, lut, colourStart, colourEnd
self.tbox = QLineEdit(self)
self.tbox.setMaximumWidth(150)
self.tbox.returnPressed.connect(self.birdTextEntered)
#self.connect(self.tbox, SIGNAL('textChanged(QString*)'), self.birdTextEntered)
self.tbox.setEnabled(False)

#self.close = QPushButton("Done")
Expand Down Expand Up @@ -921,24 +907,23 @@ def __init__(self, sg, audiodata, sampleRate, label, lut, colourStart, colourEnd

def playSeg(self): #This is not the right place though
import wavio
import platform
if platform.system() == 'Darwin':
filename = 'temp.wav'
else:
import tempfile
f = tempfile.NamedTemporaryFile(mode='w+t', delete=False)
filename = f.name
self.audiodata = self.audiodata.astype('int16')
wavio.write(filename,self.audiodata,self.sampleRate,scale='dtype-limits',sampwidth=2)
import PyQt4.phonon as phonon
# Create a media object
media_obj = phonon.Phonon.MediaObject(self)
audio_output = phonon.Phonon.AudioOutput(phonon.Phonon.MusicCategory, self)
phonon.Phonon.createPath(media_obj, audio_output)
media_obj.setTickInterval(20)
media_obj.setCurrentSource(phonon.Phonon.MediaSource(filename))
media_obj.seek(0)
media_obj.play()
# import platform
# if platform.system() == 'Darwin':
# filename = 'temp.wav'
# else:
# import tempfile
# f = tempfile.NamedTemporaryFile(mode='w+t', delete=False)
# filename = f.name
# self.audiodata = self.audiodata.astype('int16')
# wavio.write(filename,self.audiodata,self.sampleRate,scale='dtype-limits',sampwidth=2)
# # Create a media object
# media_obj = phonon.Phonon.MediaObject(self)
# audio_output = phonon.Phonon.AudioOutput(phonon.Phonon.MusicCategory, self)
# phonon.Phonon.createPath(media_obj, audio_output)
# media_obj.setTickInterval(20)
# media_obj.setCurrentSource(phonon.Phonon.MediaSource(filename))
# media_obj.seek(0)
# media_obj.play()

def setImage(self, sg, audiodata, sampleRate, label):

Expand Down
26 changes: 9 additions & 17 deletions SupportClasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,10 @@

# Support classes for the AviaNZ program
# Mostly subclassed from pyqtgraph
try:
from PyQt4.QtCore import *
pyqt4 = True
except ImportError as e:
pyqt4 = False

if pyqt4:
from PyQt4.QtCore import *
from PyQt4.QtGui import *
else:
# from PyQt5.QtGui import QIcon, QPixmap
from PyQt5.QtWidgets import QAbstractButton
from PyQt5.QtCore import QTime, QFile, QIODevice, QBuffer, QByteArray
from PyQt5.QtMultimedia import QAudio, QAudioOutput, QAudioFormat
from PyQt5.QtWidgets import QAbstractButton
from PyQt5.QtCore import QTime, QFile, QIODevice, QBuffer, QByteArray
from PyQt5.QtMultimedia import QAudio, QAudioOutput, QAudioFormat

import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
Expand Down Expand Up @@ -692,10 +682,11 @@ class TimeAxisHour(pg.AxisItem):
def __init__(self, *args, **kwargs):
super(TimeAxisHour, self).__init__(*args, **kwargs)
self.offset = 0
self.setLabel('Time', units='hh:mm:ss')

def tickStrings(self, values, scale, spacing):
# Overwrite the axis tick code
return [QTime().addSecs(value+self.offset).toString('hh:mm:ss') for value in values]
return [QTime(0,0,0).addSecs(value+self.offset).toString('hh:mm:ss') for value in values]

def setOffset(self,offset):
self.offset = offset
Expand All @@ -707,10 +698,11 @@ class TimeAxisMin(pg.AxisItem):
def __init__(self, *args, **kwargs):
super(TimeAxisMin, self).__init__(*args, **kwargs)
self.offset = 0
self.setLabel('Time', units='mm:ss')

def tickStrings(self, values, scale, spacing):
# Overwrite the axis tick code
return [QTime().addSecs(value+self.offset).toString('mm:ss') for value in values]
return [QTime(0,0,0).addSecs(value+self.offset).toString('mm:ss') for value in values]

def setOffset(self,offset):
self.offset = offset
Expand Down Expand Up @@ -879,6 +871,7 @@ def endListener(self):
self.stop()

def pressedPlay(self):
sleep(0.1)
# save starting position in bytes
self.startpos = self.soundFile.pos()
self.start(self.soundFile)
Expand Down Expand Up @@ -923,8 +916,7 @@ def seekToMs(self, ms):
def applyVolSlider(self, value):
# passes UI volume nonlinearly
# value = QAudio.convertVolume(value / 100, QAudio.LogarithmicVolumeScale, QAudio.LinearVolumeScale)
value = (math.exp(value/100)-1)/(math.exp(1)-1)
print("setting volume to nonl %s" % value)
value = (math.exp(value/50)-1)/(math.exp(2)-1)
self.setVolume(value)

class FlowLayout(QtGui.QLayout):
Expand Down
25 changes: 7 additions & 18 deletions WaveletFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,14 @@ def ConvertWaveletNodeName(self,i):
""" Convert from an integer to the 'ad' representations of the wavelet packets
The root is 0 (''), the next level are 1 and 2 ('a' and 'd'), the next 3, 4, 5, 6 ('aa','ad','da','dd) and so on
"""
import string
level = int(np.floor(np.log2(i + 1)))
first = 2 ** level - 1
if i == 0:
b = ''
else:
b = np.binary_repr(i - first, width=int(level))
b = string.replace(b, '0', 'a', maxreplace=-1)
b = string.replace(b, '1', 'd', maxreplace=-1)
b = np.binary_repr(int(i) - first, width=int(level))
b = b.replace('0', 'a')
b = b.replace('1', 'd')
return b

def BestTree(self,wp,threshold,costfn='threshold'):
Expand Down Expand Up @@ -165,11 +164,12 @@ def reconstructWPT(self,new_wp,wavelet,listleaves):
while level > 0:
first = 2 ** level - 1
while working[0] >= first:
# Note this is Python2!
# And also that it assumes that the whole list is backwards
parent = (working[0] - 1) / 2
# Note that it assumes that the whole list is backwards
parent = (working[0] - 1) // 2
p = self.ConvertWaveletNodeName(parent)

new_wp[p].data = pywt.idwt(new_wp[self.ConvertWaveletNodeName(working[1])].data,new_wp[self.ConvertWaveletNodeName(working[0])].data, wavelet)[:len(new_wp[p].data)]

# Delete these two nodes from working
working = np.delete(working, 1)
working = np.delete(working, 0)
Expand Down Expand Up @@ -225,23 +225,12 @@ def waveletDenoise(self,data=None,thresholdType='soft',threshold=4.5,maxLevel=5,
# pywavelet makes the whole tree. So if you don't give it blanks from places where you don't want the values in
# the original tree, it copies the details from wp even though it wasn't asked for them.
# Reconstruction with the zeros is different to not reconstructing.
# print("Checkpoint 2, %.5f" % (time.time() - opstartingtime))
# new_wp = pywt.WaveletPacket(data=np.zeros(len(wp.data)), wavelet=wp.wavelet, mode='zero', maxlevel=wp.maxlevel)

# for level in range(wp.maxlevel + 1):
# print(level)
# numpoints = len(wp.get_level(level, 'natural')[0].data)
# print(numpoints)
# for n in new_wp.get_level(level, 'natural'):
# n.data = np.zeros(numpoints)

# Copy thresholded versions of the leaves into the new wpt
new_wp = ce.ThresholdNodes(self, wp, bestleaves, threshold, thresholdType)

# Reconstruct the internal nodes and the data
# print("Checkpoint 3, %.5f" % (time.time() - opstartingtime))
new_wp = self.reconstructWPT(new_wp,wp.wavelet,bestleaves)
# print("Checkpoint 4, %.5f" % (time.time() - opstartingtime))

return new_wp[''].data

Expand Down
2 changes: 1 addition & 1 deletion ext/ce_denoise.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,6 @@ def ThresholdNodes(self, oldtree, bestleaves, threshold, type):
else:
ce_thresnode(<double*> np.PyArray_DATA(oldtree[ind].data), <double*> np.PyArray_DATA(newtree[ind].data), length, threshold, 's')
else:
newtree[ind] = np.zeros(len(oldtree[ind].data))
newtree[ind].data = np.zeros(len(oldtree[ind].data))

return newtree
Binary file added img/volume.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ scikit_learn==0.19.2
# sudo apt install python3-pyqt5.qtmultimedia
## sudo apt install python-qt4
## sudo apt install libgstreamer1.0-dev - not sure??
## sudo apt install python-qt4-phonon
## pip uninstall joblib; pip install -Iv joblib=0.11.0
# pip install git+https://github.com/pyqtgraph/pyqtgraph

0 comments on commit 8a03bf0

Please sign in to comment.