在python中将netcdf数据重新分配为更精细的分辨率 [英] regrid netcdf data to finer resolution in python

查看:460
本文介绍了在python中将netcdf数据重新分配为更精细的分辨率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过简单地创建具有与较粗分辨率像元相同值的新的较细分辨率的网格像元,将netcdf数据的分辨率从0.5度降低到0.25(或更低).我有傻瓜.代码可用于创建较粗糙的分辨率文件:

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

推荐答案

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

您已经使用较粗的网格进行了核心操作(即,以4度为步长增加坐标),现在只需通过重新定义lons_sublats_sub作为网格间距来做相反的操作以0.25度为增量.像下面这样的东西应该起作用.

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)

这篇关于在python中将netcdf数据重新分配为更精细的分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆