JiaweiZhuang / xESMF

Universal Regridder for Geospatial Data
http://xesmf.readthedocs.io/
MIT License
269 stars 49 forks source link

xESMF with CMIP6 models #78

Open sg2400 opened 4 years ago

sg2400 commented 4 years ago

Hi

Thanks for writing this package. I have been trying to use xESMF with a number of CMIP6 models, and while some are working, others are not; and it is not clear why these are not working. The error message is not clear to me. For example, the following error was with the model CNRM-ESM2-1:

ValueError: ESMC_FieldRegridStoreFile() failed with rc = 506. Please check the log files (named "*ESMF_LogFile").

and the Log file states that:

20191210 115316.651 ERROR PET0 ESMF_Regrid.F90:360 ESMF_RegridStore Invalid argument - Internal subroutine call returned Error 20191210 115316.658 ERROR PET0 ESMF_FieldRegrid.F90:1292 ESMF_FieldRegridStoreNX Invalid argument - Internal subroutine call returned Error 20191210 115316.658 ERROR PET0 ESMF_Field_C.F90:1168 f_esmf_regridstorefile Invalid argument - Internal subroutine call returned Error 20191210 115316.713 INFO PET0 Finalizing ESMF

Thanks

JiaweiZhuang commented 4 years ago

Could you post the complete notebook to reproduce the error, so I can actually diagnose the problem? Please also include the steps/commands to obtain the data files. See more at ask for help

Just notice today that CMIP6 is now available in Google cloud storage. You can probably reproduce the workflow via Pangeo binder: https://github.com/hdrake/cmip6-temperature-demo/

sg2400 commented 4 years ago

Hi. Sorry for the delay, but I have not used the Pangeo binder before, and it seems to have a bit of a learning curve. I have attached a small script (extension changed to .txt) that shows the problem. The data file can be downloaded from

https://drive.google.com/file/d/14KTlJV6qvNlDT_xDsJ3UrzQOU2MuNeAn/view?usp=sharing

This is not the only model that has problems. As mentioned before, some models work fine.

Thanks xesmf_cmip6.py.txt

holivarez19 commented 4 years ago

Hello. I am experiencing the same error with the model IPSL. I had success using the below script for the CESM2 and CanESM5 models. Thank you in advance.

The netcdf file is here: https://www.dropbox.com/s/rcyzd97ne2raszi/IPSL_fgco2.nc?dl=0

The steps I used after loading the file: ds_out = xe.util.grid_global(1, 1) regridder = xe.Regridder(IPSL_fgco2, ds_out, 'bilinear', reuse_weights=True) dr_out = regridder(IPSL_fgco2) IPSL_conv_lon = et.grid.convert_lon(IPSL_fgco2) regridder = xe.Regridder(IPSL_conv_lon, ds_out, 'bilinear', reuse_weights=True, periodic=True) dr_out = regridder(IPSL_conv_lon)

Error:

ValueError Traceback (most recent call last)

in 1 # 3/10/20 copy and paste all of warning/error messages to send to xe designer 2 ----> 3 regridder = xe.Regridder(IPSL_conv_lon, ds_out, 'bilinear', reuse_weights=True, periodic=True) 4 dr_out = regridder(IPSL_conv_lon) /usr/local/Caskroom/miniconda/base/lib/python3.7/site-packages/xesmf/frontend.py in __init__(self, ds_in, ds_out, method, periodic, filename, reuse_weights, ignore_degenerate) 180 181 # get weight matrix --> 182 self._write_weight_file() 183 self.weights = read_weights(self.filename, self.n_in, self.n_out) 184 /usr/local/Caskroom/miniconda/base/lib/python3.7/site-packages/xesmf/frontend.py in _write_weight_file(self) 224 regrid = esmf_regrid_build(self._grid_in, self._grid_out, self.method, 225 filename=self.filename, --> 226 ignore_degenerate=self.ignore_degenerate) 227 esmf_regrid_finalize(regrid) # only need weights, not regrid object 228 /usr/local/Caskroom/miniconda/base/lib/python3.7/site-packages/xesmf/backend.py in esmf_regrid_build(sourcegrid, destgrid, method, filename, extra_dims, ignore_degenerate) 246 regrid_method=esmf_regrid_method, 247 unmapped_action=ESMF.UnmappedAction.IGNORE, --> 248 ignore_degenerate=ignore_degenerate) 249 250 return regrid /usr/local/Caskroom/miniconda/base/lib/python3.7/site-packages/ESMF/util/decorators.py in new_func(*args, **kwargs) 62 63 esmp = esmpymanager.Manager(debug = False) ---> 64 return func(*args, **kwargs) 65 return new_func 66 /usr/local/Caskroom/miniconda/base/lib/python3.7/site-packages/ESMF/api/regrid.py in __init__(self, srcfield, dstfield, filename, src_mask_values, dst_mask_values, regrid_method, pole_method, regrid_pole_npoints, line_type, norm_type, extrap_method, extrap_num_src_pnts, extrap_dist_exponent, unmapped_action, ignore_degenerate, create_rh, src_frac_field, dst_frac_field) 148 createRH=create_rh, 149 srcFracField=src_frac_field, --> 150 dstFracField=dst_frac_field) 151 else: 152 self._routehandle = ESMP_FieldRegridStore(srcfield, dstfield, /usr/local/Caskroom/miniconda/base/lib/python3.7/site-packages/ESMF/util/decorators.py in new_func(*args, **kwargs) 50 lineno=func.__code__.co_firstlineno + 1, 51 ) ---> 52 return func(*args, **kwargs) 53 return new_func 54 /usr/local/Caskroom/miniconda/base/lib/python3.7/site-packages/ESMF/interface/cbindings.py in ESMP_FieldRegridStoreFile(srcField, dstField, filename, srcMaskValues, dstMaskValues, regridmethod, polemethod, regridPoleNPnts, lineType, normType, unmappedaction, ignoreDegenerate, createRH, srcFracField, dstFracField) 2146 if rc != constants._ESMP_SUCCESS: 2147 raise ValueError('ESMC_FieldRegridStoreFile() failed with rc = '+str(rc)+ -> 2148 '. '+constants._errmsg) 2149 return routehandle 2150 ValueError: ESMC_FieldRegridStoreFile() failed with rc = 506. Please check the log files (named "*ESMF_LogFile").
amvaruolo-clarke commented 4 years ago

I just ran into this error too, it appears to be just related to the CNRM-ESM2 (and CNRM-CM6) ocean model as I am able to regrid data from the atmospheric model using the same bit of code, see below. Thank you!

set up common grid

ds_out = xr.Dataset({'lat': (['lat'], np.arange(-88.5, 89.5, 1.)), 'lon': (['lon'], np.arange(0.5, 360., 1.)), } )

def regrid_to_common(ds, ds_out): """ Regrid from rectilinear grid to common grid """ regridder = xe.Regridder(ds, ds_out, 'bilinear',periodic=True, reuse_weights=True) return regridder(ds)

ds = (load_tas_data(source_id, 'historical', mem_id).sel(time=slice('1901', '2014')))

rename spatial dimensions if necessary

if ('longitude' in ds.dims) and ('latitude' in ds.dims): ds = ds.rename({'longitude':'lon', 'latitude': 'lat'}) if ('i' in ds.dims) and ('j' in ds.dims): ds = ds.rename({'longitude':'lon', 'latitude': 'lat'}) ds = xr.decode_cf(ds)

sst_ng = ds.tos # get data on native grade sst = regrid_to_common(sst_ng, ds_out) regrid

aaronspring commented 4 years ago

I find this 506 type error for many ocean models. I dont understand the underlying problem.

aaronspring commented 4 years ago

the error doesnt occur with ignore_degenerate=True. this closes the issue from my point of view

holivarez19 commented 4 years ago

Thank you, Aaron! This worked for me as well.

-- Holly Olivarez (she/her) NSF Graduate Research Fellow Environmental Studies Program Institute of Arctic and Alpine Research (INSTAAR) University of Colorado Boulder instaar.colorado.edu/people/holly-olivarezhttps://nam01.safelinks.protection.outlook.com/?url=http%3A%2F%2Finstaar.colorado.edu%2Fpeople%2Fholly-olivarez%2F&data=01%7C01%7Ciceleste%40nmsu.edu%7Cc334f0e0680b495e4f3008d73c744f33%7Ca3ec87a89fb84158ba8ff11bace1ebaa%7C1&sdata=al3Yq0xvgDxlnaLBASzEYJ7QC%2BwYaxTJ5FmIASPR3q0%3D&reserved=0 @holivarez19

From: Aaron Spring notifications@github.com Reply-To: JiaweiZhuang/xESMF reply@reply.github.com Date: Friday, June 5, 2020 at 10:18 AM To: JiaweiZhuang/xESMF xESMF@noreply.github.com Cc: Holly Olivarez Holly.Olivarez@Colorado.EDU, Comment comment@noreply.github.com Subject: Re: [JiaweiZhuang/xESMF] xESMF with CMIP6 models (#78)

the error doesnt occur with ignore_degenerate=True. this closes the issue from my point of view

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/JiaweiZhuang/xESMF/issues/78#issuecomment-639606052, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AJOLXOTOLRP5N7GHCEY2MG3RVELHBANCNFSM4JY5IISA.

tristanballard commented 4 years ago

Setting ignore_degenerate=True does not appear to uniformly fix the issue, at least for regridding the CMIP6 MPI-ESM1-2-HR monthly precipitation values hosted on Pangeo. When including that argument within xe.Regridder() I get the error message TypeError: __init__() got an unexpected keyword argument 'ignore_degenerate'.

aaronspring commented 4 years ago

Which version of xesmf are you using?

LeparaLaMapara commented 3 years ago

Setting ignore_degenerate=True did not fix the issue. When I include that argument i get the error message AssertionError: The horizontal shape of input data is (362, 4), different from that ofthe regridder (332, 362)!

my xesmf version : '0.3.0'

aaronspring commented 3 years ago

What’s the input data? len=4 looks suspicious

LeparaLaMapara commented 3 years ago

The data has the following dimensions: axis_nbounds: 2 nvertex: 4 time: 1980 x: 362 y: 332

aaronspring commented 3 years ago

Try to get rid of axis bounds and nvertex and then regrid. Or transpose x and y to the front.

LeparaLaMapara commented 3 years ago

Thanks it work!. But what is the axis bounds and nvertex? is it the different ensembles? Where can I get information about?

aaronspring commented 3 years ago

thats some information about the grid description. how did you solve it? by transposing x and y first or dropping the other coords?

LeparaLaMapara commented 3 years ago

By dropping the other coords, such that my data dimensions are as follows: time: 1980 x: 362 y: 332