亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

重新網格化 Python xarray 坐標

重新網格化 Python xarray 坐標

胡子哥哥 2022-07-12 15:53:02
您可以通過迭代字典中的每個項目來做到這一點,但是在大型數據集中它可能效率低下。def get_key(data, query):    for key, value in data.items():        if query in value[0][1]:            return key    return 'Not Found'get_key(dictonary, word)然后,即使您的查找未能找到匹配項,您也可以調用您的函數并返回結果。# Note i changed the name of the dictionary to dicton, as dict shouldn't be used as a variable nameprint(get_key(dicton, 'three'))print(get_key(dicton, 'seven'))print(get_key(dicton, 'four'))#a#Not Found#b我有一些 0.2 度和 1 度分辨率的虛擬數據。我想對 foo 進行二次采樣,使其與 foo1 的比例相同。有什么簡單的方法可以以某種方式平均和重新排列我的經緯度坐標嗎?import pandas as pdimport xarray as xrimport matplotlib.pyplot as plt#Set at 0.2 degree grids ishfreq=20lats=240lons=1020time=pd.date_range('2000-01',periods=freq,freq='Y')data=np.random.rand(freq,lats,lons)lat=np.linspace(-19.5,19.5,lats)lon=np.linspace(120,290,lons)foo = xr.DataArray(data, coords=[time, lat,lon], dims=['time', 'lat','lon'])foo.sel(time='2005',method='nearest').plot()plt.show()#Set at 1 degree gridsfreq1=20lats1=40 #Factor of 6 differencelons1=170time1=pd.date_range('2000-01',periods=freq1,freq='Y')data1=np.random.rand(freq1,lats1,lons1)lat1=np.linspace(-19.5,19.5,lats1)lon1=np.linspace(120,290,lons1)foo1 = xr.DataArray(data1, coords=[time1, lat1,lon1], dims=['time', 'lat','lon'])foo1.sel(time='2005',method='nearest').plot()plt.show()
查看完整描述

2 回答

?
慕妹3242003

TA貢獻1824條經驗 獲得超6個贊

Xarray 可以線性插值緯度和經度,就好像它們是笛卡爾坐標一樣(如上面的示例),但這與適當的地理重新網格化不同。為此,您可能想查看xesmf。



查看完整回答
反對 回復 2022-07-12
?
慕工程0101907

TA貢獻1887條經驗 獲得超5個贊

我決定最簡單的方法是使用 foo1 網格進行解釋。


因此:


foo2=foo.interp(lat=lat1).interp(lon=lon1)

foo2.sel(time='2005',method='nearest').plot()

應生成準確的子采樣網格圖。


查看完整回答
反對 回復 2022-07-12
  • 2 回答
  • 0 關注
  • 249 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號