本文整理汇总了Python中safe.storage.raster.Raster.impact_data方法的典型用法代码示例。如果您正苦于以下问题:Python Raster.impact_data方法的具体用法?Python Raster.impact_data怎么用?Python Raster.impact_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类safe.storage.raster.Raster
的用法示例。
在下文中一共展示了Raster.impact_data方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from safe.storage.raster import Raster [as 别名]
# 或者: from safe.storage.raster.Raster import impact_data [as 别名]
#.........这里部分代码省略.........
exposure_data = self.exposure.layer.get_data(nan=True, scaling=True)
if has_no_data(exposure_data):
self.no_data_warning = True
# Make 3 data for each zone. Get the value of the exposure if the
# exposure is in the hazard zone, else just assign 0
low_exposure = numpy.where(hazard_data < low_t, exposure_data, 0)
medium_exposure = numpy.where(
(hazard_data >= low_t) & (hazard_data < medium_t),
exposure_data, 0)
high_exposure = numpy.where(
(hazard_data >= medium_t) & (hazard_data <= high_t),
exposure_data, 0)
impacted_exposure = low_exposure + medium_exposure + high_exposure
# Count totals
self.total_population = int(numpy.nansum(exposure_data))
self.affected_population[
tr('Population in high hazard areas')] = int(
numpy.nansum(high_exposure))
self.affected_population[
tr('Population in medium hazard areas')] = int(
numpy.nansum(medium_exposure))
self.affected_population[
tr('Population in low hazard areas')] = int(
numpy.nansum(low_exposure))
self.unaffected_population = (
self.total_population - self.total_affected_population)
# check for zero impact
if self.total_affected_population == 0:
message = no_population_impact_message(self.question)
raise ZeroImpactException(message)
# Don't show digits less than a 1000
self.minimum_needs = [
parameter.serialize() for parameter in
filter_needs_parameters(self.parameters['minimum needs'])
]
total_needs = self.total_needs
# Style for impact layer
colours = [
'#FFFFFF', '#38A800', '#79C900', '#CEED00',
'#FFCC00', '#FF6600', '#FF0000', '#7A0000']
classes = create_classes(impacted_exposure.flat[:], len(colours))
interval_classes = humanize_class(classes)
style_classes = []
for i in xrange(len(colours)):
style_class = dict()
if i == 1:
label = create_label(
interval_classes[i],
tr('Low Population [%i people/cell]' % classes[i]))
elif i == 4:
label = create_label(
interval_classes[i],
tr('Medium Population [%i people/cell]' % classes[i]))
elif i == 7:
label = create_label(
interval_classes[i],
tr('High Population [%i people/cell]' % classes[i]))
else:
label = create_label(interval_classes[i])
style_class['label'] = label
style_class['quantity'] = classes[i]
style_class['transparency'] = 0
style_class['colour'] = colours[i]
style_classes.append(style_class)
style_info = dict(
target_field=None,
style_classes=style_classes,
style_type='rasterStyle')
impact_data = self.generate_data()
extra_keywords = {
'map_title': self.metadata().key('map_title'),
'legend_notes': self.metadata().key('legend_notes'),
'legend_units': self.metadata().key('legend_units'),
'legend_title': self.metadata().key('legend_title'),
'total_needs': total_needs
}
impact_layer_keywords = self.generate_impact_keywords(extra_keywords)
# Create raster object and return
impact_layer = Raster(
data=impacted_exposure,
projection=self.hazard.layer.get_projection(),
geotransform=self.hazard.layer.get_geotransform(),
name=self.metadata().key('layer_name'),
keywords=impact_layer_keywords,
style_info=style_info)
impact_layer.impact_data = impact_data
self._impact = impact_layer
return impact_layer
示例2: run
# 需要导入模块: from safe.storage.raster import Raster [as 别名]
# 或者: from safe.storage.raster.Raster import impact_data [as 别名]
#.........这里部分代码省略.........
self.volcano_names = volcano_names[:-2] # Strip trailing ', '
# Run interpolation function for polygon2raster
interpolated_layer, covered_exposure_layer = \
assign_hazard_values_to_exposure_data(
self.hazard.layer,
self.exposure.layer,
attribute_name=self.target_field
)
# Initialise affected population per categories
for radius in radii:
category = 'Radius %s km ' % format_int(radius)
self.affected_population[category] = 0
if has_no_data(self.exposure.layer.get_data(nan=True)):
self.no_data_warning = True
# Count affected population per polygon and total
for row in interpolated_layer.get_data():
# Get population at this location
population = row[self.target_field]
if not numpy.isnan(population):
population = float(population)
# Update population count for this category
category = 'Radius %s km ' % format_int(
row[self.hazard_zone_attribute])
self.affected_population[category] += population
# Count totals
self.total_population = population_rounding(
int(numpy.nansum(self.exposure.layer.get_data())))
self.minimum_needs = [
parameter.serialize() for parameter in
filter_needs_parameters(self.parameters['minimum needs'])
]
# Create style
colours = ['#FFFFFF', '#38A800', '#79C900', '#CEED00',
'#FFCC00', '#FF6600', '#FF0000', '#7A0000']
classes = create_classes(
covered_exposure_layer.get_data().flat[:], len(colours))
interval_classes = humanize_class(classes)
# Define style info for output polygons showing population counts
style_classes = []
for i in xrange(len(colours)):
style_class = dict()
style_class['label'] = create_label(interval_classes[i])
if i == 1:
label = create_label(
interval_classes[i],
tr('Low Population [%i people/cell]' % classes[i]))
elif i == 4:
label = create_label(
interval_classes[i],
tr('Medium Population [%i people/cell]' % classes[i]))
elif i == 7:
label = create_label(
interval_classes[i],
tr('High Population [%i people/cell]' % classes[i]))
else:
label = create_label(interval_classes[i])
style_class['label'] = label
style_class['quantity'] = classes[i]
style_class['colour'] = colours[i]
style_class['transparency'] = 0
style_classes.append(style_class)
# Override style info with new classes and name
style_info = dict(
target_field=None,
style_classes=style_classes,
style_type='rasterStyle')
impact_data = self.generate_data()
# Create vector layer and return
extra_keywords = {
'target_field': self.target_field,
'map_title': self.metadata().key('map_title'),
'legend_notes': self.metadata().key('legend_notes'),
'legend_units': self.metadata().key('legend_units'),
'legend_title': self.metadata().key('legend_title'),
'total_needs': self.total_needs
}
impact_layer_keywords = self.generate_impact_keywords(extra_keywords)
impact_layer = Raster(
data=covered_exposure_layer.get_data(),
projection=covered_exposure_layer.get_projection(),
geotransform=covered_exposure_layer.get_geotransform(),
name=self.metadata().key('layer_name'),
keywords=impact_layer_keywords,
style_info=style_info)
impact_layer.impact_data = impact_data
self._impact = impact_layer
return impact_layer
示例3: run
# 需要导入模块: from safe.storage.raster import Raster [as 别名]
# 或者: from safe.storage.raster.Raster import impact_data [as 别名]
#.........这里部分代码省略.........
# displacements > fatalities, displacements - fatalities, 0)
# Sum up numbers for map
# We need to use matrices here and not just numbers #2235
# filter out NaN to avoid overflow additions
mmi_matches = numpy.nan_to_num(mmi_matches)
mask += mmi_matches # Displaced
# Generate text with result for this study
# This is what is used in the real time system exposure table
number_of_exposed[mmi] = exposed
number_of_displaced[mmi] = displacements
# noinspection PyUnresolvedReferences
number_of_fatalities[mmi] = fatalities
# Total statistics
total_fatalities_raw = numpy.nansum(
number_of_fatalities.values(), axis=0)
# Compute probability of fatality in each magnitude bin
if (self.__class__.__name__ == 'PAGFatalityFunction') or (
self.__class__.__name__ == 'ITBBayesianFatalityFunction'):
prob_fatality_mag = self.compute_probability(total_fatalities_raw)
else:
prob_fatality_mag = None
# Compute number of fatalities
self.total_population = numpy.nansum(number_of_exposed.values())
self.total_fatalities = numpy.median(total_fatalities_raw)
total_displaced = numpy.nansum(number_of_displaced.values())
# As per email discussion with Ole, Trevor, Hadi, total fatalities < 50
# will be rounded down to 0 - Tim
# Needs to revisit but keep it alive for the time being - Hyeuk, Jono
if self.total_fatalities < 50:
self.total_fatalities = 0
affected_population = self.affected_population
affected_population[tr('Number of fatalities')] = self.total_fatalities
affected_population[
tr('Number of people displaced')] = total_displaced
self.unaffected_population = (
self.total_population - total_displaced - self.total_fatalities)
self._evacuation_category = tr('Number of people displaced')
self.minimum_needs = [
parameter.serialize() for parameter in
filter_needs_parameters(self.parameters['minimum needs'])
]
total_needs = self.total_needs
# Create style
colours = ['#EEFFEE', '#FFFF7F', '#E15500', '#E4001B', '#730000']
classes = create_classes(mask.flat[:], len(colours))
interval_classes = humanize_class(classes)
style_classes = []
for i in xrange(len(interval_classes)):
style_class = dict()
style_class['label'] = create_label(interval_classes[i])
style_class['quantity'] = classes[i]
style_class['transparency'] = 30
style_class['colour'] = colours[i]
style_classes.append(style_class)
style_info = dict(target_field=None,
style_classes=style_classes,
style_type='rasterStyle')
impact_data = self.generate_data()
extra_keywords = {
'exposed_per_mmi': number_of_exposed,
'total_population': self.total_population,
'total_fatalities': population_rounding(self.total_fatalities),
'total_fatalities_raw': self.total_fatalities,
'fatalities_per_mmi': number_of_fatalities,
'total_displaced': population_rounding(total_displaced),
'displaced_per_mmi': number_of_displaced,
'map_title': self.metadata().key('map_title'),
'legend_notes': self.metadata().key('legend_notes'),
'legend_units': self.metadata().key('legend_units'),
'legend_title': self.metadata().key('legend_title'),
'total_needs': total_needs,
'prob_fatality_mag': prob_fatality_mag,
}
impact_layer_keywords = self.generate_impact_keywords(extra_keywords)
# Create raster object and return
impact_layer = Raster(
mask,
projection=self.exposure.layer.get_projection(),
geotransform=self.exposure.layer.get_geotransform(),
keywords=impact_layer_keywords,
name=self.metadata().key('layer_name'),
style_info=style_info)
impact_layer.impact_data = impact_data
self._impact = impact_layer
return impact_layer
示例4: run
# 需要导入模块: from safe.storage.raster import Raster [as 别名]
# 或者: from safe.storage.raster.Raster import impact_data [as 别名]
#.........这里部分代码省略.........
# merely initialize
impact = None
for i, lo in enumerate(thresholds):
if i == len(thresholds) - 1:
# The last threshold
thresholds_name = tr(
'People in >= %.1f m of water') % lo
impact = medium = numpy.where(data >= lo, population, 0)
self.impact_category_ordering.append(thresholds_name)
self._evacuation_category = thresholds_name
else:
# Intermediate thresholds
hi = thresholds[i + 1]
thresholds_name = tr(
'People in %.1f m to %.1f m of water' % (lo, hi))
medium = numpy.where((data >= lo) * (data < hi), population, 0)
# Count
val = int(numpy.nansum(medium))
self.affected_population[thresholds_name] = val
# Put the deepest area in top #2385
self.impact_category_ordering.reverse()
# Carry the no data values forward to the impact layer.
impact = numpy.where(numpy.isnan(population), numpy.nan, impact)
impact = numpy.where(numpy.isnan(data), numpy.nan, impact)
# Count totals
self.total_population = int(numpy.nansum(population))
self.unaffected_population = (
self.total_population - self.total_affected_population)
self.minimum_needs = [
parameter.serialize() for parameter in
filter_needs_parameters(self.parameters['minimum needs'])
]
# check for zero impact
if numpy.nanmax(impact) == 0 == numpy.nanmin(impact):
message = m.Message()
message.add(self.question)
message.add(tr('No people in %.1f m of water') % thresholds[-1])
message = message.to_html(suppress_newlines=True)
raise ZeroImpactException(message)
# Create style
colours = [
'#FFFFFF', '#38A800', '#79C900', '#CEED00',
'#FFCC00', '#FF6600', '#FF0000', '#7A0000']
classes = create_classes(impact.flat[:], len(colours))
interval_classes = humanize_class(classes)
style_classes = []
for i in xrange(len(colours)):
style_class = dict()
if i == 1:
label = create_label(interval_classes[i], 'Low')
elif i == 4:
label = create_label(interval_classes[i], 'Medium')
elif i == 7:
label = create_label(interval_classes[i], 'High')
else:
label = create_label(interval_classes[i])
style_class['label'] = label
style_class['quantity'] = classes[i]
style_class['transparency'] = 0
style_class['colour'] = colours[i]
style_classes.append(style_class)
style_info = dict(
target_field=None,
style_classes=style_classes,
style_type='rasterStyle')
impact_data = self.generate_data()
extra_keywords = {
'map_title': self.metadata().key('map_title'),
'legend_notes': self.metadata().key('legend_notes'),
'legend_units': self.metadata().key('legend_units'),
'legend_title': self.metadata().key('legend_title'),
'evacuated': self.total_evacuated,
'total_needs': self.total_needs
}
impact_layer_keywords = self.generate_impact_keywords(extra_keywords)
# Create raster object and return
impact_layer = Raster(
impact,
projection=self.hazard.layer.get_projection(),
geotransform=self.hazard.layer.get_geotransform(),
name=self.metadata().key('layer_name'),
keywords=impact_layer_keywords,
style_info=style_info)
impact_layer.impact_data = impact_data
self._impact = impact_layer
return impact_layer
示例5: run
# 需要导入模块: from safe.storage.raster import Raster [as 别名]
# 或者: from safe.storage.raster.Raster import impact_data [as 别名]
#.........这里部分代码省略.........
(grid_point - covered_exposure_top_left) / (
covered_exposure_dimension)).astype(int)
new_covered_exposure_data[index[1]][index[0]] = 0
# Estimate number of people in need of evacuation
if self.use_affected_field:
affected_population = tr(
'People within hazard field ("%s") of value "%s"') % (
self.hazard_class_attribute,
','.join([
unicode(hazard_class) for
hazard_class in self.hazard_class_mapping[self.wet]
]))
else:
affected_population = tr('People within any hazard polygon.')
self.affected_population[affected_population] = (
total_affected_population)
self.total_population = int(
numpy.nansum(self.exposure.layer.get_data(scaling=False)))
self.unaffected_population = (
self.total_population - self.total_affected_population)
self.minimum_needs = [
parameter.serialize() for parameter in
filter_needs_parameters(self.parameters['minimum needs'])
]
# Create style
colours = ['#FFFFFF', '#38A800', '#79C900', '#CEED00',
'#FFCC00', '#FF6600', '#FF0000', '#7A0000']
classes = create_classes(
new_covered_exposure_data.flat[:], len(colours))
# check for zero impact
if total_affected_population == 0:
message = no_population_impact_message(self.question)
raise ZeroImpactException(message)
interval_classes = humanize_class(classes)
# Define style info for output polygons showing population counts
style_classes = []
for i in xrange(len(colours)):
style_class = dict()
style_class['label'] = create_label(interval_classes[i])
if i == 1:
label = create_label(
interval_classes[i],
tr('Low Population [%i people/cell]' % classes[i]))
elif i == 4:
label = create_label(
interval_classes[i],
tr('Medium Population [%i people/cell]' % classes[i]))
elif i == 7:
label = create_label(
interval_classes[i],
tr('High Population [%i people/cell]' % classes[i]))
else:
label = create_label(interval_classes[i])
style_class['label'] = label
style_class['quantity'] = classes[i]
style_class['colour'] = colours[i]
style_class['transparency'] = 0
style_classes.append(style_class)
# Override style info with new classes and name
style_info = dict(
target_field=None,
style_classes=style_classes,
style_type='rasterStyle')
impact_data = self.generate_data()
extra_keywords = {
'target_field': self.target_field,
'map_title': self.metadata().key('map_title'),
'legend_notes': self.metadata().key('legend_notes'),
'legend_units': self.metadata().key('legend_units'),
'legend_title': self.metadata().key('legend_title'),
'affected_population': total_affected_population,
'total_population': self.total_population,
'total_needs': self.total_needs
}
impact_layer_keywords = self.generate_impact_keywords(extra_keywords)
# Create raster layer and return
impact_layer = Raster(
data=new_covered_exposure_data,
projection=covered_exposure.get_projection(),
geotransform=covered_exposure.get_geotransform(),
name=self.metadata().key('layer_name'),
keywords=impact_layer_keywords,
style_info=style_info)
impact_layer.impact_data = impact_data
self._impact = impact_layer
return impact_layer