风云四(FY-4)气象卫星 tif文件解析成txt
生活随笔
收集整理的這篇文章主要介紹了
风云四(FY-4)气象卫星 tif文件解析成txt
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
風(fēng)云四氣象衛(wèi)星 tif文件中14個(gè)通道數(shù)據(jù),分別解析成對(duì)應(yīng)的txt格式
def process(filename,fileshortname):# 導(dǎo)包 gdalfrom osgeo import gdal#導(dǎo)入數(shù)據(jù)data = gdal.Open(filename)# 顯示通道數(shù)量num_bands = data.RasterCountprint(num_bands)# 將多通道的圖片數(shù)據(jù)變成numpy當(dāng)中多維數(shù)組的形式:tmp_img = data.ReadAsArray()# img = tmp_img.transpose(2, 0, 1)# tmp_img的shape是(通道數(shù), 長(zhǎng), 寬)和傳統(tǒng)圖像多維數(shù)組的shape (長(zhǎng), 寬, 通道數(shù))是不一樣的, 因此需要進(jìn)行一次transpose變成傳統(tǒng)的圖像形狀格式:img = tmp_img.transpose(1, 2, 0)# 取出這其中某個(gè)通道的數(shù)據(jù):for i in range(14):img_rgb = img[:,:,i]# 當(dāng)然, 還需要注意的是數(shù)組中數(shù)據(jù)的dtype, 一般而言讀出來(lái)是np.float, 直接使用可能會(huì)出現(xiàn)一些異常的結(jié)果. 我們需要將其轉(zhuǎn)化為np.uint8, 作為傳統(tǒng)圖像數(shù)組當(dāng)中的dtype:import numpy as npimg_rgb = np.array(img_rgb, dtype = np.uint8)outpath=fileshortname+'-'+str(i+1)+'.txt'print(outpath)# 將數(shù)組保存為文本格式np.savetxt(outpath,img_rgb,fmt="%d",delimiter=",") import os input_path = input("請(qǐng)輸入源文件目錄")+'\\' output_path = input("請(qǐng)輸入導(dǎo)出的文件夾") # 通過(guò)listdir去項(xiàng)目下的文件夾和文件 for i in os.listdir(input_path):# 使用isdir去排除項(xiàng)目文件夾中的文件,只需要遍歷文件夾file_name=i.split('.')fileshortname=file_name[0]filename=input_path+iout_path_name=output_path+'\\'+fileshortnameprocess(filename=filename,fileshortname=out_path_name)總結(jié)
以上是生活随笔為你收集整理的风云四(FY-4)气象卫星 tif文件解析成txt的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 盘点淘宝、腾讯、百度内部使用的JavaS
- 下一篇: wallpaper怎么导入视频_vwal