public FeatureDataset open(FeatureType ftype, NetcdfDataset ncd, Object analysis, CancelTask task, Formatter errlog) throws IOException { // already been opened by isMine // DtCoverageCSBuilder dtCoverage = (DtCoverageCSBuilder) analysis; // look - use GridDataset 2/24/2016 //DtCoverageDataset dt = DtCoverageDataset.open(ncd); //return DtCoverageAdapter.factory(dt, errlog); return new ucar.nc2.dt.grid.GridDataset( ncd); }
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.GRID || wantFeatureType == FeatureType.SWATH) { ucar.nc2.dt.grid.GridDataset gds = new ucar.nc2.dt.grid.GridDataset( ncd); if (gds.getGrids().size() > 0) { return gds; } } 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.GRID || wantFeatureType == FeatureType.SWATH) { ucar.nc2.dt.grid.GridDataset gds = new ucar.nc2.dt.grid.GridDataset( ncd); if (gds.getGrids().size() > 0) { return gds; } } return null; }
/** * Open a netcdf dataset, using NetcdfDataset.defaultEnhanceMode plus CoordSystems * and turn into a GridDataset. * * @param location netcdf dataset to open, using NetcdfDataset.acquireDataset(). * @param enhanceMode open netcdf dataset with this enhanceMode * @return GridDataset * @throws java.io.IOException on read error * @see ucar.nc2.dataset.NetcdfDataset#acquireDataset */ static public GridDataset open(String location, Set<NetcdfDataset.Enhance> enhanceMode) throws java.io.IOException { NetcdfDataset ds = ucar.nc2.dataset.NetcdfDataset.acquireDataset(null, location, enhanceMode, -1, null, null); return new GridDataset(ds, null); }
/** * Open a netcdf dataset, using NetcdfDataset.defaultEnhanceMode plus CoordSystems * and turn into a GridDataset. * * @param location netcdf dataset to open, using NetcdfDataset.acquireDataset(). * @param enhanceMode open netcdf dataset with this enhanceMode * @return GridDataset * @throws java.io.IOException on read error * @see ucar.nc2.dataset.NetcdfDataset#acquireDataset */ static public GridDataset open(String location, Set<NetcdfDataset.Enhance> enhanceMode) throws java.io.IOException { NetcdfDataset ds = ucar.nc2.dataset.NetcdfDataset.acquireDataset(null, location, enhanceMode, -1, null, null); return new GridDataset(ds, null); }
/** * Get the associated Grid Dataset, if any. called by DatasetHandler.openGridDataset() * @param matchPath match.remaining * @return Grid Dataset, or null if n/a * @throws IOException on error */ public ucar.nc2.dt.GridDataset getGridDataset(String matchPath) throws IOException { int pos = matchPath.indexOf('/'); String type = (pos > -1) ? matchPath.substring(0, pos) : matchPath; String name = (pos > -1) ? matchPath.substring(pos + 1) : ""; // this assumes that these are files. also might be remote datasets from a catalog if (type.equals(FILES)) { if (topDirectory == null) return null; String filename = new StringBuilder(topDirectory) .append(topDirectory.endsWith("/") ? "" : "/") .append(name).toString(); NetcdfDataset ncd = NetcdfDataset.acquireDataset(null, filename, null, -1, null, null); // no enhancement return new ucar.nc2.dt.grid.GridDataset(ncd); } return null; }
/** * Get the associated Grid Dataset, if any. called by DatasetHandler.openGridDataset() * * @param matchPath match.remaining * @return Grid Dataset, or null if n/a * @throws IOException on error */ public ucar.nc2.dt.grid.GridDataset getGridDataset(String matchPath) throws IOException { int pos = matchPath.indexOf('/'); String type = (pos > -1) ? matchPath.substring(0, pos) : matchPath; String name = (pos > -1) ? matchPath.substring(pos + 1) : ""; // this assumes that these are files. also might be remote datasets from a catalog if (type.equals(FILES)) { if (topDirectory == null) return null; String filename = topDirectory + (topDirectory.endsWith("/") ? "" : "/") + name; NetcdfDataset ncd = NetcdfDataset.acquireDataset(null, filename, null, -1, null, null); // no enhancement return new ucar.nc2.dt.grid.GridDataset(ncd); } return null; }
/** * Open a netcdf dataset, using NetcdfDataset.defaultEnhanceMode plus CoordSystems * and turn into a GridDataset. * * @param location netcdf dataset to open, using NetcdfDataset.acquireDataset(). * @param enhanceMode open netcdf dataset with this enhanceMode * @return GridDataset * @throws java.io.IOException on read error * @see ucar.nc2.dataset.NetcdfDataset#acquireDataset */ static public GridDataset open(String location, Set<NetcdfDataset.Enhance> enhanceMode) throws java.io.IOException { NetcdfDataset ds = ucar.nc2.dataset.NetcdfDataset.acquireDataset(null, DatasetUrl.findDatasetUrl(location), enhanceMode, -1, null, null); return new GridDataset(ds, null); }
@Override public ucar.nc2.dt.grid.GridDataset getGridDataset(Dataset ds, GroupGC group, String filename, FeatureCollectionConfig config, Formatter errlog, org.slf4j.Logger logger) throws IOException { ucar.nc2.grib.collection.Grib1Iosp iosp = new ucar.nc2.grib.collection.Grib1Iosp(group, ds.getType()); NetcdfFile ncfile = new NetcdfFileSubclass(iosp, null, getLocation(), null); NetcdfDataset ncd = new NetcdfDataset(ncfile); return new ucar.nc2.dt.grid.GridDataset(ncd); }
@Override public ucar.nc2.dt.grid.GridDataset getGridDataset(Dataset ds, GroupGC group, String filename, FeatureCollectionConfig config, Formatter errlog, org.slf4j.Logger logger) throws IOException { ucar.nc2.grib.collection.Grib2Iosp iosp = new ucar.nc2.grib.collection.Grib2Iosp(group, ds.getType()); NetcdfFile ncfile = new NetcdfFileSubclass(iosp, null, getLocation(), null); NetcdfDataset ncd = new NetcdfDataset(ncfile); return new ucar.nc2.dt.grid.GridDataset(ncd); }
public void utestReadNcMLInputStream() throws Exception { String ncmlLoc = "file:G:/work/jasmin/snpp.ncml"; GridDataset fullDataset = GridDataset.open( ncmlLoc); System.out.printf("full size= %d%n", fullDataset.getGrids().size()); // read ncml through a InputStream. String ncml = "<netcdf xmlns=\"http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2\">\n" + "<aggregation type=\"union\">\n" + " <netcdf location=\"file:G:/work/jasmin/SVM01_npp_d20120120_t0531354_e0532596_b01189_c20120120120033631216_noaa_ops.h5\" />\n" + " <netcdf location=\"file:G:/work/jasmin/GMTCO_npp_d20120120_t0531354_e0532596_b01189_c20120120115420527613_noaa_ops.h5\" />\n" + " </aggregation>\n" + "</netcdf>"; NetcdfDataset aggregatedDataset = NcMLReader.readNcML( new ByteArrayInputStream(ncml.getBytes(CDM.utf8Charset)), null ); GridDataset emptyDataset = new GridDataset( aggregatedDataset ); System.out.printf("empty= %s%n", emptyDataset.getGrids().size()); assert emptyDataset.getGrids().size() == fullDataset.getGrids().size(); }
static public FeatureDataset factory(FeatureType wantFeatureType, String endpoint) throws IOException { if (endpoint.startsWith(SCHEME)) endpoint = endpoint.substring(SCHEME.length()); Document doc = getCapabilities(endpoint); Element root = doc.getRootElement(); Element elem = root.getChild("featureDataset"); String fType = elem.getAttribute("type").getValue(); // LOOK, may be multiple types String uri = elem.getAttribute("url").getValue(); if (debug) System.out.printf("CdmrFeatureDataset endpoint %s%n ftype= %s url=%s%n", endpoint, fType, uri); FeatureType ft = FeatureType.getType(fType); if (ft == null || ft == FeatureType.NONE || ft == FeatureType.GRID) { CdmRemote ncremote = new CdmRemote(uri); NetcdfDataset ncd = new NetcdfDataset(ncremote, null); return new GridDataset(ncd); } else { List<VariableSimpleIF> dataVars = FeatureDatasetPointXML.getDataVariables(doc); LatLonRect bb = FeatureDatasetPointXML.getSpatialExtent(doc); CalendarDateRange dr = FeatureDatasetPointXML.getTimeSpan(doc); return new PointDatasetRemote(ft, uri, dataVars, bb, dr); } }
@Override public ucar.nc2.dt.grid.GridDataset getGridDataset(Dataset ds, GroupGC group, String filename, FeatureCollectionConfig gribConfig, Formatter errlog, org.slf4j.Logger logger) throws IOException { if (filename == null) { Grib1Iosp iosp = new Grib1Iosp(group, ds.getType()); NetcdfFile ncfile = new NetcdfFileSubclass(iosp, null, getLocation()+"#"+group.getId(), null); NetcdfDataset ncd = new NetcdfDataset(ncfile); return new ucar.nc2.dt.grid.GridDataset(ncd); // LOOK - replace with custom GridDataset?? } else { MFile wantFile = findMFileByName(filename); if (wantFile != null) { GribCollectionImmutable gc = GribCdmIndex.openGribCollectionFromDataFile(true, wantFile, CollectionUpdateType.nocheck, gribConfig, errlog, logger); // LOOK thread-safety : creating ncx if (gc == null) return null; Grib1Iosp iosp = new Grib1Iosp(gc); NetcdfFile ncfile = new NetcdfFileSubclass(iosp, null, getLocation(), null); NetcdfDataset ncd = new NetcdfDataset(ncfile); return new ucar.nc2.dt.grid.GridDataset(ncd); // LOOK - replace with custom GridDataset?? } return null; } }
static public FeatureDataset factory(FeatureType wantFeatureType, String endpoint) throws IOException { if (endpoint.startsWith(SCHEME)) endpoint = endpoint.substring(SCHEME.length()); Document doc = getCapabilities(endpoint); Element root = doc.getRootElement(); Element elem = root.getChild("featureDataset"); String fType = elem.getAttribute("type").getValue(); // LOOK, may be multiple types String uri = elem.getAttribute("url").getValue(); if (debug) System.out.printf("CdmrFeatureDataset endpoint %s%n ftype= %s url=%s%n", endpoint, fType, uri); FeatureType ft = FeatureType.getType(fType); if (ft == null || ft == FeatureType.NONE || ft == FeatureType.GRID) { CdmRemote ncremote = new CdmRemote(uri); NetcdfDataset ncd = new NetcdfDataset(ncremote, null); return new GridDataset(ncd); } else { List<VariableSimpleIF> dataVars = FeatureDatasetPointXML.getDataVariables(doc); LatLonRect bb = FeatureDatasetPointXML.getSpatialExtent(doc); CalendarDateRange dr = FeatureDatasetPointXML.getTimeSpan(doc); DateUnit timeUnit = FeatureDatasetPointXML.getTimeUnit(doc); String altUnits = FeatureDatasetPointXML.getAltUnits(doc); return new PointDatasetRemote(ft, uri, timeUnit, altUnits, dataVars, bb, dr); } }
@Test public void testTimeAxisEval() throws IOException { /** * The following tests BugFixes.evalTimeAxes, called by ucar.nc2.dt.grid.GridCoordSys.isGridCoordSys */ String testFileFullPath = TestDir.cdmUnitTestDir + "ft/grid/echoTops_runtime.nc"; GridDataset runtimeDataset = new GridDataset(new NetcdfDataset(NetcdfFile.open(testFileFullPath))); if (runtimeDataset.getGrids().isEmpty()) { throw new RuntimeException("Runtime data file did not generate a dataset with grids"); } if (runtimeDataset.getGrids().get(0).getCoordinateSystem().getRunTimeAxis() == null) { throw new RuntimeException("Runtime data file did not generate a dataset with a RunTime axis"); } System.out.println("BugFixesTest - completed."); }
@Test public void checkGrid() throws Exception { String endpoint = TestOnLocalServer.withHttpPath("/ncss/grid/gribCollection/GFS_CONUS_80km/GFS_CONUS_80km_20120227_0000.grib1?var=Temperature_isobaric"); byte[] content = TestOnLocalServer.getContent(endpoint, 200, ContentType.netcdf); // Open the binary response in memory try (NetcdfFile nf = NetcdfFile.openInMemory("test_data.nc", content)) { GridDataset gdsDataset = new GridDataset(new NetcdfDataset(nf)); assertNotNull(gdsDataset.findGridByName("Temperature_isobaric")); logger.debug("{}", nf); } }
@Test public void checkFmrcBest() throws Exception { String endpoint = TestOnLocalServer.withHttpPath("/ncss/grid/testGFSfmrc/GFS_CONUS_80km_nc_best.ncd?var=Relative_humidity_height_above_ground,Temperature_height_above_ground"); byte[] content = TestOnLocalServer.getContent(endpoint, 200, ContentType.netcdf); // Open the binary response in memory try (NetcdfFile nf = NetcdfFile.openInMemory("test_data.nc", content)) { GridDataset gdsDataset = new GridDataset(new NetcdfDataset(nf)); assertNotNull(gdsDataset.findGridByName("Relative_humidity_height_above_ground")); logger.debug("{}", nf); } }
@Test public void shouldGetSameVerticalProfile() throws IOException, InvalidRangeException{ System.out.printf("Open %s%n", sameUnitsFile); DatasetUrl durl = DatasetUrl.findDatasetUrl(sameUnitsFile); NetcdfDataset dsGood = NetcdfDataset.acquireDataset(durl, true, null); GridDataset gdsGood = new GridDataset(dsGood); GeoGrid gridGood = gdsGood.findGridByName(var); ProjectionImpl proj = gridGood.getProjection(); ProjectionPoint pp = proj.latLonToProj(point); double[] dataGood = getVertTransformationForPoint(pp, 0, gridGood); NetcdfDataset dsDiff = NetcdfDataset.acquireDataset(durl, true, null); GridDataset gdsDiff = new GridDataset(dsDiff); GeoGrid gridDiff = gdsDiff.findGridByName(var); proj = gridDiff.getProjection(); pp = proj.latLonToProj(point); double[] dataDiff = getVertTransformationForPoint(pp, 0, gridDiff); assertArrayEquals(dataGood, dataDiff, 0.00001); }
@Test public void testNcssFailure() throws Exception{ String filename = "scanCdmUnitTests/formats/netcdf4/COMPRESS_LEV2_20140201000000-GLOBCURRENT-L4-CURekm_15m-ERAWS_EEM-v02.0-fv01.0.nc"; String endpoint = TestOnLocalServer.withHttpPath("/ncss/grid/"+filename+ "?var=eastward_ekman_current_velocity&north=79.8750&west=-140&east=170&south=-79.8750&horizStride=1&"+ "time_start=2014-02-01T00%3A00%3A00Z&time_end=2014-02-01T00%3A00%3A00Z&timeStride=1&accept=netcdf4"); byte[] content = TestOnLocalServer.getContent(endpoint, 200, ContentType.netcdf); // Open the binary response in memory try (NetcdfFile nf = NetcdfFile.openInMemory("test_data.nc", content)) { GridDataset gdsDataset = new GridDataset(new NetcdfDataset(nf)); assertNotNull(gdsDataset.findGridByName("eastward_ekman_current_velocity")); logger.debug("{}", nf); } } }
@Test public void testEcmwfEns() throws Exception { String filename = TestDir.cdmUnitTestDir + "ft/grid/ensemble/jitka/ECME_RIZ_201201101200_00600_GB"; System.out.printf("Open %s%n", filename); try (NetcdfFile datafile = NetcdfFile.open(filename)) { NetcdfDataset netcdfDataset = new NetcdfDataset(datafile); GridDataset gridDataset = new GridDataset(netcdfDataset); String requiredName = "Total_precipitation_surface"; GridDatatype gridDatatype = gridDataset.findGridDatatype(requiredName); assertNotNull(gridDatatype); assertEquals(requiredName, gridDatatype.getFullName()); Dimension ensDimension = gridDatatype.getEnsembleDimension(); assertNotNull(ensDimension); //fails in 4.3 , null returned assertEquals(51, ensDimension.getLength()); // is 2 in 4.2, however it should be 51 (incl. control forecast) Dimension timeDimension = gridDatatype.getTimeDimension(); assertEquals(1, timeDimension.getLength()); //ok in both versions Dimension xDimension = gridDatatype.getXDimension(); assertEquals(31, xDimension.getLength()); //ok in both versions Dimension yDimension = gridDatatype.getYDimension(); assertEquals(21, yDimension.getLength()); //ok in both versions } }