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

How to avoid precision loss? #409

Closed
amarux opened this issue Aug 1, 2020 · 3 comments
Closed

How to avoid precision loss? #409

amarux opened this issue Aug 1, 2020 · 3 comments

Comments

@amarux
Copy link

amarux commented Aug 1, 2020

Dear all,

I am new using GMT in Julia and I am asking for help about the precision loss if grdmath module is used for a given operation.

If for example, I used 8 bytes float array in Julia and make a GMT grid with mat2grid, and then I computed the spatial derivatives using DDX and DDY, I can introduce rounding errors.

I am based on the grdmath documentation (6.0.0) that indicated: Regardless of the precision of the input data, GMT programs that create grid files will internally hold the grids in 4-byte floating point arrays ... Data with higher precision (i.e., double precision values) will lose that precision once GMT operates on the grid or writes out new grids. To limit loss of precision when processing data you should always consider normalizing the data prior to processing.

So, I am wondering if you could help with an example to understand how to avoid loss of precision.

Thank you!

@joa-quim
Copy link
Member

joa-quim commented Aug 1, 2020 via email

@joa-quim
Copy link
Member

joa-quim commented Aug 1, 2020

Anyway, the normalization should be obtained by, if X is your grid, with x_min & x_max as extrema,

Xnorm = (X - x_min) ./ (x_max - x_min)

@amarux
Copy link
Author

amarux commented Aug 2, 2020

Thank you very much!

@amarux amarux closed this as completed Aug 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants