Re: [netcdf-java] BUG: Rectilinear sub-grid miscalculates coord edges

Hi Christian:

The problem is that we are losing the coordinate bounds info. Ill see what i can do to fix it.

John

On 5/4/2010 8:24 PM, Christian Ward-Garrison wrote:
See test case below. foo.ncml defines a rectilinear, t-y-x, 4x4x4 grid named "foo". fooSubGrid is the 2x2x2 "central" subset of fooGrid.

foo.ncml:

<?xml version="1.0" encoding="UTF-8"?>
<netcdf xmlns="http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2";>
<dimension name="time" length="4" />
<dimension name="lat"  length="4"  />
<dimension name="lon"  length="4"  />
<dimension name="bnds" length="2"  />

<variable name="time" shape="time" type="double">
<attribute name="units" type="String" value="days since 1850-01-01" />
<attribute name="calendar" type="String" value="standard" />
<attribute name="bounds" type="String" value="time_bnds" />
<values>15.5 45.0 74.5 105.0</values>
</variable>

<variable name="time_bnds" shape="time bnds" type="double">
<values>0.0 31.0 31.0 59.0 59.0 90.0 90.0 120.0</values>
</variable>

<variable name="lat" shape="lat" type="double">
<attribute name="units" type="String" value="degrees_north" />
<attribute name="bounds" type="String" value="lat_bnds" />
<values>-54 9 54 81</values>
</variable>

<variable name="lat_bnds" shape="lat bnds" type="double">
<values>-90 -18 -18 36 36 72 72 90</values>
</variable>

<variable name="lon" shape="lon" type="double">
<attribute name="units" type="String" value="degrees_east" />
<attribute name="bounds" type="String" value="lon_bnds" />
<values>18 72 162 288</values>
</variable>

<variable name="lon_bnds" shape="lon bnds" type="double">
<values>0 36 36 108 108 216 216 360</values>
</variable>

<variable name="foo" shape="time lat lon" type="float">
<values start="1.0" increment="1.0" />
</variable>
</netcdf>


Foo.java:

public static void main(String[] args) throws IOException, InvalidRangeException {
        File fooNcmlFile = new File("foo.ncml");
NetcdfDataset fooDataset = NetcdfDataset.openDataset(fooNcmlFile.getAbsolutePath());

        try {
            GridDataset fooGridDataset = new GridDataset(fooDataset);
GridDatatype fooGrid = fooGridDataset.findGridDatatype("foo");

CoordinateAxis1D fooTimeAxis = fooGrid.getCoordinateSystem().getTimeAxis1D(); CoordinateAxis1D fooLatAxis = (CoordinateAxis1D) fooGrid.getCoordinateSystem().getYHorizAxis(); CoordinateAxis1D fooLonAxis = (CoordinateAxis1D) fooGrid.getCoordinateSystem().getXHorizAxis();

            // Expected: [0.0, 31.0, 59.0, 90.0, 120.0]
            // Actual:   [0.0, 31.0, 59.0, 90.0, 120.0]
System.out.println(Arrays.toString(fooTimeAxis.getCoordEdges()));

            // Expected: [-90.0, -18.0, 36.0, 72.0, 90.0]
            // Actual:   [-90.0, -18.0, 36.0, 72.0, 90.0]
System.out.println(Arrays.toString(fooLatAxis.getCoordEdges()));

            // Expected: [0.0, 36.0, 108.0, 216.0, 360.0]
            // Actual:   [0.0, 36.0, 108.0, 216.0, 360.0]
System.out.println(Arrays.toString(fooLonAxis.getCoordEdges()));


            Range middleRange = new Range(1, 2);
GridDatatype fooSubGrid = fooGrid.makeSubset(null, null, middleRange, null, middleRange, middleRange);

CoordinateAxis1D fooSubTimeAxis = fooSubGrid.getCoordinateSystem().getTimeAxis1D(); CoordinateAxis1D fooSubLatAxis = (CoordinateAxis1D) fooSubGrid.getCoordinateSystem().getYHorizAxis(); CoordinateAxis1D fooSubLonAxis = (CoordinateAxis1D) fooSubGrid.getCoordinateSystem().getXHorizAxis();

            // Expected: [31.0, 59.0, 90.0]
            // Actual:   [30.25, 59.75, 89.25]
System.out.println(Arrays.toString(fooSubTimeAxis.getCoordEdges()));

            // Expected: [-18.0, 36.0, 72.0]
            // Actual:   [-13.5, 31.5, 76.5]
System.out.println(Arrays.toString(fooSubLatAxis.getCoordEdges()));

            // Expected: [36.0, 108.0, 216.0]
            // Actual:   [27.0, 117.0, 207.0]
System.out.println(Arrays.toString(fooSubLonAxis.getCoordEdges()));
        } finally {
            fooDataset.close();
        }
    }

_______________________________________________
netcdf-java mailing list
netcdf-java@xxxxxxxxxxxxxxxx
For list information or to unsubscribe, visit: http://www.unidata.ucar.edu/mailing_lists/



  • 2010 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdf-java archives: