Skip to content

Bugfix: Correct NetCDF dimension range checking to use inclusive inequalities #3164

@JohnHalleyGotway

Description

@JohnHalleyGotway

Describe the Problem

This issue arose via the dtcenter/METplus#2970 discussion when reading monthly data from a NetCDF file with a time dimension of 12.

Grid-Stat was configured to extract climatology data for all 12 months from that file like this:

climo_mean = {

   file_name = ["era5_mnth.mrg1_avg.1440x0721.Y1985-2014.T00z.nc4"];
   field     = [ { name = "u"; level = "(0:11,@500,*,*)"; } ];

Where 0:11 indicates which 0-based time indices within that range should be used. 0:11 means that all of them should be used. However, runtime log messages indicate that data is read for time indices 0 through 10, but not 11:

DEBUG 7: MetNcCFDataFile::data_plane_array(VarInfo &, DataPlaneArray &) -> time: 19850115_000000 from index 0
DEBUG 7: MetNcCFDataFile::data_plane_array(VarInfo &, DataPlaneArray &) -> time: 19850214_000000 from index 1
...
DEBUG 7: MetNcCFDataFile::data_plane_array(VarInfo &, DataPlaneArray &) -> time: 19851111_000000 from index 10

Expected Behavior

When specifying a range of dimension indices or values to be used, I would expect MET to use inclusive inequalities (e.g. including the endpoints of 0 and 11 in this example) rather the exclusive ones. For comparison, here's the line of code where ranges are checked for GRIB records:

if ( ( vinfo.level().type() != LevelType_Accum     ) &&
     ( vinfo.level().type() != LevelType_RecNumber ) &&
     ( grib_lower < lower || grib_upper > upper ) )  {

   mlog << Debug(4)
        << "For GRIB record number " << g.rec_num
        << ", the requested level values (" << lower << " and " << upper
        << ") do not fall within the current range of level values "
        << "(" << grib_lower << " and " << grib_upper << ").\n";

   return false;
}

It discards any records < min or > max which is the same as keeping any records >= min and <= max.

Please review the logic in the MET NetCDF library code to consistently include both endpoints in the ranges.

Please fix this in both the main_v12.1 and develop branches.

To Reproduce

Run this script: seneca:/d1/projects/METplus/discussions/2970/run_gs.sh

Relevant Deadlines

Recommend fixing for the upcoming MET-12.1.0 official release.

Funding Source

Please use NCAR base, but if time surpasses 8 h, please contact @michelleharrold

Define the Metadata

Assignee

  • Select engineer(s) or no engineer required
  • Select scientist(s) or no scientist required

Labels

  • Review default alert labels
  • Select component(s)
  • Select priority
  • Select requestor(s)

Milestone and Projects

  • Select Milestone as the next bugfix version
  • Select METplus-X.Y Support project for support of the current coordinated release
  • Select MET-X.Y Development project for development toward the next coordinated release

Define Related Issue(s)

Consider the impact to the other METplus components.

Bugfix Checklist

See the METplus Workflow for details.

  • Complete the issue definition above, including the Time Estimate and Funding Source.
  • Fork this repository or create a branch of main_<Version>.
    Branch name: bugfix_<Issue Number>_main_<Version>_<Description>
  • Fix the bug and test your changes.
  • Add/update log messages for easier debugging.
  • Add/update unit tests.
  • Add/update documentation.
  • Push local changes to GitHub.
  • Submit a pull request to merge into main_<Version>.
    Pull request: bugfix <Issue Number> main_<Version> <Description>
  • Define the pull request metadata, as permissions allow.
    Select: Reviewer(s) and Development issue
    Select: Milestone as the next bugfix version
    Select: METplus-X.Y Support project for support of the current coordinated release
  • Iterate until the reviewer(s) accept and merge your changes.
  • Delete your fork or branch.
  • Complete the steps above to fix the bug on the develop branch.
    Branch name: bugfix_<Issue Number>_develop_<Description>
    Pull request: bugfix <Issue Number> develop <Description>
    Select: Reviewer(s) and Development issue
    Select: Milestone as the next official version
    Select: MET-X.Y Development project for development toward the next coordinated release
  • Close this issue.

Metadata

Metadata

Assignees

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions