public void showCoordSys(java.util.Formatter sf) { sf.format("\nCoordinate Systems\n"); for (CoordinateSystem cs : ds.getCoordinateSystems()) { sf.format(" %s\n", cs); } }
public Object isMine(FeatureType wantFeatureType, NetcdfDataset ncd, Formatter errlog) throws IOException { // If they ask for a grid, and there seems to be some grids, go for it if (wantFeatureType == FeatureType.SWATH ) { if (isSwath(ncd.getCoordinateSystems())) return true; } return null; }
public Object isMine(FeatureType wantFeatureType, NetcdfDataset ncd, Formatter errlog) throws IOException { // If they ask for a grid, and there seems to be some grids, go for it if (wantFeatureType == FeatureType.SWATH ) { if (isSwath(ncd.getCoordinateSystems())) return true; } return null; }
/** * Find the CoordinateSystem with the most number of CoordinateAxes * @param ds search in this dataset * @return CoordinateSystem or null if none */ static private CoordinateSystem findBestCoordinateSystem(NetcdfDataset ds) { // find coordinate system with highest rank (largest number of axes) CoordinateSystem use = null; for (CoordinateSystem cs : ds.getCoordinateSystems()) { if (use == null) use = cs; else if (cs.getCoordinateAxes().size() > use.getCoordinateAxes().size()) use = cs; } return use; }
CoverageCS.Type classify(NetcdfDataset ds, Formatter errlog) { if (errlog != null) errlog.format("CoverageFactory for '%s'%n", ds.getLocation()); // sort by largest size first List<CoordinateSystem> css = new ArrayList<CoordinateSystem>(ds.getCoordinateSystems()); Collections.sort(css, new Comparator<CoordinateSystem>() { public int compare(CoordinateSystem o1, CoordinateSystem o2) { return o2.getCoordinateAxes().size() - o1.getCoordinateAxes().size(); } }); CoverageCS.Type isMine = null; for (CoordinateSystem cs : css) { isMine = classify(ds, cs, errlog); if (isMine != null) break; } if (errlog != null) errlog.format("coverage = %s%n", isMine); return isMine; }
CoverageCS.Type classify(NetcdfDataset ds, Formatter errlog) { if (errlog != null) errlog.format("CoverageFactory for '%s'%n", ds.getLocation()); // sort by largest size first List<CoordinateSystem> css = new ArrayList<CoordinateSystem>(ds.getCoordinateSystems()); Collections.sort(css, new Comparator<CoordinateSystem>() { public int compare(CoordinateSystem o1, CoordinateSystem o2) { return o2.getCoordinateAxes().size() - o1.getCoordinateAxes().size(); } }); CoverageCS.Type isMine = null; for (CoordinateSystem cs : css) { isMine = classify(ds, cs, errlog); if (isMine != null) break; } if (errlog != null) errlog.format("coverage = %s%n", isMine); return isMine; }
/** * Find the CoordinateSystem with the most number of CoordinateAxes * @param ds look in this dataset * @return CoordinateSystem or null if none */ static private CoordinateSystem findBestCoordinateSystem(NetcdfDataset ds) { // find coordinate system with highest rank (largest number of axes) CoordinateSystem use = null; for (CoordinateSystem cs : ds.getCoordinateSystems()) { if (use == null) use = cs; else if (cs.getCoordinateAxes().size() > use.getCoordinateAxes().size()) use = cs; } return use; }
/** * Find the CoordinateSystem with the most number of CoordinateAxes * @param ds look in this dataset * @return CoordinateSystem or null if none */ static private CoordinateSystem findBestCoordinateSystem(NetcdfDataset ds) { // find coordinate system with highest rank (largest number of axes) CoordinateSystem use = null; for (CoordinateSystem cs : ds.getCoordinateSystems()) { if (use == null) use = cs; else if (cs.getCoordinateAxes().size() > use.getCoordinateAxes().size()) use = cs; } return use; }
public static DtCoverageCSBuilder classify(NetcdfDataset ds, Formatter errlog) { if (errlog != null) errlog.format("CoverageFactory for '%s'%n", ds.getLocation()); // sort by largest size first List<CoordinateSystem> css = new ArrayList<>(ds.getCoordinateSystems()); Collections.sort(css, (o1, o2) -> o2.getCoordinateAxes().size() - o1.getCoordinateAxes().size()); DtCoverageCSBuilder builder = null; for (CoordinateSystem cs : css) { builder = new DtCoverageCSBuilder(ds, cs, errlog); if (builder.type != null) break; } if (builder == null) return null; if (errlog != null) errlog.format("coverage = %s%n", builder.type); return builder; }
/** * Returns all grid geometries (related to coordinate systems) found in the netCDF file. * This method returns a direct reference to an internal array - do not modify. * * @return all grid geometries, or an empty array if none. * @throws IOException if an I/O operation was necessary but failed. */ @Override @SuppressWarnings({"ReturnOfCollectionOrArrayField", "null"}) 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)); } } return geometries; }
public boolean compare(NetcdfFile org, NetcdfFile copy, ObjFilter filter, boolean showCompare, boolean showEach, boolean compareData) { this.compareData = compareData; this.showCompare = showCompare; this.showEach = showEach; f.format(" First file = %s%n", org.getLocation()); f.format(" Second file= %s%n", copy.getLocation()); long start = System.currentTimeMillis(); boolean ok = compareGroups(org.getRootGroup(), copy.getRootGroup(), filter); f.format(" Files are the same = %s%n", ok); long took = System.currentTimeMillis() - start; f.format(" Time to compare = %d msecs%n", took); // coordinate systems if (org instanceof NetcdfDataset && copy instanceof NetcdfDataset) { NetcdfDataset orgds = (NetcdfDataset) org; NetcdfDataset copyds = (NetcdfDataset) copy; List matches = new ArrayList(); ok &= checkAll("Dataset CS:", orgds.getCoordinateSystems(), copyds.getCoordinateSystems(), matches); for (int i = 0; i < matches.size(); i += 2) { CoordinateSystem orgCs = (CoordinateSystem) matches.get(i); CoordinateSystem copyCs = (CoordinateSystem) matches.get(i + 1); ok &= compareCoordinateSystem(orgCs, copyCs, filter); } } return ok; }
public boolean compare(NetcdfFile org, NetcdfFile copy, ObjFilter filter, boolean showCompare, boolean showEach, boolean compareData) { this.compareData = compareData; this.showCompare = showCompare; this.showEach = showEach; f.format(" First file = %s%n", org.getLocation()); f.format(" Second file= %s%n", copy.getLocation()); long start = System.currentTimeMillis(); boolean ok = compareGroups(org.getRootGroup(), copy.getRootGroup(), filter); f.format(" Files are the same = %s%n", ok); long took = System.currentTimeMillis() - start; f.format(" Time to compare = %d msecs%n", took); // coordinate systems if (org instanceof NetcdfDataset && copy instanceof NetcdfDataset) { NetcdfDataset orgds = (NetcdfDataset) org; NetcdfDataset copyds = (NetcdfDataset) copy; List matches = new ArrayList(); ok &= checkAll("Dataset CS:", orgds.getCoordinateSystems(), copyds.getCoordinateSystems(), matches); for (int i = 0; i < matches.size(); i += 2) { CoordinateSystem orgCs = (CoordinateSystem) matches.get(i); CoordinateSystem copyCs = (CoordinateSystem) matches.get(i + 1); ok &= compareCoordinateSystem(orgCs, copyCs, filter); } } return ok; }
/** * Assign CoordinateTransform objects to Coordinate Systems. */ protected void assignCoordinateTransforms(NetcdfDataset ncDataset) { super.assignCoordinateTransforms(ncDataset); // any cs whose got a vertical coordinate with no units List<CoordinateSystem> csys = ncDataset.getCoordinateSystems(); for (CoordinateSystem cs : csys) { if (cs.getZaxis() != null) { String units = cs.getZaxis().getUnitsString(); if ((units == null) || (units.trim().length() == 0)) { VerticalCT vct = makeWRFEtaVerticalCoordinateTransform(ncDataset, cs); if (vct != null) cs.addCoordinateTransform(vct); parseInfo.format("***Added WRFEta verticalCoordinateTransform to %s\n", cs.getName()); } } } }
/** * Assign CoordinateTransform objects to Coordinate Systems. */ protected void assignCoordinateTransforms(NetcdfDataset ncDataset) { super.assignCoordinateTransforms(ncDataset); // any cs whose got a vertical coordinate with no units List<CoordinateSystem> csys = ncDataset.getCoordinateSystems(); for (CoordinateSystem cs : csys) { if (cs.getZaxis() != null) { String units = cs.getZaxis().getUnitsString(); if ((units == null) || (units.trim().length() == 0)) { VerticalCT vct = makeWRFEtaVerticalCoordinateTransform(ncDataset, cs); if (vct != null) cs.addCoordinateTransform(vct); parseInfo.format("***Added WRFEta verticalCoordinateTransform to %s%n", cs.getName()); } } } }
/** * Assign CoordinateTransform objects to Coordinate Systems. */ protected void assignCoordinateTransforms(NetcdfDataset ncDataset) { super.assignCoordinateTransforms(ncDataset); // any cs whose got a vertical coordinate with no units List<CoordinateSystem> csys = ncDataset.getCoordinateSystems(); for (CoordinateSystem cs : csys) { if (cs.getZaxis() != null) { String units = cs.getZaxis().getUnitsString(); if ((units == null) || (units.trim().length() == 0)) { VerticalCT vct = makeWRFEtaVerticalCoordinateTransform(ncDataset, cs); if (vct != null) { cs.addCoordinateTransform(vct); parseInfo.format("***Added WRFEta verticalCoordinateTransform to %s\n", cs.getName()); } } } } }
/** * Assign CoordinateTransform objects to Coordinate Systems. */ protected void assignCoordinateTransforms(NetcdfDataset ncDataset) { super.assignCoordinateTransforms(ncDataset); // any cs whose got a vertical coordinate with no units List<CoordinateSystem> csys = ncDataset.getCoordinateSystems(); for (CoordinateSystem cs : csys) { if (cs.getZaxis() != null) { String units = cs.getZaxis().getUnitsString(); if ((units == null) || (units.trim().length() == 0)) { VerticalCT vct = makeWRFEtaVerticalCoordinateTransform(ncDataset, cs); if (vct != null) { cs.addCoordinateTransform(vct); parseInfo.format("***Added WRFEta verticalCoordinateTransform to %s%n", cs.getName()); } } } } }
/** * Assign CoordinateTransform objects to Coordinate Systems. */ protected void assignCoordinateTransforms(NetcdfDataset ncDataset) { super.assignCoordinateTransforms(ncDataset); // any cs whose got a vertical coordinate with no units List<CoordinateSystem> csys = ncDataset.getCoordinateSystems(); for (CoordinateSystem cs : csys) { if (cs.getZaxis() != null) { String units = cs.getZaxis().getUnitsString(); if ((units == null) || (units.trim().length() == 0)) { VerticalCT vct = makeWRFEtaVerticalCoordinateTransform(ncDataset, cs); if (vct != null) { cs.addCoordinateTransform(vct); parseInfo.format("***Added WRFEta verticalCoordinateTransform to %s%n", cs.getName()); } } } } }
/** * Assign CoordinateTransform objects to Coordinate Systems. */ protected void assignCoordinateTransforms(NetcdfDataset ncDataset) { super.assignCoordinateTransforms(ncDataset); // any cs whose got a vertical coordinate with no units List<CoordinateSystem> csys = ncDataset.getCoordinateSystems(); for (CoordinateSystem cs : csys) { if (cs.getZaxis() != null) { String units = cs.getZaxis().getUnitsString(); if ((units == null) || (units.trim().length() == 0)) { VerticalCT vct = makeWRFEtaVerticalCoordinateTransform(ncDataset, cs); if (vct != null) cs.addCoordinateTransform(vct); parseInfo.format("***Added WRFEta verticalCoordinateTransform to %s%n", cs.getName()); } } } }
@Test public void openWithEnhance() throws Exception { try (NetcdfDataset ncDataset = NetcdfDataset.openDataset(filename, true, null)) { if (show) ncDataset.writeNcML(System.out, null); Assert.assertEquals(NetcdfDataset.getDefaultEnhanceMode(), ncDataset.getEnhanceMode()); Assert.assertTrue("size="+ncDataset.getCoordinateSystems().size(), ncDataset.getCoordinateSystems().size() > 0); } } }
@Test public void testWrfNoTimeVar() throws IOException { String tstFile = TestDir.cdmLocalTestDataDir +"wrf/WrfNoTimeVar.nc"; logger.info("Open '{}'", tstFile); Set<NetcdfDataset.Enhance> defaultEnhanceMode = NetcdfDataset.getDefaultEnhanceMode(); EnumSet<NetcdfDataset.Enhance> enhanceMode = EnumSet.copyOf(defaultEnhanceMode); enhanceMode.add(NetcdfDataset.Enhance.IncompleteCoordSystems); DatasetUrl durl = DatasetUrl.findDatasetUrl (tstFile); NetcdfDataset ncd = NetcdfDataset.acquireDataset(durl, enhanceMode, null); List<CoordinateSystem> cs = ncd.getCoordinateSystems(); Assert.assertEquals(1, cs.size()); CoordinateSystem dsCs = cs.get(0); Assert.assertEquals(2, dsCs.getCoordinateAxes().size()); VariableDS var = (VariableDS) ncd.findVariable("T2"); List<CoordinateSystem> varCs = var.getCoordinateSystems(); Assert.assertEquals(1, varCs.size()); Assert.assertEquals(dsCs, varCs.get(0)); } }