Skip to content

Commit

Permalink
BUG: Remove tags with metadata added by rasterio in open_rasterio (#667)
Browse files Browse the repository at this point in the history
  • Loading branch information
snowman2 authored Apr 14, 2023
1 parent 4c0aef1 commit 061b1bf
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 12 deletions.
3 changes: 2 additions & 1 deletion docs/history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ History

Latest
------
- BUG: Fix :mod:`rioxarray.merge` CRS check
- BUG: Fix :mod:`rioxarray.merge` CRS check (pull #655)
- BUG: Remove tags with metadata added by rasterio in :func:`rioxarray.open_rasterio` (issue #666)

0.14.0
------
Expand Down
6 changes: 6 additions & 0 deletions rioxarray/_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
from rioxarray.exceptions import RioXarrayError
from rioxarray.rioxarray import _generate_spatial_coords

FILL_VALUE_NAMES = ("_FillValue", "missing_value", "fill_value", "nodata")
UNWANTED_RIO_ATTRS = ("nodatavals", "is_tiled", "res")
# TODO: should this be GDAL_LOCK instead?
RASTERIO_LOCK = SerializableLock()
NO_LOCK = contextlib.nullcontext()
Expand Down Expand Up @@ -654,6 +656,10 @@ def _get_rasterio_attrs(riods: RasterioReader):
# pylint: disable=too-many-branches
# Add rasterio attributes
attrs = _parse_tags({**riods.tags(), **riods.tags(1)})
# remove attributes with informaiton
# that should be added by GDAL/rasterio
for unwanted_attr in FILL_VALUE_NAMES + UNWANTED_RIO_ATTRS:
attrs.pop(unwanted_attr, None)
if riods.nodata is not None:
# The nodata values for the raster bands
attrs["_FillValue"] = riods.nodata
Expand Down
8 changes: 2 additions & 6 deletions rioxarray/raster_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,15 @@
from xarray.backends.file_manager import FileManager
from xarray.core.dtypes import get_fill_value

from rioxarray._io import FILL_VALUE_NAMES, UNWANTED_RIO_ATTRS
from rioxarray.crs import crs_from_user_input
from rioxarray.exceptions import (
MissingCRS,
NoDataInBounds,
OneDimensionalRaster,
RioXarrayError,
)
from rioxarray.raster_writer import (
FILL_VALUE_NAMES,
UNWANTED_RIO_ATTRS,
RasterioWriter,
_ensure_nodata_dtype,
)
from rioxarray.raster_writer import RasterioWriter, _ensure_nodata_dtype
from rioxarray.rioxarray import (
XRasterBase,
_get_data_var_message,
Expand Down
4 changes: 1 addition & 3 deletions rioxarray/raster_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from rasterio.windows import Window
from xarray.conventions import encode_cf_variable

from rioxarray._io import _get_unsigned_dtype
from rioxarray._io import FILL_VALUE_NAMES, UNWANTED_RIO_ATTRS, _get_unsigned_dtype
from rioxarray.exceptions import RioXarrayError

try:
Expand All @@ -31,8 +31,6 @@ def is_dask_collection(_) -> bool: # type: ignore
return False


FILL_VALUE_NAMES = ("_FillValue", "missing_value", "fill_value", "nodata")
UNWANTED_RIO_ATTRS = ("nodatavals", "is_tiled", "res")
# Note: transform & crs are removed in write_transform/write_crs


Expand Down
2 changes: 0 additions & 2 deletions test/integration/test_integration__io.py
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,6 @@ def test_mask_and_scale(open_rasterio):
"add_offset": 220.0,
"scale_factor": 0.1,
"_FillValue": 32767.0,
"missing_value": 32767,
"grid_mapping": "crs",
"dtype": "uint16",
"rasterio_dtype": "uint16",
Expand Down Expand Up @@ -1137,7 +1136,6 @@ def test_no_mask_and_scale(open_rasterio):
)
assert test_encoding == {
"_FillValue": 32767.0,
"missing_value": 32767,
"grid_mapping": "crs",
"dtype": "uint16",
"rasterio_dtype": "uint16",
Expand Down

0 comments on commit 061b1bf

Please sign in to comment.