# Convert EMAG2 GeoTIFF grid to GMT-compatible grid

**URL:** <https://forum.generic-mapping-tools.org/t/convert-emag2-geotiff-grid-to-gmt-compatible-grid/2248>\
**Category:** Q&A\
**Created:** [November 1, 2021, 4:18pm UTC](https://forum.generic-mapping-tools.org/t/convert-emag2-geotiff-grid-to-gmt-compatible-grid/2248 "2021-11-01T16:18:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrewg](https://avatars.discourse-cdn.com/v4/letter/a/ecd19e/32.png) [@andrewg](https://forum.generic-mapping-tools.org/u/andrewg)\
**Post date:** [November 1, 2021, 4:18pm UTC](https://forum.generic-mapping-tools.org/t/convert-emag2-geotiff-grid-to-gmt-compatible-grid/2248/1 "2021-11-01T16:18:53Z")

</div>

A relatively new version of the global 2-minute Earth Magnetic Anomaly Grid (EMAG2) grid is available in GeoTIFF grid format at this NGDC URL: [https://www.ngdc.noaa.gov/geomag/data/EMAG2/EMAG2\_V3\_20170530/EMAG2\_V3\_20170530\_UpCont.tif](https://www.ngdc.noaa.gov/geomag/data/EMAG2/EMAG2_V3_20170530/EMAG2_V3_20170530_UpCont.tif)

If I run gdal\_translate to convert that GeoTIFF grid file to a GMT-compatible grid format, everything looks good although I end up with an old “cf” deprecated GMT format:  
% gdal\_translate -b 1 -of GMT EMAG2\_V3\_20170530\_UpCont.tif EMAG2\_V3\_20170530\_UpCont.grd

If I then run grdconvert to convert that global “cf” grid to a more modern COARDS-compliant GMT grid and also use -R to chop out a smaller area, I get a very strange minimum Z value:  
% grdconvert EMAG2\_V3\_20170530\_Sealevel.grd -GEMAG2\_V3\_20170530\_Sealevel\_nf.grd=nf -R0/20/40/60 -V

I do not understand why the Z range will blow up with grdconvert (it also blows up if I simply use grdcut to extract a smaller area from the “cf” grid).

Is there a way to go straight from the GeoTIFF grid to a COARDS-compliant GMT grid without messing up the Z values?

Thanks for any pointers,  
Andrew

---

<div class="post-metadata">

**Author:** ![Joaquim](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/joaquim/32/16_2.png) [@Joaquim](https://forum.generic-mapping-tools.org/u/Joaquim)\
**Post date:** [November 1, 2021, 6:51pm UTC](https://forum.generic-mapping-tools.org/t/convert-emag2-geotiff-grid-to-gmt-compatible-grid/2248/2 "2021-11-01T18:51:09Z")

</div>

> [@andrewg](#):
>
> convert that GeoTIFF grid file to a GMT-compatible grid format

`GeoTIFFs` **are** GMT-compatible formats de _per se_. But if want to convert them to netCDF use `grdconvert` directly on the GeoTIIF. If the Z range problem persists that may indicate something wrong in GeoTIFF metadata.

---

<div class="post-metadata">

**Author:** ![pwessel](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/pwessel/32/30_2.png) [@pwessel](https://forum.generic-mapping-tools.org/u/pwessel)\
**Post date:** [November 1, 2021, 9:34pm UTC](https://forum.generic-mapping-tools.org/t/convert-emag2-geotiff-grid-to-gmt-compatible-grid/2248/3 "2021-11-01T21:34:41Z")

</div>

Whoever made that TIFF decided this was a good idea:

```
Upper Left ( -0.0166667, 89.9833333) 
Lower Left ( -0.0166667, -89.9833333) 
Upper Right ( 359.983, 89.983) 
Lower Right ( 359.983, -89.983) 
Center ( 179.9833333, 0.0000000) 
Band 1 Block=128x128 Type=Float32, ColorInterp=Gray
  NoData Value=-3.4028234663852886e+38

```

So kind of a pixel grid in latitude and a weird shift pixel grid or gridline with missing repeat in longitude.

---

<div class="post-metadata">

**Author:** ![andrewg](https://avatars.discourse-cdn.com/v4/letter/a/ecd19e/32.png) [@andrewg](https://forum.generic-mapping-tools.org/u/andrewg)\
**Post date:** [November 2, 2021, 2:21am UTC](https://forum.generic-mapping-tools.org/t/convert-emag2-geotiff-grid-to-gmt-compatible-grid/2248/4 "2021-11-02T02:21:39Z")

</div>

Thanks to Joaquim and Paul for responding. With that new knowledge, it was easy to use grdconvert to directly convert the EMAG2 GeoTIFF grids to GMT-compatible COARDS-compliant netCDF grids (commands included below). And, from there, I was able to add the data with no problem to the GeoMapApp menus. Thank you!

```
% grdconvert EMAG2_V3_20170530_Sealevel.tif -GEMAG2_V3_20170530_Sealevel.grd -V
% grdconvert EMAG2_V3_20170530_UpCont.tif -GEMAG2_V3_20170530_UpCont.grd -V
```
