本文整理汇总了Python中safe.test.utilities.standard_data_path函数的典型用法代码示例。如果您正苦于以下问题:Python standard_data_path函数的具体用法?Python standard_data_path怎么用?Python standard_data_path使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了standard_data_path函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_run
def test_run(self):
function = ClassifiedRasterHazardBuildingFunction.instance()
hazard_path = standard_data_path(
'hazard', 'classified_hazard.tif')
exposure_path = standard_data_path('exposure', 'small_building.shp')
hazard_layer = read_layer(hazard_path)
exposure_layer = read_layer(exposure_path)
function.hazard = SafeLayer(hazard_layer)
function.exposure = SafeLayer(exposure_layer)
function.run_analysis()
impact_layer = function.impact
impact_data = impact_layer.get_data()
# Count
expected_impact = {
'Not affected': 5,
'Low hazard zone': 2,
'Medium hazard zone': 9,
'High hazard zone': 5
}
result_impact = {}
for impact_feature in impact_data:
hazard_class = impact_feature[function.target_field]
if hazard_class in result_impact:
result_impact[hazard_class] += 1
else:
result_impact[hazard_class] = 1
self.assertDictEqual(expected_impact, result_impact)
示例2: test_run
def test_run(self):
"""TestClassifiedPolygonPopulationFunction: Test running the IF."""
generic_polygon_path = standard_data_path(
'hazard', 'classified_generic_polygon.shp')
population_path = standard_data_path(
'exposure', 'pop_binary_raster_20_20.asc')
generic_polygon_layer = read_layer(generic_polygon_path)
population_layer = read_layer(population_path)
impact_function = ClassifiedPolygonHazardPopulationFunction.instance()
impact_function.hazard = SafeLayer(generic_polygon_layer)
impact_function.exposure = SafeLayer(population_layer)
impact_function.run()
impact_layer = impact_function.impact
# Check the question
expected_question = ('In each of the hazard zones how many people '
'might be impacted.')
message = 'The question should be %s, but it returns %s' % (
expected_question, impact_function.question)
self.assertEqual(expected_question, impact_function.question, message)
# Count by hand
expected_affected_population = 181
result = numpy.nansum(impact_layer.get_data())
self.assertEqual(expected_affected_population, result, message)
示例3: test_run
def test_run(self):
function = AshRasterPopulationFunction.instance()
hazard_path = standard_data_path('hazard', 'ash_raster_wgs84.tif')
exposure_path = standard_data_path(
'exposure', 'pop_binary_raster_20_20.asc')
# We need clipping for both layers to be in the same dimension
clipped_hazard, clipped_exposure = clip_layers(
hazard_path, exposure_path)
hazard_layer = read_layer(clipped_hazard.source())
exposure_layer = read_layer(clipped_exposure.source())
# Let's set the extent to the hazard extent
function.hazard = SafeLayer(hazard_layer)
function.exposure = SafeLayer(exposure_layer)
function.run()
impact = function.impact
expected = [
[u'Population in very low hazard zone', 0],
[u'Population in medium hazard zone', 1374],
[u'Population in high hazard zone', 20],
[u'Population in very high hazard zone', 0],
[u'Population in low hazard zone', 8443],
[u'Total affected population', 9837],
[u'Unaffected population', 0],
[u'Total population', 9837],
[u'Population needing evacuation <sup>1</sup>', 9837]
]
self.assertListEqual(
expected, impact.impact_data['impact summary']['fields'])
示例4: test_run
def test_run(self):
function = ContinuousHazardPopulationFunction.instance()
hazard_path = standard_data_path(
'hazard', 'continuous_flood_20_20.asc')
exposure_path = standard_data_path(
'exposure', 'pop_binary_raster_20_20.asc')
hazard_layer = read_layer(hazard_path)
exposure_layer = read_layer(exposure_path)
function.hazard = SafeLayer(hazard_layer)
function.exposure = SafeLayer(exposure_layer)
function.run()
impact = function.impact
# print "keywords", keywords
keywords = impact.get_keywords()
total_needs_full = keywords['total_needs']
total_needs_weekly = OrderedDict([
[x['table name'], x['amount']] for x in
total_needs_full['weekly']
])
total_needs_single = OrderedDict([
[x['table name'], x['amount']] for x in
total_needs_full['single']
])
self.assertEqual(total_needs_weekly['Rice [kg]'], 336)
self.assertEqual(total_needs_weekly['Drinking Water [l]'], 2100)
self.assertEqual(total_needs_weekly['Clean Water [l]'], 8040)
self.assertEqual(total_needs_weekly['Family Kits'], 24)
self.assertEqual(total_needs_single['Toilets'], 6)
示例5: test_is_polygonal_layer
def test_is_polygonal_layer(self):
"""Test we can get the correct attributes back"""
# Polygon layer
layer = clone_shp_layer(
name='district_osm_jakarta',
include_keywords=True,
source_directory=standard_data_path('boundaries'))
message = 'isPolygonLayer, %s layer should be polygonal' % layer
self.assertTrue(is_polygon_layer(layer), message)
# Point layer
layer = clone_shp_layer(
name='volcano_point',
include_keywords=True,
source_directory=standard_data_path('hazard'))
message = '%s layer should be polygonal' % layer
self.assertFalse(is_polygon_layer(layer), message)
layer = clone_raster_layer(
name='padang_tsunami_mw8',
extension='.tif',
include_keywords=True,
source_directory=standard_data_path('hazard')
)
message = ('%s raster layer should not be polygonal' % layer)
self.assertFalse(is_polygon_layer(layer), message)
示例6: test_run
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)
示例7: test_run
def test_run(self):
"""TestVolcanoPointBuildingFunction: Test running the IF."""
volcano_path = standard_data_path('hazard', 'volcano_point.shp')
building_path = standard_data_path('exposure', 'buildings.shp')
hazard_layer = read_layer(volcano_path)
exposure_layer = read_layer(building_path)
impact_function = VolcanoPointBuildingFunction.instance()
impact_function.hazard = SafeLayer(hazard_layer)
impact_function.exposure = SafeLayer(exposure_layer)
impact_function._prepare()
impact_function.run()
impact_layer = impact_function.impact
# Check the question
expected_question = (
'In the event of volcano point how many buildings might be '
'affected')
message = 'The question should be %s, but it returns %s' % (
expected_question, impact_function.question)
self.assertEqual(expected_question, impact_function.question, message)
# The buildings should all be categorised into 3000 zone
zone_sum = sum(impact_layer.get_data(
attribute=impact_function.target_field))
expected_sum = 3 * 181
message = 'Expecting %s, but it returns %s' % (expected_sum, zone_sum)
self.assertEqual(zone_sum, expected_sum, message)
示例8: test_run_point_exposure
def test_run_point_exposure(self):
"""Run the IF for point exposure.
See https://github.com/AIFDR/inasafe/issues/2156.
"""
generic_polygon_path = standard_data_path(
'hazard', 'classified_generic_polygon.shp')
building_path = standard_data_path('exposure', 'building-points.shp')
hazard_layer = QgsVectorLayer(generic_polygon_path, 'Hazard', 'ogr')
exposure_layer = QgsVectorLayer(building_path, 'Buildings', 'ogr')
# Let's set the extent to the hazard extent
extent = hazard_layer.extent()
rect_extent = [
extent.xMinimum(), extent.yMaximum(),
extent.xMaximum(), extent.yMinimum()]
impact_function = ClassifiedPolygonHazardBuildingFunction.instance()
impact_function.hazard = SafeLayer(hazard_layer)
impact_function.exposure = SafeLayer(exposure_layer)
impact_function.requested_extent = rect_extent
impact_function.run()
impact_layer = impact_function.impact
# Check the question
expected_question = ('In each of the hazard zones how many buildings '
'might be affected.')
message = 'The question should be %s, but it returns %s' % (
expected_question, impact_function.question)
self.assertEqual(expected_question, impact_function.question, message)
zone_sum = impact_layer.get_data(
attribute=impact_function.target_field)
high_zone_count = zone_sum.count('High Hazard Zone')
medium_zone_count = zone_sum.count('Medium Hazard Zone')
low_zone_count = zone_sum.count('Low Hazard Zone')
# The result
expected_high_count = 12
expected_medium_count = 172
expected_low_count = 3
message = 'Expecting %s for High Hazard Zone, but it returns %s' % (
high_zone_count, expected_high_count)
self.assertEqual(high_zone_count, expected_high_count, message)
message = 'Expecting %s for Medium Hazard Zone, but it returns %s' % (
expected_medium_count, medium_zone_count)
self.assertEqual(medium_zone_count, expected_medium_count, message)
message = 'Expecting %s for Low Hazard Zone, but it returns %s' % (
expected_low_count, low_zone_count)
self.assertEqual(expected_low_count, low_zone_count, message)
示例9: test_raster_to_vector_and_line_intersection
def test_raster_to_vector_and_line_intersection(self):
"""Test the core part of the analysis.
1. Test creation of spatial index of flood cells
2. Test intersection of flood cells with roads layer
"""
raster_name = standard_data_path(
'hazard',
'tsunami_wgs84.tif')
exposure_name = standard_data_path(
'exposure',
'roads_osm_4326.shp')
raster = QgsRasterLayer(raster_name, 'Flood')
exposure = QgsVectorLayer(exposure_name, 'Exposure', 'ogr')
ranges = OrderedDict()
ranges[0] = [0, 1]
ranges[1] = [1, 2]
ranges[2] = [2, 100]
index, flood_cells_map = _raster_to_vector_cells(
raster, ranges, exposure.crs())
self.assertEqual(len(flood_cells_map), 4198)
rect_with_all_cells = raster.extent()
rect_with_4_cells = QgsRectangle(106.824, -6.177, 106.825, -6.179)
rect_with_0_cells = QgsRectangle(106.818, -6.168, 106.828, -6.175)
self.assertEqual(len(index.intersects(rect_with_all_cells)), 4198)
self.assertEqual(len(index.intersects(rect_with_4_cells)), 43)
self.assertEqual(len(index.intersects(rect_with_0_cells)), 504)
layer = create_layer(exposure)
new_field = QgsField('flooded', QVariant.Int)
layer.dataProvider().addAttributes([new_field])
request = QgsFeatureRequest()
_intersect_lines_with_vector_cells(
exposure, request, index, flood_cells_map, layer, 'flooded')
feature_count = layer.featureCount()
self.assertEqual(feature_count, 388)
flooded = 0
iterator = layer.getFeatures()
for feature in iterator:
attributes = feature.attributes()
if attributes[3] == 1:
flooded += 1
self.assertEqual(flooded, 40)
示例10: setUp
def setUp(self):
self.keyword_io = KeywordIO()
# SQLite Layer
uri = QgsDataSourceURI()
sqlite_building_path = standard_data_path(
'exposure', 'exposure.sqlite')
uri.setDatabase(sqlite_building_path)
uri.setDataSource('', 'buildings_osm_4326', 'Geometry')
self.sqlite_layer = QgsVectorLayer(
uri.uri(), 'OSM Buildings', 'spatialite')
self.expected_sqlite_keywords = {
'datatype': 'OSM'
}
# Raster Layer keywords
hazard_path = standard_data_path('hazard', 'tsunami_wgs84.tif')
self.raster_layer, _ = load_layer(hazard_path)
self.expected_raster_keywords = {
'hazard_category': 'single_event',
'title': 'Generic Continuous Flood',
'hazard': 'flood',
'continuous_hazard_unit': 'generic',
'layer_geometry': 'raster',
'layer_purpose': 'hazard',
'layer_mode': 'continuous',
'keyword_version': '3.5'
}
# Vector Layer keywords
vector_path = standard_data_path('exposure', 'buildings_osm_4326.shp')
self.vector_layer, _ = load_layer(vector_path)
self.expected_vector_keywords = {
'keyword_version': '3.5',
'structure_class_field': 'FLOODED',
'value_mapping': {},
'title': 'buildings_osm_4326',
'layer_geometry': 'polygon',
'layer_purpose': 'exposure',
'layer_mode': 'classified',
'exposure': 'structure',
}
# Keyword less layer
keywordless_path = standard_data_path('other', 'keywordless_layer.shp')
self.keywordless_layer, _ = load_layer(keywordless_path)
# Keyword file
self.keyword_path = standard_data_path(
'exposure', 'buildings_osm_4326.xml')
示例11: test_converting
def test_converting(self):
"""Test converting grif file to tiff."""
dialog = ShakemapConverterDialog(PARENT, IFACE)
dialog.use_output_default.setEnabled(False)
grid_path = standard_data_path(
'hazard',
'shake_data',
'20131105060809',
'output',
'grid.xml')
output_raster = unique_filename(
prefix='result_grid',
suffix='.tif',
dir=temp_dir('test'))
dialog.load_result.setEnabled(True)
dialog.load_result.setChecked(False)
dialog.input_path.setText(grid_path)
dialog.nearest_mode.setChecked(True)
dialog.output_path.setText(output_raster)
button = dialog.button_box.button(QDialogButtonBox.Ok)
button.click()
msg = 'Raster is not created'
output_path = '%s-nearest.tif' % output_raster[:-4]
self.assertTrue(os.path.exists(output_path), msg)
示例12: test_relative_path
def test_relative_path(self):
"""Test we calculate the relative paths correctly when saving scenario.
"""
result, message = setup_scenario(
self.DOCK,
hazard='Classified Flood',
exposure='Population')
self.assertTrue(result, message)
fake_dir = standard_data_path()
scenario_file = unique_filename(
prefix='scenarioTest', suffix='.txt', dir=fake_dir)
exposure_layer = self.DOCK.get_exposure_layer().publicSource()
hazard_layer = self.DOCK.get_hazard_layer().publicSource()
relative_exposure = self.save_scenario_dialog.relative_path(
scenario_file, exposure_layer)
relative_hazard = self.save_scenario_dialog.relative_path(
scenario_file, hazard_layer)
if 'win32' in sys.platform:
# windows
self.assertEqual(
'exposure\\pop_binary_raster_20_20.asc',
relative_exposure)
self.assertEqual(
'hazard\\classified_flood_20_20.asc',
relative_hazard)
else:
self.assertEqual(
'exposure/pop_binary_raster_20_20.asc',
relative_exposure)
self.assertEqual(
'hazard/classified_flood_20_20.asc',
relative_hazard)
示例13: setUp
def setUp(self):
"""Setup before each test."""
# Download files (which are local files) to realtime-test temp folder
local_path = os.path.join(temp_dir('realtime-test'))
shake_data = standard_data_path('hazard', 'shake_data', SHAKE_ID)
shutil.copytree(
shake_data, os.path.join(local_path, 'shakemaps', SHAKE_ID))
示例14: test_update_keywords
def test_update_keywords(self):
"""Test append file keywords with update_keywords method."""
self.maxDiff = None
layer = clone_raster_layer(
name='tsunami_wgs84',
extension='.tif',
include_keywords=True,
source_directory=standard_data_path('hazard'))
new_keywords = {
'hazard_category': 'multiple_event'
}
self.keyword_io.update_keywords(layer, new_keywords)
keywords = self.keyword_io.read_keywords(layer)
expected_keywords = {
'hazard_category': 'multiple_event',
'title': 'Tsunami',
'hazard': 'tsunami',
'continuous_hazard_unit': 'metres',
'layer_geometry': 'raster',
'layer_purpose': 'hazard',
'layer_mode': 'continuous',
'keyword_version': inasafe_keyword_version
}
expected_keywords = {
k: get_unicode(v) for k, v in expected_keywords.iteritems()
}
self.assertDictEqual(keywords, expected_keywords)
示例15: test_is_polygonal_layer
def test_is_polygonal_layer(self):
"""Test we can get the correct attributes back"""
# Polygon layer
layer = load_test_vector_layer(
'aggregation',
'district_osm_jakarta.geojson',
clone=True
)
message = 'isPolygonLayer, %s layer should be polygonal' % layer
self.assertTrue(is_polygon_layer(layer), message)
# Point layer
layer = load_test_vector_layer('hazard', 'volcano_point.geojson')
message = '%s layer should be polygonal' % layer
self.assertFalse(is_polygon_layer(layer), message)
# Raster layer
layer = clone_raster_layer(
name='earthquake',
extension='.tif',
include_keywords=True,
source_directory=standard_data_path('hazard')
)
message = ('%s raster layer should not be polygonal' % layer)
self.assertFalse(is_polygon_layer(layer), message)