![](/img/trans.png)
[英]Python calculate surface area bounded by the parallels lat1 and lat2 and the meridians lon1 and lon2
[英]How to get mean of a variable through time within a given boundarybox (lon1,lon2,lat1,lat2)?
我使用下面的代碼繪制了EDIR變量隨時間變化的面積平均值。 但是,我想知道如何像邊界框一樣設置最小和最大緯度/經度,以便在設置緯度/經度框中繪制EDIR變量的面積平均值。 謝謝!
ld0 = xr.open_mfdataset('path/*LDASOUT*', condcat_dim='time') t2=ld0.EDIR.mean(dim='x','y')) t2.plot.line('-',color='black',linewidth=3,label='control_run') plt.legend() plt.show
如果lat
和lon
是數據集中的坐標變量,則可以使用sel
方法。
da = ld0['EDIR'].sel(lon=slice(min_lon, max_lon), lat=slice(min_lat, max_lat))
可以在xarray文檔中找到使用xarray基於坐標的選擇的更多示例: http ://xarray.pydata.org/en/stable/indexing.html
從這里的文檔中,您似乎可以使用t2.where(t2.x < lon2, drop=True)
選擇坐標邊界。 我在用手機打電話,所以現在無法測試,但類似:
temp = ld0.where( ( (t2.x > lon1) & (t2.x < lon2) & (t2.y > lat1) & (t2.y < lat2) ), drop=True)
應該給你合適的口罩。 然后,您可以計算並繪制此數組的空間平均值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.