Example #1
0
    def run(layers,
            a=0.97429, b=11.037):
        """Risk plugin for earthquake fatalities

        Input
          layers: List of layers expected to contain
              H: Raster layer of MMI ground shaking
              P: Raster layer of population data on the same grid as H
        """

        # Identify input layers
        intensity = get_hazard_layer(layers)

        # Get population and gender ratio
        population = gender_ratio = None
        for layer in get_exposure_layers(layers):
            keywords = layer.get_keywords()

            if 'datatype' not in keywords:
                population = layer
            else:
                datatype = keywords['datatype']

                if not 'ratio' in datatype:
                    population = layer
                else:
                    # 'female' in datatype and 'ratio' in datatype:
                    gender_ratio_unit = keywords['unit']

                    msg = ('Unit for gender ratio must be either '
                           '"percent" or "ratio"')
                    if gender_ratio_unit not in ['percent', 'ratio']:
                        raise RuntimeError(msg)

                    gender_ratio = layer

        msg = 'No population layer was found in: %s' % str(layers)
        if population is None:
            raise RuntimeError(msg)

        # Extract data
        H = intensity.get_data(nan=0)
        P = population.get_data(nan=0)
        #print
        #print 'Population', population.get_name()

        # Calculate impact
        F = 10 ** (a * H - b) * P

        if gender_ratio is not None:
            # Extract gender ratio at each pixel (as ratio)
            G = gender_ratio.get_data(nan=0)
            if gender_ratio_unit == 'percent':
                G /= 100

            # Calculate breakdown
            P_female = P * G
            P_male = P - P_female

            F_female = F * G
            F_male = F - F_female

        # Generate text with result for this study
        count = numpy.nansum(F.flat)
        total = numpy.nansum(P.flat)

        # Create report
        impact_summary = ('<table border="0" width="320px">'
                   '   <tr><td>%s&#58;</td><td>%s</td></tr>'
                   % ('Jumlah Penduduk', format_int(int(total))))
        if gender_ratio is not None:
            impact_summary += ('        <tr><td>%s&#58;</td><td>%s</td></tr>'
                        % (' - Wanita',
                           format_int(int(numpy.nansum(P_female.flat)))))
            impact_summary += ('        <tr><td>%s&#58;</td><td>%s</td></tr>'
                        % (' - Pria',
                           format_int(int(numpy.nansum(P_male.flat)))))
        impact_summary += ('   <tr><td>%s&#58;</td><td>%s</td></tr>'
                    % ('Perkiraan Orang Meninggal', format_int(int(count))))

        if gender_ratio is not None:
            impact_summary += ('        <tr><td>%s&#58;</td><td>%s</td></tr>'
                        % (' - Wanita',
                           format_int(int(numpy.nansum(F_female.flat)))))
            impact_summary += ('        <tr><td>%s&#58;</td><td>%s</td></tr>'
                        % (' - Pria',
                           format_int(int(numpy.nansum(F_male.flat)))))

        impact_summary += '</table>'

        # Create new layer and return
        R = Raster(F,
                   projection=population.get_projection(),
                   geotransform=population.get_geotransform(),
                   name='Estimated fatalities',
                   keywords={'impact_summary': impact_summary},
                   style_info=earthquake_fatality_style)  # See issue #126
        return R
Example #2
0
    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
        """

        # Depth above which people are regarded affected [m]
        threshold = 0.1
        # Identify hazard and exposure layers
        inundation = get_hazard_layer(layers)  # Flood inundation [m]

        # Get population and gender ratio
        population = gender_ratio = None
        for layer in get_exposure_layers(layers):
            keywords = layer.get_keywords()

            if 'datatype' not in keywords:
                population = layer
            else:
                datatype = keywords['datatype']

                if 'ratio' not in datatype:
                    population = layer
                else:
                    # if 'female' in datatype and 'ratio' in datatype:
                    gender_ratio_unit = keywords['unit']

                    msg = ('Unit for gender ratio must be either '
                           '"percent" or "ratio"')
                    if gender_ratio_unit not in ['percent', 'ratio']:
                        raise Exception(msg)

                    gender_ratio = layer

        msg = 'No population layer was found in: %s' % str(layers)
        verify(population is not None, msg)

        # Extract data as numeric arrays
        D = inundation.get_data(nan=0.0)  # Depth

        # Calculate impact as population exposed to depths > threshold
        if population.get_resolution(native=True, isotropic=True) < 0.0005:
            # Keep this for backwards compatibility just a little while
            # This uses the original custom population set and
            # serves as a reference

            P = population.get_data(nan=0.0)  # Population density
            pixel_area = 2500
            I = numpy.where(D > threshold, P, 0) / 100000.0 * pixel_area
        else:
            # This is the new generic way of scaling (issue #168 and #172)
            P = population.get_data(nan=0.0, scaling=True)
            I = numpy.where(D > threshold, P, 0)

        if gender_ratio is not None:
            # Extract gender ratio at each pixel (as ratio)
            G = gender_ratio.get_data(nan=0.0)
            if gender_ratio_unit == 'percent':
                G /= 100

            # Calculate breakdown
            P_female = P * G
            P_male = P - P_female

            I_female = I * G
            I_male = I - I_female

        # Generate text with result for this study
        total = format_int(int(nansum(P.flat) / 1000))
        count = format_int(int(nansum(I.flat) / 1000))

        # Create report
        impact_summary = ('<table border="0" width="320px">'
                          '   <tr><td><b>%s&#58;</b></td>'
                          '<td align="right"><b>%s</b></td></tr>' %
                          ('Jumlah Penduduk', total))
        if gender_ratio is not None:
            total_female = format_int(int(nansum(P_female.flat) / 1000))
            total_male = format_int(int(nansum(P_male.flat) / 1000))

            impact_summary += ('        <tr><td>%s&#58;</td>'
                               '<td align="right">%s</td></tr>' %
                               (' - Wanita', total_female))
            impact_summary += ('        <tr><td>%s&#58;</td>'
                               '<td align="right">%s</td></tr>' %
                               (' - Pria', total_male))
            impact_summary += '<tr><td>&nbsp;</td></tr>'  # Blank row

        impact_summary += (
            '   <tr><td><b>%s&#58;</b></td>'
            '<td align="right"><b>%s</b></td></tr>' %
            ('Perkiraan Jumlah Terdampak (> %.1fm)' % threshold, count))

        if gender_ratio is not None:
            affected_female = format_int(int(nansum(I_female.flat) / 1000))
            affected_male = format_int(int(nansum(I_male.flat) / 1000))

            impact_summary += ('        <tr><td>%s&#58;</td>'
                               '<td align="right">%s</td></tr>' %
                               (' - Wanita', affected_female))
            impact_summary += ('        <tr><td>%s&#58;</td>'
                               '<td align="right">%s</td></tr>' %
                               (' - Pria', affected_male))

        impact_summary += '</table>'

        impact_summary += '<br>'  # Blank separation row
        impact_summary += 'Catatan&#58; Semua nomor x 1000'

        # 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
Example #3
0
    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
        """

        # Depth above which people are regarded affected [m]
        threshold = 0.1

        # Identify hazard and exposure layers
        inundation = get_hazard_layer(layers)  # Flood inundation [m]

        # Get population and gender ratio
        population = gender_ratio = None
        for layer in get_exposure_layers(layers):
            keywords = layer.get_keywords()

            if 'datatype' not in keywords:
                population = layer
            else:
                datatype = keywords['datatype']

                if 'ratio' not in datatype:
                    population = layer
                else:
                    # if 'female' in datatype and 'ratio' in datatype:
                    gender_ratio_unit = keywords['unit']

                    msg = ('Unit for gender ratio must be either '
                           '"percent" or "ratio"')
                    if gender_ratio_unit not in ['percent', 'ratio']:
                        raise Exception(msg)

                    gender_ratio = layer

        msg = 'No population layer was found in: %s' % str(layers)
        verify(population is not None, msg)

        # Extract data as numeric arrays
        D = inundation.get_data(nan=0.0)  # Depth

        # Calculate impact as population exposed to depths > threshold
        if population.get_resolution(native=True, isotropic=True) < 0.0005:
            # Keep this for backwards compatibility just a little while
            # This uses the original custom population set and
            # serves as a reference

            P = population.get_data(nan=0.0)  # Population density
            pixel_area = 2500
            I = numpy.where(D > threshold, P, 0) / 100000.0 * pixel_area
        else:
            # This is the new generic way of scaling (issue #168 and #172)
            P = population.get_data(nan=0.0, scaling=True)
            I = numpy.where(D > threshold, P, 0)

        if gender_ratio is not None:
            # Extract gender ratio at each pixel (as ratio)
            G = gender_ratio.get_data(nan=0.0)
            if gender_ratio_unit == 'percent':
                G /= 100

            # Calculate breakdown
            P_female = P * G
            P_male = P - P_female

            I_female = I * G
            I_male = I - I_female

        # Generate text with result for this study
        total = str(int(sum(P.flat) / 1000))
        count = str(int(sum(I.flat) / 1000))

        # Create report
        impact_summary = ('<table border="0" width="320px">'
                   '   <tr><td><b>%s&#58;</b></td>'
                   '<td align="right"><b>%s</b></td></tr>'
                   % ('Jumlah Penduduk', total))
        if gender_ratio is not None:
            total_female = str(int(sum(P_female.flat) / 1000))
            total_male = str(int(sum(P_male.flat) / 1000))

            impact_summary += ('        <tr><td>%s&#58;</td>'
                        '<td align="right">%s</td></tr>'
                        % (' - Wanita', total_female))
            impact_summary += ('        <tr><td>%s&#58;</td>'
                        '<td align="right">%s</td></tr>'
                        % (' - Pria', total_male))
            impact_summary += '<tr><td>&nbsp;</td></tr>'  # Blank row

        impact_summary += ('   <tr><td><b>%s&#58;</b></td>'
                    '<td align="right"><b>%s</b></td></tr>'
                    % ('Perkiraan Jumlah Terdampak (> %.1fm)' % threshold,
                       count))

        if gender_ratio is not None:
            affected_female = str(int(sum(I_female.flat) / 1000))
            affected_male = str(int(sum(I_male.flat) / 1000))

            impact_summary += ('        <tr><td>%s&#58;</td>'
                        '<td align="right">%s</td></tr>'
                        % (' - Wanita', affected_female))
            impact_summary += ('        <tr><td>%s&#58;</td>'
                        '<td align="right">%s</td></tr>'
                        % (' - Pria', affected_male))

        impact_summary += '</table>'

        impact_summary += '<br>'  # Blank separation row
        impact_summary += 'Catatan&#58; Semua nomor x 1000'

        # 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
    def run(layers,
            a=0.97429, b=11.037):
        """Risk plugin for earthquake fatalities

        Input
          layers: List of layers expected to contain
              H: Raster layer of MMI ground shaking
              P: Raster layer of population data on the same grid as H
        """

        # Identify input layers
        intensity = get_hazard_layer(layers)

        # Get population and gender ratio
        population = gender_ratio = None
        for layer in get_exposure_layers(layers):
            keywords = layer.get_keywords()

            if 'datatype' not in keywords:
                population = layer
            else:
                datatype = keywords['datatype']

                if 'ratio' not in datatype:
                    population = layer
                else:
                    # 'female' in datatype and 'ratio' in datatype:
                    gender_ratio_unit = keywords['unit']

                    msg = ('Unit for gender ratio must be either '
                           '"percent" or "ratio"')
                    if gender_ratio_unit not in ['percent', 'ratio']:
                        raise RuntimeError(msg)

                    gender_ratio = layer

        msg = 'No population layer was found in: %s' % str(layers)
        if population is None:
            raise RuntimeError(msg)

        # Extract data
        H = intensity.get_data(nan=0)
        P = population.get_data(nan=0)
        # print
        # print 'Population', population.get_name()

        # Calculate impact
        F = 10 ** (a * H - b) * P

        if gender_ratio is not None:
            # Extract gender ratio at each pixel (as ratio)
            G = gender_ratio.get_data(nan=0)
            if gender_ratio_unit == 'percent':
                G /= 100

            # Calculate breakdown
            P_female = P * G
            P_male = P - P_female

            F_female = F * G
            F_male = F - F_female

        # Generate text with result for this study
        count = numpy.nansum(F.flat)
        total = numpy.nansum(P.flat)

        # Create report
        impact_summary = ('<table border="0" width="320px">'
                   '   <tr><td>%s&#58;</td><td>%s</td></tr>'
                   % ('Jumlah Penduduk', format_int(int(total))))
        if gender_ratio is not None:
            impact_summary += ('        <tr><td>%s&#58;</td><td>%s</td></tr>'
                        % (' - Wanita',
                           format_int(int(numpy.nansum(P_female.flat)))))
            impact_summary += ('        <tr><td>%s&#58;</td><td>%s</td></tr>'
                        % (' - Pria',
                           format_int(int(numpy.nansum(P_male.flat)))))
        impact_summary += ('   <tr><td>%s&#58;</td><td>%s</td></tr>'
                    % ('Perkiraan Orang Meninggal', format_int(int(count))))

        if gender_ratio is not None:
            impact_summary += ('        <tr><td>%s&#58;</td><td>%s</td></tr>'
                        % (' - Wanita',
                           format_int(int(numpy.nansum(F_female.flat)))))
            impact_summary += ('        <tr><td>%s&#58;</td><td>%s</td></tr>'
                        % (' - Pria',
                           format_int(int(numpy.nansum(F_male.flat)))))

        impact_summary += '</table>'

        # Create new layer and return
        R = Raster(F,
                   projection=population.get_projection(),
                   geotransform=population.get_geotransform(),
                   name='Estimated fatalities',
                   keywords={'impact_summary': impact_summary},
                   style_info=earthquake_fatality_style)  # See issue #126
        return R
Example #5
0
    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
        """

        # Value above which people are regarded affected
        # For this dataset, 0 is no data, 1 is cloud, 2 is normal water level
        # and 3 is overflow.
        threshold = 0

        # Identify hazard and exposure layers
        inundation = get_hazard_layer(layers)

        [population] = get_exposure_layers(layers)

        # Extract data as numeric arrays
        D = inundation.get_data(nan=0.0)  # Depth

        # Scale the population layer
        P = population.get_data(nan=0.0, scaling=True)
        I = numpy.where(D > threshold, P, 0)

        # Assume an evenly distributed population for Gender
        G = 0.5
        pregnant_ratio = 0.024  # 2.4% of women are estimated to be pregnant

        # Calculate breakdown
        P_female = P * G
        P_male = P - P_female
        P_pregnant = P_female * pregnant_ratio

        I_female = I * G
        I_male = I - I_female
        I_pregnant = I_female * pregnant_ratio

        # Generate text with result for this study
        total = str(int(sum(P.flat) / 1000))
        count = str(int(sum(I.flat) / 1000))

        total_female = str(int(sum(P_female.flat) / 1000))
        total_male = str(int(sum(P_male.flat) / 1000))
        total_pregnant = str(int(sum(P_pregnant.flat) / 1000))

        affected_female = str(int(sum(I_female.flat) / 1000))
        affected_male = str(int(sum(I_male.flat) / 1000))
        affected_pregnant = str(int(sum(I_pregnant.flat) / 1000))

        # Create raster object and return
        R = Raster(I,
                   projection=inundation.get_projection(),
                   geotransform=inundation.get_geotransform(),
                   name='People affected',
                   keywords={
                       'total': total,
                       'count': count,
                       'total_female': total_female,
                       'affected_female': affected_female,
                       'total_male': total_male,
                       'affected_male': affected_male,
                       'total_pregnant': total_pregnant,
                       'affected_pregnant': affected_pregnant,
                   })
        return R
Example #6
0
    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
        """

        # Value above which people are regarded affected
        # For this dataset, 0 is no data, 1 is cloud, 2 is normal water level
        # and 3 is overflow.
        threshold = 0

        # Identify hazard and exposure layers
        inundation = get_hazard_layer(layers)

        [population] = get_exposure_layers(layers)

        # Extract data as numeric arrays
        D = inundation.get_data(nan=0.0) # Depth

        # Scale the population layer
        P = population.get_data(nan=0.0, scaling=True)
        I = numpy.where(D > threshold, P, 0)

        # Assume an evenly distributed population for Gender
        G = 0.5
        pregnant_ratio = 0.024 # 2.4% of women are estimated to be pregnant

        # Calculate breakdown
        P_female = P * G
        P_male = P - P_female
        P_pregnant = P_female * pregnant_ratio

        I_female = I * G
        I_male = I - I_female
        I_pregnant = I_female * pregnant_ratio

        # Generate text with result for this study
        total = str(int(sum(P.flat) / 1000))
        count = str(int(sum(I.flat) / 1000))

        total_female = str(int(sum(P_female.flat) / 1000))
        total_male = str(int(sum(P_male.flat) / 1000))
        total_pregnant = str(int(sum(P_pregnant.flat) / 1000))

        affected_female = str(int(sum(I_female.flat) / 1000))
        affected_male = str(int(sum(I_male.flat) / 1000))
        affected_pregnant = str(int(sum(I_pregnant.flat) / 1000))

        # Create raster object and return
        R = Raster(I,
                   projection=inundation.get_projection(),
                   geotransform=inundation.get_geotransform(),
                   name='People affected',
                   keywords={'total': total, 'count': count,
                             'total_female': total_female, 'affected_female': affected_female,
                             'total_male': total_male, 'affected_male': affected_male,
                             'total_pregnant': total_pregnant, 'affected_pregnant': affected_pregnant,
                            })
        return R