日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

利用python提取SWAT模型output.rch中固定sub编号的逐月径流到Excel

發(fā)布時間:2023/12/10 python 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 利用python提取SWAT模型output.rch中固定sub编号的逐月径流到Excel 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

利用python提取SWAT模型output.rch中固定sub編號的逐月徑流到Excel

程序作用:SWAT模型輸出output.rch文件中,按照指定的sub的每個月的徑流到Excel。
只用修改if name == ‘main’: 中指出的部分即可。
具體代碼如下:

# -*- coding: gbk -*- import numpy as np import os import sys import xlwt import xlrd#程序作用:輸出output.rch文件中指定的sub的每個月的徑流到Exceldef read(file,hru,star_year,end_year,excel_outpath):#創(chuàng)建EXCELw = xlwt.Workbook(encoding = 'UTF-8')sheet= w.add_sheet("sheet")# sheet.write(0, 0, "LULC")sheet.write(0, 1, "HRU")sheet.write(0, 2, "GIS")# sheet.write(0, 3, "SUB")sheet.write(0, 3, "month")sheet.write(0, 4, "FLOW_INcms")sheet.write(0, 5, "FLOW_OUTcms")hang=0#遍歷文件for i in file:f=open(i)txt=f.readlines()print (len(txt))# print txt[0:10]print("Executing",i)for year in range(star_year, end_year+1):for j in range(0,12): #指定月份:生長季的月份data = txt[hru_sum*((year-star_year)*13+j)+hru+8] #8;頭文件hang = hang + 1# sheet.write(hang, 0, data[0:4])sheet.write(hang, 1, data[5:11]) #hrusheet.write(hang, 2, data[11:20]) #gis# sheet.write(hang, 3, data[20:25]) #mondate=(txt[hru_sum*((year-star_year)*13+j)+hru+8][20:26]) #monthwhile len(date.strip())<2:date="0"+date.strip()sheet.write(hang, 3, str(year)+str(date).strip()) #year+monthsheet.write(hang, 4, float(data[38:50])) #FLOW_incmssheet.write(hang, 5, float(data[50:62])) # FLOW_OUTcmsw.save(excel_outpath) #用戶修改輸出路徑和文件名def scearch(inp,type):filepath1 = [] # 存儲路徑+數(shù)據列表for dirpath1, dirname1, dirfile1 in os.walk(inp):for file in dirfile1:if file.endswith(type):filepath1.append(os.path.join(dirpath1, file)) # 空列表添加路徑數(shù)據print("數(shù)據列表是:",filepath1)return filepath1def main(inp,hru,star_year,end_year,excel_outpath,type):filepath=scearch(inp,type)print("TXT查詢完畢,開始讀取")read(filepath,hru,star_year,end_year,excel_outpath)print("TXT寫入EXCEL完畢,程序結束")if __name__ == '__main__':# 用戶修改開始inp=U"F:\畢業(yè)論文數(shù)據\ISIMIP3b\SWAT-ISIMIP3B-sim\\ukesm-SSP5" #用戶修改.rch文件路徑outp=U"F:\畢業(yè)論文數(shù)據\ISIMIP3b\SWAT-ISIMIP3B-sim\\ukesm-SSP5" #用戶修改輸出文件路徑#在此改變子流域的編號hru=285 #徑流對應的子流域編號star_year=2017 #必須是模擬開始的年份end_year=2100 #實際模擬結束年份-需要提取截止的年份hru_sum=425 #總共流域數(shù)# 用戶修改部分結束type=".rch"# row=1# row=13 #月excel_outpath=os.path.join(outp,'output.rch_hru_'+str(hru)+'_'+str(star_year)+'_'+str(end_year)+'.xls')main(inp,hru,star_year,end_year,excel_outpath,type)

總結

以上是生活随笔為你收集整理的利用python提取SWAT模型output.rch中固定sub编号的逐月径流到Excel的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。