如何在python中内插大矩阵?
我想插入5685 x 5567矩阵。
这是具有正交投影的卫星数据集。
因此,经度和纬度矩阵与数据集的形状也相同(5685 x 5567)
我想像墨卡托投影一样,使其具有一维经度和纬度的低分辨率数据集。
所以我尝试了
import fnmatch
import glob
import os
import numpy as np
import h5py
from netCDF4 import Dataset
from scipy import interpolate
for file in os.listdir('.'):
if fnmatch.fnmatch(file,'COMS*L2A*'):
chlfn=file
elif fnmatch.fnmatch(file,'*SST.nc'):
sstfn=file
elif fnmatch.fnmatch(file,'daylength.nc'):
dlfn=file
elif fnmatch.fnmatch(file,'*OC.nc'):
ocfn=file
elif fnmatch.fnmatch(file,'COMS*LON*.he5'):
glonfn=file
elif fnmatch.fnmatch(file,'COMS*LAT*.he5'):
glatfn=file
sstnc = Dataset(glob.glob(sstfn)[0])
ocnc = Dataset(glob.glob(ocfn)[0])
dlnc = Dataset(glob.glob(dlfn)[0])
chlh5 = h5py.File(chlfn,'r')
glonh5=h5py.File(glonfn,'r')
glath5=h5py.File(glatfn,'r')
daynum = int(glob.glob(sstfn)[0][5:8])
modis_lon = sstnc.variables['lon'][:]
modis_lat = sstnc.variables['lat'][:]
goci_lon=glonh5['/HDFEOS/GRIDS/Image Data/Data Fields/Longitude Image Pixel Values']
goci_lat=glath5['/HDFEOS/GRIDS/Image Data/Data Fields/Latitude Image Pixel Values']
sst = sstnc.variables['sst'][:]
kd = ocnc.variables['Kd_490'][:]
par = ocnc.variables['par'][:]
dl = dlnc.variables['Daylength'][daynum - 1, :, :]
chl=chlh5['HDFEOS/GRIDS/Image Data/Data Fields/CHL Image Pixel Values']
chl_masked=np.ma.masked_less(chl[:],0)
flags_sst = sstnc.variables['flags_sst'][:]
flags_oc = ocnc.variables['l2_flags'][:]
setflags_oc = [1, 2, 8, 512, 4096, 16384, 32768, 16777216, 1073741824]
setflags_sst = [2, 4, 8, 16, 32, 4096, 8192, 16384, -32768]
modis_lon2d, modis_lat2d = np.meshgrid(modis_lon, modis_lat)
interp2=interpolate.interp2d(goci_lon,goci_lat,chl)
chl_int=interp2(modis_lon2d,modis_lat2d)
modis_lon和modis_lat是一维数组(分别为2031 x 1和3006 x 1,)
goci_lon和goci_lat是二维数组(5685 x 5567)
但是它显示错误消息“ OverflowError:要插入的数据点太多”。
使用griddata也不起作用。