regrid netcdf data to finer resolution in python

点点圈 提交于 2019-12-12 01:47:53

问题


I would like to downscale netcdf data from 0.5 degree to 0.25 (or lower) resolution by simply creating new finer resolution grid cells that have the same value as the coarser resolution cell. I have the foll. code which works fine for creating a coarser resolution file:

from mpl_toolkits.basemap import Basemap
from netCDF4 import Dataset
import numpy as np
import pdb

filename = '/Users/r/global_aug4.region.nc'
pdb.set_trace()
with Dataset(filename, mode='r') as fh:
   lons = fh.variables['lon'][:]
   lats = fh.variables['lat'][:]
   biom = fh.variables['biomass'][:].squeeze()

lons_sub, lats_sub = np.meshgrid(lons[::4], lats[::4])

coarse = Basemap.interp(biom, lons, lats, lons_sub, lats_sub, order=1)

How do I create something which goes the other way i.e. from coarser to finer scale


回答1:


Note in the docs that you just need to supply the interp method with xout and yout, which are the new desired grids.

You've already done it corectly with a coarser grid (i.e. by incrementing the coordinates with a step of 4 degrees), now you just need to do the opposite by redefining lons_sub and lats_sub to be the grid spacing in 0.25 degree increments. Something like the following should work.

lats_fine = np.arange(lats[0], lats[-1], 0.25) # 0.25 degree fine grid
lons_fine = np.arange(lons[0], lons[-1], 0.25)
lons_sub, lats_sub = np.meshgrid(lons_fine, lats_fine)


来源:https://stackoverflow.com/questions/31819754/regrid-netcdf-data-to-finer-resolution-in-python

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!