wgs84_to_ha.py
def raster_to_area_raster(base_raster_path, target_raster_path):
    """Convert base to a target raster of same shape with per area pixels."""
    base_raster_info = pygeoprocessing.get_raster_info(base_raster_path)

    # create 1D array of pixel size vs. lat
    n_rows = base_raster_info['raster_size'][1]
    pixel_height = abs(base_raster_info['geotransform'][5])
    # the / 2 is to get in the center of the pixel
    miny = base_raster_info['bounding_box'][1] + pixel_height/2
    maxy = base_raster_info['bounding_box'][3] - pixel_height/2
    lat_vals = numpy.linspace(maxy, miny, n_rows)

    pixel_area_per_lat = 1.0 / 10000.0 * numpy.array([
        [area_of_pixel(pixel_height, lat_val)] for lat_val in lat_vals])

    pygeoprocessing.raster_calculator(
        [(base_raster_path, 1), pixel_area_per_lat],
        lambda x, y: y, target_raster_path,
        gdal.GDT_Float32, -1)
Convert base to a target raster of same shape with per area pixels.
Convert base to a target raster of same shape with per area pixels.
Convert base to a target raster of same shape with per area pixels .
def raster_to_area_raster(base_raster_path, target_raster_path):
    base_raster_info = pygeoprocessing.get_raster_info(base_raster_path)
    n_rows = base_raster_info['raster_size'][1]
    pixel_height = abs(base_raster_info['geotransform'][5])
    miny = base_raster_info['bounding_box'][1] + pixel_height/2
    maxy = base_raster_info['bounding_box'][3] - pixel_height/2
    lat_vals = numpy.linspace(maxy, miny, n_rows)
    pixel_area_per_lat = 1.0 / 10000.0 * numpy.array([
        [area_of_pixel(pixel_height, lat_val)] for lat_val in lat_vals])
    pygeoprocessing.raster_calculator(
        [(base_raster_path, 1), pixel_area_per_lat],
        lambda x, y: y, target_raster_path,
        gdal.GDT_Float32, -1)
def raster_to_area_raster ( base_raster_path , target_raster_path ) : base_raster_info = pygeoprocessing . get_raster_info ( base_raster_path ) n_rows = base_raster_info [ 'raster_size' ] [ 1 ] pixel_height = abs ( base_raster_info [ 'geotransform' ] [ 5 ] ) miny = base_raster_info [ 'bounding_box' ] [ 1 ] + pixel_height / 2 maxy = base_raster_info [ 'bounding_box' ] [ 3 ] - pixel_height / 2 lat_vals = numpy . linspace ( maxy , miny , n_rows ) pixel_area_per_lat = 1.0 / 10000.0 * numpy . array ( [ [ area_of_pixel ( pixel_height , lat_val ) ] for lat_val in lat_vals ] ) pygeoprocessing . raster_calculator ( [ ( base_raster_path , 1 ) , pixel_area_per_lat ] , lambda x , y : y , target_raster_path , gdal . GDT_Float32 , - 1 )
Convert base to a target raster of same shape with per area pixels.
Convert base to a target raster of same shape with per area pixels .
"""Convert base to a target raster of same shape with per area pixels.""" # create 1D array of pixel size vs. lat
 # the / 2 is to get in the center of the pixel

base_raster_path
target_raster_path