Open matthiasdemuzere opened 1 year ago
Hello @Jiacan , @matthiasdemuzere , @jesusff,
Thank you @Jiacan for proposing this methodology and adding the main parts of the script!
As discussed in our last call, and also based on common approaches (e.g. indicated here: https://climatedataguide.ucar.edu/climate-tools/regridding-overview), possibly we could follow two different regridding techniques.
1). For the urban fraction & land-surface data, the "nearest neighbor" interpolation seems the best way forward, as it is specifically advisable for categorical/land-surface data. 2). For the climate projections data (e.g. temperature) we could possibly use bi-linear or another approach for the interpolation? What would you think?
During our last call, there was also the comment to stick with the original grid definitions, which would generally be preferred to not lose information. Nevertheless we are dealing with different grid definitions for; 1). REMO vs RegCM: 2). Across the domains; 3). for urban fraction vs. land surface data (esp. for RegCM). Acknowledging this complexity, it might be better to have a regridding strategy to be able to handle the data in a more efficient way. Glad to hear if you have other thoughts on this?
@JavierDiezSierra will work on this during the next weeks, comparing conservative and nearest neighbor interpolation. He already has some tools to do it using the xesmf package. See https://github.com/SantanderMetGroup/python-resources/blob/main/lib/interpolater.py
I have worked out one solution for this question. Please see my code below:
import xarray as xr
import numpy as np
import pyproj
from scipy.interpolate import griddata
% Load the input data
ds = xr.open_dataset('/Users/jiacanyuan/data/Data/CORDEX-CORE/tasmin_EAS-22_NCC-NorESM1-M_rcp26_r1i1p1_ICTP-RegCM4-4_v0_mon_200601-201012.nc')
% Create a regular lat-lon grid that matches the desired resolution and domain
lon = ds.lon[:]%360
lat = ds.lat[:]
points = np.column_stack([lat.values.flatten(), lon.values.flatten()])
lon_min, lon_max, lat_min, lat_max = [lon.min(), lon.max(), lat.min(), lat.max()]
resolution = 0.25
new_lon, new_lat = np.meshgrid(np.arange(lon_min, lon_max, resolution),np.arange(lat_min, lat_max, resolution))
% Interpolate the data from the rotated grid to the regular lat-lon grid
new_data = griddata(points, ds.tasmin[1,:,:].values.flatten(), (new_lat, new_lon), method='linear')
% Save the reprojected data to a new filenew_ds = xr.Dataset({'data': (['lat', 'lon'], new_data)}, coords={'lat': new_lat[:,0], 'lon': new_lon[0,:]})
new_ds.to_netcdf('output_file.nc')
The output for EAS22 is like this