Repository navigation
Closed
Labels
feature requestRequest a new feature
Description
Description of the desired feature
We still seem to have some inconsistencies when it comes to vector scaling (converting user vector magnitude to plot length) and attribute shrinking (reduce head size and stem pen width when vectors are smaller than a limit)
Scaling issues:
- Cartesian vectors plotted by plot are expected with direction and length (in plot units, say cm) in columns 3 and 4. However, if you prefer to give components dx, dy instead then these are scaled by +zscale and combined with hypot. So while I can then give dx and dy in some random user unit (say mm/yr) and use scale to convert that to reasonable component lengths in inches, I cannot give the polar form in anything but final plot units. This is inconsistent (same is true in plot3). In contrast, for grdvector the vectors are of course expected to be in user units in both polar and component forms, and they are scaled via the information in -S to get them into plot lengths. This makes sense, and the same is true in velo.
- Geovectors are special great-circle vectors whose lengths are given in map distances (e.g., km or spherical degrees). In plot and plot3 the input is expected to be azimuth and length (in any map distance unit). The +z modifier does not apply to geovectors. In grdvector, one can create geovectors from user data by selecting a suitable scale in -S. This converts user unit magnitudes to map distances, then plots the geovector. This cannot be done in plot or plot3, but in velo, so a bit inconsistent.
Shrinking issues:
- Cartesian vectors can shrink if their lengths are below a threshold. That threshold is currently in plot units (e.g., 0.5i, 1c, 24p) and if the plot length is shorter we compute a shrink scale as
s = length/limit, but also prevent s from being smaller than a user-selectable threshold [0.25]. If my input data are in mm/yr then I am out of luck to specify a limit in mm/yr and I would have to work out via the plot scale what such a limit would be in cm or points. - In contrast, geovectors have their attributes shrunk in a similar way but the length here is the geographic map length (e.g., in km). Since the plot length of these vectors vary with projection and view point it makes no sense to use a plot-length limit, hence the limit is in map lengths. Yet, if my data in grdvector are in mm/yr and I wanted a shrink limit in those units I am out of luck again.
Proposals:
- Offer a way, like +zscale, to accept polar form direction, length input, with length in data units to be scaled to plot units. A possible modifier is +vscale for "scale vector data length to plot length". Append a unit from c|i|p to indicate the unit of the product.
- Allow the shrinking limit to be given in data units or plot units. Follow the lead of plot -Sb and use unit u to indicate data units (since no unit would mean cm and hence a plot unit for Cartesian vectors and km as map unit for geovectors).
- Allow +z in plot and plot3 to accept components for a geovector and have them scaled to map distances. Properly compute what azimuth and length this corresponds to and plot the geovector accordingly. Should be possible to plot a vector given by components in, say, km along the parallel and meridian.
- Disable (or give error) +z in grdvector since here we control polar vs component via -A.
- If geovectors are plotted in grdvector, allow shrink limit to be given either in map length (current choice) or data length (new). Here we have a problem in that unit u means "survey foot" and another letter is needed. Perhaps l for length?
- Ensure that any use of vector modifiers that cannot apply in a particular module result in errors.
- Accept a default scale of 1 if +z has no argument (currently this would give junk).
Let me know if I am missing anything and if you are OK with this proposal, @GenericMappingTools/gmt-team.
Metadata
Metadata
Assignees
Labels
feature requestRequest a new feature
Activity
Improve vector scaling and shrinking
maxrjones commentedon Jan 4, 2022
The grdvector docs list +z as an option to give dx/dy - is this actually supported in the code? If so, I do not think we should disable it now.
I do not see a way to get the same result as grdvector -Si or -Sl in plot/plot3d.
PaulWessel commentedon Jan 4, 2022
See point 4 above
For -Sl and -Si there could be +v[i|l]scale
maxrjones commentedon Jan 4, 2022
Isn't this breaking backward compatibility though?
PaulWessel commentedon Jan 4, 2022
No. comp dx,dy vs r,az is entirely controlled by -A in grdvector. Any effect +z may or may not have is a bug and unintended.
Address items 3, 4, 7 in vector proposal
Address items 3, 4, 7 in vector proposal (#6194)
PaulWessel commentedon Jan 6, 2022
Think we need some clarification and consistency for options and modifiers that requests a scale for vectors. This happens with -S in grdvector and in +x (and soon +v) for vector attributes set in plot. These are used to scale the length or dx,dy-components read from file. There seems to be cases where unit conversions happen twice, leading to wrong results. There are basically two separate situations:
We need to keep these two situations separate because decisions based on data values (e.g., CPT lookup for coloring or shrinking for short vectors) may require access to data magnitude and not vector length.
While this is handled in grdvector (the input is really considered to be in user units), in plot we basically consider length to be in plot unit and if you want to color those vectors based on something like the data magnitude then you will need to supply that extra data column that -C implies. So, if you have
lon lat dx dydata and want to plot vectors colored by data magnitude then you would have to add a column afterlatthat equalshypot(dx,dy). That is very inconvenient. But, you say, should you not be using velo for this? Well, you could say that but the counter argument is that velo is part of an optional geodesy supplement and was specifically developed to plot GPS velocities.Should we not be able to plot colored wind velocities, thermal gradients, and other vector data in plot without having to resort to gmt math and hypot first?
If the answer is yes then we need a way to tell plot that
It seems the way to do this is to specify the (new) unit q for user quantity in the scaling. I.e.,
plot -Sv12p+e+v10q -Ct.cptmeansFor geovectors in plot we also only support lengths in map length (e.g., km), but we should be able to do the same as for Cartesian, i.e.,
plot -S=12p+e+v10q -Ct.cptmeans:The resulting geovector length is then plotted on the map. You may have noticed I snuck in a reference to a nonexistent GMT defaults called MAP_LENGTH_UNIT. We currently do not have a way to change the default unit for map distances. The default is meter but we have places where we state km unless a unit is appended. So not very consistent. In the geovector case above we can either say the product is assumed to be km and that is it, or we will have to introduce a default to control this separately.
Finally, current syntax in grdvector is to accept plot unit via the scale (if not we default to PROJ_LENGTH_UNIT). This differs from the scheme outlined for plot since plot would have the existing ability to plot lengths given in plot units OR lengths given in data units, whereas grdvector never considers input to be in plot units. Changing the syntax in grdvector to take q would be a consistent solution (would certainly have to be backwards compatible).
Comments on this, folks?
maxrjones commentedon Jan 6, 2022
I'm not clear on your last point. Are you proposing to deprecate grdvector -S?
PaulWessel commentedon Jan 6, 2022
Well, not really, it makes no sense to add q there since it is already q, so -S5c already means the scale is in 5c per data unit magnitude and no q will change that. So -S5i is better than -S5q --PROJECT_LENGTH_UNIT=inch which would be tedious. So to be clear, I think grdvector is OK as is, and the +z, +v modifiers do not apply to that module.
PaulWessel commentedon Jan 6, 2022
The long post is basically about plot and plot3d and secondary a unit question:
maxrjones commentedon Jan 6, 2022
Seems like a fine idea if you're interested in implementing it.
Also fine, as long as we're careful to keep the exceptions that are already in place (where default is km). I do not think there's a good way to fix the existing inconsistencies, since these were stated as not-bugs.
PaulWessel commentedon Jan 6, 2022
Yes, so I will moth-ball the MAP_LENGTH_UNIT for now but do want to tackle the plot improvements.
Further vector scale improvements and enhancements (#6197)
maxrjones commentedon Jan 25, 2022
I'm thinking a bit more about your
MAP_LENGTH_UNITidea in the context of https://forum.generic-mapping-tools.org/t/plot-degenerate-ellipse-using-units-other-than-km/2548 because it is often inconvenient to append the units to the data, especially in Python.In that post, I think Liam is looking for the PyGMT equivalent of an example such as this:
Would the
MAP_LENGTH_UNITfeature allow the units to be set withgmt plotrather than in the data, for example using the following to get the same output?If so, I think this would be really useful.
PaulWessel commentedon Jan 25, 2022
Yes, that was the point. The only awkward issue is what is the default unit. We say it is meter for most of GMT but in several places (like -SE) we say it is in km.
maxrjones commentedon Jan 25, 2022
We could say "Default is m unless otherwise stated"
PaulWessel commentedon Jan 26, 2022
Yes, we will have to. I will need to find all the places where we do these things. I think map project and grdproject are among those modules, but there are other places (probably project) as well as plot.