#author("2025-01-08T13:37:52+09:00","default:Miyashita","Miyashita")
#author("2025-01-08T13:38:27+09:00","default:Miyashita","Miyashita")
* Cartesian grid から Geographic grid への変換 [#h9011778]
**状況 [#sdfd2ac7]
外部 function で生成した .grd や .nc などのファイルはデフォルトで Cartesian grid になっている場合があり,それを Geographic grid (緯度経度) 座標に変換したい.~
緯度経度なのに Cartesian のままだと projection 方法によっては思うように図が描けなかったり面倒になったりする.~
Cartesian か Geographic かは,grdinfo の表示から確認できる.
#codeprettify{{
$ gmt grdinfo hogehoge.grd
...
hogehoge_cut_geo.grd: Remark: 
hogehoge.grd: Remark: 
hogehoge.grd: Gridline node registration used [Cartesian grid]
hogehoge_cut_geo.grd: Grid file format: cf = GMT netCDF format (32-bit float, deprecated)
hogehoge.grd: Grid file format: cf = GMT netCDF format (32-bit float, deprecated)
...
}}
~

**解決方法 [#kdfd3422]
共通オプションの -f を使う.~
公式doc -> [[Common Options - GMT>https://docs.generic-mapping-tools.org/latest/std-opts.html]]~

Geographic grid への変換だけがしたい場合は grdedit を使う.
#codeprettify{{
$ gmt grdedit hogehoge.nc -fg -V
grdedit [INFORMATION]: netCDF grid hogehoge.nc has no default CPT.
grdedit [INFORMATION]: Editing parameters for grid hogehoge.nc:
grdedit [INFORMATION]: Updating grid header for file hogehoge.nc
grdedit [INFORMATION]: File hogehoge.nc updated.
}}
~
データに何らかの変換を施す場合でも,-f オプションに g を指定することで変換できる.~
grdconvert でも grdcut でも grdsample でも使い方は同じで,-fog をつけるだけ.~
下記の hogehoge.nc を grdcut で切り取ってさらに緯度経度にしたい場合は下記の通り.
#codeprettify{{
gmt grdcut hogehoge.grd -R130/142/30/36 -Ghogehoge_cut_geo.grd -fog -V
}}
オプションの -fog の o は output ファイルの指定を指す.~
生成されたファイルを grdinfo で確認すると,
#codeprettify{{
$ gmt grdinfo hogehoge_cut_geo.grd
...
hogehoge_cut_geo.grd: Remark: 
hogehoge_cut_geo.grd: Gridline node registration used [Geographic grid]
hogehoge_cut_geo.grd: Grid file format: cf = GMT netCDF format (32-bit float, deprecated)
...
}}
のように Geographic grid に変わっているはず.

Front page   Edit Diff Attach Copy Rename Reload   New List of pages Search Recent changes   Help   RSS of recent changes