NCAR / NCAR/ncplot

ncplot reports incorrect number of points in variable statistics

Open
#2 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
7
Forks
2
PR merge metrics
No merged PRs in 30d

Description

Issue

The 'Data Set Statistics' window displays an incorrect number of points ('nPoints') for variables in a dataset. Specifically, if the variable is one-dimensional, the number of points displayed will be one less than the actual number present; if a HRT variable is viewed, the number of points shown will be less than the actual number by the sampling rate.

Steps to reproduce

  1. Download and extract the test NetCDF file: test.zip
  2. Use ncdump to determine the size of the arrays contained in the file:
    ncdump -h test.nc
    Observe that the Time dimension is equal to 2007 and sps20 is equal to 20, and that the Time variable has dimension (Time) and THETA and WSPD have dimensions (Time, sps20). This means that the Time variable has 2007 points, and THETA and WSPD have 2007*20 = 40140 points.
  3. Open the test file in ncplot and plot the variables by selecting them in the 'Variable Selection' window:
    ncplot test.nc
  4. Select 'View' -> 'Statistics' from the main ncplot window.
  5. Observe that ncplot shows Time to have 2006 points (2007-1) and THETA and WSPD to have 40120 (40140-20) points.

I suspect also that the statistics that are shown do not factor in the last "row" of datapoints (see 'Cause' section below).

Cause

Statistics are printed in the PrintStats function in stats.c. This function uses the nPoints member of a DATASET_INFO structure set to print the number of points. As well, the ComputeStats() function in stats.c uses the same nPoints member as the upper bound on loops in which it computes statistics.

The nPoints member of set is initialized in readSet() in dataIO.c (called upon viewing a variable) from NumberSeconds:

count[0] = set->nPoints = NumberSeconds / file->baseDataRate;

NumberSeconds is itself initialized as

NumberSeconds = UserEndTime[3] - UserStartTime[3];

on line 116 of dataIO.c in NewDataFile().

The mistake appears to be in computing NumberSeconds; NumberSeconds is off by one in that it doesn't include the last second in the computation. This computation should perhaps be

NumberSeconds = UserEndTime[3] - UserStartTime[3] + 1;

however, I am not certain if this will break other parts of the program.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with NewDataFile() and readSet() in dataIO.c, then trace how nPoints is consumed by ComputeStats() and PrintStats() in stats.c. Reproduce the report with test.nc from test.zip and compare ncdump dimensions with the displayed counts. Done means statistics include all points for one-dimensional and HRT variables without breaking other time handling.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
data-visualization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.