Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remap ICON to swiss #44

Merged
merged 13 commits into from
Oct 23, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
linear interpolation
cfkanesan committed Sep 4, 2024
commit bfbdc01bb5779a82b4697c274ea1e08150f43419
522 changes: 285 additions & 237 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -33,8 +33,10 @@ numpy = "^1.26.4"
polytope-client = "^0.7.4"
pydantic = "*"
pyfdb = { url = "https://github.com/ecmwf/pyfdb/archive/refs/tags/0.0.3.zip" }
pyproj = "^3.6.1"
pyyaml = "^6.0.1"
rasterio = "^1.3.10"
scipy = "^1.13"
xarray = ">=2024"

[tool.poetry.group.dev.dependencies]
25 changes: 25 additions & 0 deletions src/meteodatalab/operators/regrid.py
Original file line number Diff line number Diff line change
@@ -10,6 +10,8 @@
import xarray as xr
from rasterio import transform, warp
from rasterio.crs import CRS
from scipy.interpolate import griddata
from pyproj import Transformer

# Local
from .. import icon_grid, metadata
@@ -404,3 +406,26 @@ def icon2rotlatlon(field: xr.DataArray) -> xr.DataArray:
)

return _icon2regular(field, dst, indices, weights)


def linear(field: xr.DataArray, dst: RegularGrid) -> xr.DataArray:
transformer = Transformer.from_crs("epsg:4326", dst.crs.wkt)
points = transformer.transform(field.lat, field.lon)
gx, gy = np.meshgrid(dst.x, dst.y)

def reproject_layer(values):
return griddata(points, values, (gx, gy), method="linear")

data = xr.apply_ufunc(
reproject_layer,
field,
input_core_dims=[["cell"]],
output_core_dims=[["y", "x"]],
vectorize=True,
)

attrs = field.attrs
if md := _get_metadata(dst):
attrs |= metadata.override(field.message, **md)

return xr.DataArray(data, attrs=attrs)