Arcpy处理中国1km分辨率逐月平均气温(降水)数据集NetCDF数据

下载逐月气温和降水数据

Arcpy处理中国1km分辨率逐月平均气温(降水)数据集NetCDF数据_第1张图片

 下载地址:国家地球系统科学数据中心数据详细信息

配置python环境

配置方法可以参考我的另一篇文章

 Pycharm中安装arcpy_冬_冬_的博客-CSDN博客_arcpy安装

编写python代码

# Name: MakeNetCDFRasterLayer_Ex_02.py
# Description: Create a raster layer from a netCDF file.
# Requirements: None

# Import system modules
import arcpy
import os
arcpy.env.overwriteOutput = True

ncpath="E:/BaiduNetdiskDownload/tem"
nclist=os.listdir(ncpath)
variable = "tmp"
x_dimension = "lon"
y_dimension = "lat"
band_dimension = ""
dimension = "time"
valueSelectionMethod = "BY_VALUE"
outLoc = r'E:\BaiduNetdiskDownload\tem_geotiff'


for ncfile in nclist:  # type: str
    suby=ncfile[4:8] #Draw the start year of each file.
    inNetCDF = os.path.join(ncpath,ncfile)

    nc_FP = arcpy.NetCDFFileProperties(inNetCDF)#get information of file
    nc_Dim = nc_FP.getDimensions() #Get dimension of time

    for dimension in nc_Dim:

        top = nc_FP.getDimensionSize(dimension)

        for i in range(0, top):

            if dimension == "time":

                dimension_values = nc_FP.getDimensionValue(dimension, i)
                nowFile = str(dimension_values)

                #Get date of data
                month=str("%02d" % ((dimension_values)%12))
                year=str(int(int(suby)+dimension_values//12))
                if month == '00':
                    month = '12'
                    year=str(int(year)-1)

                #THIS IS THE NEW CODE HERE
                dv1 = ["time", dimension_values]
                dimension_values = [dv1]
                #END NEW CODE

                arcpy.MakeNetCDFRasterLayer_md(inNetCDF, variable, x_dimension, y_dimension, nowFile, band_dimension, dimension_values, valueSelectionMethod)#create the layer
                arcpy.CopyRaster_management(nowFile, os.path.join (outLoc,year+month + ".tif"), "", "", "", "NONE", "NONE", "")#save layer as geotiff
                print dimension_values, i,'date:',year+month

你可能感兴趣的:(数据处理笔记,python,arcgis,NetCDF,气象数据)