我正在尝试使用xarray在数组中进行计算,该数组由纬度和经度(501x572)和温度数据组成。当条件满足每个数据点的温度<230时,我想对整个数组进行计算。
import xarray as xr
import matplotlib as mpl
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
fname='home/atmos/data/GRIDSAT-B1.2013.07.01.*.v02r01.nc'
ds=xr.open_mfdataset(fname)
imr = ds.sel(lat=slice(0,35),lon=slice(60,100)) #subset the data
imrtemp = imr['irwin_cdr']
temp = imrbt.mean('time') # daily mean of temp data (of 3 hourly data)
a = 6.96 # a constant
if (temp < 230).all():
pi = a*(230-temp)
print(pi)
但是我稍后在代码中遇到错误
NameError:未定义名称'pi'
问题仍然存在。 如何解决这个问题?有些人可以提出任何解决方案,我对此表示感谢。
问题是:
if (temp < 230).all(): # all() doesn't not calculate if any value doesn't satisfy the condition
if (temp < 230).any(): # any() worked, since some data doesn't satisfies but some other data does.