Beispiel #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_read_csv_cirrus_details(filename):
    from acoustics.aio import read_csv_cirrus
    file = "_".join(filename) + ".csv"
    csv_path = os.path.join(data_path(), "cirrus", file)
    data = read_csv_cirrus(csv_path)
    if filename[0] == "det_global":
        np.sum(data.LAeq)
    else:
        np.sum(data["125Hz"])
Beispiel #3
0
def test_read_csv_cirrus_details(filename):
    from acoustics.aio import read_csv_cirrus
    file = "_".join(filename) + ".csv"
    csv_path = os.path.join(data_path(), "cirrus", file)
    data = read_csv_cirrus(csv_path)
    if filename[0] == "det_global":
        np.sum(data.LAeq)
    else:
        np.sum(data["125Hz"])
    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)
Beispiel #5
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
Beispiel #6
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])),
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