Skip to content

Commit 4b7489f

Browse files
committed
Removes the deprecated parameter from ShoeBox, Room.from_corners, and Room.extrude.
1 parent b897953 commit 4b7489f

2 files changed

Lines changed: 24 additions & 162 deletions

File tree

CHANGELOG.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ adheres to `Semantic Versioning <http://semver.org/spec/v2.0.0.html>`_.
1414
Changed
1515
~~~~~~~
1616

17+
- Removed the deprecated ``absorption`` parameter from ``ShoeBox``,
18+
``Room.from_corners``, and ``Room.extrude``.
1719
- Modernized the build system to use ``pyproject.toml`` and ``CMake``.
1820
- External dependencies (``Eigen``, ``nanoflann``, ``pybind11``) are now
1921
automatically managed via CMake's ``FetchContent``.

pyroomacoustics/room.py

Lines changed: 22 additions & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,7 +1210,6 @@ def _wall_mapping(self):
12101210
def from_corners(
12111211
cls,
12121212
corners,
1213-
absorption=None,
12141213
fs=8000,
12151214
t0=0.0,
12161215
max_order=1,
@@ -1227,9 +1226,6 @@ def from_corners(
12271226
----------
12281227
corners: (np.array dim 2xN, N>2)
12291228
list of corners, must be antiClockwise oriented
1230-
absorption: float array or float
1231-
list of absorption factor for each wall or single value
1232-
for all walls (deprecated, use ``materials`` instead)
12331229
fs: int, optional
12341230
The sampling frequency in Hz. Default is 8000.
12351231
t0: float, optional
@@ -1266,37 +1262,7 @@ def from_corners(
12661262
if libroom.area_2d_polygon(corners) <= 0:
12671263
corners = corners[:, ::-1]
12681264

1269-
############################
1270-
# BEGIN COMPATIBILITY CODE #
1271-
############################
1272-
1273-
if absorption is None:
1274-
absorption = 0.0
1275-
absorption_compatibility_request = False
1276-
else:
1277-
absorption_compatibility_request = True
1278-
1279-
absorption = np.array(absorption, dtype="float64")
1280-
if absorption.ndim == 0:
1281-
absorption = absorption * np.ones(n_walls)
1282-
elif absorption.ndim >= 1 and n_walls != len(absorption):
1283-
raise ValueError(
1284-
"Arg absorption must be the same size as corners or must be a single value."
1285-
)
1286-
1287-
############################
1288-
# BEGIN COMPATIBILITY CODE #
1289-
############################
1290-
12911265
if materials is not None:
1292-
if absorption_compatibility_request:
1293-
import warnings
1294-
1295-
warnings.warn(
1296-
"Because materials were specified, deprecated absorption parameter is ignored.",
1297-
DeprecationWarning,
1298-
)
1299-
13001266
if not isinstance(materials, list):
13011267
materials = [materials] * n_walls
13021268

@@ -1308,21 +1274,9 @@ def from_corners(
13081274
materials[i], Material
13091275
), "Material not specified using correct class"
13101276

1311-
elif absorption_compatibility_request:
1312-
import warnings
1313-
1314-
warnings.warn(
1315-
"Using absorption parameter is deprecated. In the future, use materials instead."
1316-
)
1317-
1318-
# Fix the absorption
1319-
# 1 - a1 == sqrt(1 - a2) <-- a1 is former incorrect absorption, a2 is the correct definition based on energy
1320-
# <=> a2 == 1 - (1 - a1) ** 2
1321-
correct_absorption = 1.0 - (1.0 - absorption) ** 2
1322-
materials = make_materials(*correct_absorption)
1323-
13241277
else:
1325-
# In this case, no material is provided, use totally reflective walls, no scattering
1278+
# In this case, no material is provided, use totally reflective
1279+
# walls, no scattering
13261280
materials = [Material(0.0, 0.0)] * n_walls
13271281

13281282
# Resample material properties at octave bands
@@ -1359,10 +1313,11 @@ def from_corners(
13591313
**kwargs,
13601314
)
13611315

1362-
def extrude(self, height, v_vec=None, absorption=None, materials=None):
1316+
def extrude(self, height, v_vec=None, materials=None):
13631317
"""
13641318
Creates a 3D room by extruding a 2D polygon.
1365-
The polygon is typically the floor of the room and will have z-coordinate zero. The ceiling
1319+
The polygon is typically the floor of the room and will have
1320+
z-coordinate zero. The ceiling
13661321
13671322
Parameters
13681323
----------
@@ -1372,15 +1327,11 @@ def extrude(self, height, v_vec=None, absorption=None, materials=None):
13721327
A unit vector. An orientation for the extrusion direction. The
13731328
ceiling will be placed as a translation of the floor with respect
13741329
to this vector (The default is [0,0,1]).
1375-
absorption : float or array-like, optional
1376-
Absorption coefficients for all the walls. If a scalar, then all the walls
1377-
will have the same absorption. If an array is given, it should have as many elements
1378-
as there will be walls, that is the number of vertices of the polygon plus two. The two
1379-
last elements are for the floor and the ceiling, respectively.
1380-
It is recommended to use materials instead of absorption parameter. (Default: 1)
1381-
materials : dict
1382-
Absorption coefficients for floor and ceiling. This parameter overrides absorption.
1383-
(Default: {"floor": 1, "ceiling": 1})
1330+
materials : dict[str, pyroomacoustics.Material]
1331+
Material properties of the floor and ceiling.
1332+
A single Material object will be repeated for both floor and ceiling.
1333+
Otherwise, a dict with keys 'floor' and 'ceiling' is expected.
1334+
(Default: {"floor": pra.Material(0, 0), "ceiling": pra.Material(0, 0)})
13841335
"""
13851336

13861337
if self.dim != 2:
@@ -1453,67 +1404,34 @@ def extrude(self, height, v_vec=None, absorption=None, materials=None):
14531404
"Encountered a material with inconsistent number of bands."
14541405
)
14551406

1456-
############################
1457-
# BEGIN COMPATIBILITY CODE #
1458-
############################
1459-
if absorption is not None:
1460-
absorption = 0.0
1461-
absorption_compatibility_request = True
1462-
else:
1463-
absorption_compatibility_request = False
1464-
##########################
1465-
# END COMPATIBILITY CODE #
1466-
##########################
1467-
14681407
if materials is not None:
1469-
if absorption_compatibility_request:
1470-
import warnings
1471-
1472-
warnings.warn(
1473-
"Because materials were specified, "
1474-
"deprecated absorption parameter is ignored.",
1475-
DeprecationWarning,
1476-
)
1477-
14781408
if not isinstance(materials, dict):
14791409
materials = {"floor": materials, "ceiling": materials}
14801410

1481-
for mat in materials.values():
1482-
assert isinstance(
1483-
mat, Material
1484-
), "Material not specified using correct class"
1485-
1486-
elif absorption_compatibility_request:
1487-
import warnings
1488-
1489-
warnings.warn(
1490-
"absorption parameter is deprecated for Room.extrude",
1491-
DeprecationWarning,
1492-
)
1493-
1494-
absorption = np.array(absorption)
1495-
if absorption.ndim == 0:
1496-
absorption = absorption * np.ones(2)
1497-
elif absorption.ndim == 1 and absorption.shape[0] != 2:
1411+
if "floor" not in materials or "ceiling" not in materials:
14981412
raise ValueError(
1499-
"The size of the absorption array must be 2 for extrude, "
1500-
"for the floor and ceiling"
1413+
"Expected to find keys 'floor' and 'ceiling' in materials."
15011414
)
15021415

1503-
materials = make_materials(
1504-
floor=(absorption[0], 0.0), ceiling=(absorption[0], 0.0)
1505-
)
1416+
for mat in materials.values():
1417+
if not isinstance(mat, Material):
1418+
raise TypeError(
1419+
"Expected materials of type pyroomacoustics.Material "
1420+
f"(got {type(mat)})."
1421+
)
15061422

15071423
else:
1508-
# In this case, no material is provided, use totally reflective walls, no scattering
1424+
# In this case, no material is provided, use totally reflective
1425+
# walls, no scattering.
15091426
new_mat = Material(0.0, 0.0)
15101427
materials = {"floor": new_mat, "ceiling": new_mat}
15111428

15121429
new_corners = {}
15131430
new_corners["floor"] = np.pad(floor_corners, ((0, 1), (0, 0)), mode="constant")
15141431
new_corners["ceiling"] = (new_corners["floor"].T + height * v_vec).T
15151432

1516-
# we need the floor corners to ordered clockwise (for the normal to point outward)
1433+
# we need the floor corners to ordered clockwise
1434+
# (for the normal to point outward)
15171435
new_corners["floor"] = np.fliplr(new_corners["floor"])
15181436

15191437
# Concatenate new walls param with old ones.
@@ -2848,9 +2766,6 @@ class ShoeBox(Room):
28482766
The sampling frequency in Hz. Default is 8000.
28492767
t0: float, optional
28502768
The global starting time of the simulation in seconds. Default is 0.
2851-
absorption : float
2852-
Average amplitude absorption of walls. Note that this parameter is
2853-
deprecated; use `materials` instead!
28542769
max_order: int, optional
28552770
The maximum reflection order in the image source model. Default is 1,
28562771
namely direct sound and first order reflections.
@@ -2893,7 +2808,6 @@ def __init__(
28932808
p,
28942809
fs=8000,
28952810
t0=0.0,
2896-
absorption=None, # deprecated
28972811
max_order=1,
28982812
sigma2_awgn=None,
28992813
sources=None,
@@ -2941,32 +2855,7 @@ def __init__(
29412855

29422856
n_walls = len(self.wall_names)
29432857

2944-
############################
2945-
# BEGIN COMPATIBILITY CODE #
2946-
############################
2947-
2948-
if absorption is None:
2949-
absorption_compatibility_request = False
2950-
absorption = 0.0
2951-
else:
2952-
absorption_compatibility_request = True
2953-
2954-
# copy over the absorption coefficient
2955-
if isinstance(absorption, float):
2956-
absorption = dict(zip(self.wall_names, [absorption] * n_walls))
2957-
2958-
##########################
2959-
# END COMPATIBILITY CODE #
2960-
##########################
2961-
29622858
if materials is not None:
2963-
if absorption_compatibility_request:
2964-
warnings.warn(
2965-
"Because `materials` were specified, deprecated "
2966-
"`absorption` parameter is ignored.",
2967-
DeprecationWarning,
2968-
)
2969-
29702859
if isinstance(materials, Material):
29712860
materials = dict(zip(self.wall_names, [materials] * n_walls))
29722861
elif not isinstance(materials, dict):
@@ -2982,35 +2871,6 @@ def __init__(
29822871
materials[w_name], Material
29832872
), "Material not specified using correct class"
29842873

2985-
elif absorption_compatibility_request:
2986-
warnings.warn(
2987-
"Using absorption parameter is deprecated. Use `materials` with "
2988-
"`Material` object instead.",
2989-
DeprecationWarning,
2990-
)
2991-
2992-
# order the wall absorptions
2993-
if not isinstance(absorption, dict):
2994-
raise ValueError(
2995-
"`absorption` must be either a scalar or a "
2996-
"2x dim dictionary with entries for each "
2997-
"wall, namely: 'east', 'west', 'north', "
2998-
"'south', 'ceiling' (3d), 'floor' (3d)."
2999-
)
3000-
3001-
materials = {}
3002-
for w_name in self.wall_names:
3003-
if w_name in absorption:
3004-
# Fix the absorption
3005-
# 1 - a1 == sqrt(1 - a2) <-- a1 is former incorrect absorption, a2 is the correct definition based on energy
3006-
# <=> a2 == 1 - (1 - a1) ** 2
3007-
correct_abs = 1.0 - (1.0 - absorption[w_name]) ** 2
3008-
materials[w_name] = Material(energy_absorption=correct_abs)
3009-
else:
3010-
raise KeyError(
3011-
"Absorption needs to have keys 'east', 'west', "
3012-
"'north', 'south', 'ceiling' (3d), 'floor' (3d)."
3013-
)
30142874
else:
30152875
# In this case, no material is provided, use totally reflective
30162876
# walls, no scattering

0 commit comments

Comments
 (0)