- 积分
- 180
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2015-11-25
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
我用python读取了cmorph数据,cmorph数据是0.25*0.25,我想要进行插值成为0.1*0.1的数据,但是总是报错,求大神能否告知错误如何解决。
#!/usr/lib64/python2.6/
#! -*- coding: UTF-8 -*-
import numpy as np
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
import pylab
from scipy import linspace, polyval, polyfit, sqrt, stats
from pylab import *
from mpl_toolkits.basemap import Basemap, cm
import math
import netCDF4 as nc
from netCDF4 import Dataset
from netCDF4 import num2date
from scipy.interpolate import griddata
from functools import partial
import struct
from scipy import interpolate
from scipy.interpolate import griddata
file_name=‘/data/dailypre/bld/2001/CMORPH_V1.0BETA_BLD_0.25deg-DLY_EOD_20010602'
fopen = open(file_name, 'rb')
pre = np.zeros((720,1440))
i=0
with open(file_name,'rb') as fd:
byte_len = 4
records = iter(partial(fopen.read, 4), b'')
for r in records:
j=i//1440
k=i%1440
precipitation = struct.unpack('<f',r)
pre[j][k]=precipitation[0]
i=i+1
fopen.close()
我用的是interpolate.interpn
x = np.arange(-89.875,90.125, 0.25)#原本cmorph数据是-89.875~89.875,但是由于arange会不录取最后一个89.875,所以我直接改成了90.125,这样能把89.875录进去,以下数字都是这个原因
y = np.arange(0.125,360.125, 0.25)
x2 = np.arange(-89.875,89.885, 0.01)
y2 = np.arange(0.125,359.885, 0.01)
#yi2,xi2=np.meshgrid(y,x);
grid_z0 = interpolate.interpn((x,y), pre, (x2,y2), method='linear', fill_value=-999.0)
报错内容是:
grid_z0 = interpolate.interpn((x,y), pre, (x2,y2), method='linear', fill_value=-999.0)
File "/wind1/home/17liuysh/anaconda2/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 2568, in interpn
xi = _ndim_coords_from_arrays(xi, ndim=len(grid))
File "interpnd.pyx", line 154, in scipy.interpolate.interpnd._ndim_coords_from_arrays
File "interpnd.pyx", line 165, in scipy.interpolate.interpnd._ndim_coords_from_arrays
File "/wind1/home/17liuysh/anaconda2/lib/python2.7/site-packages/numpy/lib/stride_tricks.py", line 249, in broadcast_arrays
shape = _broadcast_shape(*args)
File "/wind1/home/17liuysh/anaconda2/lib/python2.7/site-packages/numpy/lib/stride_tricks.py", line 184, in _broadcast_shape
b = np.broadcast(*args[:32])
ValueError: shape mismatch: objects cannot be broadcast to a single shape
|
|