Feature #441

grdpaste should paste grids with non-matching scale/offset

Added by Florian almost 4 years ago. Updated almost 4 years ago.

Status:FeedbackStart date:2013-11-13
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:-
Target version:Candidate for next minor release
Platform:

Description

grdpaste does not paste grids with non-matching scale/offset. However these are common since we have an auto-scale/offset feature with, e.g., -Gfoo.nc=ns/a.

History

#1 Updated by Paul almost 4 years ago

  • Status changed from New to Feedback

Agreed. What scheme should be used to select output scale/offset? Just return to 1/0 unless user supplied it? I am curious why we had this limitation since once the grid is read the scale/offset has been applied and all is well. And only one header is used on output so not sure I see what the problem was...

#2 Updated by Florian almost 4 years ago

Agreed. What scheme should be used to select output scale/offset? Just return to 1/0 unless user supplied it?

Yes.

I am curious why we had this limitation since once the grid is read the scale/offset has been applied and all is well.

I am too. I disabled the test but afterwards the pasted grids had bogus values.

#3 Updated by Paul almost 4 years ago

Would you be able to add a test that fails? Then we have something to work towards.

#4 Updated by Florian almost 4 years ago

Sure:

--- src/grdpaste.c    (revision 12532)
+++ src/grdpaste.c    (working copy)
@@ -189,7 +189,7 @@
         error++;
     if ((A->header->z_scale_factor != B->header->z_scale_factor) || (A->header->z_add_offset != B->header->z_add_offset)) {
         GMT_Report (API, GMT_MSG_NORMAL, "Scale/offset not compatible!\n");
-        Return (EXIT_FAILURE);
+        //Return (EXIT_FAILURE);
     }

     if (! (fabs (A->header->inc[GMT_X] - B->header->inc[GMT_X]) < 1.0e-6 && fabs (A->header->inc[GMT_Y] - B->header->inc[GMT_Y]) < 1.0e-6)) {

gmt grdmath -R10/20/0/10 -r -I0.1 100 250 RAND = b.nc=nb/a
gmt grdmath -R0/10/0/10 -r -I0.1 0 100 RAND = a.nc=nb/a
gmt grdpaste a.nc b.nc -Gc.nc=nb/a
gmt grdinfo [abc].nc
a.nc: Title: Produced by grdmath
a.nc: Command: grdmath -R0/10/0/10 -r -I0.1 0 100 RAND = a.nc=nb/a
a.nc: Remark:
a.nc: Pixel node registration used [Cartesian grid]
a.nc: Grid file format: nb = GMT netCDF format (8-bit integer), COARDS, CF-1.5
a.nc: x_min: 0 x_max: 10 x_inc: 0.1 name: x nx: 100
a.nc: y_min: 0 y_max: 10 y_inc: 0.1 name: y ny: 100
a.nc: z_min: 0.000551762059331 z_max: 99.9994482379 name: z
a.nc: scale_factor: 0.393696442818 add_offset: 50 packed z-range: [-127,127]
a.nc: format: classic
b.nc: Title: Produced by grdmath
b.nc: Command: grdmath -R10/20/0/10 -r -I0.1 100 250 RAND = b.nc=nb/a
b.nc: Remark:
b.nc: Pixel node registration used [Cartesian grid]
b.nc: Grid file format: nb = GMT netCDF format (8-bit integer), COARDS, CF-1.5
b.nc: x_min: 10 x_max: 20 x_inc: 0.1 name: x nx: 100
b.nc: y_min: 0 y_max: 10 y_inc: 0.1 name: y ny: 100
b.nc: z_min: 100.002418518 z_max: 249.997581482 name: z
b.nc: scale_factor: 0.590532137653 add_offset: 175 packed z-range: [-127,127]
b.nc: format: classic
c.nc: Title: Produced by grdmath
c.nc: Command: grdpaste a.nc b.nc -Gc.nc=nb/a
c.nc: Remark:
c.nc: Pixel node registration used [Cartesian grid]
c.nc: Grid file format: nb = GMT netCDF format (8-bit integer), COARDS, CF-1.5
c.nc: x_min: 0 x_max: 20 x_inc: 0.1 name: x nx: 200
c.nc: y_min: 0 y_max: 10 y_inc: 0.1 name: y ny: 100
c.nc: z_min: -126.509419118 z_max: 249.997589111 name: z
c.nc: scale_factor: 1.488169993 add_offset: 61 packed z-range: [-126,127]
c.nc: format: netCDF-4 chunk_size: 200,100 shuffle: on deflation_level: 3

#5 Updated by Florian almost 4 years ago

Or do you mean a real test script in the sources?

#6 Updated by Paul almost 4 years ago

No this is OK for now. Should this be considered a feature in 5.2 or a bugfix in 5.1?

#7 Updated by Florian almost 4 years ago

New feature in 5.2, I suppose.

Also available in: Atom PDF