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

Bug with grdtrack and -Ejustification and -C?? #8194

Closed
Esteban82 opened this issue Dec 15, 2023 · 7 comments · Fixed by #8211
Closed

Bug with grdtrack and -Ejustification and -C?? #8194

Esteban82 opened this issue Dec 15, 2023 · 7 comments · Fixed by #8211
Labels
bug Something isn't working

Comments

@Esteban82
Copy link
Member

I strangely got some NaN with the third command where I only revert the sense of the main profile (-E)

gmt grdmath -R0/4/1/2 -I1 X = grid.nc
gmt grdtrack -ECT/CB -Ggrid.nc -C4/1/1
gmt grdtrack -ECB/CT -Ggrid.nc -C4/1/1

Output:

> Cross profile number -L"0-0" at 2/2 az=090.0
0       2       -2      90      0
1       2       -1      90      1
2       2       0       90      2
3       2       1       90      3
4       2       2       90      4
> Cross profile number -L"0-1" at 2/1 az=090.0
0       1       -2      90      0
1       1       -1      90      1
2       1       0       90      2
3       1       1       90      3
4       1       2       90      4
grdtrack [WARNING]: Some points along your profiles were outside the grid domain(s).
> Cross profile number -L"0-0" at 2/1 az=090.0
4       1       -2      270     4
3       1       -1      270     3
2       1       0       270     2
1       1       1       270     NaN
0       1       2       270     NaN
> Cross profile number -L"0-1" at 2/2 az=090.0
4       2       -2      270     NaN
3       2       -1      270     3
2       2       0       270     2
1       2       1       270     1
0       2       2       270     0
grdtrack [WARNING]: Some input points were outside the grid domain(s).
@Esteban82 Esteban82 added the bug Something isn't working label Dec 15, 2023
@PaulWessel
Copy link
Member

This might be a simpler example of what @seisman pointed out (those towers near TL BL corners for grids subjected to blending. Darn, can you remind moe of that issue, @seisman ?

@joa-quim
Copy link
Member

@PaulWessel
Copy link
Member

Yes. I will try to debug @Esteban82 example - it is annoying but I spent a lot of time on the grid version already...

@PaulWessel
Copy link
Member

This is what I have learned. grdtrack -E creates the profiles, then the cross track machinery computes the angle of the cross profiles to be 180. Then we can sincosd (angle, &s, &c) and get cos = -1 (good) and sin = -1.2246467991473532E-16 (oops). Then, coordinates are computed and instead of getting y = 1 we get 0.99999999999999988 and then it is determined by BCR that the point is outside the grid and we get the default NaN answer.

I think for some reason sincosd fails since it actually calls sincos (angle*D2R) and hence roundoff is likely. So where do we intercept? Make the macro check for angle being exact multiple of 90 and set those returns manually? This is in many places... Suggestions - gotta take a break.

@joa-quim
Copy link
Member

joa-quim commented Dec 17, 2023 via email

@joa-quim
Copy link
Member

joa-quim commented Dec 17, 2023 via email

@PaulWessel
Copy link
Member

Lamely, this fixes the issue

angle = 90.0 - az_cross - deviation;	/* The direction */
sincosd (angle, &sa, &ca);	/* Trig on the direction */
i_angle = rint (angle);
if (i_angle == 0 || i_angle == 360) sa = 0.0, ca = 1.0;
else if (i_angle == 90) sa = 1.0, ca = 0.0;
else if (i_angle == 180 || i_angle == -180) sa = 0.0, ca = -1.0;
else if (i_angle == 270 || i_angle == -90) sa = -1.0, ca = 0.0;

PaulWessel added a commit that referenced this issue Dec 17, 2023
WHile sincos/sincosd are used in places where speed matters map projections) we also use it in places where time is not relevant but accuracy is, such as the silliness of #8194. This PR introduces local function sincosdegree in gmt_support that makes sure if we are within 10^-4 degrees of a multiple of 90 that we return sin and cosine exactly 0 or ±1.  Closes #8194.
joa-quim pushed a commit that referenced this issue Dec 18, 2023
WHile sincos/sincosd are used in places where speed matters map projections) we also use it in places where time is not relevant but accuracy is, such as the silliness of #8194. This PR introduces local function sincosdegree in gmt_support that makes sure if we are within 10^-4 degrees of a multiple of 90 that we return sin and cosine exactly 0 or ±1.  Closes #8194.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants