Package org.geotools.imageio.netcdf

Examples of org.geotools.imageio.netcdf.NetCDFImageReader


    }

    @Override
    public GranuleSource getGranules(String coverageName, boolean readOnly) throws IOException,
            UnsupportedOperationException {
        NetCDFImageReader reader = (NetCDFImageReader) ((NetCDFAccess)access).reader;
        final CoverageSlicesCatalog catalog = reader.getCatalog();
        return new CoverageSlicesCatalogSource(catalog, coverageName);
    }
View Full Code Here


            LOGGER.warning("Unable to find file polyphemus_20130301.nc");
            return;
        }
        final NetCDFImageReaderSpi unidataImageReaderSpi = new NetCDFImageReaderSpi();
        assertTrue(unidataImageReaderSpi.canDecodeInput(file));
        NetCDFImageReader reader = null;
        try {
            reader = (NetCDFImageReader) unidataImageReaderSpi.createReaderInstance();
            reader.setInput(file);
            int numImages = reader.getNumImages(true);
            assertEquals(1008, numImages);
            for (int i = 0; i < numImages; i++) {
                Slice2DIndex sliceIndex = reader.getSlice2DIndex(i);
                assertNotNull(sliceIndex);
                spitOutSliceInformation(i, sliceIndex);
            }

            // check coverage names
            final List<Name> names = reader.getCoveragesNames();
            assertNotNull(names);
            assertTrue(!names.isEmpty());
            assertTrue(3 == names.size());
            assertTrue(names.contains(new NameImpl("NO2")));
            assertTrue(names.contains(new NameImpl("O3")));
            assertTrue(names.contains(new NameImpl("V")));

            // checking slice catalog
            final CoverageSlicesCatalog cs = reader.getCatalog();
            assertNotNull(cs);

            // get typenames
            final String[] typeNames = cs.getTypeNames();
            for (String typeName : typeNames) {
                final List<CoverageSlice> granules = cs.getGranules(new Query(typeName,
                        Filter.INCLUDE));
                assertNotNull(granules);
                assertFalse(granules.isEmpty());
                for (CoverageSlice slice : granules) {
                    final SimpleFeature sf = slice.getOriginator();
                    if (TestData.isInteractiveTest()) {
                        LOGGER.info(DataUtilities.encodeFeature(sf));
                    }

                    // checks
                    for (Property p : sf.getProperties()) {
                        assertNotNull("Property " + p.getName() + " had a null value!",
                                p.getValue());
                    }
                }
            }
        } finally {
            if (reader != null) {
                try {
                    reader.dispose();
                } catch (Throwable t) {
                    // Does nothing
                }
            }
        }
View Full Code Here

    @Test
    public void testImageReaderPolyphemusSimple() throws Exception {
        final File file = TestData.file(this, "O3-NO2.nc");
        final NetCDFImageReaderSpi unidataImageReaderSpi = new NetCDFImageReaderSpi();
        assertTrue(unidataImageReaderSpi.canDecodeInput(file));
        NetCDFImageReader reader = null;
        try {

            // checking low level
            reader = (NetCDFImageReader) unidataImageReaderSpi.createReaderInstance();
            reader.setInput(file);
            int numImages = reader.getNumImages(true);
            LOGGER.info("Found " + numImages + " images.");
            for (int i = 0; i < numImages; i++) {
                Slice2DIndex sliceIndex = reader.getSlice2DIndex(i);
                assertNotNull(sliceIndex);
                spitOutSliceInformation(i, sliceIndex);
            }

            // checking slice catalog
            final CoverageSlicesCatalog cs = reader.getCatalog();
            assertNotNull(cs);

            // get typenames
            final String[] typeNames = cs.getTypeNames();
            for (String typeName : typeNames) {
                final List<CoverageSlice> granules = cs.getGranules(new Query(typeName,
                        Filter.INCLUDE));
                assertNotNull(granules);
                assertFalse(granules.isEmpty());
                for (CoverageSlice slice : granules) {
                    final SimpleFeature sf = slice.getOriginator();
                    if (TestData.isInteractiveTest()) {
                        LOGGER.info(DataUtilities.encodeFeature(sf));
                    }

                    // checks
                    for (Property p : sf.getProperties()) {
                        assertNotNull("Property " + p.getName() + " had a null value!",
                                p.getValue());
                    }
                }
            }
        } finally {
            if (reader != null) {
                try {
                    reader.dispose();
                } catch (Throwable t) {
                    // Does nothing
                }
            }
        }
View Full Code Here

        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();
                } catch (Throwable t) {
                    // Does nothing
                }
            }
        }
View Full Code Here

            LOGGER.warning("Unable to find file IASI_C_EUMP_20121120062959_31590_eps_o_l2.nc");
            return;
        }
        final NetCDFImageReaderSpi unidataImageReaderSpi = new NetCDFImageReaderSpi();
        assertTrue(unidataImageReaderSpi.canDecodeInput(file));
        NetCDFImageReader reader = null;
        try {
            reader = (NetCDFImageReader) unidataImageReaderSpi.createReaderInstance();
            reader.setInput(file);
            int numImages = reader.getNumImages(true);
            for (int i = 0; i < numImages; i++) {
                Slice2DIndex sliceIndex = reader.getSlice2DIndex(i);
                assertNotNull(sliceIndex);
                spitOutSliceInformation(i, sliceIndex);
            }

            // cloud_phase
            CoverageSourceDescriptor cd = reader.getCoverageDescriptor(new NameImpl("cloud_phase"));
            final List<AdditionalDomain> additionalDomains = cd.getAdditionalDomains();
            assertTrue(!additionalDomains.isEmpty());
            final AdditionalDomain ad = additionalDomains.get(0);
            assertTrue(ad.getType().equals(DomainType.NUMBER));
            assertEquals("cloud_phase", ad.getName());

        } finally {
            if (reader != null) {
                try {
                    reader.dispose();
                } catch (Throwable t) {
                    // Does nothing
                }
            }
        }
View Full Code Here

    @Test
    public void testImageReaderGOME2() throws Exception {
        final File file = TestData.file(this, "20130101.METOPA.GOME2.NO2.DUMMY.nc");
        final NetCDFImageReaderSpi unidataImageReaderSpi = new NetCDFImageReaderSpi();
        assertTrue(unidataImageReaderSpi.canDecodeInput(file));
        NetCDFImageReader reader = null;
        try {

            // checking low level
            reader = (NetCDFImageReader) unidataImageReaderSpi.createReaderInstance();
            reader.setInput(file);
            int numImages = reader.getNumImages(true);
            assertEquals(1, numImages);
            LOGGER.info("Found " + numImages + " images.");
            for (int i = 0; i < numImages; i++) {
                Slice2DIndex sliceIndex = reader.getSlice2DIndex(i);
                assertNotNull(sliceIndex);
                spitOutSliceInformation(i, sliceIndex);
            }

            // check coverage names
            final List<Name> names = reader.getCoveragesNames();
            assertNotNull(names);
            assertTrue(!names.isEmpty());
            assertTrue(1 == names.size());
            assertEquals("NO2", names.get(0).toString());

            // checking slice catalog
            final CoverageSlicesCatalog cs = reader.getCatalog();
            assertNotNull(cs);

            // get typenames
            final String[] typeNames = cs.getTypeNames();
            for (String typeName : typeNames) {
                final List<CoverageSlice> granules = cs.getGranules(new Query(typeName,
                        Filter.INCLUDE));
                assertNotNull(granules);
                assertFalse(granules.isEmpty());
                for (CoverageSlice slice : granules) {
                    final SimpleFeature sf = slice.getOriginator();
                    if (TestData.isInteractiveTest()) {
                        LOGGER.info(DataUtilities.encodeFeature(sf));
                    }

                    // checks
                    for (Property p : sf.getProperties()) {
                        final String pName = p.getName().toString();
                        if (!pName.equalsIgnoreCase("time") && !pName.equalsIgnoreCase("elevation")) {
                            assertNotNull("Property " + p.getName() + " had a null value!",
                                    p.getValue());
                        } else {
                            assertNull("Property " + p.getName() + " did not have a null value!",
                                    p.getValue());
                        }
                    }
                }
            }
        } finally {
            if (reader != null) {
                try {
                    reader.dispose();
                } catch (Throwable t) {
                    // Does nothing
                }
            }
        }
View Full Code Here

    @Test
    public void testImageReaderGOME2AncillaryFiles() throws Exception {
        final File file = TestData.file(this, "20130101.METOPA.GOME2.NO2.DUMMY.nc");
        final NetCDFImageReaderSpi unidataImageReaderSpi = new NetCDFImageReaderSpi();
        assertTrue(unidataImageReaderSpi.canDecodeInput(file));
        NetCDFImageReader reader = null;
        try {

            // checking low level
            reader = (NetCDFImageReader) unidataImageReaderSpi.createReaderInstance();
            reader.setInput(file);
            int numImages = reader.getNumImages(true);
            assertEquals(1, numImages);
            LOGGER.info("Found " + numImages + " images.");
            for (int i = 0; i < numImages; i++) {
                Slice2DIndex sliceIndex = reader.getSlice2DIndex(i);
                assertNotNull(sliceIndex);
                spitOutSliceInformation(i, sliceIndex);
            }

            // check coverage names
            final List<Name> names = reader.getCoveragesNames();
            assertNotNull(names);
            assertTrue(!names.isEmpty());
            assertTrue(1 == names.size());
            assertEquals("NO2", names.get(0).toString());

            // checking slice catalog
            final CoverageSlicesCatalog cs = reader.getCatalog();
            assertNotNull(cs);

            MessageDigest md = MessageDigest.getInstance("SHA-1");
            md.update(file.getCanonicalPath().getBytes());
            String hashCode = AncillaryFileManager.convertToHex(md.digest());

            // Check if the auxiliary files directory is present
            File parentDir = file.getParentFile();

            String auxiliaryDirPath = parentDir + File.separator + "."
                    + FilenameUtils.getBaseName(file.getName()) + "_" + hashCode;

            File auxiliaryDir = new File(auxiliaryDirPath);

            assertTrue(auxiliaryDir.exists());
            assertTrue(auxiliaryDir.isDirectory());

            // Check if the Auxiliary File Directory contains the origin.txt file
            FilenameFilter nameFileFilter = FileFilterUtils.nameFileFilter("origin.txt");
            File[] files = auxiliaryDir.listFiles(nameFileFilter);
            assertTrue(files != null);
            assertTrue(files[0].exists());
        } finally {
            if (reader != null) {
                try {
                    reader.dispose();
                } catch (Throwable t) {
                    // Does nothing
                }
            }
        }
View Full Code Here

            LOGGER.warning("Unable to find file ascatl1.nc");
            return;
        }
        final NetCDFImageReaderSpi unidataImageReaderSpi = new NetCDFImageReaderSpi();
        assertTrue(unidataImageReaderSpi.canDecodeInput(file));
        NetCDFImageReader reader = null;
        try {
            reader = (NetCDFImageReader) unidataImageReaderSpi.createReaderInstance();
            reader.setInput(file);
            int numImages = reader.getNumImages(true);
            for (int i = 0; i < numImages; i++) {
                Slice2DIndex sliceIndex = reader.getSlice2DIndex(i);
                assertNotNull(sliceIndex);
                spitOutSliceInformation(i, sliceIndex);
            }

            // check coverage names
            final List<Name> names = reader.getCoveragesNames();
            assertNotNull(names);
            assertTrue(!names.isEmpty());
            assertTrue(2 == names.size());
            assertEquals("cell_index", names.get(0).toString());
            assertEquals("f_land", names.get(1).toString());

            // checking slice catalog
            final CoverageSlicesCatalog cs = reader.getCatalog();
            assertNotNull(cs);

            // get typenames
            final String[] typeNames = cs.getTypeNames();
            for (String typeName : typeNames) {
                final List<CoverageSlice> granules = cs.getGranules(new Query(typeName,
                        Filter.INCLUDE));
                assertNotNull(granules);
                assertFalse(granules.isEmpty());
                for (CoverageSlice slice : granules) {
                    final SimpleFeature sf = slice.getOriginator();
                    if (TestData.isInteractiveTest()) {
                        LOGGER.info(DataUtilities.encodeFeature(sf));
                    }

                    // checks
                    for (Property p : sf.getProperties()) {
                        final String pName = p.getName().toString();
                        if (!pName.equalsIgnoreCase("time") && !pName.equalsIgnoreCase("elevation")) {
                            assertNotNull("Property " + p.getName() + " had a null value!",
                                    p.getValue());
                        } else {
                            assertNull("Property " + p.getName() + " did not have a null value!",
                                    p.getValue());
                        }
                    }
                }
            }

        } finally {
            if (reader != null) {
                try {
                    reader.dispose();
                } catch (Throwable t) {
                    // Does nothing
                }
            }
        }
View Full Code Here

        }
        FileUtils.copyFile(file, new File(TestData.file(this, null), "polyphemus.nc"));
        file = TestData.file(this, "polyphemus.nc");
        final NetCDFImageReaderSpi unidataImageReaderSpi = new NetCDFImageReaderSpi();
        assertTrue(unidataImageReaderSpi.canDecodeInput(file));
        NetCDFImageReader reader = null;
        try {
            reader = (NetCDFImageReader) unidataImageReaderSpi.createReaderInstance();
            reader.setInput(file);
            int numImages = reader.getNumImages(true);
            assertEquals(1008, numImages);
            for (int i = 0; i < numImages; i++) {
                Slice2DIndex sliceIndex = reader.getSlice2DIndex(i);
                assertNotNull(sliceIndex);
                spitOutSliceInformation(i, sliceIndex);
            }

            // check dimensions
            CoverageSourceDescriptor cd = reader.getCoverageDescriptor(new NameImpl("NO2"));
            final List<AdditionalDomain> additionalDomains = cd.getAdditionalDomains();
            assertNull(additionalDomains);

            final List<DimensionDescriptor> dimensions = cd.getDimensionDescriptors();
            assertNotNull(dimensions);
            assertTrue(!dimensions.isEmpty());
            assertEquals("wrong dimensions", 2, dimensions.size());
            DimensionDescriptor dim = dimensions.get(0);
            assertTrue(dim.getName().equals("TIME"));
            assertTrue(dim.getStartAttribute().equals("time"));
            dim = dimensions.get(1);
            assertTrue(dim.getName().equals("ELEVATION"));
            assertTrue(dim.getStartAttribute().equals("z"));

            // check coverage names
            final List<Name> names = reader.getCoveragesNames();
            assertNotNull(names);
            assertTrue(!names.isEmpty());
            assertTrue(3 == names.size());
            assertTrue(names.contains(new NameImpl("NO2")));
            assertTrue(names.contains(new NameImpl("O3")));
            assertTrue(names.contains(new NameImpl("V")));

            // checking slice catalog
            final CoverageSlicesCatalog cs = reader.getCatalog();
            assertNotNull(cs);

            // get typenames
            final String[] typeNames = cs.getTypeNames();
            for (String typeName : typeNames) {
                final List<CoverageSlice> granules = cs.getGranules(new Query(typeName,
                        Filter.INCLUDE));
                assertNotNull(granules);
                assertFalse(granules.isEmpty());
                for (CoverageSlice slice : granules) {
                    final SimpleFeature sf = slice.getOriginator();
                    if (TestData.isInteractiveTest()) {
                        LOGGER.info(DataUtilities.encodeFeature(sf));
                    }

                    // checks
                    for (Property p : sf.getProperties()) {
                        assertNotNull("Property " + p.getName() + " had a null value!",
                                p.getValue());
                    }
                }
            }
        } finally {

            // close reader
            if (reader != null) {
                try {
                    reader.dispose();
                } catch (Throwable t) {
                    // Does nothing
                }
            }
View Full Code Here

TOP

Related Classes of org.geotools.imageio.netcdf.NetCDFImageReader

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.