我想实现计算每日 netCDF4 文件温度最小值的事件数。我有一个像下面这样的代码,但它一直告诉我索引超出范围。netCDf4 文件是一个 349x277x2920 的三维数组。第三个维度是时间,每三个小时测一次温度,所以总共有365天的温度。我想计算像素低于266的每日最小值,然后计算所有365天的每日计数。代码是这样的:
from osgeo import gdal
from osgeo import osr
import numpy as np
import netCDF4 as net
finalgrid=np.zeros(shape=[277,349],dtype=int)
infile=net.Dataset("W:/air.2m.2014.nc")
value=infile.variables['air'][:,:,]
infile.close()
dailymean=np.full([277,349],300,dtype=float)
for k in range(0,2921,8):
emptygrid=np.zeros(shape=[277,349],dtype=int)
for i in range(0,278):
for j in range(0,350):
try:
if value[k][i][j]>1:
dailymean[i][j]=min(value[k][i][j],value[k+1][i][j],value[k+2][i][j],value[k+3][i][j],value[k+4][i][j],value[k+5][i][j],value[k+6][i][j],value[k+7][i][j])
except:
continue
emptygrid[dailymean<=266.0]=emptygrid[dailymean<=266.0]+1
finalgrid=finalgrid+emptygrid
print k
driver=gdal.GetDriverByName('gtiff')
print finalgrid.max()
outDs=driver.Create('W:/2014aircount.tif',349,277,1,gdal.GDT_Float64)
outBand=outDs.GetRasterBand(1)
outBand.WriteArray(finalgrid,0,0)
ds=gdal.Open("W:/air.2m.2014.nc")
gt = ds.GetGeoTransform()
outDs.SetGeoTransform(gt)
outDs.SetProjection(ds.GetProjection())
#outDs.SetProjection(ds.GetProjection())
outBand.FlushCache()
ds=None