Skip to content

Commit 5f8a8c5

Browse files
authored
Dem gridded_data shifted coordinates (#1682)
1 parent 6e0fb56 commit 5f8a8c5

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

docs/whats-new.rst

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ Bug fixes
2424
glacier mask when preserving the total values. This is a bad
2525
bug that is now fixed (:pull:`1661`).
2626
By `Patrick Schmitt <https://github.com/pat-schmitt>`_
27+
- When converting a variable of gridded_data to an tiff-file using
28+
``tasks.gridded_data_var_to_geotiff`` the resulting coordinates where
29+
shifted half a pixel, this is now fixed (:pull:`1682`).
30+
By `Patrick Schmitt <https://github.com/pat-schmitt>`_
2731

2832

2933
v1.6.1 (August 27, 2023)

oggm/core/gis.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1678,7 +1678,7 @@ def gridded_data_var_to_geotiff(gdir, varname, fname=None):
16781678
# Prepare the profile dict
16791679
crs = ds.pyproj_srs
16801680
var = ds[varname]
1681-
grid = ds.salem.grid
1681+
grid = ds.salem.grid.corner_grid
16821682
data = var.data
16831683
data_type = data.dtype.name
16841684
height, width = var.data.shape

oggm/tests/test_prepro.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
salem = pytest.importorskip('salem')
1414
rasterio = pytest.importorskip('rasterio')
1515
gpd = pytest.importorskip('geopandas')
16+
rioxr = pytest.importorskip('rioxarray')
1617

1718
# Local imports
1819
import oggm
@@ -514,10 +515,18 @@ def test_gridded_data_var_to_geotiff(self):
514515

515516
with xr.open_dataset(gdir.get_filepath('gridded_data')) as ds:
516517
gridded_topo = ds[target_var]
517-
gtiff_ds = salem.open_xr_dataset(gtiff_path)
518-
assert ds.salem.grid == gtiff_ds.salem.grid
518+
gtiff_ds = rioxr.open_rasterio(gtiff_path)
519+
np.allclose(ds.salem.grid.x_coord, gtiff_ds.x)
520+
np.allclose(ds.salem.grid.y_coord, gtiff_ds.y)
519521
assert np.allclose(gridded_topo.data, gtiff_ds.data)
520522

523+
# compare coordinates of topo.tif with dem.tif
524+
demtiff_ds = rioxr.open_rasterio(gdir.get_filepath('dem'))
525+
gtiff_ds = rioxr.open_rasterio(gtiff_path)
526+
assert np.allclose(demtiff_ds.data, gtiff_ds.data)
527+
assert np.allclose(demtiff_ds.x, gtiff_ds.x)
528+
assert np.allclose(demtiff_ds.y, gtiff_ds.y)
529+
521530

522531
class TestCenterlines(unittest.TestCase):
523532

0 commit comments

Comments
 (0)