clean up carbon raster helper function

This commit is contained in:
Claire Simpson 2025-03-11 15:12:52 -06:00
parent e1b93f3c6e
commit b943e65767
1 changed files with 11 additions and 17 deletions

View File

@ -14,8 +14,9 @@ import pygeoprocessing
gdal.UseExceptions()
def make_simple_raster(base_raster_path, fill_val, nodata_val):
"""Create a 10x10 raster on designated path with fill value.
"""Create a 10x10 int32 raster on designated path with fill value.
Args:
base_raster_path (str): the raster path for making the new raster.
@ -26,29 +27,22 @@ def make_simple_raster(base_raster_path, fill_val, nodata_val):
lulc_path (str): the path of the raster file.
"""
srs = osr.SpatialReference()
srs.ImportFromEPSG(26910) # UTM Zone 10N
projection_wkt = srs.ExportToWkt()
# origin hand-picked for this epsg:
geotransform = [461261, 1.0, 0.0, 4923265, 0.0, -1.0]
origin = (461261, 4923265)
n = 10
gtiff_driver = gdal.GetDriverByName('GTiff')
new_raster = gtiff_driver.Create(
base_raster_path, n, n, 1, gdal.GDT_Int32, options=[
'TILED=YES', 'BIGTIFF=YES', 'COMPRESS=LZW',
'BLOCKXSIZE=16', 'BLOCKYSIZE=16'])
new_raster.SetProjection(projection_wkt)
new_raster.SetGeoTransform(geotransform)
new_band = new_raster.GetRasterBand(1)
array = numpy.empty((n, n))
array = numpy.empty((n, n), dtype=numpy.int32)
array.fill(fill_val)
new_band.WriteArray(array)
if nodata_val is not None:
new_band.SetNoDataValue(nodata_val)
new_raster.FlushCache()
new_band = None
new_raster = None
pixel_size = (1, -1)
pygeoprocessing.numpy_array_to_raster(
array, nodata_val, pixel_size, origin, projection_wkt,
base_raster_path)
def assert_raster_equal_value(base_raster_path, val_to_compare):