示例#1
0
    def test_attenuation_coefficient(self):
        
        """Test data is all at an air pressure of one standard atmosphere, 101.325 Pa."""
        data = np.loadtxt(data_path() + 'absorption_coefficient.csv', skiprows=1, delimiter=',')

        f = np.array([50.0, 63.0, 80.0, 100.0, 125.0, 160.0, 200.0, 250.0, 315.0, 400.0, 500.0, 630.0, 800.0, 1000.0, 1250.0, 1600.0, 2000.0, 2500.0, 3150.0, 4000.0, 5000.0, 6300.0, 8000.0, 10000.0])
        
        for row in data:
            temperature = 273.15 + row[0]   # Degrees Celsius to Kelvin
            relative_humidity = row[1]
            alpha = row[2:] / 1000.0    # Given in dB/km while we calculate in dB/m.
            
            assert(f.shape==alpha.shape)
            
            a = Atmosphere(temperature=temperature, relative_humidity=relative_humidity)
            calculated_alpha = a.attenuation_coefficient(f)
            
            np.testing.assert_array_almost_equal(alpha, calculated_alpha, decimal=2)
def test_nrc_1d():
    alpha = np.array([0.1, 0.25, 0.5, 0.9])
    calculated = nrc(alpha)
    real = 0.4375
    assert_almost_equal(calculated, real)


def test_nrc_2d():
    alphas = np.array([[0.1, 0.2, 0.3, 0.4], [0.4, 0.5, 0.6, 0.7]])
    calculated = nrc(alphas)
    real = np.array([0.25, 0.55])
    assert_array_almost_equal(calculated, real)


@pytest.mark.parametrize("file_name, bands, rt, expected", [
    (data_path() + 'ir_sportscentre_omni.wav', octave(125, 4000), 't30',
     np.array([7.24027654, 8.47019681, 6.79466752,
               6.51780663, 4.79692643, 4.08912686])),
    (data_path() + 'ir_sportscentre_omni.wav', octave(125, 4000), 'edt',
     np.array([4.71644743, 5.94075422, 6.00702329,
               5.94062563, 5.03778274, 3.73465316])),
    (data_path() + 'living_room_1.wav', octave(63, 8000), 't30',
     np.array([0.27658574, 0.36466480, 0.30282462, 0.25946725, 0.22710926,
               0.21056449, 0.20445301, 0.18080435])),
    (data_path() + 'living_room_1.wav', octave(63, 8000), 't20',
     np.array([0.30418539, 0.36486166, 0.15138373, 0.15594470, 0.10192937,
               0.07587109, 0.14564938, 0.15231023])),
    (data_path() + 'living_room_1.wav', octave(63, 8000), 't10',
     np.array([0.18067203, 0.06121885, 0.10898306, 0.02377203, 0.03865264,
               0.02303814, 0.10484486, 0.07141563])),
    (data_path() + 'living_room_1.wav', octave(63, 8000), 'edt',
示例#3
0
def test_nrc_1d():
    alpha = np.array([0.1, 0.25, 0.5, 0.9])
    calculated = nrc(alpha)
    real = 0.4375
    assert_almost_equal(calculated, real)


def test_nrc_2d():
    alphas = np.array([[0.1, 0.2, 0.3, 0.4], [0.4, 0.5, 0.6, 0.7]])
    calculated = nrc(alphas)
    real = np.array([0.25, 0.55])
    assert_array_almost_equal(calculated, real)


@pytest.mark.parametrize("file_name, bands, rt, expected", [
    (data_path() + 'ir_sportscentre_omni.wav', octave(125, 4000), 't30',
     np.array([7.388, 8.472, 6.795, 6.518, 4.797, 4.089])),
    (data_path() + 'ir_sportscentre_omni.wav', octave(125, 4000), 'edt',
     np.array([4.667, 5.942, 6.007, 5.941, 5.038, 3.735])),
    (data_path() + 'living_room_1.wav', octave(63, 8000), 't30',
     np.array([0.274, 0.365, 0.303, 0.259, 0.227, 0.211, 0.204, 0.181])),
    (data_path() + 'living_room_1.wav', octave(63, 8000), 't20',
     np.array([0.300, 0.365, 0.151, 0.156, 0.102, 0.076, 0.146, 0.152])),
    (data_path() + 'living_room_1.wav', octave(63, 8000), 't10',
     np.array([0.185, 0.061, 0.109, 0.024, 0.039, 0.023, 0.105, 0.071])),
    (data_path() + 'living_room_1.wav', octave(63, 8000), 'edt',
     np.array([0.267, 0.159, 0.080, 0.037, 0.021, 0.010, 0.022, 0.020])),
    (data_path() + 'living_room_1.wav', third(100, 5000), 't30',
     np.array([0.318, 0.340, 0.259, 0.311, 0.267, 0.376,
               0.342, 0.268, 0.212, 0.246, 0.211, 0.232,
               0.192, 0.231, 0.252, 0.202, 0.184, 0.216])),