Skip to content

histogram -di does not set values to NaN #5630

Closed

Description

@maxrjones

Description of the problem

The -dinodata value does not replace values equal to nodata with nan, at least when used in the histogram module.

Full script that generated the error

#!/bin/bash

echo "0" > data.txt
echo "1" >> data.txt
echo "2" >> data.txt
gmt histogram data.txt -Bafg -R-0.5/2.5/0/2 -T-0.5/2.5/1 -W1p -Gred3 -di0 -png test

Full error message

No error message
Actual outcome
test

Expected outcome

No counts at zero

System information

  • Operating system: macOS
  • GMT version (gmt --version): 6.3.0

Activity

  1. added
    bug
    on Aug 11, 2021
  2. PaulWessel commented on Aug 11, 2021

    @PaulWessel
    Contributor

    While certainly not documented well, I believe -d only affects the z column, which is not used here. It originated in tools like xyz2grd and similar. Perhaps it will need a +ccol modifier... [2].

  3. maxrjones commented on Aug 11, 2021

    @maxrjones
    MemberAuthor

    While certainly not documented well, I believe -d only affects the z column, which is not used here. It originated in tools like xyz2grd and similar. Perhaps it will need a +ccol modifier... [2].

    Yes, a +ccol modifier seems helpful and the simplest solution.

  4. maxrjones commented on Aug 11, 2021

    @maxrjones
    MemberAuthor

    Actually, it would be nice for this to work for multiple or all columns. So either [+ccol][+a] or [cols] with the usual column range notation.

  5. PaulWessel commented on Aug 12, 2021

    @PaulWessel
    Contributor

    A bit of looking reveals the following implementation truths.

    1. On input, any column after the first two (x, y) may be affected by -di:
      if (col_no > 1 && gmt_input_is_nan_proxy (GMT, GMT->current.io.curr_rec[col_no])) /* Input matched no-data setting, so change to NaN */
    2. On output, all columns that have a NaN will be changed by -do:
      if (GMT->common.d.active[GMT_OUT] && gmt_M_is_dnan (val)) val = GMT->common.d.nan_proxy[GMT_OUT]; /* Write this value instead of NaNs */

    There is no trace of this being discussed in the docs, so we can choose to make this a feature or a bug :-).

    I assume I skipped examining the x,y coordinates since those are unlikely to be flagged as -99999 as such a point would not be useful in a data set (x,y by itself could be useful as a station location even though the observation z is invalid). However, I did not think that through as many datasets are instead time or spatial series (t,y) in which case perhaps the 2nd column should be affected by -di) or simply a list of observations (e..g, the one-column input to histogram).
    The fact that a NaN x or y can be replaced on output by the chosen -99999 or similar seems to suggest the limitation in input is a bit dumb.

    Proposal: Since the unique value (e.g., -99999 or similar) is unique (there won't be another one like 9898989 for column 4, for instance), I think it makes sense to apply this to all columns both on input and output. We would then declare a bug since we currently do not do this on input.
    We instead remember that -d was born from deprecated options like -Nnodata in xyzgrd where we strictly only examined the z [third] column for such values. In that case, the -di is close in spirit but will also do columns beyond three

    I think the first proposal makes most sense, and we also require some documentation clarification. Thoughts, @GenericMappingTools/core

  6. maxrjones commented on Aug 12, 2021

    @maxrjones
    MemberAuthor

    I agree with the first proposal for a short-term bug fix. Adding an option for specifying the columns could be a low-priority feature request. The only case that I could imagine where it would be useful is if someone unwraps a grid that has 0 as the NaN value for z-data, though they could always specify that in grd2xyz first.

  7. PaulWessel commented on Aug 12, 2021

    @PaulWessel
    Contributor

    Unless @joa-quim or @seisman have strong opinions on this issue I will declare a bug and apply -d to all columns.

  8. PaulWessel commented on Aug 13, 2021

    @PaulWessel
    Contributor

    Letting -di apply to all columns causes one test failure as we are using -di0 to say 0 is a NaN, but that then (with the revision) replaces various x and y coordinates that happen to be 0 with NaNs as well, breaking the test. Given we don't want to break things, my second proposal is simply that we let -d only operate on the columns following the coordinates (2 for most modules, 1 for time-series cases, 0 for histogram/rose, etc) unless a (new and future) +a modifiers says "do this for all columns".

  9. maxrjones commented on Aug 13, 2021

    @maxrjones
    MemberAuthor

    Letting -di apply to all columns causes one test failure as we are using -di0 to say 0 is a NaN, but that then (with the revision) replaces various x and y coordinates that happen to be 0 with NaNs as well, breaking the test. Given we don't want to break things, my second proposal is simply that we let -d only operate on the columns following the coordinates (2 for most modules, 1 for time-series cases, 0 for histogram/rose, etc) unless a (new and future) +a modifiers says "do this for all columns".

    Sounds good.

  10. added this to the milestone on Sep 22, 2021
  11. maxrjones commented on Nov 9, 2021

    @maxrjones
    MemberAuthor

    Closed by #5966

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions