Skip to content

Address a series of issues related to vectors#6161

Merged
PaulWessel merged 1 commit intomasterfrom
fixup-vec-heads-scaling
Dec 28, 2021
Merged

Address a series of issues related to vectors#6161
PaulWessel merged 1 commit intomasterfrom
fixup-vec-heads-scaling

Conversation

@PaulWessel
Copy link
Member

There have been several bugs and omissions identified in GMT vectors lately (e.g., #6108) and we have had some partial fixes. This PR reconciles several problems and completes incomplete enhancements:

  1. The new minimum vector shrink in +nnorm/limit was documented to default to 0.25, but in fact it was never set so it was still zero. This is now fixed.
  2. The check for geovectors to skip heads if they exceed the vector length was flawed so some small vectors ended up with bad heads (e.g., Better presentation of wind field #6108). Now the test is fixed and heads exceeding size are not plotted.
  3. Cartesian vectors never bothered to check and hence always plotted the heads even though exceeding the vector lengths. This has now been addressed.
  4. Finally, there are uses of vectors where the vector length should not be considered when plotting heads (e.g., adding a head to an existing line). Many of these are internal (e.g., adding a vector head at the end of the line via plot -W or adding one at the end of a math x-axis for --MAP_FRAME_TYPE = graph), but placing flow vectors on a graph may also fall prey to the limitation. Using +n without any argument now means we always plot the requested heads regardless of vector length.

These corrections meant that 8-10 PostScript plots needed to be updated. For some I chose to use +n to avoid having to change the plot, while others would benefit from a refresh (e.g., properly giving scaling in km for geographic vectors in sample.sh).

Closes #6158 and #6108; the latter is also the inspiration for new test met_uv.sh

There have been several issues identified in GMT vectors lately (e.g., #6108) and we have had some partial fixes.  This PR reconciles several problems and completes started enhancements:

The new minimum vector shrink in +mnorm/limit was stated to be 0.25 but in fact was never set so it was still zero.  This is now fixed.
The check for geovector to skip heads if exceeding the vector length was flawed so some small vectors ended up with bad heads (e.g., #6108).  Now the test is fixed and heads exceeding size is not plotted.
Cartesian vectors never bothered to check and hence always plotted the heads even though exceeding vector length.  This has now been addressed.
FInally, there are uses of vectors where the vector length should not be considered when plotting heads. Many of these are internal (e.g., adding a vector head at the end of the line or at the end of a math x-axis), but placing flow vectors on a graph may also fall prey to the limitation.  Using +n without any argument means always plot the head regardless of vector length.

These corrections meant that 8-10 PostScript plots needed to be updated. For some I chose to use +n to avoid having to change the  plot, while others would benefit from a refresh (e.g., properly giving scaling in km for geographic bectors in sample.sh).

Closes #6158 and #6108.
@PaulWessel PaulWessel added bug Something isn't working documentation Improve documentation enhancement Improving an existing feature labels Dec 28, 2021
@PaulWessel PaulWessel added this to the 6.4.0 milestone Dec 28, 2021
@PaulWessel PaulWessel self-assigned this Dec 28, 2021
@PaulWessel PaulWessel merged commit c923ecc into master Dec 28, 2021
@PaulWessel PaulWessel deleted the fixup-vec-heads-scaling branch December 28, 2021 02:34
@maxrjones
Copy link
Member

The new met_uv test is failing on linux and windows due to rounding error when the vector length is close to the vector head size (see diff below). @PaulWessel, would you be able to modify the test to avoid this?

met_uv

@PaulWessel
Copy link
Member Author

Interesting. The decision to draw head or not is just

if (dr[0] > h_length_limit)

so there is nothing I can do code-wise to beat any roundoff. As for the test, I guess we would have to hunt for a slightly different scale or initial head size that gives the same plot?

Another take: I am about to improve the documentation on the geovector and Cartesian vector as the docs are not clear enough. Basically, the geovector means you specify a length in map units (km, for example) and then we plot that length on the map. This means the actual plot length on the paper depends on the map projection. A 50 km-long vector at Equator is half that of one at 60N. This is not what people who have vectors in other units (plate velocity, wind speed, etc) want, since it is biasing what the user sees. For those applications they need to plot Cartesian vectors, which do have the same length regardless of location and projection. To make matters worse, we have some tests that mixes these cases up, such as met_uv.sh which you can see is using geovector due to the -Si20k setting instead of, say, a -Si5c argument (random number, not sure what it needs to be to be visible). But for some perspective projections (-JG for instance), a geovector is suitable for those applications since the length is affected by the perspective. Documentation with figures on the grdvector page is needed for this.

So I think I will fix met_uv.sh to use Cartesian vectors first, and then we can see if that causes different images for different OS. OK?

@joa-quim
Copy link
Member

I don't understand the roundoff story. There are rules for rounding and all compilers should produce the same result. Unless some are using fastmath compiler options.

@PaulWessel
Copy link
Member Author

Hm, yes. Perhaps the cloud are doing things lie -O3 or -O? for some other setting that affects accuracy at the benefit of speed? Do we know the compilation flags for GMT as they are used in the cloud, @meghanrjones ?

@maxrjones
Copy link
Member

I got the failure locally on linux using the same compilation flags as on macOS. If it's worthwhile, I could run through the debugger to check exactly what is different between the two.

@joa-quim
Copy link
Member

If the examples can be reduced to a very simple case where the results are different in MacOS vs Others you can print the dr[0] & h_length_limit of the if (dr[0] > h_length_limit) and at least have an idea of the different values involved.

@maxrjones
Copy link
Member

dr[1] and h_length_limit are the same on macOS and linux, but for this particular vector it is only drawn on macOS:

grdvector [INFORMATION]: dr[1] = 0.23587; h_length_limit = 0.23587 

@PaulWessel
Copy link
Member Author

Probably needs %.16lg to see the difference in values.

@maxrjones
Copy link
Member

maxrjones commented Dec 29, 2021

Sorry, here is the comparison (I'll edit the post to add the linux case):

macOS linux
dr[1] = 0.2358698342821208; h_length_limit = 0.2358698342821207 dr[1] = 0.2358698342821207; h_length_limit = 0.2358698342821207

@joa-quim
Copy link
Member

So, it's the last bit that differs. This case can be solved by setting >= instead of = but there will be others.

@maxrjones maxrjones mentioned this pull request Dec 29, 2021
4 tasks
@PaulWessel
Copy link
Member Author

Would be OK to use >= instead of > in general here, since that means the length equals or is larger than the limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working documentation Improve documentation enhancement Improving an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Vectors with heads exceeding vector length

3 participants