# Grdedit -A seems not to work

**URL:** <https://forum.generic-mapping-tools.org/t/grdedit-a-seems-not-to-work/636>\
**Category:** Q&A\
**Created:** [July 8, 2020, 5:39am UTC](https://forum.generic-mapping-tools.org/t/grdedit-a-seems-not-to-work/636 "2020-07-08T05:39:32Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![EJFielding](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/ejfielding/32/82_2.png) [@EJFielding](https://forum.generic-mapping-tools.org/u/EJFielding)\
**Post date:** [July 8, 2020, 5:39am UTC](https://forum.generic-mapping-tools.org/t/grdedit-a-seems-not-to-work/636/1 "2020-07-08T05:39:32Z")

</div>

I have a GMT grid that I created with grdlandmask to match a grid that I created with gdal\_translate. When I try to use grdmath to multiply the mask and the data, grdmath complains:

> grdmath [ERROR]: (x\_max-x\_min) must equal (NX + eps) \* x\_inc), where NX is an integer and |eps| \<= 0.0001.  
> grdmath (gmtlib\_read\_grd\_info): Use grdedit -A on your grid file to make region and increments compatible [landmask.grd]

I then tried to run “gmt grdedit -A landmask.grd -Glandmask-A.grd” on my landmask.grd, but the output still gives the same error about the increment mismatch.

> gmt grdinfo landmask-A.grd  
> grdinfo [ERROR]: (x\_max-x\_min) must equal (NX + eps) \* x\_inc), where NX is an integer and |eps| \<= 0.0001.  
> grdinfo (gmtlib\_read\_grd\_info): Use grdedit -A on your grid file to make region and increments compatible [landmask-A.grd]  
> landmask-A.grd: Title: z  
> landmask-A.grd: Command: grdlandmask -Glandmask.grd -R/Users/fielding/Google\_Drive\_JPL/Mexico-Drive/Oaxaca-EQ-2020/S1AB/A107/ARIA\_proc/results/S1\_A107\_20200625\_20200619\_disp\_cm.grd -Df  
> landmask-A.grd: Remark: Derived from the full resolution shorelines  
> landmask-A.grd: Pixel node registration used [Geographic grid]  
> landmask-A.grd: Grid file format: nf = GMT netCDF format (32-bit float), CF-1.7  
> landmask-A.grd: x\_min: -96.5451065365 x\_max: -93.9876553945 x\_inc: 0.00083331741351 (3 sec) name: longitude n\_columns: 3069  
> landmask-A.grd: y\_min: 15.046045981 y\_max: 16.7804535652 y\_inc: 0.000833449103383 name: latitude n\_rows: 2081  
> landmask-A.grd: z\_min: 0 z\_max: 1 name: z  
> landmask-A.grd: scale\_factor: 1 add\_offset: 0  
> landmask-A.grd: format: netCDF-4 chunk\_size: 134,131 shuffle: on deflation\_level: 3

Am I missing something about how to use “grdedit -A”?  
I am using GMT 6.0.0 installed with MacPorts.

---

<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:** [July 8, 2020, 7:54pm UTC](https://forum.generic-mapping-tools.org/t/grdedit-a-seems-not-to-work/636/2 "2020-07-08T19:54:54Z")

</div>

Hm, if you can make that large grid available then I can have a look. Does the ARIA grid really have slightly different dx/dy or is this all sloppy rounding on that end?

---

<div class="post-metadata">

**Author:** ![EJFielding](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/ejfielding/32/82_2.png) [@EJFielding](https://forum.generic-mapping-tools.org/u/EJFielding)\
**Post date:** [July 8, 2020, 8:17pm UTC](https://forum.generic-mapping-tools.org/t/grdedit-a-seems-not-to-work/636/3 "2020-07-08T20:17:44Z")

</div>

The original ARIA InSAR product is available online ([https://aria-share.jpl.nasa.gov/20200623\_Oaxaca\_Mexico\_EQ/Displacements/S1-GUNW\_COSEISMIC-A-R-107-tops-20200625\_20200619-003043-16794N\_15045N-RR-35f2-v2\_0\_3.nc](https://aria-share.jpl.nasa.gov/20200623_Oaxaca_Mexico_EQ/Displacements/S1-GUNW_COSEISMIC-A-R-107-tops-20200625_20200619-003043-16794N_15045N-RR-35f2-v2_0_3.nc)), and it should be exactly 3-arcsecond spacing. It is stored in a complicated multilayer NetCDF HDF5 format, so I use some Python tools to extract the displacement grid into a GeoTIFF, then I used `gdal_translate` to convert the GeoTIFF to a GMT-format grid. I am not sure why the dx and dy are slightly different but it seems that sloppy rounding must have happened somewhere. I was not able to read the GeoTIFF directly with GMT6.0.

---

<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:** [July 8, 2020, 8:45pm UTC](https://forum.generic-mapping-tools.org/t/grdedit-a-seems-not-to-work/636/4 "2020-07-08T20:45:12Z")

</div>

> [@EJFielding](#):
>
> It is stored in a complicated multilayer NetCDF HDF5 format, so I use some Python tools to extract

Long, but simple.

```auto
gmt grdconvert S1-GUNW_COSEISMIC-A-R-107-tops-20200625_20200619-003043-16794N_15045N-RR-35f2-v2_0_3.nc=gd?NETCDF:"S1-GUNW_COSEISMIC-A-R-107-tops-20200625_20200619-003043-16794N_15045N-RR-35f2-v2_0_3.nc:/science/grids/data/amplitude" -Gamp.grd

```

increments are exactly equal

```auto
grdinfo amp.grd
amp.grd: Title: Produced by grdconvert
amp.grd: Command: grdconvert S1-GUNW_COSEISMIC-A-R-107-tops-20200625_20200619-003043-16794N_15045N-RR-35f2-v2_0_3.nc=gd?NETCDF:S1-GUNW_COSEISMIC-A-R-107-tops-20200625_20200619-003043-16794N_15045N-RR-35f2-v2_0_3.nc:/science/grids/data/amplitude -Gamp.grd
amp.grd: Remark:
amp.grd: Gridline node registration used [Geographic grid]
amp.grd: Grid file format: nf = GMT netCDF format (32-bit float), CF-1.7
amp.grd: x_min: -96.5533333333 x_max: -93.91 x_inc: 0.000833333333333 (3 sec) name: longitude n_columns: 3173
amp.grd: y_min: 15.045 y_max: 16.795 y_inc: 0.000833333333333 (3 sec) name: latitude n_rows: 2101
amp.grd: z_min: 0 z_max: 754838.0625 name: z
amp.grd: scale_factor: 1 add_offset: 0
amp.grd: format: netCDF-4 chunk_size: 133,132 shuffle: on deflation_level: 3
GEOGCS["unknown",
    DATUM["Unknown based on WGS84 ellipsoid",
        SPHEROID["WGS 84",6378137,298.257223563,
            AUTHORITY["EPSG","7030"]]],
    PRIMEM["Greenwich",0,
        AUTHORITY["EPSG","8901"]],
    UNIT["degree",0.0174532925199433,
        AUTHORITY["EPSG","9122"]],
    AXIS["Longitude",EAST],
    AXIS["Latitude",NORTH]]

```

---

<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:** [July 8, 2020, 8:57pm UTC](https://forum.generic-mapping-tools.org/t/grdedit-a-seems-not-to-work/636/5 "2020-07-08T20:57:16Z")

</div>

Thanks @Joaquim, so the gdal\_translate route messes up node registration and resets increments etc. I think that is the root of the problems, @EJFielding. The number of nodes are very different from the two files - sure it is the same file?

---

<div class="post-metadata">

**Author:** ![EJFielding](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/ejfielding/32/82_2.png) [@EJFielding](https://forum.generic-mapping-tools.org/u/EJFielding)\
**Post date:** [July 8, 2020, 9:31pm UTC](https://forum.generic-mapping-tools.org/t/grdedit-a-seems-not-to-work/636/6 "2020-07-08T21:31:54Z")

</div>

Yes, the data came from the same original file, but obviously there was some resampling or cropping at some step. I did not try to use `grdconvert` directly on the original file. That looks like the best option for the simple layers. There are some layers that are stored at different resolutions that have to be resampled to be used, but the amplitude and unwrapped phase of the interferogram are simple layers. Thanks, @Joaquim !

---

<div class="post-metadata">

**Author:** ![EJFielding](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/ejfielding/32/82_2.png) [@EJFielding](https://forum.generic-mapping-tools.org/u/EJFielding)\
**Post date:** [July 8, 2020, 9:38pm UTC](https://forum.generic-mapping-tools.org/t/grdedit-a-seems-not-to-work/636/7 "2020-07-08T21:38:09Z")

</div>

I heard that GDAL really only knows about pixel registration for grids, so it must be resampling the data to force the pixel registration. The original ARIA interferogram product is geocoded to the SRTM DEM, which is grid registration, so I am glad to see that reading the original file directly sees that and gets the correct information.

The Python tools for reading the ARIA standard products are at:

> **[GitHub - aria-tools/ARIA-tools: Tools for exploiting ARIA standard products](https://github.com/aria-tools/ARIA-tools)**
>
> Tools for exploiting ARIA standard products

I will open an issue there to discuss the problem of the dx and dy changing.

---

<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:** [July 8, 2020, 10:06pm UTC](https://forum.generic-mapping-tools.org/t/grdedit-a-seems-not-to-work/636/8 "2020-07-08T22:06:01Z")

</div>

Yes, it’s true that for GDAL everything is pixel reg, but I’m not sure that it will resample. It’s just much simpler to to adjust the limits by half a cell width. That is exactly what we do when we ask GDAL to read a file/layer and return the data to GMT. Like the `grdconvert` example above.

---

<div class="post-metadata">

**Author:** ![EJFielding](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/ejfielding/32/82_2.png) [@EJFielding](https://forum.generic-mapping-tools.org/u/EJFielding)\
**Post date:** [July 8, 2020, 10:19pm UTC](https://forum.generic-mapping-tools.org/t/grdedit-a-seems-not-to-work/636/9 "2020-07-08T22:19:24Z")

</div>

It is probably the `ariaExtract.py` program from ARIA-tools that is resampling. Maybe you saw there are some layers in the ARIA interferogram product that are 3-D layers at coarse resolution. Those have to be resampled to match the unwrapped phase and amplitude images. I guess that means the code also resamples the full-resolution layers. Bottom line is that I think the ultimate bug is in the ARIA-tools `ariaExtract` writing out files with inconsistent limits and spacing.

It is still strange that GMT `grdedit -A` can’t adjust the spacing or region so that other GMT programs can use the grid files.

---

<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:** [July 8, 2020, 10:24pm UTC](https://forum.generic-mapping-tools.org/t/grdedit-a-seems-not-to-work/636/10 "2020-07-08T22:24:54Z")

</div>

Yes, I saw it but I’m almost sure you can do the resampling with GMT alone by giving `-Ramp.grd` (to use my example).

But regarding `grdedit -A`, I suspect you are right. A couple of months ago there was another forum thread where it apparently also failed to do the promised.

---

<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:** [July 8, 2020, 10:30pm UTC](https://forum.generic-mapping-tools.org/t/grdedit-a-seems-not-to-work/636/11 "2020-07-08T22:30:32Z")

</div>

Offer to look at your file that fails in grdedit -A still stands!

---

<div class="post-metadata">

**Author:** ![EJFielding](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/ejfielding/32/82_2.png) [@EJFielding](https://forum.generic-mapping-tools.org/u/EJFielding)\
**Post date:** [July 8, 2020, 10:56pm UTC](https://forum.generic-mapping-tools.org/t/grdedit-a-seems-not-to-work/636/12 "2020-07-08T22:56:35Z")

</div>

I have uploaded the GMT grd file that I used as the region for the `grdlandmask` command that made the `landmask.grd` file that `grdedit -A` fails to correct. It is at:  
[https://aria-share.jpl.nasa.gov/20200623\_Oaxaca\_Mexico\_EQ/Displacements/S1\_A107\_20200625\_20200619\_disp\_cm.grd](https://aria-share.jpl.nasa.gov/20200623_Oaxaca_Mexico_EQ/Displacements/S1_A107_20200625_20200619_disp_cm.grd)

Note that I will likely delete this file later as it is obviously not a correct GMT grid.

---

<div class="post-metadata">

**Author:** ![EJFielding](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/ejfielding/32/82_2.png) [@EJFielding](https://forum.generic-mapping-tools.org/u/EJFielding)\
**Post date:** [July 8, 2020, 11:11pm UTC](https://forum.generic-mapping-tools.org/t/grdedit-a-seems-not-to-work/636/13 "2020-07-08T23:11:08Z")

</div>

I am afraid that GMT can’t do the resampling of the 3D grid layers directly from the ARIA product. They require a 3D interpolation using an additional DEM, not a basic 2D interpolation. I could use the “hammer” approach of resampling the files to a correct GMT grid with `-Ramp.grd` after extracting them from the ARIA product with `ariaExtract`. The extra layers are quite smooth so extra resampling should not hurt much.

---

<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:** [July 8, 2020, 11:17pm UTC](https://forum.generic-mapping-tools.org/t/grdedit-a-seems-not-to-work/636/14 "2020-07-08T23:17:12Z")

</div>

OK, but keep an eye on [#2966](https://github.com/GenericMappingTools/gmt/pull/2966)

---

<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:** [July 8, 2020, 11:19pm UTC](https://forum.generic-mapping-tools.org/t/grdedit-a-seems-not-to-work/636/15 "2020-07-08T23:19:59Z")

</div>

I got your grid Eric so you can remote it any time.

---

<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:** [July 8, 2020, 11:32pm UTC](https://forum.generic-mapping-tools.org/t/grdedit-a-seems-not-to-work/636/16 "2020-07-08T23:32:59Z")

</div>

I can reproduce the eps messages. Interestingly, they don’t come if I run grdinfo your grid (which has hardly any netcdf metadata in it) but once GMT writes out that landmask it complains if I run grdinfo on that one, despite having exactly same -R -I -r as your start file…

---

<div class="post-metadata">

**Author:** ![EJFielding](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/ejfielding/32/82_2.png) [@EJFielding](https://forum.generic-mapping-tools.org/u/EJFielding)\
**Post date:** [July 8, 2020, 11:48pm UTC](https://forum.generic-mapping-tools.org/t/grdedit-a-seems-not-to-work/636/17 "2020-07-08T23:48:17Z")

</div>

Thanks. Good to see you folks are working on the 3D grids.

The ARIA interferogram format is a prototype for the NISAR mission interferogram products, so it would be great to eventually add direct reading of this kind of file in GMT. NISAR launch is not until 2022, so there is still plenty of time ;-).

---

<div class="post-metadata">

**Author:** ![EJFielding](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/ejfielding/32/82_2.png) [@EJFielding](https://forum.generic-mapping-tools.org/u/EJFielding)\
**Post date:** [July 9, 2020, 1:24am UTC](https://forum.generic-mapping-tools.org/t/grdedit-a-seems-not-to-work/636/18 "2020-07-09T01:24:41Z")

</div>

> [@Joaquim](#):
>
> gmt grdconvert S1-GUNW\_COSEISMIC-A-R-107-tops-20200625\_20200619-003043-16794N\_15045N-RR-35f2-v2\_0\_3.nc=gd?NETCDF:“S1-GUNW\_COSEISMIC-A-R-107-tops-20200625\_20200619-003043-16794N\_15045N-RR-35f2-v2\_0\_3.nc:/science/grids/data/amplitude” -Gamp.grd

I had to use

```auto
gmt grdconvert 'S1-GUNW_COSEISMIC-A-R-107-tops-20200625_20200619-003043-16794N_15045N-RR-35f2-v2_0_3.nc=gd?NETCDF:"S1-GUNW_COSEISMIC-A-R-107-tops-20200625_20200619-003043-16794N_15045N-RR-35f2-v2_0_3.nc":/science/grids/data/amplitude' -Gamp.grd

```

on my Mac.

---

<div class="post-metadata">

**Author:** ![EJFielding](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/ejfielding/32/82_2.png) [@EJFielding](https://forum.generic-mapping-tools.org/u/EJFielding)\
**Post date:** [July 9, 2020, 4:33am UTC](https://forum.generic-mapping-tools.org/t/grdedit-a-seems-not-to-work/636/19 "2020-07-09T04:33:58Z")

</div>

@pwessel I am glad you can reproduce the eps messages. It seems there is something going subtly wrong somewhere.

---

<div class="post-metadata">

**Author:** ![EJFielding](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/ejfielding/32/82_2.png) [@EJFielding](https://forum.generic-mapping-tools.org/u/EJFielding)\
**Post date:** [July 21, 2020, 4:50am UTC](https://forum.generic-mapping-tools.org/t/grdedit-a-seems-not-to-work/636/20 "2020-07-21T04:50:46Z")

</div>

Note that the ARIA-tools software has been revised to provide output with original 3-arcsecond spacing and consistent region values.
