New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for int64, uint64, and int8 #353
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great! Thanks @emlys . I just had a couple comments on docstrings in the new functions and a question about how GDAL handles duplicate creation options.
@@ -13,8 +13,7 @@ build-backend = "setuptools.build_meta" | |||
|
|||
[tool.pytest.ini_options] | |||
# Raise warnings to exceptions. | |||
filterwarnings = 'error' | |||
|
|||
filterwarnings = ["error", "default::DeprecationWarning", "default::FutureWarning"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. This is a great idea and I'm glad they're supporting this in pyproject.toml
now.
@@ -3703,7 +3665,7 @@ def mask_op(base_array, mask_array): | |||
os.remove(mask_raster_path) | |||
|
|||
|
|||
def _gdal_to_numpy_type(band): | |||
def _gdal_to_numpy_type(gdal_type, metadata): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the function interface is changing, could you update the docstring here as well?
('PIXELTYPE' in metadata and metadata['PIXELTYPE'] == 'SIGNEDBYTE'))): | ||
return numpy.int8 | ||
|
||
numpy_type = gdal_array.GDALTypeCodeToNumericTypeCode(gdal_type) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well how about that! This is a nice function to know about.
|
||
if band.DataType != gdal.GDT_Byte: | ||
raise ValueError("Unsupported DataType: %s" % str(band.DataType)) | ||
def _numpy_to_gdal_type(numpy_type): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a docstring here that includes the input and output types? Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a docstring!
geoprocessing._numpy_to_gdal_type(target_numpy_type)) | ||
|
||
driver, creation_options = raster_driver_creation_tuple | ||
creation_options = list(creation_options) + type_creation_options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to handle the case where a creation option is defined both in creation_options
and in type_creation_options
? Will GDAL work as we hope if an option is defined in both?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to work as expected if PIXELTYPE=SIGNEDBYTE
is defined twice. And it seems that SIGNEDBYTE
is the only recognized value for PIXELTYPE
, so it wouldn't overwrite a different option.
numpy_type = pygeoprocessing.get_raster_info( | ||
base_raster_path_band[0])['numpy_type'] | ||
if numpy.issubdtype(numpy_type, numpy.integer): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a really nice update - one less thing to have to worry about updating if GDAL adds more int or float types!
Looks great! Just waiting for the tests to finish before merging. |
Fixes #352
Fixes #329
gdal.GDT_Int8
is just like any other GDAL type, I don't think we need to add tests specifically for it.create_raster_from_base
, where dtype-related metadata (PIXELTYPE=SIGNEDBYTE
) was copied over from the base raster, even though the target dtype is not copied from the base raster. Now that metadata has to be set in theraster_creation_tuple
.behavior of GDAL 3.7+ with signed bytes
A warning is raised if you create a raster using the deprecated flag:
It seems that drivers will still be able to read signed byte rasters. They just treat them as a new data type (Int8) and don't return the
PIXELTYPE=SIGNEDBYTE
metadata element:From the migration guide,