Skip to content

Proposal for more consistency for scaling vectors and shrinking attributes #6190

Closed

Description

@PaulWessel

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:

  1. 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.
  2. 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).
  3. 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.
  4. Disable (or give error) +z in grdvector since here we control polar vs component via -A.
  5. 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?
  6. Ensure that any use of vector modifiers that cannot apply in a particular module result in errors.
  7. 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.

Activity

  1. added
    feature request
    on Jan 4, 2022
  2. added this to the milestone on Jan 4, 2022
  3. self-assigned this
    on Jan 4, 2022
  4. added a commit that references this issue on Jan 4, 2022
  5. maxrjones commented on Jan 4, 2022

    @maxrjones
    Member

    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.

  6. PaulWessel commented on Jan 4, 2022

    @PaulWessel
    ContributorAuthor

    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.

    See point 4 above

    I do not see a way to get the same result as grdvector -Si or -Sl in plot/plot3d.

    For -Sl and -Si there could be +v[i|l]scale

  7. maxrjones commented on Jan 4, 2022

    @maxrjones
    Member

    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.

    See point 4 above

    Isn't this breaking backward compatibility though?

  8. PaulWessel commented on Jan 4, 2022

    @PaulWessel
    ContributorAuthor

    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.

  9. PaulWessel commented on Jan 6, 2022

    @PaulWessel
    ContributorAuthor

    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:

    1. Your input data are given in user units (e.g., mm/yr) and you use the scale to convert to plot length. The scale is therefore in units of plot unit per data unit. You can append a unit to the scale or rely on the default. E.g., a scale of 2c means 2 cm per data unit (In GMT, 2 and 2c is the same thing unless you have messed with PROJ_LENGTH_UNIT)
    2. Your input data are given in plot units and you use the scale to magnify the length. The scale is then nondimensional, i..e, a factor.

    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 dy data and want to plot vectors colored by data magnitude then you would have to add a column after lat that equals hypot(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

    • Input data magnitude or components are given in data units
    • Despite -C[cpt] there is no expectation of a separate column with sizes

    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.cpt means

    1. Input vector length is in data units and shall be used as the size to look up color via t.cpt
    2. The data magnitude shall be scaled by 10 and the result is plot length in prevailing plot unit (e.g. cm). Use PROJ_LENGTH_UNIT if you prefer another unit.
    3. No extra data column is expected for reading size on input since we will use data magnitude.

    For 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.cpt means:

    1. Input vector length is in data units and shall be used as the size to look up color via t.cpt
    2. The data magnitude shall be scaled by 10 and the result is map length in prevailing plot unit (e.g. km). Use MAP_LENGTH_UNIT if you prefer another unit.
    3. No extra data column is expected for reading size on input.

    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?

  10. maxrjones commented on Jan 6, 2022

    @maxrjones
    Member

    I'm not clear on your last point. Are you proposing to deprecate grdvector -S?

  11. PaulWessel commented on Jan 6, 2022

    @PaulWessel
    ContributorAuthor

    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.

  12. PaulWessel commented on Jan 6, 2022

    @PaulWessel
    ContributorAuthor

    The long post is basically about plot and plot3d and secondary a unit question:

    1. Should allow them to plot data with color based on data magnitude without having to add that on input?
    2. Should we control map length units via a new default?
  13. maxrjones commented on Jan 6, 2022

    @maxrjones
    Member

    The long post is basically about plot and plot3d and secondary a unit question:

    1. Should allow them to plot data with color based on data magnitude without having to add that on input?
    

    Seems like a fine idea if you're interested in implementing it.

    2. Should we control map length units via a new default?
    

    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.

  14. PaulWessel commented on Jan 6, 2022

    @PaulWessel
    ContributorAuthor

    Yes, so I will moth-ball the MAP_LENGTH_UNIT for now but do want to tackle the plot improvements.

  15. maxrjones commented on Jan 25, 2022

    @maxrjones
    Member

    I'm thinking a bit more about your MAP_LENGTH_UNIT idea 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:

    echo "0 0 20d" | gmt plot -SE- -Bafg10 -JH10c -Rd -W2p,green -png test
    

    Would the MAP_LENGTH_UNIT feature allow the units to be set with gmt plot rather than in the data, for example using the following to get the same output?

    echo "0 0 20" | gmt plot -SE- -Bafg10 -JH10c -Rd -W2p,green --MAP_LENGTH_UNIT=d -png test
    

    If so, I think this would be really useful.

  16. PaulWessel commented on Jan 25, 2022

    @PaulWessel
    ContributorAuthor

    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.

  17. maxrjones commented on Jan 25, 2022

    @maxrjones
    Member

    We could say "Default is m unless otherwise stated"

  18. PaulWessel commented on Jan 26, 2022

    @PaulWessel
    ContributorAuthor

    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.

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

Metadata

Metadata

Assignees

Labels

feature request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions