I've been trying to use xESMF to regrid an existing dataset to a coarser grid taken from a different example file. I've tried many variations but I have not managed to solve the problem... The original dataset has a non-coordinate dimension called "bnds" which has a value of 2, whereas the new dataset doesn't have it since no variable of interest uses "bnds". Here is my python3 script:
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import numpy as np
import xarray as xr
import xesmf as xe
from netCDF4 import Dataset
import h5py
import shutil
import subprocess as sub
import os
import glob
import sys
[gadi-login-03.gadi.nci.org.au:2763401] shmem: posix: file name search - max attempts exceeded.cannot continue with posix.
[gadi-login-03.gadi.nci.org.au:2763702] shmem: posix: file name search - max attempts exceeded.cannot continue with posix.
Traceback (most recent call last):
File "regridding_dataset_with_xESMF_v1.py", line 63, in
regridder = xe.Regridder(ds, ds_out, 'conservative', periodic=True)
File "/g/data3/hh5/public/apps/miniconda3/envs/analysis3-21.01/lib/python3.8/site-packages/xesmf/frontend.py", line 689, in init
grid_in, shape_in, input_dims = ds_to_ESMFgrid(
File "/g/data3/hh5/public/apps/miniconda3/envs/analysis3-21.01/lib/python3.8/site-packages/xesmf/frontend.py", line 129, in ds_to_ESMFgrid
lon_b, lat_b = _get_lon_lat_bounds(ds)
File "/g/data3/hh5/public/apps/miniconda3/envs/analysis3-21.01/lib/python3.8/site-packages/xesmf/frontend.py", line 75, in _get_lon_lat_bounds
lon_b = cfxr.bounds_to_vertices(lon_bnds, 'bounds', order=None)
File "/g/data3/hh5/public/apps/miniconda3/envs/analysis3-21.01/lib/python3.8/site-packages/cf_xarray/helpers.py", line 53, in bounds_to_vertices
values = bounds.transpose(bnd_dim, *old_dims).data
File "/g/data3/hh5/public/apps/miniconda3/envs/analysis3-21.01/lib/python3.8/site-packages/xarray/core/dataarray.py", line 2210, in transpose
dims = tuple(utils.infix_dims(dims, self.dims, missing_dims))
File "/g/data3/hh5/public/apps/miniconda3/envs/analysis3-21.01/lib/python3.8/site-packages/xarray/core/utils.py", line 788, in infix_dims
existing_dims = drop_missing_dims(dims_supplied, dims_all, missing_dims)
File "/g/data3/hh5/public/apps/miniconda3/envs/analysis3-21.01/lib/python3.8/site-packages/xarray/core/utils.py", line 879, in drop_missing_dims
raise ValueError(
ValueError: Dimensions {'bounds'} do not exist. Expected one or more of ('lon', 'bnds')
I've been trying to use xESMF to regrid an existing dataset to a coarser grid taken from a different example file. I've tried many variations but I have not managed to solve the problem... The original dataset has a non-coordinate dimension called "bnds" which has a value of 2, whereas the new dataset doesn't have it since no variable of interest uses "bnds". Here is my python3 script:
import matplotlib.pyplot as plt import cartopy.crs as ccrs import numpy as np import xarray as xr import xesmf as xe from netCDF4 import Dataset import h5py
import shutil import subprocess as sub import os import glob import sys
years_list = [2000,2001,2002,2003,2004,2005,2006,2007,2008,2009]
data_DIR_root = '/my_path1/' output_DIR_root = '/my_path2/'
reference_file_for_regridding = '/my_path3/file_pluc_Newloc.nc' reference_file_for_regridding_name_only = os.path.basename(reference_file_for_regridding)
data_DIR = data_DIR_root list_of_files = glob.glob(data_DIR + 'gpm_3imerg_v06b_20*.nc') if not os.path.exists('./xESMF_regrid/'): os.makedirs('./xESMF_regrid/')
for file in list_of_files: print( "WORKING ON FILE " + file)
And I get the following error message:
[gadi-login-03.gadi.nci.org.au:2763401] shmem: posix: file name search - max attempts exceeded.cannot continue with posix. [gadi-login-03.gadi.nci.org.au:2763702] shmem: posix: file name search - max attempts exceeded.cannot continue with posix. Traceback (most recent call last): File "regridding_dataset_with_xESMF_v1.py", line 63, in
regridder = xe.Regridder(ds, ds_out, 'conservative', periodic=True)
File "/g/data3/hh5/public/apps/miniconda3/envs/analysis3-21.01/lib/python3.8/site-packages/xesmf/frontend.py", line 689, in init
grid_in, shape_in, input_dims = ds_to_ESMFgrid(
File "/g/data3/hh5/public/apps/miniconda3/envs/analysis3-21.01/lib/python3.8/site-packages/xesmf/frontend.py", line 129, in ds_to_ESMFgrid
lon_b, lat_b = _get_lon_lat_bounds(ds)
File "/g/data3/hh5/public/apps/miniconda3/envs/analysis3-21.01/lib/python3.8/site-packages/xesmf/frontend.py", line 75, in _get_lon_lat_bounds
lon_b = cfxr.bounds_to_vertices(lon_bnds, 'bounds', order=None)
File "/g/data3/hh5/public/apps/miniconda3/envs/analysis3-21.01/lib/python3.8/site-packages/cf_xarray/helpers.py", line 53, in bounds_to_vertices
values = bounds.transpose(bnd_dim, *old_dims).data
File "/g/data3/hh5/public/apps/miniconda3/envs/analysis3-21.01/lib/python3.8/site-packages/xarray/core/dataarray.py", line 2210, in transpose
dims = tuple(utils.infix_dims(dims, self.dims, missing_dims))
File "/g/data3/hh5/public/apps/miniconda3/envs/analysis3-21.01/lib/python3.8/site-packages/xarray/core/utils.py", line 788, in infix_dims
existing_dims = drop_missing_dims(dims_supplied, dims_all, missing_dims)
File "/g/data3/hh5/public/apps/miniconda3/envs/analysis3-21.01/lib/python3.8/site-packages/xarray/core/utils.py", line 879, in drop_missing_dims
raise ValueError(
ValueError: Dimensions {'bounds'} do not exist. Expected one or more of ('lon', 'bnds')
The file to regrid can be downloaded from the hyrax server (https://gpm1.gesdisc.eosdis.nasa.gov/opendap/hyrax/GPM_L3/GPM_3IMERGHH.06/2020/001/contents.html), using the opendap protocol, in netcdf4 format instead of the original HDF5.
The reference file from which to take the new grid can be found at https://wetransfer.com/downloads/f017ea89c61431310b3889e4897c56f120210709035420/a8b5f112e6b89266597bc5415865112020210709035729/6be6f6