我有一个技术问题,我试图解决整个一周。我从沿特定轨道的地理网格(纬度/经度)上的空气质量测量值的观测中创建了一个 netcdf 文件。现在我想从更大的网格(来自具有大面积平均值的计算机模型的数据)计算这些值的偏离(或异常)。
我的两个 netcdf 文件结构如下:
观察结果(仪器测量):
方面:
lat: 1321, lon: 1321
数据变量:
Longitude (lon) float64 8.413 8.411 8.409 ... 4.904 4.905
Latitude (lat) float64 47.4 47.4 47.41 ... 52.37 52.37
obs_data (lat, lon) float64 ...
模型数据:
方面:
latitude: 140, level: 1, longitude: 215, time: 24
坐标:
longitude (longitude) float32 357.55 357.65 ... 18.85 18.95
latitude (latitude) float32 55.95 55.85 55.75 ... 42.15 42.05
level (level) float32 0.0
time (time) timedelta64[ns] 00:00:00 01:00:00 ... 23:00:00
数据变量:
model_data (time, level, latitude, longitude) float32 ...
我尝试了各种不同的方法,但每次遇到某种似乎没有解决方案的错误时,我最终不得不尝试不同的方法。我得到的最接近的是遵循这个伟大的教程,但在这里我也碰壁了。当我尝试为这两个数据集找到最近的纬度和经度时,通过
lat_idx = np.abs(model_lat - obs_lat).argmin() #subtract train lat from model lat
lon_idx = np.abs(model_lon - obs_lon).argmin() #subtract train lon from model lon
我收到以下错误
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-437-9396b00ba22f> in <module>
18
19 # Find the nearest latitude and longitude for the train data
---> 20 lat_idx = np.abs(model_lat - obs_lat).argmin()
21 lon_idx = np.abs(model_lon - obs_lon).argmin()
22
~/opt/anaconda3/lib/python3.7/site-packages/numpy/ma/core.py in __sub__(self, other)
4115 if self._delegate_binop(other):
4116 return NotImplemented
-> 4117 return subtract(self, other)
4118
4119 def __rsub__(self, other):
~/opt/anaconda3/lib/python3.7/site-packages/numpy/ma/core.py in __call__(self, a, b, *args, **kwargs)
1024 with np.errstate():
1025 np.seterr(divide='ignore', invalid='ignore')
-> 1026 result = self.f(da, db, *args, **kwargs)
1027 # Get the mask for the result
1028 (ma, mb) = (getmask(a), getmask(b))
ValueError: operands could not be broadcast together with shapes (140,) (1321,)
有没有办法简单地计算:
anomaly = model_data[lat, lon] - obs_data[lat, lon]
?
我最新的希望是xarray,但我真的很纠结他们的文档,而且我花了几天时间寻找前进的方向。
你们有没有人找到解决这个问题的方法?任何提示都非常感谢。
编辑:
根据 V. Ayrat 的要求:
In: type(model_data)
Out: xarray.core.dataset.Dataset
obs_data是同一类型。
如果两个obs_data值落入同一个model_data单元格,obs_data则应从同一个model_data单元格中减去 。