def test_generate_ascent_route_success(): test_variables = "array, start_coordinate, expected_result" test_data = [ param(np.array([[0, 1, 0], [0, 0, 0], [0, 0, 0]]), Coordinate(0, 0), [Coordinate(0, 0), Coordinate(1, 0)], id='single_step'), param(np.array([[1, 2, 3], [0, 0, 4], [0, 0, 5]]), Coordinate(0, 0), [ Coordinate(0, 0), Coordinate(1, 0), Coordinate(2, 0), Coordinate(2, 1), Coordinate(2, 2) ], id='north_east_pass') # param( # np.array([[1, 2, 3], # [2, 2, 4], # [1, 1, 5]]), # Coordinate(0, 0), # [Coordinate(0, 0), Coordinate(1, 0), Coordinate(2, 0), # Coordinate(2, 1), Coordinate(2, 2)], # id='north_east_pass' # ), ] return test_variables, test_data
def test_is_visited_success(): test_variables = "ascender, summit_heatmap, coordinate, expected_result" test_data = [ param(create_ascender(np.array([[1, 2, 3], [2, 2, 4], [1, 1, 5]])), np.array([[-1, -1, -1], [-1, -1, -1], [0, -1, -1]]), Coordinate(0, 2), True, id='bottom_left_visited'), param(create_ascender(np.array([[1, 2, 3], [2, 2, 4], [1, 1, 5]])), np.array([[-1, -1, -1], [-1, -1, -1], [0, -1, -1]]), Coordinate(2, 2), False, id='bottom_right_unvisited') ] return test_variables, test_data
def test_get_summit_coord_success(): test_variables = "ascender, expected_result" test_data = [ param(create_ascender(np.array([[1, 2, 3], [2, 2, 4], [8, 1, 5]])), Coordinate(0, 2), id='summit_bottom_left') ] return test_variables, test_data
def test_calculate_steepest_ascent_coordinate_success(): test_variables = "array, current_coordinate, expected_result" test_data = [ param(np.array([[1, 2, 3], [4, 5, 6], [6, 8, 9]]), Coordinate(1, 1), Coordinate(1, 2), id='move_south'), param(np.array([[1, 2, 3], [4, 9, 6], [6, 8, 5]]), Coordinate(2, 2), Coordinate(1, 2), id='move_west'), param(np.array([[1, 2, 3], [4, 5, 6], [6, 8, 9]]), Coordinate(2, 2), Coordinate(2, 2), id='stay_stationary'), param(np.array([[0, 0, 0], [1, 2, 3], [0, 0, 0]]), Coordinate(1, 1), Coordinate(2, 1), id='move_west_from_centre') ] return test_variables, test_data
from gradientascent.ascent_plotter import AscentPlotter from gradientascent.digital_elevation_model import DigitalElevationModel from gradientascent.ascender import Ascender, Coordinate EVEREST_PATH = r"C:\Users\jacob\OneDrive\Documents\Data\HeightData\Everest\GeoTiffs\n27e086.tif" dem = DigitalElevationModel.from_file_path(EVEREST_PATH) array = dem.get_array() array = array[-500:, -500:] coord = Coordinate(130, 194) asc = Ascender(array, coord) ap = AscentPlotter.animate(asc)
def create_ascender(array): return Ascender(array, Coordinate(0, 0))
def _get_next_unvisited_coord(self): try: cy, cx = np.argwhere(self.summit_heatmap == -1)[0] return Coordinate(cx, cy) except IndexError: return None
def _get_summit_coord(array): y, x = np.unravel_index(np.argmax(array), array.shape) return Coordinate(x, y)
trace, value = self._get_trace_to_visited_coordinate( next_unvisited_coord) self._mark_trace_state(trace, value) return self.summit_heatmap def plot_summit_heatmap(self): summit_heatmap = self.create_summit_heatmap() plt.figure(figsize=(5, 5)) sns.heatmap(summit_heatmap, annot=False, xticklabels=False, yticklabels=False, cbar=False) plt.show() if __name__ == '__main__': from utils import generate_gaussian_array from gradientascent.ascent_plotter import AscentPlotter arr = generate_gaussian_array(200, 200, 1e-3) crd = Coordinate(5, 44) asc = Ascender(arr, crd) AscentPlotter.animate(asc) smt = Summitter(asc) c = smt.summit_coord smt.plot_summit_heatmap() print(smt.summit_heatmap)
plt.axis('off') ax[0].set_axis_off() ax[1].set_axis_off() plt.show() @staticmethod def _create_height_array(current_height, max_, min_, height, width, **kwargs): height_val = int(height * (current_height - min_) / (max_ - min_)) array = np.zeros((height, 1)) array[-height_val:] = 1 return np.concatenate([array] * width, axis=1) @staticmethod def _highlight_cell(coordinate: Coordinate, ax, **kwargs): rect = plt.Rectangle((coordinate.x-.5, coordinate.y-.5), 1, 1, fill=False, **kwargs) ax.add_patch(rect) return rect if __name__ == '__main__': import numpy as np from utils import generate_gaussian_array arr = generate_gaussian_array(20, 20, 0.05) crd = Coordinate(0, 0) asc = Ascender(arr, crd) ap = AscentPlotter.animate(asc)
def test_get_bordering_coordinates_success(): test_variables = "array, current_coordinate, expected_result" test_data = [ param(np.zeros((3, 3)), Coordinate(0, 0), [Coordinate(1, 0), Coordinate(0, 1)], id='top_left'), param(np.zeros((3, 3)), Coordinate(1, 1), [ Coordinate(0, 1), Coordinate(2, 1), Coordinate(1, 2), Coordinate(1, 0) ], id='centre'), param(np.zeros((3, 3)), Coordinate(2, 2), [Coordinate(1, 2), Coordinate(2, 1)], id='bottom_right'), param(np.zeros((3, 3)), Coordinate(1, 0), [Coordinate(0, 0), Coordinate(2, 0), Coordinate(1, 1)], id='central_top') ] return test_variables, test_data