本文整理汇总了Python中safe.impact_functions.core.get_exposure_layer函数的典型用法代码示例。如果您正苦于以下问题:Python get_exposure_layer函数的具体用法?Python get_exposure_layer怎么用?Python get_exposure_layer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_exposure_layer函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: run
def run(layers):
"""Risk plugin for earthquake school damage
"""
# Extract data
H = get_hazard_layer(layers) # Ground shaking
E = get_exposure_layer(layers) # Building locations
# Interpolate hazard level to building locations
H = assign_hazard_values_to_exposure_data(H, E,
attribute_name='MMI')
# Extract relevant numerical data
coordinates = E.get_geometry()
shaking = H.get_data()
# Calculate building damage
building_damage = []
for i in range(len(shaking)):
x = float(shaking[i]['MMI'])
if x < 6.0 or (x != x): # x != x -> check for nan pre python 2.6
value = 0.0
else:
value = (0.692 * (x ** 4) -
15.82 * (x ** 3) +
135.0 * (x ** 2) -
509.0 * x + 714.4)
building_damage.append({'DAMAGE': value, 'MMI': x})
# Create new layer and return
V = Vector(data=building_damage,
projection=E.get_projection(),
geometry=coordinates)
return V
开发者ID:ingenieroariel,项目名称:inasafe,代码行数:35,代码来源:unspecific_building_impact_model.py
示例2: run
def run(layers):
"""Risk plugin for earthquake fatalities
Input
layers: List of layers expected to contain
H: Raster layer of flood depth
P: Raster layer of population data on the same grid as H
"""
threshold = 1 # Load above which people are regarded affected [kg/m2]
# Identify hazard and exposure layers
inundation = get_hazard_layer(layers) # Tephra load [kg/m2]
population = get_exposure_layer(layers) # Density [people/km^2]
# Extract data as numeric arrays
D = inundation.get_data(nan=0.0) # Depth
P = population.get_data(nan=0.0, scaling=True) # Population density
# Calculate impact as population exposed to depths > threshold
I = numpy.where(D > threshold, P, 0)
# Generate text with result for this study
number_of_people_affected = numpy.nansum(I.flat)
impact_summary = ('%i people affected by ash levels greater '
'than %i kg/m^2' % (number_of_people_affected,
threshold))
# Create raster object and return
R = Raster(I,
projection=inundation.get_projection(),
geotransform=inundation.get_geotransform(),
name='People affected',
keywords={'impact_summary': impact_summary})
return R
开发者ID:CharlesRethman,项目名称:inasafe,代码行数:35,代码来源:ashload_population_impact.py
示例3: prepare
def prepare(self, layers):
"""Prepare this impact function for running the analysis.
This method should normally be called in your concrete class's
run method before it attempts to do any real processing. This
method will do any needed house keeping such as:
* checking that the exposure and hazard layers sufficiently
overlap (post 3.1)
* clipping or subselecting features from both layers such that
only features / coverage within the actual analysis extent
will be analysed (post 3.1)
* raising errors if any untenable condition exists e.g. extent has
no valid CRS. (post 3.1)
We suggest to overload this method in your concrete class
implementation so that it includes any impact function specific checks
too.
..note: For 3.1, we will still do those preprocessing in analysis
class. We will just need to check if the function_type is
'qgis2.0', it needs to have the extent set.
:param layers: List of layers (hazard and exposure). This is
necessary now, until we streamline the preprocess in the base class
and remove unnecessary routines in analysis, impact_calculator,
impact_calculator_thread, and calculate_safe_impact module.
:type layers: list
# """
if layers is not None:
self.hazard = get_hazard_layer(layers)
self.exposure = get_exposure_layer(layers)
开发者ID:Charlotte-Morgan,项目名称:inasafe,代码行数:32,代码来源:base.py
示例4: run
def run(layers):
"""Risk plugin for volcano population impact
Input
layers: List of layers expected to contain
H: Raster layer of volcanic hazard level
P: Raster layer of population data on the same grid as H
"""
# Identify hazard and exposure layers
# Volcanic hazard level [0-1]
volcanic_hazard_level = get_hazard_layer(layers)
population = get_exposure_layer(layers) # Density [people/area]
# Extract data as numeric arrays
V = volcanic_hazard_level.get_data(nan=0.0)
# Population density
P = population.get_data(nan=0.0, scaling=True)
# Calculate impact as population exposed to depths > threshold
I = numpy.where(V > 2.0 / 3, P, 0)
# Generate text with result for this study
number_of_people_affected = numpy.nansum(I.flat)
impact_summary = ('%i people affected by volcanic hazard level greater'
' than 0.667' % number_of_people_affected)
# Create raster object and return
R = Raster(I,
projection=volcanic_hazard_level.get_projection(),
geotransform=volcanic_hazard_level.get_geotransform(),
name='People affected',
keywords={'impact_summary': impact_summary})
return R
开发者ID:CharlesRethman,项目名称:inasafe,代码行数:34,代码来源:general_volcanic_population_impact.py
示例5: run
def run(self, layers):
"""Risk plugin for tsunami population
"""
thresholds = [0.2, 0.3, 0.5, 0.8, 1.0]
#threshold = 1 # Depth above which people are regarded affected [m]
# Identify hazard and exposure layers
inundation = get_hazard_layer(layers) # Tsunami inundation [m]
population = get_exposure_layer(layers) # Population density
# Extract data as numeric arrays
D = inundation.get_data(nan=0.0) # Depth
P = population.get_data(nan=0.0, scaling=True) # Population density
# Calculate impact as population exposed to depths > 1m
I_map = numpy.where(D > thresholds[-1], P, 0)
# Generate text with result for this study
number_of_people_affected = numpy.nansum(I_map.flat)
# Do breakdown
# Create report
impact_summary = ('<table border="0" width="320px">'
' <tr><th><b>%s</b></th><th><b>%s</b></th></th>'
' <tr></tr>' % ('Ambang batas',
'Jumlah orang terdampak'))
counts = []
for i, threshold in enumerate(thresholds):
I = numpy.where(D > threshold, P, 0)
counts.append(numpy.nansum(I.flat))
impact_summary += ' <tr><td>%s m</td><td>%i</td></tr>' % (
threshold, counts[i])
impact_summary += '</table>'
# Create raster object and return
R = Raster(I_map,
projection=inundation.get_projection(),
geotransform=inundation.get_geotransform(),
name='People affected by more than 1m of inundation',
keywords={'impact_summary': impact_summary})
return R
开发者ID:CharlesRethman,项目名称:inasafe,代码行数:46,代码来源:tsunami_population_impact.py
示例6: run
def run(layers,
teta=14.05, beta=0.17): # zeta=2.15):
"""Risk plugin for earthquake fatalities
Input
H: Numerical array of hazard data
E: Numerical array of exposure data
"""
# Suppress warnings about invalid value in multiply and divide zero
# http://comments.gmane.org/gmane.comp.python.numeric.general/43218
# http://docs.scipy.org/doc/numpy/reference/generated/numpy.seterr.html
old_numpy_setting = numpy.seterr(invalid='ignore')
numpy.seterr(divide='ignore')
# Identify input layers
intensity = get_hazard_layer(layers)
population = get_exposure_layer(layers)
# Extract data
H = intensity.get_data(nan=0)
P = population.get_data(nan=0)
# Calculate impact
logHazard = 1 / beta * numpy.log(H / teta)
# Convert array to be standard floats expected by cdf
arrayout = numpy.array([[float(value) for value in row]
for row in logHazard])
x = arrayout * P
F = normal_cdf(x)
numpy.seterr(**old_numpy_setting)
# Create new layer and return
R = Raster(F,
projection=population.get_projection(),
geotransform=population.get_geotransform(),
name='Estimated fatalities')
return R
开发者ID:lptorres,项目名称:noah-inasafe,代码行数:40,代码来源:empirical_fatality_model.py
示例7: run
def run(layers):
"""Risk plugin for earthquake school damage
"""
# Extract data
H = get_hazard_layer(layers) # Ground shaking
E = get_exposure_layer(layers) # Building locations
# Interpolate hazard level to building locations
H = H.interpolate(E)
# Extract relevant numerical data
coordinates = E.get_geometry()
shaking = H.get_data()
# Calculate building damage
building_damage = []
for i in range(len(shaking)):
x = float(shaking[i].values()[0])
if x < 6.0 or (x != x): # x != x -> check for nan pre python 2.6
value = 0.0
else:
print x
value = (0.692 * (x ** 4) -
15.82 * (x ** 3) +
135.0 * (x ** 2) -
509.0 * x + 714.4)
building_damage.append({'DAMAGE': value, 'MMI': x})
# FIXME (Ole): Need helper to generate new layer using
# correct spatial reference
# (i.e. sensibly wrap the following lines)
projection = E.get_projection()
V = Vector(data=building_damage,
projection=E.get_projection(),
geometry=coordinates)
return V
开发者ID:inasafe,项目名称:python-safe,代码行数:39,代码来源:unspecific_building_impact_model.py
示例8: run
def run(self, layers):
"""Earthquake impact to buildings (e.g. from Open Street Map)
"""
LOGGER.debug('Running earthquake building impact')
# Thresholds for mmi breakdown
t0 = self.parameters['low_threshold']
t1 = self.parameters['medium_threshold']
t2 = self.parameters['high_threshold']
class_1 = tr('Low')
class_2 = tr('Medium')
class_3 = tr('High')
# Extract data
H = get_hazard_layer(layers) # Depth
E = get_exposure_layer(layers) # Building locations
question = get_question(H.get_name(),
E.get_name(),
self)
# Define attribute name for hazard levels
hazard_attribute = 'mmi'
# Determine if exposure data have NEXIS attributes
attribute_names = E.get_attribute_names()
if ('FLOOR_AREA' in attribute_names and
'BUILDING_C' in attribute_names and
'CONTENTS_C' in attribute_names):
is_NEXIS = True
else:
is_NEXIS = False
# Interpolate hazard level to building locations
I = assign_hazard_values_to_exposure_data(H, E,
attribute_name=hazard_attribute)
# Extract relevant exposure data
#attribute_names = I.get_attribute_names()
attributes = I.get_data()
N = len(I)
# Calculate building impact
lo = 0
me = 0
hi = 0
building_values = {}
contents_values = {}
for key in range(4):
building_values[key] = 0
contents_values[key] = 0
for i in range(N):
# Classify building according to shake level
# and calculate dollar losses
if is_NEXIS:
try:
area = float(attributes[i]['FLOOR_AREA'])
except (ValueError, KeyError):
#print 'Got area', attributes[i]['FLOOR_AREA']
area = 0.0
try:
building_value_density = float(attributes[i]['BUILDING_C'])
except (ValueError, KeyError):
#print 'Got bld value', attributes[i]['BUILDING_C']
building_value_density = 0.0
try:
contents_value_density = float(attributes[i]['CONTENTS_C'])
except (ValueError, KeyError):
#print 'Got cont value', attributes[i]['CONTENTS_C']
contents_value_density = 0.0
building_value = building_value_density * area
contents_value = contents_value_density * area
x = float(attributes[i][hazard_attribute]) # MMI
if t0 <= x < t1:
lo += 1
cls = 1
elif t1 <= x < t2:
me += 1
cls = 2
elif t2 <= x:
hi += 1
cls = 3
else:
# Not reported for less than level t0
cls = 0
attributes[i][self.target_field] = cls
if is_NEXIS:
# Accumulate values in 1M dollar units
building_values[cls] += building_value
#.........这里部分代码省略.........
开发者ID:gvallarelli,项目名称:inasafe,代码行数:101,代码来源:earthquake_building_impact.py
示例9: run
def run(self, layers):
"""Flood impact to buildings (e.g. from Open Street Map)
"""
# Extract data
H = get_hazard_layer(layers) # Depth
E = get_exposure_layer(layers) # Building locations
question = get_question(H.get_name(),
E.get_name(),
self)
# Interpolate hazard level to building locations
I = assign_hazard_values_to_exposure_data(H, E)
# Extract relevant exposure data
#attribute_names = I.get_attribute_names()
attributes = I.get_data()
N = len(I)
# Calculate road impact
count = 0
#flooded_distance = 0
for i in range(N):
# Use interpolated polygon attribute
atts = attributes[i]
if 'FLOODPRONE' in atts:
res = atts['FLOODPRONE']
if res is None:
x = False
else:
x = res.lower() == 'yes'
else:
# If there isn't a flood prone attribute,
# assume that building is wet if inside polygon
# as flag by generic attribute AFFECTED
res = atts['Affected']
if res is None:
x = False
else:
x = res
# Count all roads
if x is True:
# Count total affected roads
count += 1
# Add calculated impact to existing attributes
attributes[i][self.target_field] = x
if i == 0:
print attributes[0].keys()
# Generate simple impact report
table_body = [question,
TableRow([tr('Building type'),
tr('Temporarily closed'),
tr('Total')],
header=True),
TableRow([tr('All'), count, N])]
impact_summary = Table(table_body).toNewlineFreeString()
#impact_table = impact_summary
map_title = tr('Roads inundated')
# Create style
style_classes = [dict(label=tr('Not Flooded'), min=0, max=0,
colour='#1EFC7C', transparency=0, size=1),
dict(label=tr('Flooded'), min=1, max=1,
colour='#F31A1C', transparency=0, size=1)]
style_info = dict(target_field=self.target_field,
style_classes=style_classes)
# Create vector layer and return
V = Vector(data=attributes,
projection=I.get_projection(),
geometry=I.get_geometry(),
geometry_type=I.get_geometry_type(),
name=tr('Estimated roads affected'),
keywords={'impact_summary': impact_summary,
'map_title': map_title,
'target_field': self.target_field},
style_info=style_info)
return V
开发者ID:gvallarelli,项目名称:inasafe,代码行数:83,代码来源:flood_road_impact_experimental.py
示例10: run
def run(self, layers):
"""Risk plugin for flood population evacuation
Input
layers: List of layers expected to contain
H: Raster layer of flood depth
P: Raster layer of population data on the same grid as H
Counts number of people exposed to flood levels exceeding
specified threshold.
Return
Map of population exposed to flood levels exceeding the threshold
Table with number of people evacuated and supplies required
"""
# Identify hazard and exposure layers
H = get_hazard_layer(layers) # Flood inundation
E = get_exposure_layer(layers)
question = get_question(H.get_name(),
E.get_name(),
self)
# Check that hazard is polygon type
if not H.is_vector:
msg = ('Input hazard %s was not a vector layer as expected '
% H.get_name())
raise Exception(msg)
msg = ('Input hazard must be a polygon layer. I got %s with layer '
'type %s' % (H.get_name(),
H.get_geometry_name()))
if not H.is_polygon_data:
raise Exception(msg)
# Run interpolation function for polygon2raster
P = assign_hazard_values_to_exposure_data(H, E,
attribute_name='population')
# Initialise attributes of output dataset with all attributes
# from input polygon and a population count of zero
new_attributes = H.get_data()
category_title = 'FLOODPRONE' # FIXME: Should come from keywords
categories = {}
for attr in new_attributes:
attr[self.target_field] = 0
cat = attr[category_title]
categories[cat] = 0
# Count affected population per polygon, per category and total
evacuated = 0
for attr in P.get_data():
# Get population at this location
pop = float(attr['population'])
# Update population count for associated polygon
poly_id = attr['polygon_id']
new_attributes[poly_id][self.target_field] += pop
# Update population count for each category
cat = new_attributes[poly_id][category_title]
categories[cat] += pop
# Update total
evacuated += pop
# Count totals
total = int(numpy.sum(E.get_data(nan=0, scaling=False)))
# Don't show digits less than a 1000
if total > 1000:
total = total // 1000 * 1000
if evacuated > 1000:
evacuated = evacuated // 1000 * 1000
# Calculate estimated needs based on BNPB Perka 7/2008 minimum bantuan
rice = evacuated * 2.8
drinking_water = evacuated * 17.5
water = evacuated * 67
family_kits = evacuated / 5
toilets = evacuated / 20
# Generate impact report for the pdf map
table_body = [question,
TableRow([_('People needing evacuation'),
'%i' % evacuated],
header=True),
TableRow(_('Map shows population affected in each flood '
'prone area ')),
TableRow([_('Needs per week'), _('Total')],
header=True),
[_('Rice [kg]'), int(rice)],
[_('Drinking Water [l]'), int(drinking_water)],
[_('Clean Water [l]'), int(water)],
[_('Family Kits'), int(family_kits)],
[_('Toilets'), int(toilets)]]
impact_table = Table(table_body).toNewlineFreeString()
# Extend impact report for on-screen display
#.........这里部分代码省略.........
开发者ID:ingenieroariel,项目名称:inasafe,代码行数:101,代码来源:flood_population_evacuation_polygon_hazard.py
示例11: run
def run(self, layers):
"""Risk plugin for volcano population evacuation
Input
layers: List of layers expected to contain
H: Vector polygon layer of volcano impact zones
P: Raster layer of population data on the same grid as H
Counts number of people exposed to volcano event.
Return
Map of population exposed to the volcano hazard zone.
Table with number of people evacuated and supplies required.
"""
# Identify hazard and exposure layers
H = get_hazard_layer(layers) # Flood inundation
E = get_exposure_layer(layers)
question = get_question(H.get_name(),
E.get_name(),
self)
# Input checks
if not H.is_vector:
msg = ('Input hazard %s was not a vector layer as expected '
% H.get_name())
raise Exception(msg)
msg = ('Input hazard must be a polygon or point layer. '
'I got %s with layer '
'type %s' % (H.get_name(),
H.get_geometry_name()))
if not (H.is_polygon_data or H.is_point_data):
raise Exception(msg)
if H.is_point_data:
# Use concentric circles
radii = self.parameters['distance [km]']
centers = H.get_geometry()
attributes = H.get_data()
rad_m = [x * 1000 for x in radii] # Convert to meters
H = make_circular_polygon(centers,
rad_m,
attributes=attributes)
# NOTE (Sunni) : I commented out this one because there will be
# a permission problem on windows
#H.write_to_file('Evac_zones_%s.shp' % str(radii)) # To check
category_title = 'Radius'
category_header = tr('Distance [km]')
category_names = radii
name_attribute = 'NAME' # As in e.g. the Smithsonian dataset
else:
# Use hazard map
category_title = 'KRB'
category_header = tr('Category')
# FIXME (Ole): Change to English and use translation system
category_names = ['Kawasan Rawan Bencana III',
'Kawasan Rawan Bencana II',
'Kawasan Rawan Bencana I']
name_attribute = 'GUNUNG' # As in e.g. BNPB hazard map
attributes = H.get_data()
# Get names of volcanos considered
if name_attribute in H.get_attribute_names():
D = {}
for att in H.get_data():
# Run through all polygons and get unique names
D[att[name_attribute]] = None
volcano_names = ''
for name in D:
volcano_names += '%s, ' % name
volcano_names = volcano_names[:-2] # Strip trailing ', '
else:
volcano_names = tr('Not specified in data')
if not category_title in H.get_attribute_names():
msg = ('Hazard data %s did not contain expected '
'attribute %s ' % (H.get_name(), category_title))
raise InaSAFEError(msg)
# Run interpolation function for polygon2raster
P = assign_hazard_values_to_exposure_data(H, E,
attribute_name='population')
# Initialise attributes of output dataset with all attributes
# from input polygon and a population count of zero
new_attributes = H.get_data()
categories = {}
for attr in new_attributes:
attr[self.target_field] = 0
cat = attr[category_title]
categories[cat] = 0
#.........这里部分代码省略.........
开发者ID:imadedikyadehermawan,项目名称:inasafe,代码行数:101,代码来源:volcano_population_evacuation_polygon_hazard.py
示例12: run
def run(self, layers):
"""Earthquake impact to buildings (e.g. from OpenStreetMap).
:param layers: All the input layers (Hazard Layer and Exposure Layer)
"""
LOGGER.debug('Running earthquake building impact')
# merely initialize
building_value = 0
contents_value = 0
# Thresholds for mmi breakdown.
t0 = self.parameters['low_threshold']
t1 = self.parameters['medium_threshold']
t2 = self.parameters['high_threshold']
# Class Attribute and Label.
class_1 = {'label': tr('Low'), 'class': 1}
class_2 = {'label': tr('Medium'), 'class': 2}
class_3 = {'label': tr('High'), 'class': 3}
# Extract data
hazard_layer = get_hazard_layer(layers) # Depth
exposure_layer = get_exposure_layer(layers) # Building locations
question = get_question(
hazard_layer.get_name(),
exposure_layer.get_name(),
self
)
# Define attribute name for hazard levels.
hazard_attribute = 'mmi'
# Determine if exposure data have NEXIS attributes.
attribute_names = exposure_layer.get_attribute_names()
if ('FLOOR_AREA' in attribute_names and
'BUILDING_C' in attribute_names and
'CONTENTS_C' in attribute_names):
is_nexis = True
else:
is_nexis = False
# Interpolate hazard level to building locations.
my_interpolate_result = assign_hazard_values_to_exposure_data(
hazard_layer,
exposure_layer,
attribute_name=hazard_attribute
)
# Extract relevant exposure data
#attribute_names = my_interpolate_result.get_attribute_names()
attributes = my_interpolate_result.get_data()
interpolate_size = len(my_interpolate_result)
# Calculate building impact
lo = 0
me = 0
hi = 0
building_values = {}
contents_values = {}
for key in range(4):
building_values[key] = 0
contents_values[key] = 0
for i in range(interpolate_size):
# Classify building according to shake level
# and calculate dollar losses
if is_nexis:
try:
area = float(attributes[i]['FLOOR_AREA'])
except (ValueError, KeyError):
#print 'Got area', attributes[i]['FLOOR_AREA']
area = 0.0
try:
building_value_density = float(attributes[i]['BUILDING_C'])
except (ValueError, KeyError):
#print 'Got bld value', attributes[i]['BUILDING_C']
building_value_density = 0.0
try:
contents_value_density = float(attributes[i]['CONTENTS_C'])
except (ValueError, KeyError):
#print 'Got cont value', attributes[i]['CONTENTS_C']
contents_value_density = 0.0
building_value = building_value_density * area
contents_value = contents_value_density * area
try:
x = float(attributes[i][hazard_attribute]) # MMI
except TypeError:
x = 0.0
if t0 <= x < t1:
lo += 1
cls = 1
#.........这里部分代码省略.........
开发者ID:SamudraYe,项目名称:inasafe,代码行数:101,代码来源:earthquake_building_impact.py
示例13: run
def run(self, layers):
"""Risk plugin for flood population evacuation
Input
layers: List of layers expected to contain
H: Raster layer of flood depth
P: Raster layer of population data on the same grid as H
Counts number of people exposed to flood levels exceeding
specified threshold.
Return
Map of population exposed to flood levels exceeding the threshold
Table with number of people evacuated and supplies required
"""
# Identify hazard and exposure layers
inundation = get_hazard_layer(layers) # Flood inundation [m]
population = get_exposure_layer(layers)
question = get_question(inundation.get_name(),
population.get_name(),
self)
# Determine depths above which people are regarded affected [m]
# Use thresholds from inundation layer if specified
thresholds = get_thresholds(inundation)
if len(thresholds) == 0:
# Default threshold
thresholds = [1.0]
verify(isinstance(thresholds, list),
'Expected thresholds to be a list. Got %s' % str(thresholds))
# Extract data as numeric arrays
D = inundation.get_data(nan=0.0) # Depth
# Calculate impact as population exposed to depths > max threshold
P = population.get_data(nan=0.0, scaling=True)
# Calculate impact to intermediate thresholds
counts = []
for i, lo in enumerate(thresholds):
if i == len(thresholds) - 1:
# The last threshold
I = M = numpy.where(D >= lo, P, 0)
else:
# Intermediate thresholds
hi = thresholds[i + 1]
M = numpy.where((D >= lo) * (D < hi), P, 0)
# Count
val = int(numpy.sum(M))
# Don't show digits less than a 1000
if val > 1000:
val = val // 1000 * 1000
counts.append(val)
# Count totals
evacuated = counts[-1]
total = int(numpy.sum(P))
# Don't show digits less than a 1000
if total > 1000:
total = total // 1000 * 1000
# Calculate estimated needs based on BNPB Perka 7/2008 minimum bantuan
rice = evacuated * 2.8
drinking_water = evacuated * 17.5
water = evacuated * 67
family_kits = evacuated / 5
toilets = evacuated / 20
# Generate impact report for the pdf map
table_body = [question,
TableRow([_('People needing evacuation'),
'%i' % evacuated],
header=True),
TableRow(_('Map shows population density needing '
'evacuation')),
TableRow([_('Needs per week'), _('Total')],
header=True),
[_('Rice [kg]'), int(rice)],
[_('Drinking Water [l]'), int(drinking_water)],
[_('Clean Water [l]'), int(water)],
[_('Family Kits'), int(family_kits)],
[_('Toilets'), int(toilets)]]
impact_table = Table(table_body).toNewlineFreeString()
# Extend impact report for on-screen display
table_body.extend([TableRow(_('Notes'), header=True),
_('Total population: %i') % total,
_('People need evacuation if flood levels '
'exceed %(eps).1f m') % {'eps': thresholds[-1]},
_('Minimum needs are defined in BNPB '
'regulation 7/2008')])
if len(counts) > 1:
table_body.append(TableRow(_('Detailed breakdown'), header=True))
#.........这里部分代码省略.........
开发者ID:ingenieroariel,项目名称:inasafe,代码行数:101,代码来源:flood_population_evacuation.py
示例14: run
def run(self, layers):
"""Indonesian Earthquake Fatality Model
Input
layers: List of layers expected to contain
H: Raster layer of MMI ground shaking
P: Raster layer of population density
"""
# Establish model coefficients
x = self.parameters['x']
y = self.parameters['y']
# Define percentages of people being displaced at each mmi level
displacement_rate = self.parameters['displacement_rate']
# Tolerance for transparency
tolerance = self.parameters['tolerance']
# Extract input layers
intensity = get_hazard_layer(layers)
population = get_exposure_layer(layers)
question = get_question(intensity.get_name(),
population.get_name(),
self)
# Extract data grids
H = intensity.get_data() # Ground Shaking
P = population.get_data(scaling=True) # Population Density
# Calculate population affected by each MMI level
# FIXME (Ole): this range is 2-9. Should 10 be included?
mmi_range = range(2, 10)
number_of_exposed = {}
number_of_displaced = {}
number_of_fatalities = {}
# Calculate fatality rates for observed Intensity values (H
# based on ITB power model
R = numpy.zeros(H.shape)
for mmi in mmi_range:
# Identify cells where MMI is in class i
mask = (H > mmi - 0.5) * (H <= mmi + 0.5)
# Count population affected by this shake level
I = numpy.where(mask, P, 0)
# Calculate expected number of fatalities per level
fatality_rate = numpy.power(10.0, x * mmi - y)
F = fatality_rate * I
# Calculate expected number of displaced people per level
try:
D = displacement_rate[mmi] * I
except KeyError, e:
msg = 'mmi = %i, I = %s, Error msg: %s' % (mmi, str(I), str(e))
raise InaSAFEError(msg)
# Adjust displaced people to disregard fatalities.
# Set to zero if there are more fatalities than displaced.
D = numpy.where(D > F, D - F, 0)
# Sum up numbers for map
R += D # Displaced
# Generate text with result for this study
# This is what is used in the real time system exposure table
number_of_exposed[mmi] = numpy.nansum(I.flat)
number_of_displaced[mmi] = numpy.nansum(D.flat)
number_of_fatalities[mmi] = numpy.nansum(F.flat)
开发者ID:dichapabe,项目名称:inasafe,代码行数:73,代码来源:itb_fatality_model_configurable.py
示例15: run
def run(self, layers):
"""Risk plugin for earthquake school damage
"""
# Extract data
H = get_hazard_layer(layers) # Ground shaking
E = get_exposure_layer(layers) # Building locations
keywords = E.get_keywords()
if 'datatype' in keywords:
datatype = keywords['datatype']
if datatype.lower() == 'osm':
# Map from OSM attributes to the guideline classes (URM and RM)
E = osm2bnpb(E, target_attribute=self.vclass_tag)
elif datatype.lower() == 'sigab':
# Map from SIGAB attributes to the guideline classes
# (URM and RM)
E = sigab2bnpb(E)
else:
E = unspecific2bnpb(E, target_attribute=self.vclass_tag)
else:
E = unspecific2bnpb(E, target_attribute=self.vclass_tag)
# Interpolate hazard level to building locations
H = assign_hazard_values_to_exposure_data(H, E,
attribute_name='MMI')
# Extract relevant numerical data
coordinates = E.get_geometry()
shaking = H.get_data()
N = len(shaking)
# List attributes to carry forward to result layer
attributes = E.get_attribute_names()
# Calculate building damage
count3 = 0
count2 = 0
count1 = 0
count_unknown = 0
building_damage = []
for i in range(N):
mmi = float(shaking[i]['MMI'])
building_class = E.get_data(self.vclass_tag, i)
lo, hi = damage_parameters[building_class]
if numpy.isnan(mmi):
# If we don't know the shake level assign Not-a-Number
damage = numpy.nan
count_unknown += 1
elif mmi < lo:
damage = 1 # Low
count1 += 1
elif lo <= mmi < hi:
damage = 2 # Medium
count2 += 1
elif mmi >= hi:
damage = 3 # High
count3 += 1
else:
msg = 'Undefined shakelevel %s' % str(mmi)
raise Exception(msg)
# Collect shake level and calculated damage
result_dict = {self.target_field: damage,
'MMI': mmi}
# Carry all orginal attributes forward
for key in attributes:
result_dict[key] = E.get_data(key, i)
# Record result for this feature
building_damage.append(result_dict)
# Create report
impact_summary = ('<table border="0" width="320px">'
' <tr><th><b>%s</b></th><th><b>%s</b></th></th>'
' <tr></tr>'
' <tr><td>%s:</td><td>%s</td></tr>'
' <tr><td>%s (10-25%%):</td><td>%s</td></tr>'
' <tr><td>%s (25-50%%):</td><td>%s</td></tr>'
' <tr><td>%s (50-100%%):</td><td>%s</td></tr>'
% (tr('Buildings'), tr('Total'),
tr('All'), format_int(N),
tr('Low damage'), format_int(count1),
tr('Medium damage'), format_int(count2),
tr('High damage'), format_int(count3)))
impact_summary += (' <tr><td>%s (NaN):</td><td>%s</td></tr>'
% ('Unknown', format_int(count_unknown)))
impact_summary += '</table>'
# Create style
style_classes = [dict(label=tr('Low damage'), min=0.5, max=1.5,
colour='#fecc5c', transparency=0),
dict(label=tr('Medium damage'), min=1.5, max=2.5,
colour='#fd8d3c', transparency=0),
dict(label=tr('High damage'), min=2.5, max=3.5,
colour='#f31a1c', transparency=0)]
style_info = dict(target_field=self.target_field,
#.........这里部分代码省略.........
开发者ID:imadedikyadehermawan,项目名称:inasafe,代码行数:101,代码来源:BNPB_earthquake_guidelines.py
示例16: run
def run(self, layers):
"""Plugin for impact of population as derived by categorised hazard.
:param layers: List of layers expected to contain
* hazard_layer: Raster layer of categorised hazard
* exposure_layer: Raster layer of population data
Counts number of people exposed to each category of the hazard
:returns:
Map of population exposed to high category
Table with number of people in each category
"""
# The 3 category
high_t = self.parameters['Categorical thresholds'][2]
medium_t = self.parameters['Categorical thresholds'][1]
low_t = self.parameters['Categorical thresholds'][0]
# Identify hazard and exposure layers
hazard_layer = get_hazard_layer(layers) # Categorised Hazard
exposure_layer = get_exposure_layer(layers) # Population Raster
question = get_question(
hazard_layer.get_name(), exposure_layer.get_name(), self)
# Extract data as numeric arrays
C = hazard_layer.get_data(nan=0.0) # Category
# Calculate impact as population exposed to each category
P = exposure_layer.get_data(nan=0.0, scaling=True)
H = numpy.where(C <= high_t, P, 0)
M = numpy.where(C < medium_t, P, 0)
L = numpy.where(C < low_t, P, 0)
# Count totals
total = int(numpy.sum(P))
high = int(numpy.sum(H)) - int(numpy.sum(M))
medium = int(numpy.sum(M)) - int(numpy.sum(L))
low = int(numpy.sum(L))
total_impact = high + medium + low
# Don't show digits less than a 1000
total = population_rounding(total)
total_impact = population_rounding(total_impact)
high = population_rounding(high)
medium = population_rounding(medium)
low = population_rounding(low)
minimum_needs = [
parameter.serialize() for parameter in
self.parameters['minimum needs']
]
# Generate impact report for the pdf map
table_body = [
question,
TableRow([tr('People impacted '),
'%s' % format_int(total_impact)],
header=True),
TableRow([tr('People in high hazard area '),
'%s' % format_int(high)],
header=True),
TableR
|
请发表评论