Skip to content

Commit

Permalink
Merge pull request #42 from wantysal/SDT_dependency_suppress
Browse files Browse the repository at this point in the history
SDT and pytest dependencies made optional
  • Loading branch information
Martin Glesser authored Mar 2, 2022
2 parents 1460032 + ccd07d6 commit 7d83590
Show file tree
Hide file tree
Showing 23 changed files with 241 additions and 79 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,24 @@ MOSQITO is available on [pip](https://pypi.org/project/pip/). Simply type in a s

pip install mosqito

This command line should download and install MOSQITO on your computer, along with all the needed dependencies.
This command line should download and install MOSQITO on your computer, along with the dependencies needed to compute SQ metrics.

If you want to perform tests, for instance if you developed a new feature, you will need pytest dependency that can be installed using:

pip install mosqito[testing]

If you need to import .uff or .unv files, you will need the pyuff package dependency. Note that 'pyuff' is released under the GPL license which prevents MOSQITO from being used in other software that must be under a more permissive license. To include the 'pyuff' dependancy anyway, type the following command:

pip install mosqito[uff]

If you want to use MOSQITO coupled with SciDataTool, you will need SDT package dependency. To install it along with MOSQITO, use the following command:

pip install mosqito[SciDataTool]

Note that all the depencies needed for uff, SDT and tests proceeding can be installed at once using:

pip install mosqito[all]

## Contact

You can contact us on Github by opening an issue (to request a feature, ask a question or report a bug).
Expand Down
6 changes: 6 additions & 0 deletions full_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
numpy
scipy
matplotlib
pyuff
pytest
scidatatool
16 changes: 12 additions & 4 deletions mosqito/classes/Audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
@author: wantysal
"""

# import SciDataTool objects
from SciDataTool import DataTime, DataLinspace
# Optional package import
try:
import SciDataTool
except ImportError:
SciDataTool = None


# import methods
from mosqito.functions.shared.load import load
Expand Down Expand Up @@ -44,6 +48,10 @@ def __init__(self, file, is_stationary=False, calib=1, mat_signal="", mat_fs="")
in case of a .mat file, name of the sampling frequency variable
"""
if SciDataTool is None:
raise RuntimeError(
"In order to create an audio object you need the 'SciDataTool' package."
)

# Import audio signal
values, fs = load(
Expand All @@ -54,7 +62,7 @@ def __init__(self, file, is_stationary=False, calib=1, mat_signal="", mat_fs="")
)

# Create Data object for time axis
time_axis = DataLinspace(
time_axis = SciDataTool.DataLinspace(
name="time",
unit="s",
initial=0,
Expand All @@ -66,7 +74,7 @@ def __init__(self, file, is_stationary=False, calib=1, mat_signal="", mat_fs="")
# Create audio signal Data object and populate the object
self.fs = fs
self.is_stationary = is_stationary
self.signal = DataTime(
self.signal = SciDataTool.DataTime(
name="Audio signal",
symbol="x",
unit="Pa",
Expand Down
21 changes: 14 additions & 7 deletions mosqito/methods/Audio/comp_3oct_spec.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# -*- coding: utf-8 -*-

from numpy import squeeze
# Optional package import
try:
import SciDataTool
except ImportError:
SciDataTool = None

from SciDataTool import Data1D, DataTime, DataFreq

from mosqito.functions.shared.A_weighting import A_weighting
from mosqito.functions.loudness_zwicker.calc_third_octave_levels import (
calc_third_octave_levels,
)
Expand All @@ -26,6 +27,12 @@ def comp_3oct_spec(
Filter center frequency of the highest 1/3 oct. band [Hz]
"""

if SciDataTool is None:
raise RuntimeError(
"In order to create an audio object you need the 'SciDataTool' package."
)


# Compute third octave band spectrum
if self.is_stationary:
Expand All @@ -41,22 +48,22 @@ def comp_3oct_spec(
third_spec = 2e-5 * 10 ** (third_spec / 20)

# Define axis objects
frequency = Data1D(
frequency = SciDataTool.Data1D(
name="freqs",
unit="Hz",
values=freq_val,
)
axes = [frequency]
if not self.is_stationary:
time = Data1D(
time = SciDataTool.Data1D(
name="time",
unit="s",
values=time_val,
)
axes.append(time)

# Define Data object
self.third_spec = DataFreq(
self.third_spec = SciDataTool.DataFreq(
name="Audio signal",
symbol="x",
axes=axes,
Expand Down
16 changes: 13 additions & 3 deletions mosqito/methods/Audio/compute_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

from numpy import log10, linspace, mean, sqrt

from SciDataTool import Data1D, DataTime
# Optional package import
try:
import SciDataTool
except ImportError:
SciDataTool = None


def compute_level(self, nb_points=[], start=[], stop=[]):
Expand All @@ -23,6 +27,12 @@ def compute_level(self, nb_points=[], start=[], stop=[]):
SPL in dB
"""
if SciDataTool is None:
raise RuntimeError(
"In order to create an audio object you need the 'SciDataTool' package."
)


# Check the inputs
if nb_points != []:
if type(nb_points) != int:
Expand Down Expand Up @@ -67,7 +77,7 @@ def compute_level(self, nb_points=[], start=[], stop=[]):
# Case of a given number of points
if nb_points != []:

time = Data1D(
time = SciDataTool.Data1D(
name="time", unit="s", values=linspace(start, stop, num=nb_points)
)

Expand All @@ -77,7 +87,7 @@ def compute_level(self, nb_points=[], start=[], stop=[]):
peff = sqrt(mean(frame_i ** 2))
level.append(10 * log10((peff ** 2 / (2e-05) ** 2)))

self.level = DataTime(
self.level = SciDataTool.DataTime(
name="Sound Pressure Level",
symbol="SPL",
unit="dB",
Expand Down
18 changes: 13 additions & 5 deletions mosqito/methods/Audio/compute_loudness.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# -*- coding: utf-8 -*-

from SciDataTool import DataLinspace, DataTime, DataFreq, Data1D
# Optional package import
try:
import SciDataTool
except ImportError:
SciDataTool = None

from mosqito.functions.loudness_zwicker.loudness_zwicker_stationary import (
loudness_zwicker_stationary,
Expand All @@ -19,13 +23,17 @@ def compute_loudness(self, field_type="free"):
'free' by default or 'diffuse'
"""
if SciDataTool is None:
raise RuntimeError(
"In order to create an audio object you need the 'SciDataTool' package."
)

# Compute third octave band spetrum if necessary
if self.third_spec == None:
self.comp_3oct_spec()

# define bark_axis
barks = DataLinspace(
barks = SciDataTool.DataLinspace(
name="cr_band",
unit="Bark",
initial=0.1,
Expand All @@ -49,10 +57,10 @@ def compute_loudness(self, field_type="free"):
)
# Get time axis
# Decimation from temporal resolution 0.5 ms to 2ms
time = Data1D(
time = SciDataTool.Data1D(
name="time", unit="s", values=self.third_spec.get_axes()[1].values[::4]
)
self.loudness_zwicker = DataTime(
self.loudness_zwicker = SciDataTool.DataTime(
name="Loudness",
symbol="N_{zw}",
unit="sone",
Expand All @@ -61,7 +69,7 @@ def compute_loudness(self, field_type="free"):
)
axes = [barks, time]

self.loudness_zwicker_specific = DataFreq(
self.loudness_zwicker_specific = SciDataTool.DataFreq(
name="Specific Loudness",
symbol="N'_{zw}",
unit="sone/Bark",
Expand Down
19 changes: 13 additions & 6 deletions mosqito/methods/Audio/compute_roughness.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
"""
Created on Tue Feb 23 14:05:22 2021
@author: Salomé
@author: wantysal
"""
# Import SciDataTool objects

from SciDataTool import DataTime, Data1D
# Optional package import
try:
import SciDataTool
except ImportError:
SciDataTool = None

# Import MOSQITO function
from mosqito.functions.roughness_danielweber.comp_roughness import comp_roughness
Expand All @@ -23,6 +25,11 @@ def compute_roughness(self, method="dw", overlap=0.5):
overlapping coefficient for the time windows of 200ms, default is 0.5
"""

if SciDataTool is None:
raise RuntimeError(
"In order to create an audio object you need the 'SciDataTool' package."
)

# check the input parameters
if method != "dw":
raise ValueError("ERROR: method must be 'dw'")
Expand All @@ -32,9 +39,9 @@ def compute_roughness(self, method="dw", overlap=0.5):

R = comp_roughness(self.signal.values, self.fs, overlap)

time = Data1D(name="time", unit="s", values=R["time"])
time = SciDataTool.Data1D(name="time", unit="s", values=R["time"])

self.roughness["Daniel Weber"] = DataTime(
self.roughness["Daniel Weber"] = SciDataTool.DataTime(
symbol="R_{dw}",
axes=[time],
values=R["values"],
Expand Down
28 changes: 18 additions & 10 deletions mosqito/methods/Audio/compute_sharpness.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
"""
import numpy as np

# Import SciDataTool objects
from SciDataTool import DataTime, Data1D
# Optional package import
try:
import SciDataTool
except ImportError:
SciDataTool = None

# Import MOSQITO functions
from mosqito.functions.sharpness.sharpness_aures import comp_sharpness_aures
Expand All @@ -27,6 +30,11 @@ def compute_sharpness(self, method="din", skip=0.2):
number of second to be cut at the beginning of the analysis
"""
if SciDataTool is None:
raise RuntimeError(
"In order to create an audio object you need the 'SciDataTool' package."
)

# check the input parameters
if (
method != "din"
Expand Down Expand Up @@ -72,14 +80,14 @@ def compute_sharpness(self, method="din", skip=0.2):
S = S[cut_index:]

# Define time axis
time = Data1D(
time = SciDataTool.Data1D(
symbol="T",
name="time",
unit="s",
values=self.loudness_zwicker.get_axes()[0].values[cut_index:],
)

self.sharpness["din"] = DataTime(
self.sharpness["din"] = SciDataTool.DataTime(
symbol="S_{DIN}", axes=[time], values=S, name="Sharpness", unit="Acum"
)

Expand Down Expand Up @@ -111,14 +119,14 @@ def compute_sharpness(self, method="din", skip=0.2):
S = S[cut_index:]

# Define time axis
time = Data1D(
time = SciDataTool.Data1D(
symbol="T",
name="time",
unit="s",
values=self.loudness_zwicker.get_axes()[0].values[cut_index:],
)

self.sharpness["aures"] = DataTime(
self.sharpness["aures"] = SciDataTool.DataTime(
symbol="S_{Aures}", axes=[time], values=S, name="Sharpness", unit="Acum"
)

Expand Down Expand Up @@ -149,14 +157,14 @@ def compute_sharpness(self, method="din", skip=0.2):
S = S[cut_index:]

# Define time axis
time = Data1D(
time = SciDataTool.Data1D(
symbol="T",
name="time",
unit="s",
values=self.loudness_zwicker.get_axes()[0].values[cut_index:],
)

self.sharpness["bismarck"] = DataTime(
self.sharpness["bismarck"] = SciDataTool.DataTime(
symbol="S_{Bismarck}",
axes=[time],
values=S,
Expand Down Expand Up @@ -191,13 +199,13 @@ def compute_sharpness(self, method="din", skip=0.2):
S = S[cut_index:]

# Define time axis
time = Data1D(
time = SciDataTool.Data1D(
symbol="T",
name="time",
unit="s",
values=self.loudness_zwicker.get_axes()[0].values[cut_index:],
)

self.sharpness["fastl"] = DataTime(
self.sharpness["fastl"] = SciDataTool.DataTime(
symbol="S_{Fastl}", axes=[time], values=S, name="Sharpness", unit="Acum"
)
Loading

0 comments on commit 7d83590

Please sign in to comment.