import xarray as xr import matplotlib.pyplot as plt if name=='main': ds=xr.open_dataset(r'D:\pythonsx\zl\sst.mnmean.nc') sst=ds['sst'] sstsel=sst.loc[:,5:-5,190:240] #5°S-5°N,170°W-120°W enso=sstsel.mean(dim=['lat', 'lon'])#区域平均 ensom=enso.mean('time') #print(ensom) ensoa=enso-ensom #print(ensoa)修改这段代码,筛选出大于0.5的值
时间: 2023-06-14 10:05:05 浏览: 110
import xarray as xr
import matplotlib.pyplot as plt
if __name__ == '__main__':
ds = xr.open_dataset(r'D:\pythonsx\zl\sst.mnmean.nc')
sst = ds['sst']
sstsel = sst.loc[:, 5:-5, 190:240] # 5°S-5°N,170°W-120°W
enso = sstsel.mean(dim=['lat', 'lon']) # 区域平均
ensom = enso.mean('time')
ensoa = enso - ensom
# 选取大于0.5的值
ensoa_selected = ensoa.where(ensoa > 0.5, drop=True)
print(ensoa_selected)
相关问题
import xarray as xr import matplotlib.pyplot as plt if __name__=='__main__': ds=xr.open_dataset(r'D:\pythonsx\zl\sst.mnmean.nc') sst=ds['sst'] sstsel=sst.loc[:,5:-5,190:240] #5°S-5°N,170°W-120°W enso=sstsel.mean(dim=['lat', 'lon'])#区域平均 ensom=enso.mean('time') #print(ensom) ensoa=enso-ensom #print(ensoa)修改这段代码,筛选出大于0.5的年份
import xarray as xr
import numpy as np
import matplotlib.pyplot as plt
if __name__=='__main__':
ds=xr.open_dataset(r'D:\pythonsx\zl\sst.mnmean.nc')
sst=ds['sst']
sstsel=sst.loc[:,5:-5,190:240] #5°S-5°N,170°W-120°W
enso=sstsel.mean(dim=['lat', 'lon'])#区域平均
ensom=enso.mean('time')
ensoa=enso-ensom
# Modified code to filter out years with values greater than 0.5
enso_yearly = ensoa.resample(time="Y").mean()
enso_yearly = enso_yearly.dropna(dim="time")
enso_yearly = enso_yearly.where(enso_yearly > 0.5, drop=True)
print(enso_yearly)
import xarray as xr import matplotlib.pyplot as plt from netCDF4 import Dataset import cartopy.crs as ccrs#投影方式 import cartopy.feature as cfeature import cartopy.io.shapereader as shpreader import numpy as np import pandas as pd from matplotlib.font_manager import fontManager da=pd.read_csv(r'E:\python11\STATION_58237.txt',sep='\s+') print(da) tem=da['TEM'] #print(tem.shape) rhu=da['RHU'] tem_ave=[] for i in range(0,24): tem_data=tem[i:147:24] print(tem_data) tem_ave[i]=np.mean(tem_data) print(tem_ave) plt.plot(tem_ave)帮我改一下
import xarray as xr
import matplotlib.pyplot as plt
from netCDF4 import Dataset
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import cartopy.io.shapereader as shpreader
import numpy as np
import pandas as pd
from matplotlib.font_manager import fontManager
da = pd.read_csv(r'E:\python11\STATION_58237.txt', sep='\s+')
print(da)
tem = da['TEM']
rhu = da['RHU']
tem_ave = []
for i in range(0, 24):
tem_data = tem[i:147:24]
print(tem_data)
tem_ave.append(np.mean(tem_data)) # 将结果添加到列表中
print(tem_ave)
plt.plot(tem_ave)
plt.show() # 显示图形
阅读全文