diff --git a/docs/history.rst b/docs/history.rst index 0b882a47..40951557 100644 --- a/docs/history.rst +++ b/docs/history.rst @@ -4,6 +4,7 @@ History Latest ------ - BUG: Fix setting spatial dims internally during propagation (pull #682) +- ENH: Pass on on-disk chunk sizes as preferred chunk sizes to the xarray backend (pull #678) 0.14.1 ------ diff --git a/rioxarray/_io.py b/rioxarray/_io.py index 111926bf..81911bce 100644 --- a/rioxarray/_io.py +++ b/rioxarray/_io.py @@ -1236,7 +1236,7 @@ def open_rasterio( ) result.encoding = encoding - # update attributes from NetCDF attributess + # update attributes from NetCDF attributes _load_netcdf_attrs(riods.tags(), result) result = _decode_datetime_cf( result, decode_times=decode_times, decode_timedelta=decode_timedelta @@ -1262,6 +1262,12 @@ def open_rasterio( if chunks is not None: result = _prepare_dask(result, riods, filename, chunks) + else: + result.encoding["preferred_chunks"] = { + result.rio.y_dim: riods.block_shapes[0][0], + result.rio.x_dim: riods.block_shapes[0][1], + coord_name: 1, + } # add file path to encoding result.encoding["source"] = riods.name diff --git a/rioxarray/xarray_plugin.py b/rioxarray/xarray_plugin.py index 0e6b7a64..a08549a2 100644 --- a/rioxarray/xarray_plugin.py +++ b/rioxarray/xarray_plugin.py @@ -38,8 +38,6 @@ def open_dataset( filename_or_obj, drop_variables=None, parse_coordinates=None, - chunks=None, - cache=None, lock=None, masked=False, mask_and_scale=True, @@ -56,8 +54,7 @@ def open_dataset( rds = _io.open_rasterio( filename_or_obj, parse_coordinates=parse_coordinates, - chunks=chunks, - cache=cache, + cache=False, lock=lock, masked=masked, mask_and_scale=mask_and_scale, diff --git a/test/integration/test_integration__io.py b/test/integration/test_integration__io.py index bd13eb00..3dd6f732 100644 --- a/test/integration/test_integration__io.py +++ b/test/integration/test_integration__io.py @@ -1121,6 +1121,7 @@ def test_mask_and_scale(open_rasterio): "grid_mapping": "crs", "dtype": "uint16", "rasterio_dtype": "uint16", + "preferred_chunks": dict(band=1, x=1386, y=585), } attrs = rds.air_temperature.attrs assert "_Unsigned" not in attrs @@ -1146,6 +1147,7 @@ def test_no_mask_and_scale(open_rasterio): "grid_mapping": "crs", "dtype": "uint16", "rasterio_dtype": "uint16", + "preferred_chunks": {"band": 1, "x": 1386, "y": 585}, } attrs = rds.air_temperature.attrs assert attrs["_Unsigned"] == "true" diff --git a/test/integration/test_integration_xarray_plugin.py b/test/integration/test_integration_xarray_plugin.py index 2421ab35..aaa2ba04 100644 --- a/test/integration/test_integration_xarray_plugin.py +++ b/test/integration/test_integration_xarray_plugin.py @@ -20,6 +20,7 @@ def test_xarray_open_dataset(): assert "spatial_ref" in ds.coords assert "grid_mapping" not in ds.data_vars["band_data"].attrs assert "grid_mapping" in ds.data_vars["band_data"].encoding + assert "preferred_chunks" in ds.data_vars["band_data"].encoding ds = xarray.open_dataset(cog_file)