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 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 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 static void main(String[] args) throws IOException { GridDataset gds = ucar.nc2.dt.grid.GridDataset.open(args[0]); ucar.nc2.dt.GridDatatype grid = gds.findGridDatatype( args[1]); ucar.nc2.dt.GridCoordSystem gcs = grid.getCoordinateSystem(); CoordinateAxis xAxis = gcs.getXHorizAxis(); CoordinateAxis yAxis = gcs.getXHorizAxis(); CoordinateAxis1D zAxis = gcs.getVerticalAxis(); // may be null if (gcs.hasTimeAxis1D()) { CoordinateAxis1D tAxis = gcs.getTimeAxis1D(); } else if (gcs.hasTimeAxis()) { CoordinateAxis tAxis = gcs.getTimeAxis(); } } }
@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(); } } }
GridDatatype fooGrid = fooGridDataset.findGridDatatype("foo"); assert fooGrid != null;
/** * Test GridCoordSystem.findXYindexFromLatLonBounded() * @throws IOException */ @Test public void checkGridCoordSystem_findXYindexFromLatLonBounded() throws IOException { GridDataset gd = GridDataset.open( datasetLocation ); GridDatatype hsGrid = gd.findGridDatatype( "hs" ); GridCoordSystem coordSys = hsGrid.getCoordinateSystem(); CalendarDate date = coordSys.getTimeAxis1D().getCalendarDate(0); int[] xy = coordSys.findXYindexFromLatLonBounded( lat, lon, null ); assertEquals( i, xy[0] ); assertEquals( j, xy[1] ); GridAsPointDataset hsGridAsPoint = new GridAsPointDataset( Collections.singletonList( hsGrid )); GridAsPointDataset.Point point = hsGridAsPoint.readData( hsGrid, date, lat, lon ); assertEquals( lat, point.lat, 0.001 ); assertEquals( lon, point.lon, 0.001 ); } }
@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 } }
GridDatatype targetGrid = dataset.findGridDatatype(targetGridName); if (targetGrid == null) { throw new RuntimeException("Grid '" + targetGridName + "' does not exist in data file");