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

unstructured grids #115

Open
aaronspring opened this issue Sep 15, 2021 · 11 comments
Open

unstructured grids #115

aaronspring opened this issue Sep 15, 2021 · 11 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@aaronspring
Copy link

Has anyone used xesmf to regrid from unstructured grids like ICON, MPAS or FESOM?

Unstructured grids like ICON just have one spatial dimension like ncells and 2 spatial coordinates clon and clat.

I tried and failed.

https://gist.github.com/aaronspring/fd54970f71a39e26ab54a8b47170533d

@aaronspring
Copy link
Author

Is this to be done with LocStream? https://pangeo-xesmf.readthedocs.io/en/latest/notebooks/Using_LocStream.html

@aaronspring
Copy link
Author

for method in ['nearest_s2d','nearest_d2s']: # only works for these two methods
    re = xe.Regridder(ds, ds_out, method, locstream_in=True)
    plt.show()
    re(ds).t2m.isel(time=0,lev=0).plot()
    plt.title(f'method={method}')

image

@aaronspring
Copy link
Author

Whats the reason that the other methods do not work here?

@raphaeldussin
Copy link
Contributor

Hi @aaronspring
ESMF and its python wrapper ESMPy provides the capabilities to remap unstructured (Mesh) to structured (Grid) but xESMF has not yet implemented those capabilities. You can find some examples in the ESMPy documentation and we'd welcome a contribution in xESMF to implement support for Meshes!

@aaronspring
Copy link
Author

more context in JiaweiZhuang/xESMF#18

@andersy005 andersy005 added enhancement New feature or request help wanted Extra attention is needed labels Sep 23, 2021
@sol1105
Copy link
Contributor

sol1105 commented Oct 1, 2021

Using locstream to at least offer nearest neighbour remapping is a nice idea, since apparently the data on unstructured grids of the CMIP models is stored in this locstream-like format.
I tested it for CMIP6 published ICON-OES and FESOM data:
https://nbviewer.jupyter.org/github/roocs/regrid-prototype/blob/main/docs/notebooks/xESMF_unstructured_locstream_ref.ipynb

The only problem I encountered originates from the following lines in xesmf/backend.py:

def esmf_regrid_build( [...]):
[...]
    # ESMF bug? when using locstream objects, options src_mask_values
    # and dst_mask_values produce runtime errors
    allow_masked_values = True
    if isinstance(sourcefield.grid, ESMF.api.locstream.LocStream):
        allow_masked_values = False
    if isinstance(destfield.grid, ESMF.api.locstream.LocStream):
        allow_masked_values = False
[...]

Due to an ESMF bug masks are ignored when generating the weights. I tried then to apply a mask for target grid, by manipulating the weights after their creation and by applying the mask on the regridded data. Both options worked. So one could

  • add the option to manipulate the weights when a mask for the target grid is defined and the locstream option is used to make up for at least half of the ESMF bug
  • add the possibility to apply a mask on the regridded data to frontend.BaseRegridder.__call__ to be able to call it like: ds_out=regridder(ds, keep_attrs, skipna, na_thres, mask_out)
  • Should a warning be issued when a mask is ignored? It would have helped me at least :)
    What do you think?

@aaronspring
Copy link
Author

sounds like you have a path to a solution here @sol1105 ?

Should a warning be issued when a mask is ignored? It would have helped me at least :)

sounds reasonable to add at first

add the possibility to apply a mask on the regridded data to frontend.BaseRegridder.call to be able to call it like: ds_out=regridder(ds, keep_attrs, skipna, na_thres, mask_out)

not sure whether a new keyword is welcome

I tried then to apply a mask for target grid, by manipulating the weights after their creation and by applying the mask on the regridded data.

do you think you could provide a PR which implements this by default?

@kthyng
Copy link

kthyng commented Mar 4, 2022

@aaronspring Do you know the status of using xESMF with unstructured grids? Thanks.

@aaronspring
Copy link
Author

Nope. Nothing more than the examples above

@kthyng
Copy link

kthyng commented Mar 4, 2022

ok thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

5 participants