I'm trying to use xesmf to regrid onto a curvilinear ROMS grid. It is telling me:
File "/import/c1/AKWATERS/kate/.conda/envs/snowdrifts/lib/python3.7/site-packages/xesmf/frontend.py", line 94, in ds_to_ESMFlocstream
raise ValueError("lon can only be 1d")
ValueError: lon can only be 1d
The test code:
import xarray as xr
import xesmf
def regrid_tracer(fld, method='bilinear'):
coords = xr.open_dataset('/import/AKWATERS/kshedstrom/gridpak/Arctic2/grid_Arctic_4.nc')
coords = coords.rename({'lon_rho': 'lon', 'lat_rho': 'lat'})
gsource = xr.open_dataset('/import/AKWATERS/kshedstrom/HYCOM/Svalbard/data/HYCOM_GLBv0.08_2018_001.nc')
regrid = xesmf.Regridder(
gsource,
coords,
method=method,
locstream_out=True,
periodic=False,
filename='regrid_t.nc',
reuse_weights=True
)
tdest = regrid(gsource.ssh)
return tdest
myssh = regrid_tracer('ssh')
myssh.to_netcdf('myssh.nc')
What am I doing wrong?
I wonder why ds_to_ESMFlocstream is involved. I would have expected an ESMF grid object. The locstream is indeed a 1D thing. I think xesmf must be getting confused and not instantiating an ESMF grid object from your data.
cc @geocat
Oh, I was copying from a code that had locstream set to true. It works without that. Thanks!
Ah, had I looked more closely at your code, I would have seen that. Glad it's working!
Last updated: May 16 2025 at 17:14 UTC