Esempio n. 1
0
def example_4():
    # Collect a Grid
    grid_1 = Grid.read_envira(
        '../tests/data/MER2019 H_500_doc29_VVR/MER2018 - Doc29 - Lden y1974.dat'
    )

    # Collect a Grid to compare
    grid_2 = Grid.read_envira(
        '../tests/data/H_500_00_doc29/MER2015 - Doc29 - Lden y1974.dat')

    # Create a figure
    plot = GridPlot(grid_1)

    # Add the background
    plot.add_background('../data/Schiphol_RD900dpi.png')

    # Add a scale
    plot.add_scale()

    # Add the comparison heatmap
    plot.add_comparison_heatmap(grid_2, vmin=-3, vmax=3)

    # Add a colorbar
    plot.add_colorbar()

    # Save the figure
    plot.save('figures/plot_grid_example_4.pdf')

    # And show the plot
    plot.show()
Esempio n. 2
0
def test_statistics_multigrid():
    # Get the path to the Envira files
    file_paths = abs_path('data/MINIMER2015')

    # Set the pattern
    pattern = r'[\w\d\s]+\.dat'

    # Create a grid object from the data file
    grid = Grid.read_enviras(file_paths, pattern)
    stats = Grid.statistics(grid)

    assert isinstance(stats, dict)
Esempio n. 3
0
def test_statistics_nan():
    # Get the path to the Envira files
    file_paths = abs_path('data/MINIMER2015')

    # Set the pattern
    pattern = r'[\w\d\s]+\.dat'

    # Create a grid object from the data file
    grid = Grid.read_enviras(file_paths, pattern)

    # Modify the data
    grid.data = np.nan

    # Check if the statistics can be calculated
    Grid.statistics(grid)
Esempio n. 4
0
def example_1():
    # Collect a Grid
    grid = Grid.read_envira('../tests/data/MER2015 - Doc29 - Lden y1974.dat')

    # Create a figure
    plot = GridPlot(grid)

    # Add the background
    plot.add_background('../data/Schiphol_RD900dpi.png')

    # Add a scale
    plot.add_scale()

    # Add the terrain
    plot.add_terrain('../data/2013-spl-luchtvaartterrein.shp')

    # Add the place names
    plot.add_place_names('../data/plaatsnamen.csv')

    # Add the 58dB contour
    plot.add_contours(58, default['kleuren']['schemergroen'],
                      default['kleuren']['wolkengrijs_1'])

    # Add the 48dB contour
    plot.add_contours(48, default['kleuren']['schipholblauw'],
                      default['kleuren']['middagblauw'])

    # Save the figure
    plot.save('figures/plot_grid_example_1.pdf')

    # And show the plot
    plot.show()
Esempio n. 5
0
def test_read_enviras_inconsistent_list_size():
    # Get the path to the Envira files
    file_paths = abs_path('data/')

    # Set the pattern
    pattern = r'GP2018 - Lnight y201[67].dat'

    # Get the envira files
    file_names = [f for f in os.listdir(file_paths) if re.search(pattern, f)]

    # Create info and data lists
    cls_info = []
    cls_data = []

    # Read the envira files
    for file_name in file_names:
        info, data = read_envira(os.path.join(file_paths, file_name))
        cls_info.append(info)
        cls_data.append(data)

    try:
        # Add the data to a Grid object
        grid = Grid(data=cls_data, info=cls_info[0], unit='Lnight')

        # If the test reaches this point, the method is not working properly
        assert False
    except TypeError:

        # Check if the file names are correct
        assert file_names == ['GP2018 - Lnight y2016.dat', 'GP2018 - Lnight y2017.dat']
Esempio n. 6
0
def test_scale_per_time_interval_apply_night_time_correction():
    # Get the path to the Envira files
    file_paths = abs_path('data/H_500_00_doc29')

    # Create a dict for the meteotoeslag grids
    meteotoeslag = {}

    for unit in ['Lden', 'Lnight']:
        # Set the pattern
        pattern = r'[\w\d\s]+{}[\w\d\s]+\.dat'.format(unit)

        # Create a meteotoeslag grid object from the data file
        meteotoeslag[unit] = Grid.read_enviras(file_paths, pattern).meteotoeslag_grid_from_method('hybride')

    # Scale the meteotoeslag 2.1%
    meteotoeslag_lden_scaled_with = meteotoeslag['Lden'].copy().scale_per_time_interval(meteotoeslag['Lnight'],
                                                                                        scale_de=1.021)

    # Scale the meteotoeslag 2.1% without lnight time correction
    meteotoeslag_lden_scaled_without = meteotoeslag['Lden'].copy().scale_per_time_interval(meteotoeslag['Lnight'],
                                                                                           scale_de=1.021,
                                                                                           apply_lnight_time_correction=False)

    # Without lnight time correction, the scaled data Lden should be lower
    assert (meteotoeslag_lden_scaled_with.data > meteotoeslag_lden_scaled_without.data).all()
Esempio n. 7
0
def test_interpolation_function_nan():
    # Get the path to the Envira file
    file_path = abs_path('data/GP2018 - Lnight y2016.dat')

    # Create a grid object from the data file
    grid = Grid.read_envira(file_path)
    grid.data = np.nan
    grid.interpolation_function()
Esempio n. 8
0
def test_read_envira_other_shape():
    # Get the path to the Envira file
    file_path = abs_path('data/GP2018 - Lnight y2016h.dat')

    # Create a grid object from the data file
    grid = Grid.read_envira(file_path)

    assert grid.data.shape == (grid.info['y_number'], grid.info['x_number'])
Esempio n. 9
0
def test_refine_value():
    # Get the path to the Envira file
    file_path = abs_path('data/GP2018 - Lnight y2016.dat')

    # Create a grid object from the data file
    grid = Grid.read_envira(file_path)
    factor = np.nan
    grid.refine(factor)
Esempio n. 10
0
def test_refine_type():
    # Get the path to the Envira file
    file_path = abs_path('data/GP2018 - Lnight y2016.dat')

    # Create a grid object from the data file
    grid = Grid.read_envira(file_path)

    grid.data = []
    grid.refine(2)
Esempio n. 11
0
def test_to_shapefile():
    # Get the path to the Envira file
    file_path = abs_path('data/GP2018 - Lnight y2016.dat')

    # Create a grid object from the data file
    grid = Grid.read_envira(file_path)

    # Refine the grid and export as shapefile
    grid.refine(20).to_shapefile(abs_path('data/GP2018 - Lnight y2016.shp'), 48)
Esempio n. 12
0
def test_interpolation_function_nominal():
    # Get the path to the Envira file
    file_path = abs_path('data/GP2018 - Lnight y2016.dat')

    # Create a grid object from the data file
    grid = Grid.read_envira(file_path)
    interpolation = grid.interpolation_function()

    assert isinstance(interpolation, RectBivariateSpline)
Esempio n. 13
0
def test_hg():
    # Get the path to the Envira file
    file_path = abs_path('data/GP2018 - Lnight y2016.dat')

    # Create a grid object from the data file
    grid = Grid.read_envira(file_path)

    # Calculate the Hoeveelheid Geluid
    hg = grid.hg()

    assert isinstance(hg, float)
Esempio n. 14
0
def test_meteotoeslag_from_years_doubles():
    # Get the path to the Envira files
    file_paths = abs_path('data/MINIMER2015')

    # Set the pattern
    pattern = r'[\w\d\s]+\.dat'

    # Create a grid object from the data file
    grid = Grid.read_enviras(file_paths, pattern)

    # Calculate the meteotoeslag
    grid.meteotoeslag_from_years(np.ones((32,), dtype=int) * 1981)
Esempio n. 15
0
def test_meteotoeslag_from_years():
    # Get the path to the Envira files
    file_paths = abs_path('data/MINIMER2015')

    # Set the pattern
    pattern = r'[\w\d\s]+\.dat'

    # Create a grid object from the data file
    grid = Grid.read_enviras(file_paths, pattern)

    # Calculate the meteotoeslag
    grid.meteotoeslag_from_years([1981, 1984, 1993, 1994, 1996, 2000, 2002, 2010])
Esempio n. 16
0
def test_to_envira():
    # Get the path from the original Envira file
    original_file_path = abs_path('data/GP2018 - Lnight y2016.dat')

    # Create a grid object from the data file
    grid = Grid.read_envira(original_file_path)

    # Set the path to the new Envira file
    new_file_path = abs_path('data/envira-test.dat')

    # Export the grid to the new file
    grid.to_envira(new_file_path)

    # Create a grid object from the new data file
    grid_new = Grid.read_envira(new_file_path)

    # Test if the headers of the files are the same
    assert grid_new.info == grid.info

    # Check if the data is still correct
    np.testing.assert_equal(grid_new.data, grid.data)
Esempio n. 17
0
def test_hg_multigrid():
    # Get the path to the Envira files
    file_paths = abs_path('data/MINIMER2015')

    # Set the pattern
    pattern = r'[\w\d\s]+\.dat'

    # Create a grid object from the data file
    grid = Grid.read_enviras(file_paths, pattern)

    # Calculate the Hoeveelheid Geluid
    grid.hg()
Esempio n. 18
0
def test_read_enviras():
    # Get the path to the Envira files
    file_paths = abs_path('data/')

    # Set the pattern
    pattern = r'GP2018 - Lnight y201[67].dat'

    # Create a grid object from the data file
    grid = Grid.read_enviras(file_paths, pattern)

    # Check if the data is stored correctly
    assert isinstance(grid.data, list) and len(grid.data) == 2
    assert isinstance(grid.info, list) and len(grid.data) == 2
Esempio n. 19
0
def test_refine():
    """
    Test various use cases for consistency
    """
    # Get the path to the Envira file
    file_path = abs_path('data/GP2018 - Lnight y2016.dat')

    # Create a grid object from the data file
    grid2 = Grid.read_envira(file_path)

    # Refine the grid with a factor 2
    grid2.refine(2)

    # Check if the shape of the data matches the changed input
    assert grid2.data.shape == (285, 285)
    assert grid2.shape.x_number == 285
    assert grid2.shape.y_number == 285

    # Create a grid object from the data file
    grid05 = Grid.read_envira(file_path)

    # Refine the grid with a factor 0.5
    grid05.refine(0.5)

    # Check if the shape of the data matches the changed input
    assert grid05.data.shape == (72, 72)
    assert grid05.shape.x_number == 72
    assert grid05.shape.y_number == 72

    # Create a grid object from the data file
    grid35 = Grid.read_envira(file_path)

    # Refine the grid with a factor 3.5
    grid35.refine(3.5)

    assert grid35.data.shape == (498, 498)
    assert grid35.shape.x_number == 498
    assert grid35.shape.y_number == 498
Esempio n. 20
0
def test_scale():
    # Get the path to the Envira file
    file_path = abs_path('data/GP2018 - Lnight y2016.dat')

    # Create a grid object from the data file
    grid = Grid.read_envira(file_path)

    # Copy the data
    d = grid.data.copy()

    # Calculate the meteotoeslag
    grid.scale(2.)

    np.testing.assert_equal(grid.data, d + 10 * np.log10(2))
Esempio n. 21
0
def test_add_noise_from_grid_lden_lnight():
    # Get the path to the WBS file
    file_path = abs_path('../data/wbs2005.h5')

    # Create a wbs object from the data file
    wbs = WBS.read_file(file_path)

    # Get the path to the Lden Envira file
    file_path = abs_path('data/MER2015 - Doc29 - Lden y1974.dat')

    # Create a grid object from the data file
    grid = Grid.read_envira(file_path)

    # Add the interpolated Lden values from the grid
    wbs.add_noise_from_grid(grid)

    # Get the path to the Lnight Envira file
    file_path = abs_path('data/GP2018 - Lnight y2016.dat')

    # Create a grid object from the data file
    grid = Grid.read_envira(file_path)

    # Add the interpolated Lnight values from the grid
    wbs.add_noise_from_grid(grid)
Esempio n. 22
0
def test_scale_per_time_interval_incompatible_grids():
    # Get the path to the Envira files
    file_paths = abs_path('data/H_500_00_doc29')

    # Create a dict for the meteotoeslag grids
    meteotoeslag = {}

    for unit in ['Lden', 'Lnight']:
        # Set the pattern
        pattern = r'[\w\d\s]+{}[\w\d\s]+\.dat'.format(unit)

        # Create a meteotoeslag grid object from the data file
        meteotoeslag[unit] = Grid.read_enviras(file_paths, pattern).meteotoeslag_grid_from_method('hybride')

    # Scale the meteotoeslag without actually scaling
    meteotoeslag['Lden'].copy().scale_per_time_interval(meteotoeslag['Lnight'].refine(.5))
Esempio n. 23
0
def test_meteotoeslag_from_method():
    # Get the path to the Envira files
    file_paths = abs_path('data/MINIMER2015')

    # Set the pattern
    pattern = r'[\w\d\s]+\.dat'

    # Create a grid object from the data file
    grid = Grid.read_enviras(file_paths, pattern)

    # Calculate the meteotoeslag
    meteotoeslag, meteo_years = grid.meteotoeslag_from_method('hybride')

    # Check if the data is processed correctly
    assert meteo_years.shape == (32,)
    assert grid.data[0].shape == meteotoeslag.shape
    assert np.all(grid.data[0] <= meteotoeslag)
Esempio n. 24
0
def example_2():
    # Collect a Grid
    grid = Grid.read_enviras('../tests/data/MER2019 H_500_doc29_VVR',
                             r'[\w\d\s]+{}[\w\d\s]+\.dat'.format('Lden'))

    # Create a figure
    plot = GridPlot(grid)

    # Add the 58dB contour
    plot.add_contours(48, default['kleuren']['schipholblauw'],
                      default['kleuren']['middagblauw'])

    # Save the figure
    plot.save('figures/plot_grid_example_2.pdf')

    # And show the plot
    plot.show()
Esempio n. 25
0
def test_select_above_wrong_unit():
    # Get the path to the WBS file
    file_path = abs_path('../data/wbs2005.h5')

    # Create a wbs object from the data file
    wbs = WBS.read_file(file_path)

    # Get the path to the Envira file
    file_path = abs_path('data/MER2015 - Doc29 - Lden y1974.dat')

    # Create a grid object from the data file
    grid = Grid.read_envira(file_path)

    # Add the interpolated Lden values from the grid
    wbs.add_noise_from_grid(grid)

    # Select the Lnight values above 48
    wbs.select_above('Lnight', 40)
Esempio n. 26
0
def test_scale_per_time_interval_no_scale():
    # Get the path to the Envira files
    file_paths = abs_path('data/H_500_00_doc29')

    # Create a dict for the meteotoeslag grids
    meteotoeslag = {}

    for unit in ['Lden', 'Lnight']:
        # Set the pattern
        pattern = r'[\w\d\s]+{}[\w\d\s]+\.dat'.format(unit)

        # Create a meteotoeslag grid object from the data file
        meteotoeslag[unit] = Grid.read_enviras(file_paths, pattern).meteotoeslag_grid_from_method('hybride')

    # Scale the meteotoeslag without actually scaling
    meteotoeslag_lden_scaled = meteotoeslag['Lden'].copy().scale_per_time_interval(meteotoeslag['Lnight'])

    # Check if the values are still the same
    np.testing.assert_almost_equal(meteotoeslag['Lden'].data, meteotoeslag_lden_scaled.data, 12)
Esempio n. 27
0
def test_scale_per_time_interval_decrease():
    # Get the path to the Envira files
    file_paths = abs_path('data/H_500_00_doc29')

    # Create a dict for the meteotoeslag grids
    meteotoeslag = {}

    for unit in ['Lden', 'Lnight']:
        # Set the pattern
        pattern = r'[\w\d\s]+{}[\w\d\s]+\.dat'.format(unit)

        # Create a meteotoeslag grid object from the data file
        meteotoeslag[unit] = Grid.read_enviras(file_paths, pattern).meteotoeslag_grid_from_method('hybride')

    # Scale the meteotoeslag with a scaling factor below 1
    meteotoeslag_lden_scaled = meteotoeslag['Lden'].copy().scale_per_time_interval(meteotoeslag['Lnight'], scale_de=.9)

    # The Lden data should decrease due to the decrease of Lde
    assert (meteotoeslag_lden_scaled.data < meteotoeslag['Lden'].data).all()
Esempio n. 28
0
def test_select_above():
    # Get the path to the WBS file
    file_path = abs_path('../data/wbs2005.h5')

    # Create a wbs object from the data file
    wbs = WBS.read_file(file_path)

    # Get the path to the Envira file
    file_path = abs_path('data/MER2015 - Doc29 - Lden y1974.dat')

    # Create a grid object from the data file
    grid = Grid.read_envira(file_path)

    # Add the interpolated Lden values from the grid
    wbs.add_noise_from_grid(grid)

    # Select the Lden values above 40
    s = wbs.select_above(40, 'Lden').values

    assert isinstance(s, np.ndarray)
Esempio n. 29
0
def test_count_sleep_disturbed_people():
    # Get the path to the WBS file
    file_path = abs_path('../data/wbs2005.h5')

    # Create a wbs object from the data file
    wbs = WBS.read_file(file_path)

    # Get the path to the Envira file
    file_path = abs_path('data/GP2018 - Lnight y2016.dat')

    # Create a grid object from the data file
    grid = Grid.read_envira(file_path)

    # Add the interpolated Lnight values from the grid
    wbs.add_noise_from_grid(grid)

    # Count the sleep disturbed people
    s = wbs.count_sleep_disturbed_people()

    assert isinstance(s, float)
Esempio n. 30
0
def test_count_annoyed_people():
    # Get the path to the WBS file
    file_path = abs_path('../data/wbs2005.h5')

    # Create a wbs object from the data file
    wbs = WBS.read_file(file_path)

    # Get the path to the Envira file
    file_path = abs_path('data/MER2015 - Doc29 - Lden y1974.dat')

    # Create a grid object from the data file
    grid = Grid.read_envira(file_path)

    # Add the interpolated Lden values from the grid
    wbs.add_noise_from_grid(grid)

    # Count the annoyed people
    s = wbs.count_annoyed_people()

    assert isinstance(s, float)