cna_align_to_mask.py
def _convert_to_density(
        base_wgs84_raster_path, target_wgs84_density_raster_path):
    """Convert base WGS84 raster path to a per density raster path."""
    base_raster_info = pygeoprocessing.get_raster_info(
        base_wgs84_raster_path)
    # xmin, ymin, xmax, ymax
    _, lat_min, _, lat_max = base_raster_info['bounding_box']
    _, n_rows = base_raster_info['raster_size']

    m2_area_col = _create_latitude_m2_area_column(lat_min, lat_max, n_rows)
    nodata = base_raster_info['nodata'][0]

    def _div_by_area_op(base_array, m2_area_array):
        result = numpy.empty(base_array.shape, dtype=base_array.dtype)
        if nodata is not None:
            valid_mask = ~numpy.isclose(base_array, nodata)
            result[:] = nodata
        else:
            valid_mask = numpy.ones(base_array.shape, dtype=bool)

        result[valid_mask] = (
            base_array[valid_mask] / m2_area_array[valid_mask])
        return result

    pygeoprocessing.raster_calculator(
        [(base_wgs84_raster_path, 1), m2_area_col], _div_by_area_op,
        target_wgs84_density_raster_path, base_raster_info['datatype'],
        nodata)
Convert base WGS84 raster path to a per density raster path.
Convert base WGS84 raster path to a per density raster path.
Convert base WGS84 raster path to a per density raster path .
def _convert_to_density(
        base_wgs84_raster_path, target_wgs84_density_raster_path):
    base_raster_info = pygeoprocessing.get_raster_info(
        base_wgs84_raster_path)
    _, lat_min, _, lat_max = base_raster_info['bounding_box']
    _, n_rows = base_raster_info['raster_size']
    m2_area_col = _create_latitude_m2_area_column(lat_min, lat_max, n_rows)
    nodata = base_raster_info['nodata'][0]
    def _div_by_area_op(base_array, m2_area_array):
        result = numpy.empty(base_array.shape, dtype=base_array.dtype)
        if nodata is not None:
            valid_mask = ~numpy.isclose(base_array, nodata)
            result[:] = nodata
        else:
            valid_mask = numpy.ones(base_array.shape, dtype=bool)
        result[valid_mask] = (
            base_array[valid_mask] / m2_area_array[valid_mask])
        return result
    pygeoprocessing.raster_calculator(
        [(base_wgs84_raster_path, 1), m2_area_col], _div_by_area_op,
        target_wgs84_density_raster_path, base_raster_info['datatype'],
        nodata)
def _convert_to_density ( base_wgs84_raster_path , target_wgs84_density_raster_path ) : base_raster_info = pygeoprocessing . get_raster_info ( base_wgs84_raster_path ) _ , lat_min , _ , lat_max = base_raster_info [ 'bounding_box' ] _ , n_rows = base_raster_info [ 'raster_size' ] m2_area_col = _create_latitude_m2_area_column ( lat_min , lat_max , n_rows ) nodata = base_raster_info [ 'nodata' ] [ 0 ] def _div_by_area_op ( base_array , m2_area_array ) : result = numpy . empty ( base_array . shape , dtype = base_array . dtype ) if nodata is not None : valid_mask = ~ numpy . isclose ( base_array , nodata ) result [ : ] = nodata else : valid_mask = numpy . ones ( base_array . shape , dtype = bool ) result [ valid_mask ] = ( base_array [ valid_mask ] / m2_area_array [ valid_mask ] ) return result pygeoprocessing . raster_calculator ( [ ( base_wgs84_raster_path , 1 ) , m2_area_col ] , _div_by_area_op , target_wgs84_density_raster_path , base_raster_info [ 'datatype' ] , nodata )
Convert base WGS84 raster path to a per density raster path.
Convert base WGS84 raster path to a per density raster path .
"""Convert base WGS84 raster path to a per density raster path.""" # xmin, ymin, xmax, ymax
base_wgs84_raster_path
target_wgs84_density_raster_path