地形/海底地形情報(基本的にx [十進数の経度]、y [十進数の緯度]を含むグリッド)とPython 3で作業しようとしています。 z [メートル])。netCDFグリッドファイル:2D値を使用して1D配列から情報を抽出
グリッドファイルの拡張子は.ncなので、netCDFファイルです。通常はGeneric Mapping Toolsのようなマッピングツールで使用し、netCDFファイルの仕組みを気にする必要はありませんが、Pythonスクリプトで特定の情報を抽出する必要があります。現在のところ、これはデータセットを特定の経度/緯度の範囲に限定するだけです。
しかし、今私は特定のxとyの値についてz情報に到達する方法が少し失われています。ここで私は、これまでのデータについて知っていることだ
import netCDF4
#----------------------
# Load netCDF file
#----------------------
bathymetry_file = 'C:/Users/te279/Matlab/data/gebco_08.nc'
fh = netCDF4.Dataset(bathymetry_file, mode='r')
#----------------------
# Getting information about the file
#----------------------
print(fh.file_format)
NETCDF3_CLASSIC
print(fh)
root group (NETCDF3_CLASSIC data model, file format NETCDF3): title: GEBCO_08 Grid source: 20100927 dimensions(sizes): side(2), xysize(933120000) variables(dimensions): float64 x_range(side), float64 y_range(side), int16 z_range(side), float64 spacing(side), int32 dimension(side), int16 z(xysize) groups:
print(fh.dimensions.keys())
odict_keys(['side', 'xysize'])
print(fh.dimensions['side'])
: name = 'side', size = 2
print(fh.dimensions['xysize'])
: name = 'xysize', size = 933120000
#----------------------
# Variables
#----------------------
print(fh.variables.keys()) # returns all available variable keys
odict_keys(['x_range', 'y_range', 'z_range', 'spacing', 'dimension', 'z'])
xrange = fh.variables['x_range'][:]
print(xrange)
[-180. 180.] # contains the values -180 to 180 for the longitude of the whole world
yrange = fh.variables['y_range'][:]
print(yrange)
[-90. 90.] # contains the values -90 to 90 for the latitude of the whole world
zrange = fh.variables['z_range'][:]
[-10977 8685] # contains the depths/topography range for the world
spacing = fh.variables['spacing'][:]
この情報に基づいて3210[ 0.00833333 0.00833333] # spacing in both x and y. Equals the dimension, if multiplied with x and y range
dimension = fh.variables['dimension'][:]
[43200 21600] # corresponding to the shape of z if it was the 2D array I would've hoped for (it's currently an 1D array of 9333120000 - which is 43200*21600)
z = fh.variables['z'][:] # currently an 1D array of the depth/topography/z information I want
fh.close
私はまだ特定のX/Y(経度/緯度)値のZアクセスする方法がわかりません。私は基本的に私はzの1D配列を経度/緯度の値に対応する2D配列に変換する必要があると思います。私はちょうどそれをする手がかりがありませんでした。私は人々が1Dを2D配列に変換しようとしたいくつかの記事を見ましたが、私は彼らがどのような世界のどこで始まり、どのように進行するかを知る手段がありません。
私は知っている3歳のsimilar postしかし、私はどのように私の問題のアナログ "フラットアレイのインデックス"を見つけるかわからない - または正確にどのように動作するか。誰かが助けることができますか?
残念ながら緯度どちらもロングは、二つ以上で、直接のみの変数を読み取ることができます値はzだったので、1Dの配列 – Tobitobitobi
私は確かにそれを試みました。そして、私は "ValueError:スライス式が変数の次元の数を超えています"というエラーが出ました。 – Tobitobitobi