NCL/Python--替換nc文件指定格點(diǎn)的數(shù)值

需要對指定格點(diǎn)排放源的數(shù)值進(jìn)行更改,寫了ncl和python兩個(gè)腳本

圖為關(guān)閉湖南湖北排放源前后對比

code:

需要經(jīng)緯度格點(diǎn)數(shù)的txt文件del_d01.txt,del_d02.txt

NCL:

row = numAsciiRow("./del_d01.txt")

col = numAsciiCol("./del_d01.txt")

del_d01 = asciiread("./del_d01.txt",(/row,col/),"float")

printVarSummary(del_d01)

year=2019

a?= addfile("./nothb_"+year+"/wrfchemi_12z_d01", "w")

my_e_iso = a->E_ISO

do idel =0,row-1 ;緯度的格點(diǎn)數(shù)范圍

??ilon = toint(del_d01(idel,0)-1)

??ilat = toint(del_d01(idel,1)-1)

?my_e_iso(:,:,ilat,ilon)=0

end do

a->E_ISO = my_e_iso

Python:

import os

import numpy as np

import Ngl,Nio

# emission year

yyyy_emi = 2015

#-- read the ascii data

f_grid = open("./del_d01.txt",'r')

data?= f_grid.readlines()?????????#-- data: type list

nrows?= len(data)

#-- assign lists to append elements

lat0 = []

lon0 = []

for i in data:

line = i.strip()

# print(line)

cols = line.split()

lon0.append(cols[0])

lat0.append(cols[1])

#-- convert string to float

lat?= np.array(lat0).astype(int)

lon?= np.array(lon0).astype(int)

######################

#--?nc data file name

fname?= "./nothb_"+str(yyyy_emi)+"/wrfchemi_00z_d01"

#-- open file

f = Nio.open_file(fname, "w")

#-- read emission arrays

my_e_iso?= f.variables["E_ISO"]

#-- convert data change thb to 0

for i in list(range(nrows)):

ilat=lat[i]

ilon=lon[i]

my_e_iso[:,:,ilat,ilon]??=0?

#-- assign values --> write data to file

f.variables["E_ISO"].assign_value(my_e_iso)

#-- close output stream (not necessary)

f.close()

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容