Package ucar.nc2.dataset

Examples of ucar.nc2.dataset.NetcdfDataset


        if (!isCollection) { // open up atomic dataset for info
          log.info("Opening dataset to get global attributes");
          //--- if not a dataset collection then
          //--- open and check global attributes for metadata conventions
          try {
            NetcdfDataset ncD = NetcdfDataset.openDataset("thredds:"+ds.getCatalogUrl());
            Attribute mdCon = ncD.findGlobalAttributeIgnoreCase("metadata_conventions");
            if (mdCon != null) {
              List<Attribute> ga = ncD.getGlobalAttributes();
              for (Attribute att : ga ) {
                                if(log.isDebugEnabled()) log.debug("Attribute found "+att.toString());
                //--- TODO: Attach the attributes to the metadata node
                //--- for conversion into the ISO record by an xslt
              }
            } else {
                            if(log.isDebugEnabled()) log.debug("No global attribute with metadata conventions found");
            }
            ncD.close();
          } catch (Exception e) {
            log.info("Exception raised in netcdfDataset ops: "+e);
            e.printStackTrace();
          }
        }
View Full Code Here


    @Override
    public GridGeometry[] getGridGeometries() throws IOException {
        if (geometries == null) {
            List<CoordinateSystem> systems = null;
            if (file instanceof NetcdfDataset) {
                final NetcdfDataset ds = (NetcdfDataset) file;
                final EnumSet<NetcdfDataset.Enhance> mode = EnumSet.copyOf(ds.getEnhanceMode());
                if (mode.add(NetcdfDataset.Enhance.CoordSystems)) {
                    ds.enhance(mode);
                }
                systems = ds.getCoordinateSystems();
            }
            geometries = new GridGeometry[(systems != null) ? systems.size() : 0];
            for (int i=0; i<geometries.length; i++) {
                geometries[i] = new GridGeometryWrapper(systems.get(i));
            }
View Full Code Here

     * @param  name The file name as one of the above-cited constants.
     * @return The decoder for the given name.
     * @throws IOException If an error occurred while opening the file.
     */
    protected Decoder createDecoder(final String name) throws IOException {
        return new DecoderWrapper(LISTENERS, new NetcdfDataset(open(name)));
    }
View Full Code Here

     * @throws IOException Should never happen.
     */
    @Test
    public void testUCAR() throws IOException {
        final Metadata metadata;
        final Decoder input = new DecoderWrapper(TestCase.LISTENERS, new NetcdfDataset(open(NCEP)));
        try {
            metadata = new MetadataReader(input).read();
        } finally {
            input.close();
        }
View Full Code Here

     * @param input the input object.
     * @return the dataset or <code>null</code>.
     * @throws IOException
     */
    private NetcdfDataset extractDataset( Object input ) throws IOException {
        NetcdfDataset dataset = null;
        if (input instanceof URIImageInputStream) {
            URIImageInputStream uriInStream = (URIImageInputStream) input;
            dataset = NetcdfDataset.acquireDataset(uriInStream.getUri().toString(), null);
        }
        if (input instanceof URL) {
View Full Code Here

        }
        if (source instanceof URIImageInputStream) {
            URIImageInputStream uriInStream = (URIImageInputStream) source;
            try {
                // TODO perhaps it would be better to not make an online check. Might be slowing down.
                NetcdfDataset openDataset = NetcdfDataset.acquireDataset(uriInStream.getUri().toString(), null);
                openDataset.close();
                return true;
            } catch (IOException e) {
                return false;
            }
        }
View Full Code Here

    @Test
    public void polyphemus() throws Exception {

        // acquire dataset
        final NetcdfDataset dataset = NetcdfDataset.openDataset(TestData.url(this, "O3-NO2.nc")
                .toExternalForm());
        assertNotNull(dataset);
        final List<CoordinateAxis> cvs = dataset.getCoordinateAxes();
        assertNotNull(cvs);
        assertSame(4, cvs.size());

        //
        // cloud_formations is short
        //
        Dimension dim = dataset.findDimension("time");
        assertNotNull(dim);
        assertEquals("time", dim.getShortName());

        // check type
        CoordinateAxis coordinateAxis = dataset.findCoordinateAxis(dim.getShortName());
        assertNotNull(coordinateAxis);
        assertTrue(coordinateAxis instanceof CoordinateAxis1D);
        Class<?> binding = CoordinateVariable.suggestBinding((CoordinateAxis1D) coordinateAxis);
        assertNotNull(binding);
        assertSame(Date.class, binding);
        CoordinateVariable<?> cv = CoordinateVariable.create((CoordinateAxis1D) coordinateAxis);
        assertSame(Date.class, cv.getType());

        List<?> list = cv.read();
        assertNotNull(list);
        assertEquals(2, list.size());

        final GregorianCalendar cal = new GregorianCalendar(NetCDFTimeUtilities.UTC_TIMEZONE);
        cal.set(2012, 3, 1, 0, 0, 0);
        cal.set(GregorianCalendar.MILLISECOND, 0);
        assertEquals(cal.getTime(), cv.getMinimum());
        assertEquals(list.get(0), cv.getMinimum());

        cal.set(2012, 3, 1, 1, 0, 0);
        assertEquals(cal.getTime(), cv.getMaximum());
        assertEquals(list.get(1), cv.getMaximum());
        assertEquals(2, cv.getSize());
        assertEquals("hours since 2012-04-01 0:00:00", cv.getUnit());
        CoordinateReferenceSystem crs = cv.getCoordinateReferenceSystem();
        assertNotNull(crs);
        assertTrue(crs instanceof TemporalCRS);
        //
        // lat is float
        //
        dim = dataset.findDimension("z");
        assertNotNull(dim);
        assertEquals("z", dim.getShortName());

        // check type
        coordinateAxis = dataset.findCoordinateAxis(dim.getShortName());
        assertNotNull(coordinateAxis);
        assertTrue(coordinateAxis instanceof CoordinateAxis1D);
        binding = CoordinateVariable.suggestBinding((CoordinateAxis1D) coordinateAxis);
        assertNotNull(binding);
        assertSame(Float.class, binding);

        cv = CoordinateVariable.create((CoordinateAxis1D) coordinateAxis);
        list = cv.read();
        assertNotNull(list);
        assertEquals(2, list.size());

        assertSame(Float.class, cv.getType());
        assertEquals(10f, cv.getMinimum());
        assertEquals(450f, cv.getMaximum());
        assertEquals(list.get(0), cv.getMinimum());
        assertEquals(list.get(1), cv.getMaximum());
        assertEquals(2, cv.getSize());
        assertEquals("meters", cv.getUnit());

        crs = cv.getCoordinateReferenceSystem();
        assertNotNull(crs);
        assertTrue(crs instanceof VerticalCRS);

        dataset.close();

    }
View Full Code Here

        //
        // IASI does not have time or runtime, it only contains double variables besides lat e long
        //

        // acquire dataset
        final NetcdfDataset dataset = NetcdfDataset.openDataset(TestData.url(this,
                "IASI_C_EUMP_20121120062959_31590_eps_o_l2.nc").toExternalForm());
        assertNotNull(dataset);
        final List<CoordinateAxis> cvs = dataset.getCoordinateAxes();
        assertNotNull(cvs);
        assertSame(8, cvs.size());

        //
        // cloud_formations is short
        //
        Dimension dim = dataset.findDimension("cloud_formations");
        assertNotNull(dim);
        assertEquals("cloud_formations", dim.getShortName());

        // check type
        CoordinateAxis coordinateAxis = dataset.findCoordinateAxis(dim.getShortName());
        assertNotNull(coordinateAxis);
        assertTrue(coordinateAxis instanceof CoordinateAxis1D);
        Class<?> binding = CoordinateVariable.suggestBinding((CoordinateAxis1D) coordinateAxis);
        assertNotNull(binding);
        assertSame(Short.class, binding);
        CoordinateVariable<?> cv = CoordinateVariable.create((CoordinateAxis1D) coordinateAxis);
        assertSame(Short.class, cv.getType());
        assertEquals((short) 0, cv.getMinimum());
        assertEquals((short) 2, cv.getMaximum());
        assertEquals(3, cv.getSize());
        assertEquals("level", cv.getUnit());

        //
        // lat is float
        //
        dim = dataset.findDimension("lat");
        assertNotNull(dim);
        assertEquals("lat", dim.getShortName());

        // check type
        coordinateAxis = dataset.findCoordinateAxis(dim.getShortName());
        assertNotNull(coordinateAxis);
        assertTrue(coordinateAxis instanceof CoordinateAxis1D);
        binding = CoordinateVariable.suggestBinding((CoordinateAxis1D) coordinateAxis);
        assertNotNull(binding);
        assertSame(Float.class, binding);
        cv = CoordinateVariable.create((CoordinateAxis1D) coordinateAxis);
        assertNotNull(cv);
        assertSame(Float.class, cv.getType());
        assertEquals(-77.327934f, cv.getMinimum());
        assertEquals(89.781555f, cv.getMaximum());
        assertEquals(766, cv.getSize());
        assertEquals("degrees_north", cv.getUnit());
        assertTrue(cv.isRegular());
        assertEquals(cv.getMinimum(), cv.getStart());
        assertEquals(0.2184437770469516, cv.getIncrement());

        //
        // lon is float
        //
        dim = dataset.findDimension("lon");
        assertNotNull(dim);
        assertEquals("lon", dim.getShortName());

        // check type
        coordinateAxis = dataset.findCoordinateAxis(dim.getShortName());
        assertNotNull(coordinateAxis);
        assertTrue(coordinateAxis instanceof CoordinateAxis1D);
        binding = CoordinateVariable.suggestBinding((CoordinateAxis1D) coordinateAxis);
        assertNotNull(binding);
        assertSame(Float.class, binding);
        cv = CoordinateVariable.create((CoordinateAxis1D) coordinateAxis);
        assertNotNull(cv);
        assertEquals("degrees_east", cv.getUnit());

        //
        // pressure_levels_ozone is Double
        //
        dim = dataset.findDimension("nlo");
        assertNotNull(dim);
        assertEquals("nlo", dim.getShortName());

        // check type
        coordinateAxis = dataset.findCoordinateAxis(dim.getShortName());
        assertNotNull(coordinateAxis);
        assertTrue(coordinateAxis instanceof CoordinateAxis1D);
        binding = CoordinateVariable.suggestBinding((CoordinateAxis1D) coordinateAxis);
        assertNotNull(binding);
        assertSame(Double.class, binding);
        cv = CoordinateVariable.create((CoordinateAxis1D) coordinateAxis);
        assertNotNull(cv);
        assertEquals("Pa", cv.getUnit());

        //
        // pressure_levels_ozone is Double
        //
        dim = dataset.findDimension("nlt");
        assertNotNull(dim);
        assertEquals("nlt", dim.getShortName());

        // check type
        coordinateAxis = dataset.findCoordinateAxis(dim.getShortName());
        assertNotNull(coordinateAxis);
        assertTrue(coordinateAxis instanceof CoordinateAxis1D);
        binding = CoordinateVariable.suggestBinding((CoordinateAxis1D) coordinateAxis);
        assertNotNull(binding);
        assertSame(Double.class, binding);
        cv = CoordinateVariable.create((CoordinateAxis1D) coordinateAxis);
        assertNotNull(cv);
        assertEquals("Pa", cv.getUnit());

        dataset.close();

    }
View Full Code Here

     *                 if some error occur while opening the dataset.
     * @throws {@link IllegalArgumentException}
     *                 in case the specified input is a directory
     */
    public static NetcdfDataset getDataset(Object input) throws IOException {
        NetcdfDataset dataset = null;
        if (input instanceof File) {
          final File file= (File) input;
            if (!file.isDirectory())
                dataset = NetcdfDataset.acquireDataset(file.getPath(), null);
            else
View Full Code Here

    }

    @Test
    public void testNoValid2DVariable() throws Exception {
        final File file = TestData.file(this, "noVars.nc");
        NetcdfDataset dataset = NetcdfDataset.acquireDataset(file.getAbsolutePath(), null);
        List<Variable> variables = dataset.getVariables();
        boolean speedVariableIsPresent = false;
        String speedVariableName = "";

        for (Variable variable : variables) {
            if (variable.getShortName().equals("spd")) {
                speedVariableIsPresent = true;
                speedVariableName = variable.getFullName();
                break;
            }
        }

        assertTrue(speedVariableIsPresent);

        final NetCDFImageReaderSpi unidataImageReaderSpi = new NetCDFImageReaderSpi();
        assertTrue(unidataImageReaderSpi.canDecodeInput(file));
        NetCDFImageReader reader = null;
        try {

            // sample dataset containing a water_speed variable having
            // only time, depth dimensions. No lon/lat dims are present
            // resulting into variable not usable.
            reader = (NetCDFImageReader) unidataImageReaderSpi.createReaderInstance();
            reader.setInput(file);
            final List<Name> names = reader.getCoveragesNames();

            boolean isSpeedCoverageAvailable = false;
            for (Name name : names) {
                if (name.toString().equals(speedVariableName)) {
                    isSpeedCoverageAvailable = true;
                    break;
                }
            }
            // Checking that only "mask" variable is found
            assertFalse(isSpeedCoverageAvailable);
        } finally {
            if (dataset != null) {
                dataset.close();
            }

            if (reader != null) {
                try {
                    reader.dispose();
View Full Code Here

TOP

Related Classes of ucar.nc2.dataset.NetcdfDataset

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.