public static void test2() throws IOException { String filename = "C:/data/fmrc/apex_fmrc/Run_20091025_0000.nc"; GridDataset gds = GridDataset.open(filename); GeoGrid grid = gds.findGridByName("temp"); GridCoordSystem gcs = grid.getCoordinateSystem(); CoordinateAxis lonAxis = gcs.getXHorizAxis(); assert lonAxis instanceof CoordinateAxis2D; CoordinateAxis latAxis = gcs.getYHorizAxis(); assert latAxis instanceof CoordinateAxis2D; GridCoordinate2D g2d = new GridCoordinate2D((CoordinateAxis2D) latAxis, (CoordinateAxis2D) lonAxis); doOne(g2d, 40.166959,-73.954234); gds.close(); }
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 static void main(String[] args) throws IOException { GridDataset gds = ucar.nc2.dt.grid.GridDataset.open("Q:/cdmUnitTest/transforms/Eumetsat.VerticalPerspective.grb"); GridDatatype grid = gds.findGridDatatype( "Pixel_scene_type"); GridCoordSystem gcs = grid.getCoordinateSystem(); double lat = 8.0; double lon = 21.0; // find the x,y point for a specific lat/lon position int[] xy = gcs.findXYindexFromLatLon(lat, lon, null); // xy[0] = x, xy[1] = y // read the data at that lat, lon a specific t and z value Array data = grid.readDataSlice(0, 0, xy[1], xy[0]); // note t, z, y, x double val = data.getDouble(0); System.out.printf("Value at %f %f == %f%n", lat, lon, val); }
public void testNcmlGrid() throws IOException { String filename = "file:" + TestDir.cdmUnitTestDir + "ncml/nc/seawifs/aggDirectory.ncml"; GridDataset gds = GridDataset.open( filename); logger.debug(" TestNcmlAggExisting.openGrid {}", filename); List grids = gds.getGrids(); assert grids.size() == 2; gds.close(); }
@Test @Category(NeedsCdmUnitTest.class) public void testCoordExtract() throws IOException { try (ucar.nc2.dt.grid.GridDataset dataset = GridDataset.open(TestDir.cdmUnitTestDir + "formats/grib2/coordExtract/TestCoordExtract.grib2")) { System.out.printf("%s%n", dataset.getLocation()); GeoGrid grid = dataset.findGridByName("Convective_inhibition_surface"); assert null != grid; GridCoordSystem gcs = grid.getCoordinateSystem(); assert null != gcs; assert grid.getRank() == 3; System.out.printf("%s%n", gcs); int result[] = gcs.findXYindexFromLatLon(41.3669944444, -91.140575, null); System.out.printf("%d %d %n", result[0], result[1]); assert result[0] == 538; assert result[1] == 97; } }
static public void doOne( String dir, String name, int ngrids, int ncoordSys, int ncoordAxes, int nVertCooordAxes) throws Exception { System.out.printf("test read GridDataset= %s%s%n", dir, name); ucar.nc2.dt.grid.GridDataset gridDs = GridDataset.open(dir + name); System.out.printf(" location= %s%n%n", gridDs.getLocation()); int countGrids = gridDs.getGrids().size(); int countCoordAxes = gridDs.getNetcdfDataset().getCoordinateAxes().size(); int countCoordSys = gridDs.getNetcdfDataset().getCoordinateSystems().size(); for (CoordinateAxis axis : gridDs.getNetcdfDataset().getCoordinateAxes()) { AxisType t = axis.getAxisType(); if ((t == AxisType.GeoZ) || (t == AxisType.Height) || (t == AxisType.Pressure)) Iterator iter = gridDs.getGridsets().iterator(); while (iter.hasNext()) { GridDataset.Gridset gridset = (GridDataset.Gridset) iter.next(); assert nVertCooordAxes == countVertCooordAxes : "VertAxes " + nVertCooordAxes + " != " + countVertCooordAxes; gridDs.close();
private void testGridExists(String filename, String vname) throws IOException, InvalidRangeException { try (NetcdfFile ncfile = NetcdfFile.open(filename)) { Variable v = ncfile.findVariable(vname); assert v != null : filename+" "+vname; } try (GridDataset gds = GridDataset.open(filename)) { GeoGrid v = gds.findGridByName(vname); assert v != null : filename+" "+vname; } }
public void openDatasetAndView(String url) throws IOException { Array temp_data; try (GridDataset dataset = GridDataset.open(url)) { for (GridDatatype grid : dataset.getGrids()) { temp_data = grid.readDataSlice(0, 0, -1, -1); assert grid.getMinMaxSkipMissingData(temp_data).min == 0.0; // min assert grid.getMinMaxSkipMissingData(temp_data).max == 42.0; // max } } }
@Test @Category(NeedsCdmUnitTest.class) public void testBBSubsetVP() throws Exception { String filename = TestDir.cdmUnitTestDir + "transforms/Eumetsat.VerticalPerspective.grb"; try (GridDataset dataset = GridDataset.open(filename)) { GeoGrid grid = dataset.findGridDatatypeByAttribute(Grib.VARIABLE_ID_ATTNAME, "VAR_3-0-8"); // "Pixel_scene_type"); assert null != grid : dataset.getLocation(); GridCoordSystem gcs = grid.getCoordinateSystem(); assert null != gcs; logger.debug("original bbox = {}", gcs.getBoundingBox()); logger.debug("lat/lon bbox = {}", gcs.getLatLonBoundingBox()); ucar.unidata.geoloc.LatLonRect llbb_subset = new LatLonRect(new LatLonPointImpl(), 20.0, 40.0); logger.debug("subset lat/lon bbox = {}", llbb_subset); GeoGrid grid_section = grid.subset(null, null, llbb_subset, 1, 1, 1); GridCoordSystem gcs2 = grid_section.getCoordinateSystem(); assert null != gcs2; logger.debug("result lat/lon bbox = {}", gcs2.getLatLonBoundingBox()); logger.debug("result bbox = {}", gcs2.getBoundingBox()); ProjectionRect pr = gcs2.getProjection().getDefaultMapArea(); logger.debug("projection mapArea = {}", pr); assert (pr.nearlyEquals(gcs2.getBoundingBox())); } }
/** * Open a netcdf dataset, parse Conventions, find all the geoGrids, return a GridDataset. * * @deprecated : use GridDataset.open(). */ static public GridDataset factory(String netcdfFileURI) throws java.io.IOException { return open(netcdfFileURI); }
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(); }
@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); } }
public int readGridDataset() throws IOException { kind = KIND_GRID; int countFailures = 0; try (GridDataset gds = GridDataset.open(filename)) { NetcdfFile ncfile = gds.getNetcdfFile(); IOServiceProvider iosp = ncfile.getIosp(); isGrib1 = iosp instanceof Grib1Iosp; for (GridDatatype gdt : gds.getGrids()) { if (read(gdt)) counters.count(kind, "success"); else { counters.count(kind, "fail"); countFailures++; } } } return countFailures; }
@Test public void testJoinNewWithGroups() throws IOException, InvalidRangeException { String location = TestDir.cdmUnitTestDir + "agg/groups/groupsJoinNew.ncml"; GridDataset ncd = null; try { ncd = GridDataset.open(location); // fails here GridDatatype v = ncd.findGridDatatype("All_Data/Lifted_Index"); // the only agg var assert v != null; assert v.getRank() == 3; Section s = new Section(v.getShape()); //assert s.equals(new Section(new int[] {2, 44, 60})) : s ; v = ncd.findGridDatatype("All_Data/CAPE"); // random non-agg var assert v != null; assert v.getRank() == 2; Array a = v.readVolumeData(0); System.out.printf("array section for %s = %s%n", v, new Section(a.getShape())); } finally { if (ncd != null) ncd.close(); } } }
public GridDatasetInv(ucar.nc2.dt.grid.GridDataset gds, CalendarDate runDate) { this.location = gds.getLocationURI(); this.runDate = runDate; NetcdfFile ncfile = gds.getNetcdfFile(); if (this.runDate == null) { runTimeString = ncfile.findAttValueIgnoreCase(null, _Coordinate.ModelBaseDate, null); this.runDate = gds.getCalendarDateStart(); // LOOK not really right log.warn("GridDatasetInv using gds.getStartDate() for run date = {}", runTimeString, location); for (GridDatatype gg : gds.getGrids()) { GridCoordSystem gcs = gg.getCoordinateSystem(); Grid grid = new Grid(gg.getFullName());
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 GridDatasetInv(ucar.nc2.dt.grid.GridDataset gds, CalendarDate runDate) { this.location = gds.getLocation(); this.runDate = runDate; NetcdfFile ncfile = gds.getNetcdfFile(); if (ncfile != null && this.runDate == null) { runTimeString = ncfile.findAttValueIgnoreCase(null, _Coordinate.ModelBaseDate, null); this.runDate = gds.getCalendarDateStart(); // LOOK not really right logger.warn("GridDatasetInv using gds.getStartDate() for run date = {}", runTimeString, location); for (GridDatatype gg : gds.getGrids()) { GridCoordSystem gcs = gg.getCoordinateSystem(); Grid grid = new Grid(gg.getFullName());
@Test public void testOpenGrid() throws IOException { long start = System.currentTimeMillis(); try (GridDataset ncd = ucar.nc2.dt.grid.GridDataset.open(url)) { System.out.printf("%s%n", ncd.getLocation()); } finally { System.out.printf("**testOpenGrid took= %d msecs%n", (System.currentTimeMillis() - start)); } }
boolean ok = true; GridDataset fooGridDataset = new GridDataset(fooDataset); GridDatatype fooGrid = fooGridDataset.findGridDatatype("foo"); assert fooGrid != null;
private void testCoordinates(String filename, double startLat, double startLon, double endLat, double endLon) throws IOException, InvalidRangeException { System.out.printf("%n***Open %s%n", filename); NetcdfDataset ncd = NetcdfDataset.openDataset(filename); GridDataset gds = new GridDataset(ncd); GridCoordSystem gsys = null; ProjectionImpl p = null; for (ucar.nc2.dt.GridDataset.Gridset g : gds.getGridsets()) { gsys = g.getGeoCoordSystem(); for (CoordinateTransform t : gsys.getCoordinateTransforms()) { if (t instanceof ProjectionCT) { p = ((ProjectionCT)t).getProjection(); break; } } } assert p != null; CoordinateAxis1D xaxis = (CoordinateAxis1D) gsys.getXHorizAxis(); CoordinateAxis1D yaxis = (CoordinateAxis1D) gsys.getYHorizAxis(); p.projToLatLon(xaxis.getCoordValue(0), yaxis.getCoordValue(0) ); LatLonPoint start1 = p.projToLatLon(xaxis.getCoordValue(0), yaxis.getCoordValue(0)); LatLonPoint start2 = p.projToLatLon(xaxis.getCoordValue((int)xaxis.getSize()-1), yaxis.getCoordValue((int)yaxis.getSize()-1)); System.out.printf( "start = %f %f%n", start1.getLatitude(), start1.getLongitude()); System.out.printf( "end = %f %f%n", start2.getLatitude(), start2.getLongitude()); assert start1.nearlyEquals(new LatLonPointImpl(startLat, startLon), 2.0E-4); assert start2.nearlyEquals(new LatLonPointImpl(endLat, endLon), 2.0E-4); ncd.close(); }