def test_CalculateInsolationDarkImage(self): # given image_size = 4 input_image = Image(size=image_size, fill_color=100) insolation = Insolation(input_image) expected_image = Image(size=image_size, fill_color=0) # completely dark sun_position = [2, 2, 10] # when insolation.calculate_insolation_cpu(sun_position) # then self.assertEqual(expected_image, insolation.insolation_image)
def test_CalculateInsolationWhiteImage(self): # given image_size = 4 input_image = Image(size=image_size, fill_color=100) insolation = Insolation(input_image) expected_image = Image( size=image_size, fill_color=CAL_PER_HOUR_PER_PIXEL) # every pixel receives calories sun_position = [2, 2, 200] # when insolation.calculate_insolation_cpu(sun_position) # then self.assertEqual(expected_image, insolation.insolation_image)
def test_CalculateInsolationForDaylightHours(self): # given image_size = 10 input_image = Image(size=image_size, fill_color=0) insolation = Insolation(input_image) daylight_hours = 7 # every pixel receives calories per hour expected_image = Image(size=image_size, fill_color=CAL_PER_HOUR_PER_PIXEL * daylight_hours) # when insolation.calculate_insolation_for_daylight_hours(daylight_hours) # then self.assertEqual(expected_image, insolation.insolation_image)
def prepare_insolation_calculation(self, map_name, daylight_hours, sun_start_elevation, sun_start_azimuth, sun_max_elevation, reflection_coefficient): """ It finds the correct map obect and creates an image and an object of insolation class. Then the heightmap gets loaded and the calculation of the insolation gets started. The results will be shown in the UI and saved. :param map_name: String of the current map name :param daylight_hours: Integer of the number of daylight hours :param sun_start_elevation: Float of the start elevation of the sun :param sun_start_azimuth: Float of the start azimuth of the sun :param sun_max_elevation: Float of the maximal sun elevation (noon) :param reflection_coefficient: Float of the reflection coeficient. It states how much light of the neighbour pixel will be reflected. """ map = self.maps[map_name] self.image_insolation_map = Image(size=self.image_height_map.size) insolation = Insolation(self) self.image_height_map.load_image(map.height_map_path) self.image_insolation_map = insolation.calculate_actual_insolation(map, daylight_hours, sun_start_elevation, sun_start_azimuth, sun_max_elevation, reflection_coefficient) self.main_window.frames['ProbabilityCloudWindow'].draw_insolation_image(self.image_insolation_map) save_path = "resources/results/" + map_name + "/" + map_name + "_" + str(daylight_hours) + "daylight_hours_insolation_image.png" self.image_insolation_map.save_image(save_path)
def test_CalculateLineHeightTest1(self): # given point1 = [0.0, 0.0, 0.0] point2 = [5.0, 5.0, 3.0] x = 3.0 y = 3.0 expected_height = 1.8 # when actual_height = Insolation.calculate_line_height(point1, point2, x, y) actual_height = round(actual_height, 2) # then self.assertEqual(expected_height, actual_height)
def test_CalculateLineHeightSameXandY(self): # given point1 = [5., 5., 5.] point2 = [5., 5., 3.] x = 5. y = 5. expected_height = 5. # when actual_height = Insolation.calculate_line_height(point1, point2, x, y) actual_height = round(actual_height, 2) # then self.assertEqual(expected_height, actual_height)
def test_CalculateLineHeightTest3(self): # given point1 = [4.58584, -4.76206, -2.19952] point2 = [-6.50204, 5.6101, 1.0] x = -8.75 y = 7.71 expected_height = 1.65 # when actual_height = Insolation.calculate_line_height(point1, point2, x, y) actual_height = round(actual_height, 2) # then self.assertEqual(expected_height, actual_height)
def test_CalculateLineHeightTest2(self): # given point1 = [-4.15845, -2.84944, -1.26391] point2 = [7.20618, 2.30449, 2.61415] x = 1.1 y = -0.47 expected_height = 0.53 # when actual_height = Insolation.calculate_line_height(point1, point2, x, y) actual_height = round(actual_height, 2) # then self.assertEqual(expected_height, actual_height)