Skip to content

Commit 85a8048

Browse files
authored
Issue #1253 Fix Rasterio netcdf issue (#1337)
Fixes #1253 # Description A unit test was failing due to issues importing a netcdf file with crs data. This PR fixes that by using a different way of importing it. [rioxarray import netcdf](https://corteva.github.io/rioxarray/stable/getting_started/getting_started.html#xarray) # Checklist <!--- Before requesting review, please go through this checklist: --> - [x] Links to correct issue - [ ] Update changelog, if changes affect users - [x] PR title starts with ``Issue #nr``, e.g. ``Issue #737`` - [ ] Unit tests were added - [ ] **If feature added**: Added/extended example
1 parent e1089a9 commit 85a8048

3 files changed

Lines changed: 5475 additions & 16894 deletions

File tree

imod/tests/test_util/test_util_spatial.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,6 @@ def test_gdal_compliant_grid():
316316

317317

318318
def test_gdal_compliant_grid_crs(tmpdir):
319-
import rioxarray
320-
321319
# Arrange
322320
data = np.ones((2, 3))
323321
# explicit dx dy, equidistant
@@ -330,19 +328,22 @@ def test_gdal_compliant_grid_crs(tmpdir):
330328
dims = ("y", "x")
331329
da = xr.DataArray(data, coords, dims)
332330

331+
crs = "EPSG:28992"
332+
333333
# Act
334-
da_compliant = imod.util.spatial.gdal_compliant_grid(da, crs="EPSG:28992")
334+
da_compliant = imod.util.spatial.gdal_compliant_grid(da, crs=crs)
335335

336336
# Assert
337337
assert "spatial_ref" in da_compliant.coords
338338

339339
# Test saving to netcdf, reading with rasterio again to test if crs
340340
# understood.
341-
da_compliant.to_netcdf(tmpdir / "gdal_accepted_grid.nc")
341+
file = tmpdir / "gdal_accepted_grid.nc"
342+
da_compliant.to_netcdf(file)
342343
da_compliant.close()
343344

344-
da_read = rioxarray.open_rasterio(str(tmpdir / "gdal_accepted_grid.nc"))
345-
assert da_read.rio.crs == "EPSG:28992"
345+
da_read = xr.open_dataset(file, decode_coords="all")
346+
assert da_read.rio.crs == crs
346347

347348

348349
def test_gdal_compliant_grid_error_dims():

0 commit comments

Comments
 (0)