Re: [netcdf-java] Inconsistent lat/lon bounds returned from unstructured grid dataset

  • To: Ethan Davis <edavis@xxxxxxxxxxxxxxxx>
  • Subject: Re: [netcdf-java] Inconsistent lat/lon bounds returned from unstructured grid dataset
  • From: Rich Signell <rsignell@xxxxxxxx>
  • Date: Tue, 7 Feb 2012 18:07:10 -0500
package gov.noaa.eds.threddsutilities.util;

import static org.junit.Assert.assertTrue;

import java.util.List;

import org.junit.Test;

import ucar.ma2.Array;
import ucar.nc2.Variable;
import ucar.nc2.constants.AxisType;
import ucar.nc2.dataset.CoordinateAxis;
import ucar.nc2.dataset.CoordinateAxis1D;
import ucar.nc2.dataset.NetcdfDataset;

public class ThreddsExtentUtilTest {

        @Test
        public void getExtentTest() {
                // String urlStr =
                // 
"http://oos.soest.hawaii.edu/thredds/dodsC/pacioos/ncom/global/NCOM_Global_Ocean_Model_best.ncd";;
                // String urlStr =
                // 
"http://localhost:8080/thredds/dodsC/test/ncom_glb_sfc_2011050100.nc";;
                // String urlStr =
                // 
"dods://dods.ndbc.noaa.gov/thredds/dodsC/data/oceansites/DATA/MBARI/OS_MBARI-M0_20100614_R_M.nc";
                // String urlStr =
                // 
"dods://dods.ndbc.noaa.gov/thredds/dodsC/data/oceansites/DATA/ANTARES/OS_ANTARES-1_200509_D_CTD.nc";
                String urlStr =
"dods://testbedapps.sura.org/threddsdev/dodsC/inundation/FVCOM/ike/2Dvrwoww";
                try {
                        NetcdfDataset ncd = NetcdfDataset.openDataset(urlStr);
                        List<CoordinateAxis> coordAxes = 
ncd.getCoordinateAxes();
                        try {
                                double maxLon = -9999.999;
                                double minLon = 9999.999;
                                double maxLat = -9999.999;
                                double minLat = 9999.999;
                                for (CoordinateAxis coordAxis : coordAxes) {

                                        if (coordAxis.getAxisType() == 
AxisType.Lat) {
                                                minLat = 
coordAxis.getMinValue();
                                                maxLat = 
coordAxis.getMaxValue();
                                        }

                                        if (coordAxis.getAxisType() == 
AxisType.Lon) {
                                                minLon = 
coordAxis.getMinValue();
                                                maxLon = 
coordAxis.getMaxValue();

                                        }
                                }
                                System.out
                                                .println("Using 
coordAxis.getMinValue() method -----");
                                System.out.println("minLon=" + minLon);
                                System.out.println("maxLon=" + maxLon);

                                System.out.println("minLat=" + minLat);
                                System.out.println("maxLat=" + maxLat);
                                assertTrue(maxLon > -180.0);
                        } catch (Exception e) {
                                System.out
                                                .println("Warning CF Axis 
problem: " + e.getMessage());
                        }

                } catch (Exception e) {
                        System.err.println(e);
                }
        }

        @Test
        public void getExtentUsing1DCoordTest() {
                // String urlStr =
                // 
"dods://dods.ndbc.noaa.gov/thredds/dodsC/data/oceansites/DATA/ANTARES/OS_ANTARES-1_200509_D_CTD.nc";
                // String varName = "LONGITUDE";
                String urlStr =
"dods://testbedapps.sura.org/threddsdev/dodsC/inundation/FVCOM/ike/2Dvrwoww";
                String lonName = "lon";
                String latName = "lat";

                try {
                        NetcdfDataset ncd = NetcdfDataset.openDataset(urlStr);
                        CoordinateAxis1D coordLon = (CoordinateAxis1D) ncd
                                        .findVariable(lonName);
                        double maxLon = -9999.999;
                        double minLon = 9999.999;

                        double[] vals = coordLon.getCoordValues();
                        for (int i = 0; i < vals.length; i++) {

                                double lon = vals[i];
                                // System.out.println("lon=" + lon);

                                if (lon > maxLon) {
                                        maxLon = lon;
                                }
                                if (lon < minLon) {
                                        minLon = lon;
                                }
                        }

                        CoordinateAxis1D coordLat = (CoordinateAxis1D) ncd
                                        .findVariable(latName);
                        double maxLat = -9999.999;
                        double minLat = 9999.999;

                        vals = coordLat.getCoordValues();
                        for (int i = 0; i < vals.length; i++) {

                                double lat = vals[i];
                                // System.out.println("lat=" + lat);

                                if (lat > maxLat) {
                                        maxLat = lat;
                                }
                                if (lat < minLat) {
                                        minLat = lat;
                                }
                        }
                        System.out.println("");
                        System.out.println("Using CoordinateAxis1D method 
-----");
                        System.out.println("minLon=" + minLon);
                        System.out.println("maxLon=" + maxLon);

                        System.out.println("minLat=" + minLat);
                        System.out.println("maxLat=" + maxLat);
                        assertTrue(maxLon > -180.0);
                } catch (Exception e) {
                        System.err.println(e);
                }
        }

        @Test
        public void getExtentUsingReadTest() {
                // String urlStr =
                // 
"dods://dods.ndbc.noaa.gov/thredds/dodsC/data/oceansites/DATA/ANTARES/OS_ANTARES-1_200509_D_CTD.nc";
                // String varName = "LONGITUDE";
                String urlStr =
"dods://testbedapps.sura.org/threddsdev/dodsC/inundation/FVCOM/ike/2Dvrwoww";
                String lonName = "lon";
                String latName = "lat";

                try {
                        NetcdfDataset ncd = NetcdfDataset.openDataset(urlStr);
                        Variable varLon = ncd.findVariable(lonName);
                        double maxLon = -9999.999;
                        double minLon = 9999.999;

                        Array vals = varLon.read();
                        for (int i = 0; i < vals.getSize(); i++) {

                                double lon = vals.getDouble(i);
                                // System.out.println("lon=" + lon);

                                if (lon > maxLon) {
                                        maxLon = lon;
                                }
                                if (lon < minLon) {
                                        minLon = lon;
                                }
                        }

                        Variable varLat = ncd.findVariable(latName);
                        double maxLat = -9999.999;
                        double minLat = 9999.999;

                        vals = varLat.read();
                        for (int i = 0; i < vals.getSize(); i++) {

                                double lat = vals.getDouble(i);
                                // System.out.println("lat=" + lat);

                                if (lat > maxLat) {
                                        maxLat = lat;
                                }
                                if (lat < minLat) {
                                        minLat = lat;
                                }
                        }
                        System.out.println("");
                        System.out.println("Using read method -----");
                        System.out.println("minLon=" + minLon);
                        System.out.println("maxLon=" + maxLon);

                        System.out.println("minLat=" + minLat);
                        System.out.println("maxLat=" + maxLat);
                        assertTrue(maxLon > -180.0);
                } catch (Exception e) {
                        System.err.println(e);
                }
        }

}


On Tue, Feb 7, 2012 at 5:21 PM, Ethan Davis <edavis@xxxxxxxxxxxxxxxx> wrote:
> Hi Dave,
>
> What do you mean by "unstructured grid dataset"? Can you send me a
> sample dataset?
>
> Thanks,
>
> Ethan
>
> On 1/23/2012 10:11 AM, Dave Neufeld wrote:
>> Hello,
>>
>> In the attached test case, inconsistent coordinate results are returned
>> depending on which methods of the NetCDF Java API are called (tested
>> against v4.2.26).
>>
>> Sample output:
>>
>> Using coordAxis.getMinValue() method -----
>> minLon=-86.76239013671875
>> maxLon=268.2677307128906
>> minLat=21.105741500854492
>> maxLat=31.007230758666992
>>
>> Using CoordinateAxis1D method -----
>> minLon=-86.76998901367188
>> maxLon=280.256103515625
>> minLat=18.15138816833496
>> maxLat=31.010635375976562
>>
>> Using read method -----
>> minLon=-97.85687255859375
>> maxLon=-79.7386474609375
>> minLat=18.15138816833496
>> maxLat=31.010635375976562
>>
>> -Dave
>>
>>
>> _______________________________________________
>> netcdf-java mailing list
>> netcdf-java@xxxxxxxxxxxxxxxx
>> For list information or to unsubscribe, visit: 
>> http://www.unidata.ucar.edu/mailing_lists/
>
> --
> Ethan Davis                                       UCAR Unidata Program
> edavis@xxxxxxxxxxxxxxxx                    http://www.unidata.ucar.edu
>
> _______________________________________________
> netcdf-java mailing list
> netcdf-java@xxxxxxxxxxxxxxxx
> For list information or to unsubscribe, visit: 
> http://www.unidata.ucar.edu/mailing_lists/



-- 
Dr. Richard P. Signell   (508) 457-2229
USGS, 384 Woods Hole Rd.
Woods Hole, MA 02543-1598



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