def test_run(self): function = FloodRasterRoadsFunction.instance() hazard_path = standard_data_path('hazard', 'continuous_flood_20_20.asc') exposure_path = standard_data_path('exposure', 'roads.shp') # noinspection PyCallingNonCallable hazard_layer = QgsRasterLayer(hazard_path, 'Flood') # noinspection PyCallingNonCallable exposure_layer = QgsVectorLayer(exposure_path, 'Roads', 'ogr') # Let's set the extent to the hazard extent extent = hazard_layer.extent() rect_extent = [ extent.xMinimum(), extent.yMaximum(), extent.xMaximum(), extent.yMinimum() ] function.hazard = SafeLayer(hazard_layer) function.exposure = SafeLayer(exposure_layer) function.requested_extent = rect_extent function.run() impact = function.impact keywords = impact.get_keywords() self.assertEquals(function.target_field, keywords['target_field']) expected_inundated_feature = 182 count = sum(impact.get_data(attribute=function.target_field)) self.assertEquals(count, expected_inundated_feature)
def test_run(self): function = FloodRasterRoadsFunction.instance() hazard_path = test_data_path('hazard', 'continuous_flood_20_20.asc') exposure_path = test_data_path('exposure', 'roads.shp') # noinspection PyCallingNonCallable hazard_layer = QgsRasterLayer(hazard_path, 'Flood') # noinspection PyCallingNonCallable exposure_layer = QgsVectorLayer(exposure_path, 'Roads', 'ogr') # Let's set the extent to the hazard extent extent = hazard_layer.extent() rect_extent = [ extent.xMinimum(), extent.yMaximum(), extent.xMaximum(), extent.yMinimum()] function.hazard = SafeLayer(hazard_layer) function.exposure = SafeLayer(exposure_layer) function.requested_extent = rect_extent function.run() impact = function.impact keywords = impact.get_keywords() self.assertEquals(function.target_field, keywords['target_field']) expected_inundated_feature = 182 count = sum(impact.get_data(attribute=function.target_field)) self.assertEquals(count, expected_inundated_feature)
def test_is_valid(self): """Test is_valid.""" impact_functions = [ # Earthquake EarthquakeBuildingFunction(), ITBFatalityFunction(), PAGFatalityFunction(), # Generic ClassifiedPolygonHazardBuildingFunction(), ClassifiedPolygonHazardPopulationFunction(), ClassifiedRasterHazardBuildingFunction(), ClassifiedRasterHazardPopulationFunction(), ContinuousHazardPopulationFunction(), # Inundation FloodEvacuationVectorHazardFunction(), FloodPolygonRoadsFunction(), FloodRasterBuildingFunction(), FloodEvacuationRasterHazardFunction(), FloodRasterRoadsFunction(), FloodPolygonBuildingFunction(), TsunamiEvacuationFunction(), # Volcanic VolcanoPointBuildingFunction(), VolcanoPointPopulationFunction(), VolcanoPolygonBuildingFunction(), VolcanoPolygonPopulationFunction() ] for impact_function in impact_functions: valid = impact_function.metadata().is_valid() impact_function_name = impact_function.__class__.__name__ message = '%s is invalid because %s' % (impact_function_name, valid[1]) self.assertTrue(valid[0], message) if valid[0]: print '%s has a valid metadata.' % impact_function_name
def test_is_valid(self): """Test is_valid.""" impact_functions = [ # Earthquake EarthquakeBuildingFunction(), ITBFatalityFunction(), PAGFatalityFunction(), ITBBayesianFatalityFunction(), # Generic ClassifiedPolygonHazardBuildingFunction(), ClassifiedPolygonHazardLandCoverFunction(), ClassifiedPolygonHazardPopulationFunction(), ClassifiedPolygonHazardPolygonPeopleFunction(), ClassifiedRasterHazardBuildingFunction(), ClassifiedRasterHazardPopulationFunction(), ContinuousHazardPopulationFunction(), # Inundation FloodEvacuationVectorHazardFunction(), FloodPolygonRoadsFunction(), FloodRasterBuildingFunction(), FloodEvacuationRasterHazardFunction(), FloodRasterRoadsFunction(), FloodPolygonBuildingFunction(), # Tsunami TsunamiEvacuationFunction(), TsunamiRasterRoadsFunction(), TsunamiRasterLandcoverFunction(), TsunamiRasterBuildingFunction(), # Volcanic VolcanoPointBuildingFunction(), VolcanoPointPopulationFunction(), VolcanoPolygonBuildingFunction(), VolcanoPolygonPopulationFunction(), # Volcanic Ash AshRasterLandCoverFunction(), AshRasterPlacesFunction(), AshRasterPopulationFunction() ] self.assertEqual(len(impact_functions), len(EXPECTED_IF)) for impact_function in impact_functions: valid = impact_function.metadata().is_valid() impact_function_name = impact_function.__class__.__name__ message = '%s is invalid because %s' % (impact_function_name, valid[1]) self.assertTrue(valid[0], message) if valid[0]: # print '%s has a valid metadata.' % impact_function_name continue
def test_zero_intersection(self): hazard_path = test_data_path('hazard', 'continuous_flood_20_20.asc') exposure_path = test_data_path('exposure', 'roads.shp') # noinspection PyCallingNonCallable hazard_layer = QgsRasterLayer(hazard_path, 'Flood') # noinspection PyCallingNonCallable exposure_layer = QgsVectorLayer(exposure_path, 'Roads', 'ogr') # Let's set the extent to the hazard extent function = FloodRasterRoadsFunction.instance() rect_extent = [106.831991, -6.170044, 106.834868, -6.167793] function.hazard = SafeLayer(hazard_layer) function.exposure = SafeLayer(exposure_layer) function.requested_extent = rect_extent with self.assertRaises(ZeroImpactException): function.run()
def test_zero_intersection(self): hazard_path = test_data_path( 'hazard', 'continuous_flood_20_20.asc') exposure_path = test_data_path( 'exposure', 'roads.shp') # noinspection PyCallingNonCallable hazard_layer = QgsRasterLayer(hazard_path, 'Flood') # noinspection PyCallingNonCallable exposure_layer = QgsVectorLayer(exposure_path, 'Roads', 'ogr') # Let's set the extent to the hazard extent function = FloodRasterRoadsFunction.instance() rect_extent = [106.831991, -6.170044, 106.834868, -6.167793] function.hazard = SafeLayer(hazard_layer) function.exposure = SafeLayer(exposure_layer) function.requested_extent = rect_extent with self.assertRaises(ZeroImpactException): function.run()