# Subtracting average values from grid file with grdmath

**URL:** <https://forum.generic-mapping-tools.org/t/subtracting-average-values-from-grid-file-with-grdmath/428>\
**Category:** Q&A\
**Created:** [April 29, 2020, 3:06am UTC](https://forum.generic-mapping-tools.org/t/subtracting-average-values-from-grid-file-with-grdmath/428 "2020-04-29T03:06:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mcoo951](https://avatars.discourse-cdn.com/v4/letter/m/9e8a1a/32.png) [@mcoo951](https://forum.generic-mapping-tools.org/u/mcoo951)\
**Post date:** [April 29, 2020, 3:06am UTC](https://forum.generic-mapping-tools.org/t/subtracting-average-values-from-grid-file-with-grdmath/428/1 "2020-04-29T03:06:39Z")

</div>

Hi all,

I am new to GMT and I have been using GMTSAR to create deformation maps. But extracting deformation from an area depends on having a stable reference point to estimate relative velocity in respect to that reference point.

I have a file called unwrap\_ll.grd, which is in lat/lon coordinates. I am trying to select a stable reference area in this file and then subtract the average z value of that stable area from the original unwrap\_ll.grd file. To do this I did the following steps:

1. Used grdcut to cut out the stable reference area:  
gmt grdcut unwrap\_ll.grd -Gref\_area\_ll.grd -R174.7825/174.7875/-36.82771/-36.824265 -V

2. Used grdinfo to extract the average z value of the stable reference area:  
gmt grdinfo ref\_area\_ll.grd -L2  
(average z value is -0.64)

3. Used grdmath to subtract the average value of the ref\_area\_ll.grd file from the original unwrapped\_ll.grd file:  
gmt grdmath -0.64 unwrap\_ll.grd SUB = unwrap\_ref\_ll.grd

I am not sure if I have done the final step correctly. When I compare the unwrap\_ll.grd and unwrap\_ref\_ll.grd the values seem to be the opposite. Like the unwrap\_ref\_ll.grd has been inverted. Can anyone see where I am going wrong? I have attached images of the unwrap\_ll and unwrap\_ref\_ll as an example.

I hope this made sense!

Thanks,

Matt

 ![unwrap_ll](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/1X/9ee747ced5f5920e220567a66450bca6ff650a71.jpeg) ![unwrap_ref_ll](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/1X/d53ab97939ac7f860db1f6a8fd21e4cea04e3c33.jpeg)

---

<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:** [April 29, 2020, 3:19am UTC](https://forum.generic-mapping-tools.org/t/subtracting-average-values-from-grid-file-with-grdmath/428/2 "2020-04-29T03:19:56Z")

</div>

Hi Matt, you are subtracting your grid from -0.64 instead of the other way around (switch their order in the grdmath call).

---

<div class="post-metadata">

**Author:** ![mcoo951](https://avatars.discourse-cdn.com/v4/letter/m/9e8a1a/32.png) [@mcoo951](https://forum.generic-mapping-tools.org/u/mcoo951)\
**Post date:** [April 29, 2020, 3:56am UTC](https://forum.generic-mapping-tools.org/t/subtracting-average-values-from-grid-file-with-grdmath/428/3 "2020-04-29T03:56:20Z")

</div>

Ahh yes I see. Thank you so much!
