Skip to content

Commit

Permalink
fix for #150
Browse files Browse the repository at this point in the history
  • Loading branch information
OnnoEbbens committed Mar 13, 2023
1 parent d867c4f commit c2bb7a0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 28 deletions.
24 changes: 3 additions & 21 deletions docs/examples/16_groundwater_transport.ipynb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -35,7 +34,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -72,7 +70,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -89,7 +86,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -150,7 +146,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -180,7 +175,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -210,12 +204,11 @@
" da=cli_da.isel(layer=ilay), method=\"nearest\"\n",
" )\n",
"\n",
"# set chloride data in model dataset\n",
"ds[\"chloride\"] = cli_da"
"# set chloride data in model dataset, keep only layer, y and x coordinates\n",
"ds[\"chloride\"] = ('layer', 'y', 'x'), cli_da.values "
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -240,7 +233,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -273,7 +265,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -319,7 +310,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -342,7 +332,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -365,7 +354,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -427,7 +415,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -444,7 +431,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -471,7 +457,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -492,7 +477,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -513,7 +497,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -547,7 +530,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -572,5 +554,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
25 changes: 18 additions & 7 deletions nlmod/dims/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,12 @@ def structured_da_to_ds(da, ds, method="average", nodata=np.NaN):
kwargs = {}
if ds.gridtype == "structured":
kwargs["fill_value"] = "extrapolate"

da_out = da.interp(x=ds.x, y=ds.y, method=method, kwargs=kwargs)
return da_out

# some stuff is added by the interp function that should not be there
added_coords = set(da_out.coords) - set(ds.coords)
return da_out.drop_vars(added_coords)
if isinstance(method, rasterio.enums.Resampling):
resampling = method
else:
Expand Down Expand Up @@ -525,12 +529,19 @@ def structured_da_to_ds(da, ds, method="average", nodata=np.NaN):
else:
raise (Exception(f"Gridtype {ds.gridtype} not supported"))

# somehow the spatial_ref (jarkus) and band (ahn) coordinates are added by the reproject_match function
if "spatial_ref" in da_out.coords:
da_out = da_out.drop_vars("spatial_ref")
if "grid_mapping" in da_out.encoding:
del da_out.encoding["grid_mapping"]

# some stuff is added by the reproject_match function that should not be there
added_coords = set(da_out.coords) - set(ds.coords)
da_out = da_out.drop_vars(added_coords)

if "grid_mapping" in da_out.encoding:
del da_out.encoding["grid_mapping"]

# remove the long_name, standard_name and units attributes of the x and y coordinates
for coord in ['x', 'y']:
for name in ['long_name', 'standard_name', 'units', 'axis']:
if name in da_out[coord].attrs.keys():
del da_out[coord].attrs[name]

return da_out


Expand Down

0 comments on commit c2bb7a0

Please sign in to comment.