python - 为什么 nc 文件中的 lat 和 lon 维度会因组装两个 nc 文件而改变?
问题描述
我有两个.nc
文件,它们具有相似的纬度和经度尺寸、CRS 和其他所有内容。
Dimensions: (lat: 62, lon: 94)
Coordinates:
* lat (lat) float64 58.46 58.79 59.12 59.44 ... 77.45 77.78 78.11 78.44
* lon (lon) float64 -150.0 -149.4 -148.9 -148.3 ... -98.56 -98.0 -97.43
然后当我将这两个文件添加在一起时,整个维度都会发生变化:
dem = xr.open_dataset(path + 'DEM.nc')
dc = xr.open_dataset(path + 'DC.nc')
X = 1 / (1 + np.exp(-(-2.2432e+01 + (dem.Band1 * 1.97521e-06) + (dc.Band1 * 5.97414e-04))))
print(X)
<xarray.DataArray 'Band1' (lat: 11, lon: 94)>
* lat (lat) float64 65.01 65.34 65.67 65.99 ... 73.52 74.18 77.78 78.44
* lon (lon) float64 -150.0 -149.4 -148.9 -148.3 ... -98.56 -98.0 -97.43
怎么了?为什么这个添加会改变整个维度?
注意。该dc
文件有一些没有数据的网格单元nan
。这会影响它吗?
编辑:给出答案后,我仍然认为这不仅仅是因为缺少数据,请单独查看数据集的图像并将数据集组合起来:
解决方案
你已经给自己答案了
the dc file has some grid cells without data nan. Does that influence it?
是的,因为 xarray 也在寻找坐标,而不仅仅是进行矢量化操作。查看文档以了解更多信息。
解决方法很简单:让 numpy 为您完成这项工作!
X = 1 / (1 + np.exp(-(-2.2432e+01 + (dem.Band1.values * 1.97521e-06) + (dc.Band1.values * 5.97414e-04))))
data_array = xarray.DataArray(X, coords={'lat': dem.lat, 'lon': dem.lon}, dims=['lat', 'lon'])
dem['combined'] = data_array
推荐阅读
- c# - 如何验证其 CA 证书和中间证书仅在线可用的证书链
- asp.net-mvc - 是否可以将我在 Internet 上的网站连接到我的本地 SQL Server 数据库?
- python - Tensorflow 2.0 beta 没有属性 keras
- sms - 如何为 Twilio SMS 设置时区?
- javascript - 在 reducer 中更新数组项
- typescript - 我们应该如何在 Typescript 中使用猫鼬?
- powershell - Start-AzureStorageBlobCopy :远程服务器返回错误:(409)冲突。HTTP 状态码:当前有一个挂起的复制操作
- laravel - 如何在 yajra 数据表中设置编辑路径
- javascript - 按 ID 将博文插入集合
- go - 不能在赋值中使用 (type string) 作为类型 func()