Skip to content

Commit ef44e60

Browse files
authored
Merge branch 'master' into gdirs
2 parents 1b31f69 + 5f8a8c5 commit ef44e60

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
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/core/massbalance.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1973,7 +1973,7 @@ def perturbate_mb_params(gdir, perturbation=None, reset_default=False, filesuffi
19731973

19741974
gdir.write_json(df, 'mb_calib', filesuffix=filesuffix)
19751975
return df
1976-
1976+
19771977

19781978
def _check_terminus_mass_flux(gdir, fls):
19791979
# Check that we have done this correctly

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)