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

Generate SCRIP grid file from scratch #4

Closed
JiaweiZhuang opened this issue Oct 3, 2017 · 3 comments
Closed

Generate SCRIP grid file from scratch #4

JiaweiZhuang opened this issue Oct 3, 2017 · 3 comments

Comments

@JiaweiZhuang
Copy link
Owner

To solve #2 (the biggest, or perhaps the only barrier for xESMF), I would like a Python version of ESMF_RegridWeightGen. According to @bekozi and @rokuingh, this function will eventually be available in ESMPy. Before that, we can actually use the Fortran version of ESMF_RegridWeightGen to generate offline regridding weights. This command line utility comes with conda ESMF so users don't need to worry about compiling Fortran source code. In the future we can easily replace it by the Python equivalent, without affecting other parts of xESMF.

However,ESMF_RegridWeightGen requires the grid information to be stored in SCRIP Grid File Format. Here are possible ways to get this format:

  • Use SCRIP itself? Not a good approach because SCRIP is an old, no-longer-maintained software.
  • Use ESMPy? I can only find ways to read this format, but not to create this format.
  • Use this NCL function? This is perhaps the only easy way right now. I want to write a Python version of it, but its source code looks unnecessarily complicated.

I am wondering what's the best&quickest way to convert pure numpy arrays to SCRIP format, which can then be fed to ESMF_RegridWeightGen? xESMF only focuses on quadrilateral (i.e. logically rectilinear) grids so there's no need to worry about unstructured meshes. @bekozi and @rokuingh do you have minimal Python scripts to make this format?

@JiaweiZhuang
Copy link
Owner Author

Also, will the Python version of ESMF_RegridWeightGen be able to produce everything from pure numpy arrays or it will still rely on the SCRIP format?

@bekozi
Copy link

bekozi commented Oct 3, 2017

According to @bekozi and @rokuingh, this function will eventually be available in ESMPy. Before that, we can actually use the Fortran version of ESMF_RegridWeightGen to generate offline regridding weights.

We are very close to an implementation. Dealing with a couple test failures gratingly unrelated to the weight file writing.

However, ESMF_RegridWeightGen requires the grid information to be stored in SCRIP Grid File Format.

CF-Grid is the main structured grid format read by ESMF - the spiritual successor to SCRIP.

I am wondering what's the best&quickest way to convert pure numpy arrays to SCRIP format, which can then be fed to ESMF_RegridWeightGen?

ocgis is one option. This should work with ESMF_RegridWeightGen out-of-the-box:

conda create -n ocgis -c conda-forge ocgis
source activate ocgis
# Get the latest repository version.
conda remove ocgis
git clone https://github.com/NCPP/ocgis.git
cd ocgis
python setup.py install
import ocgis
import numpy as np

time = ocgis.TemporalVariable(name='time', value=[1, 2, 3, 4, 5, 6], dimensions='time')
lat = ocgis.Variable(name='lat', value=[-90, 0, 90.], dimensions='lat')
lon = ocgis.Variable(name='lon', value=[0., 90., 180., 270., 359.], dimensions='lon')
data = ocgis.Variable(name='data', value=np.random.rand(6, 3, 5), dimensions=['time', 'lat', 'lon'])
grid = ocgis.Grid(lon, lat, crs=ocgis.crs.Spherical())
field = ocgis.Field(time=time, grid=grid, is_data=data)
path = '/tmp/cf-data.nc'
field.write(path)
ocgis.RequestDataset(path).inspect()

One can also create an ESMPy field:

source activate ocgis
conda install -c conda-forge esmpy
...
from ocgis.regrid.base import get_esmf_field_from_ocgis_field

efield = get_esmf_field_from_ocgis_field(field)
print(type(efield))

Also, will the Python version of ESMF_RegridWeightGen be able to produce everything from pure numpy arrays or it will still rely on the SCRIP format?

It will work from pure numpy arrays.

Let me know if I missed anything...

@JiaweiZhuang
Copy link
Owner Author

We are very close to an implementation. Dealing with a couple test failures gratingly unrelated to the weight file writing.

It will work from pure numpy arrays.

Sounds great! Please do tell me once it is released, so can I make a major update on xESMF 😃

(close this issue as SCRIP doesn't have to be a hard dependence)

raphaeldussin added a commit to raphaeldussin/xESMF that referenced this issue Sep 2, 2020
add HPC regridding documentation (replace PR JiaweiZhuang#4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants