Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing a grid's scale_factor #3268

Open
PaulWessel opened this issue May 6, 2020 · 6 comments
Open

Changing a grid's scale_factor #3268

PaulWessel opened this issue May 6, 2020 · 6 comments
Labels
longterm Long standing issues that need to be resolved

Comments

@PaulWessel
Copy link
Member

Description of the problem

Not sure if this is a bug or not but it is certainly not straightforward to do or figure out, and I should have an inside track on this...

I have a netCDF short int grid with values that need to be scaled by 0.01 to be used. OK, so I can plot it as grid.nc+s0.01. But this data will never be used as is, always with that scale, so better to insert the 0.01 scale into the grid. I have tried various schemes with grdedit and grdconvert but no success. Making this issue mostly so it is not forgotten and once a solution (bug fix, improved documentation) happens then we can delete it.

One can experiment with this grid whose z values should be 0-100 on output, but that requires +s0.01 when used.

gmt grdmath -R0/10/0/10 -I1 X Y MUL 100 MUL = t.nc=ns

@seisman
Copy link
Member

seisman commented May 6, 2020

Does gmt grdedit -D+s0.01 input.grd work?

@seisman
Copy link
Member

seisman commented May 6, 2020

Just find a potential bug with grdedit. Follow the steps below to reproduce it:

  1. Download a cache data for testing
$ gmt which -Gl @AFR.nc
  1. Check grid information
$ gmt grdinfo AFR.nc
AFR.nc: Title: Produced by grdcut
AFR.nc: Command: grdcut etopo2m.nc -R0/10/0/10 -GAFR.nc
AFR.nc: Remark:
AFR.nc: Pixel node registration used [Geographic grid]
AFR.nc: Grid file format: nf = GMT netCDF format (32-bit float), CF-1.7
AFR.nc: x_min: 0 x_max: 10 x_inc: 0.0333333333333 (2 min) name: longitude n_columns: 300
AFR.nc: y_min: 3.46944695195e-18 y_max: 10 y_inc: 0.0333333333333 (2 min) name: latitude n_rows: 300
AFR.nc: z_min: -5023 z_max: 3614 name: z
AFR.nc: scale_factor: 1 add_offset: 0
AFR.nc: format: netCDF-4 chunk_size: 150,150 shuffle: on deflation_level: 3
  1. Run grdedit and save it to a new grid
$ gmt grdedit AFR.nc -D+s10 -GAFR10.nc
  1. Run grdedit but overwrite the input grid
$ gmt grdedit AFR.nc -D+s10
  1. Check grid information of AFR.nc and AFR10.nc
$ gmt grdinfo AFR.nc
AFR.nc: Title: Produced by grdcut
AFR.nc: Command: grdcut etopo2m.nc -R0/10/0/10 -GAFR.nc
AFR.nc: Remark:
AFR.nc: Pixel node registration used [Geographic grid]
AFR.nc: Grid file format: nf = GMT netCDF format (32-bit float), CF-1.7
AFR.nc: x_min: 0 x_max: 10 x_inc: 0.0333333333333 (2 min) name: longitude n_columns: 300
AFR.nc: y_min: 6.93889390391e-18 y_max: 10 y_inc: 0.0333333333333 (2 min) name: latitude n_rows: 300
AFR.nc: z_min: -502300 z_max: 361400 name: z
AFR.nc: scale_factor: 10 add_offset: 0 packed z-range: [-50230,36140]
AFR.nc: format: netCDF-4 chunk_size: 150,150 shuffle: on deflation_level: 3

scale_factor is 10 in the grid, but the z_min and z_max is 100 times of the original data. Why?

$ gmt grdinfo AFR10.nc
AFR10.nc: Title: Produced by grdcut
AFR10.nc: Command: grdcut etopo2m.nc -R0/10/0/10 -GAFR.nc
AFR10.nc: Remark:
AFR10.nc: Pixel node registration used [Geographic grid]
AFR10.nc: Grid file format: nf = GMT netCDF format (32-bit float), CF-1.7
AFR10.nc: x_min: 0 x_max: 10 x_inc: 0.0333333333333 (2 min) name: longitude n_columns: 300
AFR10.nc: y_min: 6.93889390391e-18 y_max: 10 y_inc: 0.0333333333333 (2 min) name: latitude n_rows: 300
AFR10.nc: z_min: -5023 z_max: 3614 name: z
AFR10.nc: scale_factor: 1 add_offset: 0
AFR10.nc: format: netCDF-4 chunk_size: 150,150 shuffle: on deflation_level: 3

scale_factor is still 1.

@PaulWessel
Copy link
Member Author

In my case the grdedit -D+s0.01 works exactly as I want, but if I want to write that to a new grid via -Gnew.grd the new grid is not correct.
Your AFR case behaves the same way. Yes, the xin/max is affected since you are scaling the data by 10. In my case I want to scale by 1/100 and the zmax changes accordingly, which is what I want. So in your case, when you use your grid you recover correct depths since your data is now stored in decimeters...

@seisman
Copy link
Member

seisman commented May 6, 2020

So in your case, when you use your grid you recover correct depths since your data is now stored in decimeters...

AFR.nc: z_min: -502300 z_max: 361400 name: z
AFR.nc: scale_factor: 10 add_offset: 0 packed z-range: [-50230,36140]

If I understand it correctly, the z_min and z_max should be -50230 and 36140, not -502300 and 361400. If I use grd2xyz to output the data, I should see the z value in the range -5023 to 3614, right?

@PaulWessel
Copy link
Member Author

Yes, there is clearly some problems here:

gmt which -Gl @AFR.nc
echo 5 5 | gmt grdtrack -GAFR.nc -nn
5	5	-79
gmt grdedit AFR.nc -D+s10
echo 5 5 | gmt grdtrack -GAFR.nc -nn
5	5	-790

We getting the factor of 10 twice. However, my other case seems to work:

gmt grdmath -R0/10/0/10 -I1 X Y MUL 100 MUL = t.nc=ns
echo 10 10 | gmt grdtrack -Gt.nc -nn
10	10	10000
gmt grdedit t.nc -D+s0.01
echo 10 10 | gmt grdtrack -Gt.nc -nn
10	10	100

@stale
Copy link

stale bot commented Aug 5, 2020

This issue has been automatically marked as stale because it has not had activity in the last 90 days. It will be closed if no further activity occurs within 7 days. Thank you for your contributions.

@stale stale bot added the stale This will not be worked on label Aug 5, 2020
@seisman seisman added the longterm Long standing issues that need to be resolved label Aug 5, 2020
@stale stale bot removed the stale This will not be worked on label Aug 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
longterm Long standing issues that need to be resolved
Projects
None yet
Development

No branches or pull requests

2 participants