簡體   English   中英

如何在 Python 中過濾具有特定條件的 netCDF 變量?

[英]How can I filter netCDF variables with specific conditions in Python?

我正在讀取 netCDF 文件,並希望根據過濾條件 (vwc < 5) 保留來自其他變量的數據,其中 vwc 是一個變量。

我的錯誤包括 AttributeError: NetCDF: Attribute not found 和 AttributeError: 'numpy.ndarray' object has no attribute 'where' 因為我嘗試使用 where function 但我可能使用了不正確的語法。

# read in netCDF file
f = nc4.Dataset(fn[0], 'r')

# read in group from file
sm_am = f.groups['Retrieval_Data_AM']

# extract variables
vwc = np.asarray(sm_am.variables['water_content'][:,:])
any_variable = np.asarray(sm_am.variables['generic_variables'][:,:])

然后我只想在 vwc<5 時提取其他變量。

這適用於過濾掉我的數據。

x = vwc > 5.0 # Boolean condition
new_var = old_var.copy() # copying old data as new variable
new_var[x] = np.nan # replace elements that meet the condition with NaN

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM