科学网

 找回密码
  注册

tag 标签: Rewriting

相关帖子

版块 作者 回复/查看 最后发表

没有相关内容

相关日志

利用Python读写GIMMS NDVI3g数据
热度 6 wenzhaofei 2015-2-2 13:28
NDVI3g 是新一代 GIMMS 时序 NDVI 数据,时间范围从 1981.07-2012.12 ,数据频率为 15 天。目前,可 在线下载 数据集所有数据及其说明文档,一共有约 13.5G 。 针对该数据不能直接用 ENVI 或 ArcGIS 读取和需手动配准的问题,网上已介绍很多方法,包括 利用 ENVI 读取和配准 、 ArcGIS 读取和配准 以及利用 MATLAB 读写 该数据的方法 。前两个方法都试了,个人觉得后一种方法靠谱些,主要是配准的时候出现的一些小问题后一种解决得好一些。我没用过 matlab ,虽然很它强大,但据说处理影像速度慢。因此,我很多时候习惯用 python+gdal 来处理影像。下面是我参考 Prof.Nan 的 matlab 代码写的利用 python+gdal+numpy 读写 GIMMS 的代码 ( 已测 ) 。简单修改一下这段代码,就可以做批量处理了。 # -*- coding: utf-8 -*- Created on Sat Jan 31 21:52:23 2015 @author: Zhaofei Wen Note: The output NDVI value have been multiplied by 1000 # importing modules from osgeo import gdal import numpy as np # setting pj parameters transform = (-180.0000000, 0.083333, 0.0,90.00000, 0.0, -0.083333) proj = 'GEOGCS ],\ AUTHORITY ],PRIMEM ,\ UNIT ,AUTHORITY ]' # read ndvi3g data and reshape it to 2-D array inds = np.fromfile('F:/test/ geo81sep15b ',dtype='i2') # ‘geo81sep15b’ is the filename of ndvi3g inds = inds.reshape(4320, 2160) #transpose (flip and rotate) ndvi3g = np.transpose(inds) # retrieve ndvi and flag data ndvi = np.floor(ndvi3g/10) # ndvi*1000 flag = ndvi3g-np.floor(ndvi3g/10)*10+1 #output data fn_ndvi = 'F:/test/ndvi.tif' fn_flag = 'F:/test/flag.tif' driver = gdal.GetDriverByName('GTIFF') # other formats can also be specified here outndvi = driver.Create(fn_ndvi, 4320,2160, 1, gdal.GDT_Int16) outflag = driver.Create(fn_flag, 4320,2160, 1, gdal.GDT_Byte) # 1 = flagvalue= 7 bandndvi = outndvi.GetRasterBand(1) bandndvi.WriteArray(ndvi, 0, 0) bandndvi.FlushCache() bandndvi.SetNoDataValue(-9999) bandndvi.GetStatistics(0, 1) bandflag = outflag.GetRasterBand(1) bandflag.WriteArray(flag, 0, 0) bandflag.FlushCache() bandflag.SetNoDataValue(-9999) bandflag.GetStatistics(0, 1) # georeferencing the output images outndvi.SetGeoTransform(transform) outndvi.SetProjection(proj) outflag.SetGeoTransform(transform) outflag.SetProjection(proj) # release memory outndvi = None outflag = None
个人分类: 科研笔记|10229 次阅读|8 个评论

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-6-16 13:41

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部