我有2个不同的netCDF文件:一个"网格",一个"未编辑" (见下面的例子)。
我正在尝试两种方法来执行网格网格,如下所示:
dataset = Dataset(file_name)
data = dataset.variables['air_temp'][:]
lats = dataset.variables['lat'][:]
lons = dataset.variables['lon'][:]
print lats.shape
print lons.shape
lons, lats = np.meshgrid(lons,lats)
print lons.shape
print lats.shape
网格化:lats
:1-D数组(720,)和lons
:1-D数组(1440,)
并在meshgrid
二维数组(720,1440)之后返回。
lats:
[-89.875 -89.625 -89.375 -89.125 -88.875 -88.625 -88.375 -88.125 -87.875
-87.625 -87.375 -87.125 -86.875 -86.625 -86.375 -86.125 -85.875 -85.625
...
85.625 85.875 86.125 86.375 86.625 86.875 87.125 87.375 87.625
87.875 88.125 88.375 88.625 88.875 89.125 89.375 89.625 89.875]
lons:
[ 1.25000000e-01 3.75000000e-01 6.25000000e-01 ..., 3.59375000e+02
3.59625000e+02 3.59875000e+02]
未校正:lats
:2-D阵列(1080,2048)和lons
(1080,2048)我希望在meshgrid
2-D阵列(1080,2048)之后但它返回MemoryError
lats:
[[-34.18847656 -34.20410156 -34.21972656 ..., -40.50195312 -40.50488281
-40.5078125 ]
[-34.19726562 -34.21289062 -34.22851562 ..., -40.51171875 -40.51367188
-40.51660156]
[-34.20605469 -34.22167969 -34.23828125 ..., -40.52246094 -40.52441406
-40.52734375]
...,
[-43.77441406 -43.79394531 -43.81347656 ..., -50.73339844 -50.73339844
-50.734375 ]
[-43.78320312 -43.80175781 -43.82226562 ..., -50.7421875 -50.74316406
-50.74316406]
[-43.79199219 -43.81054688 -43.83105469 ..., -50.75195312 -50.75195312
-50.75292969]]
lons:
[[ 4.93164062 4.9765625 5.02148438 ..., 36.7734375 36.82421875
36.875 ]
[ 4.92675781 4.97167969 5.015625 ..., 36.77246094 36.82324219
36.87402344]
[ 4.921875 4.96679688 5.01171875 ..., 36.77148438 36.82226562
36.87304688]
...,
[ -1.18457031 -1.13574219 -1.08691406 ..., 36.3359375 36.3984375
36.45996094]
[ -1.19238281 -1.14257812 -1.09375 ..., 36.3359375 36.3984375
36.45996094]
[ -1.19921875 -1.14941406 -1.09960938 ..., 36.3359375 36.3984375
36.45996094]]
np.meshgrid
在网格状态下完美运行:几毫秒内几乎没有使用RAM,另一方面,网格状态完全崩溃了我的Mac。我必须通过Activity Monitor杀死python进程。我以为是因为我的电脑只有4GB的内存,但是我和一个在Windows上运行的朋友试了16GB并且问题一样。
我只看到一篇文章谈论使用较小的数据块,但这个netCDF文件只有2Mb!它如何生成16Gb的RAM?
"未编号"的lats
和lons
数组的形状一个原因是数据来自卫星测量,然后像素不完美"正方形"。