Skip to content

Commit 7d83590

Browse files
author
Martin Glesser
authored
Merge pull request #42 from wantysal/SDT_dependency_suppress
SDT and pytest dependencies made optional
2 parents 1460032 + ccd07d6 commit 7d83590

23 files changed

+241
-79
lines changed

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,24 @@ MOSQITO is available on [pip](https://pypi.org/project/pip/). Simply type in a s
4040

4141
pip install mosqito
4242

43-
This command line should download and install MOSQITO on your computer, along with all the needed dependencies.
43+
This command line should download and install MOSQITO on your computer, along with the dependencies needed to compute SQ metrics.
44+
45+
If you want to perform tests, for instance if you developed a new feature, you will need pytest dependency that can be installed using:
46+
47+
pip install mosqito[testing]
4448

4549
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:
4650

4751
pip install mosqito[uff]
4852

53+
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:
54+
55+
pip install mosqito[SciDataTool]
56+
57+
Note that all the depencies needed for uff, SDT and tests proceeding can be installed at once using:
58+
59+
pip install mosqito[all]
60+
4961
## Contact
5062

5163
You can contact us on Github by opening an issue (to request a feature, ask a question or report a bug).

full_requirements.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
numpy
2+
scipy
3+
matplotlib
4+
pyuff
5+
pytest
6+
scidatatool

mosqito/classes/Audio.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55
@author: wantysal
66
"""
77

8-
# import SciDataTool objects
9-
from SciDataTool import DataTime, DataLinspace
8+
# Optional package import
9+
try:
10+
import SciDataTool
11+
except ImportError:
12+
SciDataTool = None
13+
1014

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

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

5664
# Create Data object for time axis
57-
time_axis = DataLinspace(
65+
time_axis = SciDataTool.DataLinspace(
5866
name="time",
5967
unit="s",
6068
initial=0,
@@ -66,7 +74,7 @@ def __init__(self, file, is_stationary=False, calib=1, mat_signal="", mat_fs="")
6674
# Create audio signal Data object and populate the object
6775
self.fs = fs
6876
self.is_stationary = is_stationary
69-
self.signal = DataTime(
77+
self.signal = SciDataTool.DataTime(
7078
name="Audio signal",
7179
symbol="x",
7280
unit="Pa",

mosqito/methods/Audio/comp_3oct_spec.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# -*- coding: utf-8 -*-
22

3-
from numpy import squeeze
3+
# Optional package import
4+
try:
5+
import SciDataTool
6+
except ImportError:
7+
SciDataTool = None
48

5-
from SciDataTool import Data1D, DataTime, DataFreq
6-
7-
from mosqito.functions.shared.A_weighting import A_weighting
89
from mosqito.functions.loudness_zwicker.calc_third_octave_levels import (
910
calc_third_octave_levels,
1011
)
@@ -26,6 +27,12 @@ def comp_3oct_spec(
2627
Filter center frequency of the highest 1/3 oct. band [Hz]
2728
2829
"""
30+
31+
if SciDataTool is None:
32+
raise RuntimeError(
33+
"In order to create an audio object you need the 'SciDataTool' package."
34+
)
35+
2936

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

4350
# Define axis objects
44-
frequency = Data1D(
51+
frequency = SciDataTool.Data1D(
4552
name="freqs",
4653
unit="Hz",
4754
values=freq_val,
4855
)
4956
axes = [frequency]
5057
if not self.is_stationary:
51-
time = Data1D(
58+
time = SciDataTool.Data1D(
5259
name="time",
5360
unit="s",
5461
values=time_val,
5562
)
5663
axes.append(time)
5764

5865
# Define Data object
59-
self.third_spec = DataFreq(
66+
self.third_spec = SciDataTool.DataFreq(
6067
name="Audio signal",
6168
symbol="x",
6269
axes=axes,

mosqito/methods/Audio/compute_level.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
from numpy import log10, linspace, mean, sqrt
44

5-
from SciDataTool import Data1D, DataTime
5+
# Optional package import
6+
try:
7+
import SciDataTool
8+
except ImportError:
9+
SciDataTool = None
610

711

812
def compute_level(self, nb_points=[], start=[], stop=[]):
@@ -23,6 +27,12 @@ def compute_level(self, nb_points=[], start=[], stop=[]):
2327
SPL in dB
2428
2529
"""
30+
if SciDataTool is None:
31+
raise RuntimeError(
32+
"In order to create an audio object you need the 'SciDataTool' package."
33+
)
34+
35+
2636
# Check the inputs
2737
if nb_points != []:
2838
if type(nb_points) != int:
@@ -67,7 +77,7 @@ def compute_level(self, nb_points=[], start=[], stop=[]):
6777
# Case of a given number of points
6878
if nb_points != []:
6979

70-
time = Data1D(
80+
time = SciDataTool.Data1D(
7181
name="time", unit="s", values=linspace(start, stop, num=nb_points)
7282
)
7383

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

80-
self.level = DataTime(
90+
self.level = SciDataTool.DataTime(
8191
name="Sound Pressure Level",
8292
symbol="SPL",
8393
unit="dB",

mosqito/methods/Audio/compute_loudness.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# -*- coding: utf-8 -*-
22

3-
from SciDataTool import DataLinspace, DataTime, DataFreq, Data1D
3+
# Optional package import
4+
try:
5+
import SciDataTool
6+
except ImportError:
7+
SciDataTool = None
48

59
from mosqito.functions.loudness_zwicker.loudness_zwicker_stationary import (
610
loudness_zwicker_stationary,
@@ -19,13 +23,17 @@ def compute_loudness(self, field_type="free"):
1923
'free' by default or 'diffuse'
2024
2125
"""
26+
if SciDataTool is None:
27+
raise RuntimeError(
28+
"In order to create an audio object you need the 'SciDataTool' package."
29+
)
2230

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

2735
# define bark_axis
28-
barks = DataLinspace(
36+
barks = SciDataTool.DataLinspace(
2937
name="cr_band",
3038
unit="Bark",
3139
initial=0.1,
@@ -49,10 +57,10 @@ def compute_loudness(self, field_type="free"):
4957
)
5058
# Get time axis
5159
# Decimation from temporal resolution 0.5 ms to 2ms
52-
time = Data1D(
60+
time = SciDataTool.Data1D(
5361
name="time", unit="s", values=self.third_spec.get_axes()[1].values[::4]
5462
)
55-
self.loudness_zwicker = DataTime(
63+
self.loudness_zwicker = SciDataTool.DataTime(
5664
name="Loudness",
5765
symbol="N_{zw}",
5866
unit="sone",
@@ -61,7 +69,7 @@ def compute_loudness(self, field_type="free"):
6169
)
6270
axes = [barks, time]
6371

64-
self.loudness_zwicker_specific = DataFreq(
72+
self.loudness_zwicker_specific = SciDataTool.DataFreq(
6573
name="Specific Loudness",
6674
symbol="N'_{zw}",
6775
unit="sone/Bark",

mosqito/methods/Audio/compute_roughness.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
"""
33
Created on Tue Feb 23 14:05:22 2021
44
5-
@author: Salomé
5+
@author: wantysal
66
"""
7-
# Import SciDataTool objects
8-
9-
from SciDataTool import DataTime, Data1D
7+
# Optional package import
8+
try:
9+
import SciDataTool
10+
except ImportError:
11+
SciDataTool = None
1012

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

28+
if SciDataTool is None:
29+
raise RuntimeError(
30+
"In order to create an audio object you need the 'SciDataTool' package."
31+
)
32+
2633
# check the input parameters
2734
if method != "dw":
2835
raise ValueError("ERROR: method must be 'dw'")
@@ -32,9 +39,9 @@ def compute_roughness(self, method="dw", overlap=0.5):
3239

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

35-
time = Data1D(name="time", unit="s", values=R["time"])
42+
time = SciDataTool.Data1D(name="time", unit="s", values=R["time"])
3643

37-
self.roughness["Daniel Weber"] = DataTime(
44+
self.roughness["Daniel Weber"] = SciDataTool.DataTime(
3845
symbol="R_{dw}",
3946
axes=[time],
4047
values=R["values"],

mosqito/methods/Audio/compute_sharpness.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
"""
77
import numpy as np
88

9-
# Import SciDataTool objects
10-
from SciDataTool import DataTime, Data1D
9+
# Optional package import
10+
try:
11+
import SciDataTool
12+
except ImportError:
13+
SciDataTool = None
1114

1215
# Import MOSQITO functions
1316
from mosqito.functions.sharpness.sharpness_aures import comp_sharpness_aures
@@ -27,6 +30,11 @@ def compute_sharpness(self, method="din", skip=0.2):
2730
number of second to be cut at the beginning of the analysis
2831
2932
"""
33+
if SciDataTool is None:
34+
raise RuntimeError(
35+
"In order to create an audio object you need the 'SciDataTool' package."
36+
)
37+
3038
# check the input parameters
3139
if (
3240
method != "din"
@@ -72,14 +80,14 @@ def compute_sharpness(self, method="din", skip=0.2):
7280
S = S[cut_index:]
7381

7482
# Define time axis
75-
time = Data1D(
83+
time = SciDataTool.Data1D(
7684
symbol="T",
7785
name="time",
7886
unit="s",
7987
values=self.loudness_zwicker.get_axes()[0].values[cut_index:],
8088
)
8189

82-
self.sharpness["din"] = DataTime(
90+
self.sharpness["din"] = SciDataTool.DataTime(
8391
symbol="S_{DIN}", axes=[time], values=S, name="Sharpness", unit="Acum"
8492
)
8593

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

113121
# Define time axis
114-
time = Data1D(
122+
time = SciDataTool.Data1D(
115123
symbol="T",
116124
name="time",
117125
unit="s",
118126
values=self.loudness_zwicker.get_axes()[0].values[cut_index:],
119127
)
120128

121-
self.sharpness["aures"] = DataTime(
129+
self.sharpness["aures"] = SciDataTool.DataTime(
122130
symbol="S_{Aures}", axes=[time], values=S, name="Sharpness", unit="Acum"
123131
)
124132

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

151159
# Define time axis
152-
time = Data1D(
160+
time = SciDataTool.Data1D(
153161
symbol="T",
154162
name="time",
155163
unit="s",
156164
values=self.loudness_zwicker.get_axes()[0].values[cut_index:],
157165
)
158166

159-
self.sharpness["bismarck"] = DataTime(
167+
self.sharpness["bismarck"] = SciDataTool.DataTime(
160168
symbol="S_{Bismarck}",
161169
axes=[time],
162170
values=S,
@@ -191,13 +199,13 @@ def compute_sharpness(self, method="din", skip=0.2):
191199
S = S[cut_index:]
192200

193201
# Define time axis
194-
time = Data1D(
202+
time = SciDataTool.Data1D(
195203
symbol="T",
196204
name="time",
197205
unit="s",
198206
values=self.loudness_zwicker.get_axes()[0].values[cut_index:],
199207
)
200208

201-
self.sharpness["fastl"] = DataTime(
209+
self.sharpness["fastl"] = SciDataTool.DataTime(
202210
symbol="S_{Fastl}", axes=[time], values=S, name="Sharpness", unit="Acum"
203211
)

0 commit comments

Comments
 (0)