我正在尝试使用Python NetCDF4解析我的NetCDF文件。
以下是我打印数据的方式:
import netCDF4
data = netCDF4.Dataset('MYFILE.nc')
variable = data.variables['my_var']
print variable[:]
这是输出:
[[[[ 0.14626905 0.15073127 0.15702666 ..., 2.16087079 1.85385954
1.6330229 ]
[ 0.15199603 0.1524792 0.16023833 ..., 2.08785558 1.7945435
1.53411531]
[ 0.15741037 0.15567663 0.15938567 ..., 1.98954475 1.74069858
1.46132731]
...,
[ 9.2788887 9.50980091 9.68098545 ..., 31.48118973 32.40645981
29.94233894]
[ 8.79353142 8.8413229 8.9353838 ..., 32.1477623 31.02648544
27.81228828]
[ 7.49527025 7.49693298 7.49859571 ..., 31.26473045 29.31586647
28.24591827]]]
[[[ 0.14930199 0.15448895 0.16149491 ..., 1.79938114 1.54701066
1.35455298]
[ 0.15029675 0.15359367 0.16234756 ..., 1.68896282 1.43696177
1.24431944]
[ 0.15308209 0.15446053 0.16128175 ..., 1.56143463 1.31972218
1.13472533]
...,
[ 9.06274796 9.3060236 9.5291338 ..., 31.62846184 31.67973518
29.1291008 ]
[ 8.62317753 8.68691349 8.79741669 ..., 31.8617897 30.73691559
27.1242466 ]
[ 7.4323082 7.4356761 7.439044 ..., 30.26707649 28.77895927
27.37334824]]]
[[[ 0.14486383 0.15053397 0.1580373 ..., 1.58220649 1.37771237
1.21789706]
[ 0.14881445 0.1508324 0.1601405 ..., 1.4683634 1.26993716
1.11644578]
[ 0.1533193 0.15873364 0.1618458 ..., 1.34273946 1.15582407
1.01318967]
...,
[ 8.90223217 8.90035629 8.73252583 ..., 32.53005219 31.91935349
28.7775898 ]
[ 8.13422012 7.95513535 7.98284674 ..., 31.12573433 30.1478157
27.24931145]
[ 6.96614504 6.94814014 6.93012047 ..., 29.86423683 28.73914909
27.61774254]]]
...,
[[[ 0.24114145 0.23916614 0.25755498 ..., 2.01377511 1.97436833
1.97307515]
[ 0.24045934 0.24496417 0.26440462 ..., 2.50367999 2.33576465
2.21460295]
[ 0.27951077 0.29309633 0.29956228 ..., 2.36718488 2.32561803
2.05150485]
...,
[ 3.00640321 3.27329731 3.54564834 ..., 18.4679985 26.38918495
24.96532822]
[ 2.99567413 3.15291715 3.30652237 ..., 22.98442078 31.35761261
33.92588425]
[ 2.77546263 2.85286927 2.91519809 ..., 41.55749512 44.26428223
43.38713074]]]
[[[ 0.2288377 0.22707555 0.23796105 ..., 2.27481699 2.18916821
2.13653135]
[ 0.23349886 0.23983689 0.25768572 ..., 2.68985939 2.51502323
2.37905359]
[ 0.2801531 0.29236022 0.2961545 ..., 2.30413413 2.25314546
2.01824021]
...,
[ 2.53119516 2.6628871 2.92897105 ..., 19.72961235 29.04187202
25.78588104]
[ 2.50243235 2.62220144 2.73698258 ..., 25.07536697 35.14706802
37.07580948]
[ 2.30301142 2.31611371 2.31827378 ..., 45.08309937 46.73181152
46.26189041]]]
[[[ 0.20954911 0.21473609 0.22343312 ..., 2.62998462 2.43386054
2.28494501]
[ 0.22019306 0.22859167 0.24688104 ..., 2.32324314 2.16715121
2.03508973]
[ 0.26845312 0.28306186 0.28679934 ..., 2.11179996 2.00885653
1.89133275]
...,
[ 2.6847105 2.87929988 3.09413958 ..., 19.82722282 28.60776711
26.12558556]
[ 2.6023159 2.83243227 3.02930951 ..., 28.37161255 36.661129
41.15200043]
[ 2.45840263 2.65044808 2.71863174 ..., 45.63036728 46.6840744
47.9279213 ]]]]
正如您所看到的,我只获得了部分数据。有些数据被...
取代,我不知道为什么。也许linux终端无法打印所有数据或我使用NetCDF4库而我的文件是经典的Netcdf?
以下是我所有数据的screenshot。您可以看到水平和垂直滚动条非常小。所以我有很多数据。
如何在python输出中获取所有数据(如我的屏幕截图)?
答案 0 :(得分:1)
numpy.array
当数组太大时,用...
替换值。
将变量打印为列表:print variable[:].tolist()