本文整理汇总了Python中safe.impact_functions.core.evacuated_population_needs函数的典型用法代码示例。如果您正苦于以下问题:Python evacuated_population_needs函数的具体用法?Python evacuated_population_needs怎么用?Python evacuated_population_needs使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了evacuated_population_needs函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_evacuated_population_needs
def test_evacuated_population_needs(self):
"""Test evacuated_population_needs function."""
water = ResourceParameter()
water.name = 'Water'
water.unit.name = 'litre'
water.unit.abbreviation = 'l'
water.unit.plural = 'litres'
water.frequency = 'weekly'
water.maximum_allowed_value = 10
water.minimum_allowed_value = 0
water.value = 5
rice = ResourceParameter()
rice.name = 'Rice'
rice.unit.name = 'kilogram'
rice.unit.abbreviation = 'kg'
rice.unit.plural = 'kilograms'
rice.frequency = 'daily'
rice.maximum_allowed_value = 1
rice.minimum_allowed_value = 0
rice.value = 0.5
total_needs = evacuated_population_needs(
10,
[water.serialize(), rice.serialize()]
)
self.assertEqual(total_needs['weekly'][0]['name'], 'Water')
self.assertEqual(total_needs['weekly'][0]['amount'], 50)
self.assertEqual(total_needs['weekly'][0]['table name'], 'Water [l]')
self.assertEqual(total_needs['daily'][0]['name'], 'Rice')
self.assertEqual(total_needs['daily'][0]['amount'], 5)
self.assertEqual(total_needs['daily'][0]['table name'], 'Rice [kg]')
示例2: _tabulate
def _tabulate(self, counts, evacuated, minimum_needs, question, rounding,
thresholds, total, no_data_warning):
# noinspection PyListCreation
table_body = [
question,
TableRow([(tr('People in %.1f m of water') % thresholds[-1]),
'%s*' % format_int(evacuated)],
header=True),
TableRow(
tr('* Number is rounded up to the nearest %s') % rounding),
TableRow(tr('Map shows the numbers of people needing evacuation'))]
total_needs = evacuated_population_needs(
evacuated, minimum_needs)
for frequency, needs in total_needs.items():
table_body.append(TableRow(
[
tr('Needs should be provided %s' % frequency),
tr('Total')
],
header=True))
for resource in needs:
table_body.append(TableRow([
tr(resource['table name']),
format_int(resource['amount'])]))
table_body.append(TableRow(tr('Action Checklist:'), header=True))
table_body.append(TableRow(tr('How will warnings be disseminated?')))
table_body.append(TableRow(tr('How will we reach stranded people?')))
table_body.append(TableRow(tr('Do we have enough relief items?')))
table_body.append(TableRow(tr('If yes, where are they located and how '
'will we distribute them?')))
table_body.append(TableRow(tr(
'If no, where can we obtain additional relief items from and how '
'will we transport them to here?')))
# Extend impact report for on-screen display
table_body.extend([
TableRow(tr('Notes'), header=True),
tr('Total population: %s') % format_int(total),
tr('People need evacuation if tsunami levels exceed %(eps).1f m') %
{'eps': thresholds[-1]},
tr('Minimum needs are defined in BNPB regulation 7/2008'),
tr('All values are rounded up to the nearest integer in order to '
'avoid representing human lives as fractions.')])
if len(counts) > 1:
table_body.append(TableRow(tr('Detailed breakdown'), header=True))
for i, val in enumerate(counts[:-1]):
s = (tr('People in %(lo).1f m to %(hi).1f m of water: %(val)i')
% {'lo': thresholds[i],
'hi': thresholds[i + 1],
'val': format_int(val[0])})
table_body.append(TableRow(s))
if no_data_warning:
table_body.extend([
tr('The layers contained `no data`. This missing data was '
'carried through to the impact layer.'),
tr('`No data` values in the impact layer were treated as 0 '
'when counting the affected or total population.')
])
return table_body, total_needs
示例3: _tabulate
def _tabulate(self, high, low, medium, minimum_needs, no_impact, question,
total_impact):
# Generate impact report for the pdf map
table_body = [question,
TableRow([tr('Total Population Affected '),
'%s' % format_int(total_impact)],
header=True),
TableRow([tr('Population in High hazard class areas '),
'%s' % format_int(high)]),
TableRow([tr('Population in Medium hazard class areas '),
'%s' % format_int(medium)]),
TableRow([tr('Population in Low hazard class areas '),
'%s' % format_int(low)]),
TableRow([tr('Population Not Affected'),
'%s' % format_int(no_impact)]),
TableRow(
tr('Table below shows the minimum needs for all '
'evacuated people'))]
total_needs = evacuated_population_needs(
total_impact, minimum_needs)
for frequency, needs in total_needs.items():
table_body.append(TableRow(
[
tr('Needs should be provided %s' % frequency),
tr('Total')
],
header=True))
for resource in needs:
table_body.append(TableRow([
tr(resource['table name']),
format_int(resource['amount'])]))
return table_body, total_needs
示例4: total_needs
def total_needs(self):
"""Get the total minimum needs based on the total evacuated.
:returns: Total minimum needs.
:rtype: dict
"""
total_population_evacuated = self.total_evacuated
return evacuated_population_needs(
total_population_evacuated, self.minimum_needs)
示例5: test_default_needs
def test_default_needs(self):
"""default calculated needs are as expected
"""
minimum_needs = [
parameter.serialize() for parameter in default_minimum_needs()]
# 20 Happens to be the smallest number at which integer rounding
# won't make a difference to the result
result = evacuated_population_needs(20, minimum_needs)['weekly']
result = OrderedDict([[r['table name'], r['amount']] for r in result])
assert (result['Rice [kg]'] == 56
and result['Drinking Water [l]'] == 350
and result['Clean Water [l]'] == 1340
and result['Family Kits'] == 4)
result = evacuated_population_needs(10, minimum_needs)['single']
result = OrderedDict([[r['table name'], r['amount']] for r in result])
assert result['Toilets'] == 1
示例6: test_arbitrary_needs
def test_arbitrary_needs(self):
"""custom need ratios calculated are as expected
"""
minimum_needs = [
parameter.serialize() for parameter in default_minimum_needs()]
minimum_needs[0]['value'] = 4
minimum_needs[1]['value'] = 3
minimum_needs[2]['value'] = 2
minimum_needs[3]['value'] = 1
minimum_needs[4]['value'] = 0.2
result = evacuated_population_needs(10, minimum_needs)['weekly']
result = OrderedDict([[r['table name'], r['amount']] for r in result])
assert (result['Rice [kg]'] == 40
and result['Drinking Water [l]'] == 30
and result['Clean Water [l]'] == 20
and result['Family Kits'] == 10)
result = evacuated_population_needs(10, minimum_needs)['single']
result = OrderedDict([[r['table name'], r['amount']] for r in result])
assert result['Toilets'] == 2
示例7: total_needs
def total_needs(self):
"""Get the total minimum needs based on the total evacuated.
:returns: Total minimum needs.
:rtype: dict
"""
total_population_evacuated = sum(self.affected_population.values())
self.minimum_needs = [
parameter.serialize() for parameter in
filter_needs_parameters(self.parameters['minimum needs'])
]
return evacuated_population_needs(
total_population_evacuated, self.minimum_needs)
示例8: _tabulate_notes
def _tabulate_notes(
self,
minimum_needs,
table_body,
total,
total_impact,
no_data_warning):
# Extend impact report for on-screen display
table_body.extend([
TableRow(tr('Notes'), header=True),
tr('Map shows population count in high, medium, and low hazard '
'area.'),
tr('Total population: %s') % format_int(total),
TableRow(tr(
'Table below shows the minimum needs for all '
'affected people'))])
if no_data_warning:
table_body.extend([
tr('The layers contained `no data`. This missing data was '
'carried through to the impact layer.'),
tr('`No data` values in the impact layer were treated as 0 '
'when counting the affected or total population.')
])
total_needs = evacuated_population_needs(
total_impact, minimum_needs)
for frequency, needs in total_needs.items():
table_body.append(TableRow(
[
tr('Needs should be provided %s' % frequency),
tr('Total')
],
header=True))
for resource in needs:
table_body.append(TableRow([
tr(resource['table name']),
format_int(resource['amount'])]))
return table_body, total_needs
示例9: 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),
TableRow([tr('People in medium hazard area '),
'%s' % format_int(medium)],
header=True),
TableRow([tr('People in low hazard area'),
'%s' % format_int(low)],
header=True)]
impact_table = Table(table_body).toNewlineFreeString()
# Extend impact report for on-screen display
table_body.extend([
TableRow(tr('Notes'), header=True),
tr('Map shows population count in high or medium hazard area'),
tr('Total population: %s') % format_int(total),
TableRow(tr(
'Table below shows the minimum needs for all '
'affected people'))])
total_needs = evacuated_population_needs(
total_impact, minimum_needs)
for frequency, needs in total_needs.items():
table_body.append(TableRow(
[
tr('Needs should be provided %s' % frequency),
tr('Total')
],
header=True))
for resource in needs:
table_body.append(TableRow([
tr(resource['table name']),
format_int(resource['amount'])]))
impact_summary = Table(table_body).toNewlineFreeString()
map_title = tr('People in high hazard areas')
# Generate 8 equidistant classes across the range of flooded population
#.........这里部分代码省略.........
示例10: run
def run(self, layers):
"""Risk plugin for tsunami population evacuation.
:param layers: List of layers expected to contain
hazard_layer: Raster layer of tsunami depth
exposure_layer: Raster layer of population data on the same grid
as hazard_layer
Counts number of people exposed to tsunami levels exceeding
specified threshold.
:returns: Map of population exposed to tsunami levels exceeding the
threshold. Table with number of people evacuated and supplies
required.
:rtype: tuple
"""
# Identify hazard and exposure layers
hazard_layer = get_hazard_layer(layers) # Tsunami inundation [m]
exposure_layer = get_exposure_layer(layers)
question = get_question(
hazard_layer.get_name(), exposure_layer.get_name(), self)
# Determine depths above which people are regarded affected [m]
# Use thresholds from inundation layer if specified
thresholds = self.parameters['thresholds [m]']
verify(
isinstance(thresholds, list),
'Expected thresholds to be a list. Got %s' % str(thresholds))
# Extract data as numeric arrays
data = hazard_layer.get_data(nan=0.0) # Depth
# Calculate impact as population exposed to depths > max threshold
population = exposure_layer.get_data(nan=0.0, scaling=True)
# Calculate impact to intermediate thresholds
counts = []
# merely initialize
impact = None
for i, lo in enumerate(thresholds):
if i == len(thresholds) - 1:
# The last threshold
impact = medium = numpy.where(data >= lo, population, 0)
else:
# Intermediate thresholds
hi = thresholds[i + 1]
medium = numpy.where((data >= lo) * (data < hi), population, 0)
# Count
val = int(numpy.sum(medium))
# Sensible rounding
val, rounding = population_rounding_full(val)
counts.append([val, rounding])
# Count totals
evacuated, rounding = counts[-1]
total = int(numpy.sum(population))
# Don't show digits less than a 1000
total = population_rounding(total)
minimum_needs = [
parameter.serialize() for parameter in
self.parameters['minimum needs']
]
# Generate impact report for the pdf map
# noinspection PyListCreation
table_body = [
question,
TableRow([(tr('People in %.1f m of water') % thresholds[-1]),
'%s*' % format_int(evacuated)],
header=True),
TableRow(
tr('* Number is rounded up to the nearest %s') % rounding),
TableRow(tr('Map shows the numbers of people needing evacuation'))]
total_needs = evacuated_population_needs(
evacuated, minimum_needs)
for frequency, needs in total_needs.items():
table_body.append(TableRow(
[
tr('Needs should be provided %s' % frequency),
tr('Total')
],
header=True))
for resource in needs:
table_body.append(TableRow([
tr(resource['table name']),
format_int(resource['amount'])]))
table_body.append(TableRow(tr('Action Checklist:'), header=True))
table_body.append(TableRow(tr('How will warnings be disseminated?')))
table_body.append(TableRow(tr('How will we reach stranded people?')))
table_body.append(TableRow(tr('Do we have enough relief items?')))
table_body.append(TableRow(tr('If yes, where are they located and how '
'will we distribute them?')))
#.........这里部分代码省略.........
示例11: run
#.........这里部分代码省略.........
minimum_needs = [
parameter.serialize() for parameter in
self.parameters['minimum needs']
]
# Generate impact report for the pdf map
table_body = [
question,
TableRow(
[tr('People affected'), '%s*' % (
format_int(int(affected_population)))],
header=True),
TableRow(
[TableCell(
tr('* Number is rounded up to the nearest %s') % (
rounding),
col_span=2)]),
TableRow([tr('People needing evacuation'), '%s*' % (
format_int(int(evacuated)))], header=True),
TableRow(
[TableCell(
tr('* Number is rounded up to the nearest %s') % (
rounding_evacuated),
col_span=2)]),
TableRow([tr('Evacuation threshold'), '%s%%' % format_int(
self.parameters['evacuation_percentage'])], header=True),
TableRow(tr(
'Map shows the number of people affected in each flood prone '
'area')),
TableRow(tr(
'Table below shows the weekly minimum needs for all '
'evacuated people'))]
total_needs = evacuated_population_needs(
evacuated, minimum_needs)
for frequency, needs in total_needs.items():
table_body.append(TableRow(
[
tr('Needs should be provided %s' % frequency),
tr('Total')
],
header=True))
for resource in needs:
table_body.append(TableRow([
tr(resource['table name']),
format_int(resource['amount'])]))
impact_table = Table(table_body).toNewlineFreeString()
table_body.append(TableRow(tr('Action Checklist:'), header=True))
table_body.append(TableRow(tr('How will warnings be disseminated?')))
table_body.append(TableRow(tr('How will we reach stranded people?')))
table_body.append(TableRow(tr('Do we have enough relief items?')))
table_body.append(TableRow(
'If yes, where are they located and how will we distribute '
'them?'))
table_body.append(TableRow(
'If no, where can we obtain additional relief items from and '
'how will we transport them to here?'))
# Extend impact report for on-screen display
table_body.extend([
TableRow(tr('Notes'), header=True),
tr('Total population: %s') % format_int(total),
tr('People need evacuation if in the area identified as '
'"Flood Prone"'),
示例12: run
#.........这里部分代码省略.........
# Use final accumulation as total number needing evacuation
evacuated = population_rounding(cumulative)
minimum_needs = [
parameter.serialize() for parameter in
self.parameters['minimum needs']
]
# Generate impact report for the pdf map
blank_cell = ''
table_body = [question,
TableRow([tr('Volcanoes considered'),
'%s' % volcano_names, blank_cell],
header=True),
TableRow([tr('People needing evacuation'),
'%s' % format_int(evacuated),
blank_cell],
header=True),
TableRow([category_header,
tr('Total'), tr('Cumulative')],
header=True)]
for name in category_names:
table_body.append(
TableRow([name,
format_int(all_categories_population[name]),
format_int(all_categories_cumulative[name])]))
table_body.extend([
TableRow(tr(
'Map shows the number of people affected in each of volcano '
'hazard polygons.'))])
total_needs = evacuated_population_needs(
evacuated, minimum_needs)
for frequency, needs in total_needs.items():
table_body.append(TableRow(
[
tr('Needs should be provided %s' % frequency),
tr('Total')
],
header=True))
for resource in needs:
table_body.append(TableRow([
tr(resource['table name']),
format_int(resource['amount'])]))
impact_table = Table(table_body).toNewlineFreeString()
# Extend impact report for on-screen display
table_body.extend(
[TableRow(tr('Notes'), header=True),
tr('Total population %s in the exposure layer') % format_int(
total_population),
tr('People need evacuation if they are within the '
'volcanic hazard zones.')])
population_counts = [x[self.target_field] for x in new_data_table]
impact_summary = Table(table_body).toNewlineFreeString()
# check for zero impact
if numpy.nanmax(population_counts) == 0 == numpy.nanmin(
population_counts):
table_body = [
question,
TableRow([tr('People needing evacuation'),
'%s' % format_int(evacuated),
示例13: run
#.........这里部分代码省略.........
TableRow(
[tr('Volcanoes considered'),
'%s' % volcano_names,
blank_cell],
header=True),
TableRow(
[tr('People needing evacuation'),
'%s' % format_int(
population_rounding(total_affected_population)),
blank_cell],
header=True),
TableRow(
[category_header,
tr('Total'),
tr('Cumulative')],
header=True)]
for radius in rad_m:
table_body.append(
TableRow(
[radius,
format_int(
population_rounding(
affected_population[radius])),
format_int(
population_rounding(
cumulative_affected_population[radius]))]))
table_body.extend([
TableRow(tr(
'Map shows the number of people affected in each of volcano '
'hazard polygons.'))])
total_needs = evacuated_population_needs(
total_affected_population, minimum_needs)
for frequency, needs in total_needs.items():
table_body.append(TableRow(
[
tr('Needs should be provided %s' % frequency),
tr('Total')
],
header=True))
for resource in needs:
table_body.append(TableRow([
tr(resource['table name']),
format_int(resource['amount'])]))
impact_table = Table(table_body).toNewlineFreeString()
# Extend impact report for on-screen display
table_body.extend(
[TableRow(tr('Notes'), header=True),
tr('Total population %s in the exposure layer') % format_int(
total_population),
tr('People need evacuation if they are within the '
'volcanic hazard zones.')])
if nan_warning:
table_body.extend([
tr('The population layer contained `no data`. This missing '
'data was carried through to the impact layer.'),
tr('`No data` values in the impact layer were treated as 0 '
'when counting the affected or total population.')
])
impact_summary = Table(table_body).toNewlineFreeString()
示例14: run
#.........这里部分代码省略.........
medium = int(numpy.sum(med))
low = int(numpy.sum(lo))
total_impact = int(numpy.sum(impact))
# Perform population rounding based on number of people
no_impact = population_rounding(total - total_impact)
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('Total Population Affected '),
'%s' % format_int(total_impact)],
header=True),
TableRow([tr('Population in High risk areas '),
'%s' % format_int(high)]),
TableRow([tr('Population in Medium risk areas '),
'%s' % format_int(medium)]),
TableRow([tr('Population in Low risk areas '),
'%s' % format_int(low)]),
TableRow([tr('Population Not Affected'),
'%s' % format_int(no_impact)]),
TableRow(tr('Table below shows the minimum '
'needs for all evacuated people'))]
total_needs = evacuated_population_needs(
total_impact, minimum_needs)
for frequency, needs in total_needs.items():
table_body.append(TableRow(
[
tr('Needs should be provided %s' % frequency),
tr('Total')
],
header=True))
for resource in needs:
table_body.append(TableRow([
tr(resource['table name']),
format_int(resource['amount'])]))
impact_table = Table(table_body).toNewlineFreeString()
table_body.append(TableRow(tr('Action Checklist:'), header=True))
table_body.append(TableRow(tr('How will warnings be disseminated?')))
table_body.append(TableRow(tr('How will we reach stranded people?')))
table_body.append(TableRow(tr('Do we have enough relief items?')))
table_body.append(TableRow(tr('If yes, where are they located and how '
'will we distribute them?')))
table_body.append(TableRow(tr(
'If no, where can we obtain additional relief items from and how '
'will we transport them to here?')))
# Extend impact report for on-screen display
table_body.extend([
TableRow(tr('Notes'), header=True),
tr('Map shows the numbers of people in high, medium and low '
'hazard areas'),
tr('Total population: %s') % format_int(total)
])