如何在python中插值(或重磨)大型矩阵?

2024-07-02 12:01:27 发布

您现在位置:Python中文网/ 问答频道 /正文

如何在python中插值大矩阵?你知道吗

我想插值一个5685×5567的矩阵。你知道吗

它是一个具有正交投影的卫星数据集。你知道吗

所以经纬度矩阵也和数据集(5685 x 5567)有相同的形状

我想让它像墨卡托投影一样具有1维经纬度的低分辨率数据集。你知道吗

所以我试了一下

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)

但它会显示错误消息“overflowerrror:太多数据点需要插值”。你知道吗

使用griddata也不起作用。你知道吗


Tags: imageimportdatavariablesmodisglobfilelon