Skip to content

Commit 7e3966d

Browse files
committed
fix OGGM projection for topo features
1 parent 3785b24 commit 7e3966d

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

massbalancemachine/data_processing/get_topo_data.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import xarray as xr
1414
import pandas as pd
1515
import numpy as np
16+
import pyproj
1617

1718
from data_processing.Product import Product
1819
from data_processing.product_utils import rgi_id_to_folders, data_path
@@ -82,6 +83,7 @@ def get_topographical_features(
8283
assert all(gdirs_svf[i].x == gdirs_gridded[i].x) and all(
8384
gdirs_svf[i].y == gdirs_gridded[i].y
8485
)
86+
assert gdirs_svf[i].pyproj_srs == gdirs_gridded[i].pyproj_srs
8587
gdirs_gridded[i]["svf"] = gdirs_svf[i]["svf"]
8688
del gdirs_svf
8789

@@ -237,17 +239,23 @@ def _retrieve_topo_features(
237239
"""Find the nearest recorded point with topographical features on the glacier for each stake."""
238240

239241
for gdir, gdir_grid in zip(glacier_directories, gdirs_gridded):
240-
lat = xr.DataArray(
241-
grouped_stakes.get_group(gdir.rgi_id)[["POINT_LAT"]].values.flatten(),
242-
dims="points",
243-
)
244-
lon = xr.DataArray(
245-
grouped_stakes.get_group(gdir.rgi_id)[["POINT_LON"]].values.flatten(),
246-
dims="points",
242+
243+
# Coordinate transformation from WGS84 to the projection of OGGM data
244+
transf = pyproj.Transformer.from_proj(
245+
pyproj.CRS.from_user_input("EPSG:4326"),
246+
pyproj.CRS.from_user_input(gdir_grid.pyproj_srs),
247+
always_xy=True,
247248
)
249+
lon = grouped_stakes.get_group(gdir.rgi_id)[["POINT_LON"]].values.flatten()
250+
lat = grouped_stakes.get_group(gdir.rgi_id)[["POINT_LAT"]].values.flatten()
251+
x, y = transf.transform(lon, lat)
248252

249253
topo_data = (
250-
gdir_grid.sel(x=lon, y=lat, method="nearest")[voi]
254+
gdir_grid.sel(
255+
x=xr.DataArray(x, dims="points"),
256+
y=xr.DataArray(y, dims="points"),
257+
method="nearest",
258+
)[voi]
251259
.to_dataframe()
252260
.reset_index(drop=True)
253261
)

0 commit comments

Comments
 (0)