ncplot reports incorrect number of points in variable statistics
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
- Download and extract the test NetCDF file: test.zip
- Use ncdump to determine the size of the arrays contained in the file:
ncdump -h test.nc
Observe that theTimedimension is equal to 2007 andsps20is equal to 20, and that theTimevariable has dimension(Time)andTHETAandWSPDhave dimensions(Time, sps20). This means that theTimevariable has 2007 points, andTHETAandWSPDhave 2007*20 = 40140 points. - Open the test file in ncplot and plot the variables by selecting them in the 'Variable Selection' window:
ncplot test.nc - Select 'View' -> 'Statistics' from the main ncplot window.
- Observe that ncplot shows
Timeto have 2006 points (2007-1) andTHETAandWSPDto 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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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