private int[] getWeights( GeoGrid gg) { int rank = gg.getRank(); int[] w = new int[rank]; for (int n=0; n<rank; n++) { Dimension dim = gg.getDimension(n); String dimName = dim.getShortName(); if (dimName.equals("time")) w[n] = 1000; if (dimName.equals("z")) w[n] = 100; if (dimName.equals("y")) w[n] = 10; if (dimName.equals("x")) w[n] = 1; } return w; }
private int[] getWeights( GeoGrid gg) { int rank = gg.getRank(); int[] w = new int[rank]; for (int n=0; n<rank; n++) { Dimension dim = gg.getDimension(n); String dimName = dim.getShortName(); if (dimName.equals("time")) w[n] = 1000; if (dimName.equals("z")) w[n] = 100; if (dimName.equals("y")) w[n] = 10; if (dimName.equals("x")) w[n] = 1; } return w; }
private int[] getWeights( GeoGrid gg) { int rank = gg.getRank(); int[] w = new int[rank]; for (int n=0; n<rank; n++) { Dimension dim = gg.getDimension(n); String dimName = dim.getShortName(); if (dimName.equals("time")) w[n] = 1000; if (dimName.equals("z")) w[n] = 100; if (dimName.equals("y")) w[n] = 10; if (dimName.equals("x")) w[n] = 1; } return w; }
private int[] getWeights( GeoGrid gg) { int rank = gg.getRank(); int[] w = new int[rank]; for (int n=0; n<rank; n++) { Dimension dim = gg.getDimension(n); String dimName = dim.getShortName(); if (dimName.equals("time")) w[n] = 1000; if (dimName.equals("z")) w[n] = 100; if (dimName.equals("y")) w[n] = 10; if (dimName.equals("x")) w[n] = 1; } return w; }
@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; } }
public GridDatatype makeSubset(Range rt_range, Range e_range, Range t_range, Range z_range, Range y_range, Range x_range) throws InvalidRangeException { // get the ranges list int rank = getRank(); Range[] ranges = new Range[rank]; if (null != getXDimension()) ranges[xDimOrgIndex] = x_range; if (null != getYDimension()) ranges[yDimOrgIndex] = y_range; if (null != getZDimension()) ranges[zDimOrgIndex] = z_range; if (null != getTimeDimension()) ranges[tDimOrgIndex] = t_range; if (null != getRunTimeDimension()) ranges[rtDimOrgIndex] = rt_range; if (null != getEnsembleDimension()) ranges[eDimOrgIndex] = e_range; List<Range> rangesList = Arrays.asList(ranges); // subset the variable VariableDS v_section = (VariableDS) vs.section( new Section(rangesList)); List<Dimension> dims = v_section.getDimensions(); for (Dimension dim : dims) { dim.setShared(true); // make them shared (section will make them unshared) } // subset the axes in the GridCoordSys GridCoordSys gcs_section = new GridCoordSys(gcs, rt_range, e_range, t_range, z_range, y_range, x_range); // now we can make the geogrid return new GeoGrid(dataset, v_section, gcs_section); }
public GridDatatype makeSubset(Range rt_range, Range e_range, Range t_range, Range z_range, Range y_range, Range x_range) throws InvalidRangeException { // get the ranges list int rank = getRank(); Range[] ranges = new Range[rank]; if (null != getXDimension()) ranges[xDimOrgIndex] = x_range; if (null != getYDimension()) ranges[yDimOrgIndex] = y_range; if (null != getZDimension()) ranges[zDimOrgIndex] = z_range; if (null != getTimeDimension()) ranges[tDimOrgIndex] = t_range; if (null != getRunTimeDimension()) ranges[rtDimOrgIndex] = rt_range; if (null != getEnsembleDimension()) ranges[eDimOrgIndex] = e_range; List<Range> rangesList = Arrays.asList(ranges); // subset the variable VariableDS v_section = (VariableDS) vs.section( new Section(rangesList)); List<Dimension> dims = v_section.getDimensions(); for (Dimension dim : dims) { dim.setShared(true); // make them shared (section will make them unshared) } // subset the axes in the GridCoordSys GridCoordSys gcs_section = new GridCoordSys(gcs, rt_range, e_range, t_range, z_range, y_range, x_range); // now we can make the geogrid return new GeoGrid(dataset, v_section, gcs_section); }
public GridDatatype makeSubset(Range rt_range, Range e_range, Range t_range, Range z_range, Range y_range, Range x_range) throws InvalidRangeException { // get the ranges list int rank = getRank(); Range[] ranges = new Range[rank]; if (null != getXDimension()) ranges[xDimOrgIndex] = x_range; if (null != getYDimension()) ranges[yDimOrgIndex] = y_range; if (null != getZDimension()) ranges[zDimOrgIndex] = z_range; if (null != getTimeDimension()) ranges[tDimOrgIndex] = t_range; if (null != getRunTimeDimension()) ranges[rtDimOrgIndex] = rt_range; if (null != getEnsembleDimension()) ranges[eDimOrgIndex] = e_range; List<Range> rangesList = Arrays.asList(ranges); // subset the variable VariableDS v_section = (VariableDS) vs.section( new Section(rangesList)); List<Dimension> dims = v_section.getDimensions(); for (Dimension dim : dims) { dim.setShared(true); // make them shared (section will make them unshared) } // subset the axes in the GridCoordSys GridCoordSys gcs_section = new GridCoordSys(gcs, rt_range, e_range, t_range, z_range, y_range, x_range); // now we can make the geogrid return new GeoGrid(dataset, v_section, gcs_section); }
public void testSubset() throws Exception { ucar.nc2.dt.grid.GridDataset dataset = GridDataset.open(TestDir.cdmUnitTestDir + "ft/grid/stag/bora_feb.nc"); GeoGrid grid = dataset.findGridByName("u"); assert null != grid; System.out.printf("u shape= %s%n", showShape(grid.getShape())); GridCoordSystem gcs = grid.getCoordinateSystem(); assert null != gcs; assert grid.getRank() == 4; ucar.unidata.geoloc.vertical.VerticalTransform vt = gcs.getVerticalTransform(); Array a = vt.getCoordinateArray(0); System.out.printf("vt shape= %s%n", showShape(a.getShape())); dataset.close(); }
@Test @Category(NeedsCdmUnitTest.class) public void testLatLonSubset2() throws Exception { try (GridDataset dataset = GridDataset.open(TestDir.cdmUnitTestDir + "tds/ncep/GFS_Global_onedeg_20100913_0000.grib2")) { GeoGrid grid = dataset.findGridDatatypeByAttribute(Grib.VARIABLE_ID_ATTNAME, "VAR_0-3-0_L1"); // "Pressure_Surface"); assert null != grid : dataset.getLocation(); GridCoordSystem gcs = grid.getCoordinateSystem(); assert null != gcs; assert grid.getRank() == 3 : grid.getRank(); logger.debug("original bbox = {}", gcs.getBoundingBox()); logger.debug("lat/lon bbox = {}", gcs.getLatLonBoundingBox().toString2()); LatLonRect bbox = new LatLonRect(new LatLonPointImpl(40.0, -100.0), 10.0, 20.0); logger.debug("constrain bbox = {}", bbox.toString2()); GeoGrid grid_section = grid.subset(null, null, bbox, 1, 1, 1); GridCoordSystem gcs2 = grid_section.getCoordinateSystem(); assert null != gcs2; assert grid_section.getRank() == grid.getRank(); logger.debug("resulting bbox = {}", gcs2.getLatLonBoundingBox().toString2()); Array data = grid_section.readDataSlice(0, 0, -1, -1); assert data != null; assert data.getRank() == 2; int[] dataShape = data.getShape(); assert dataShape.length == 2; assert dataShape[0] == 11 : data.getShape()[0]; assert dataShape[1] == 21 : data.getShape()[1]; } }
public void utestAxisId() throws IOException { ucar.nc2.dt.grid.GridDataset dataset = GridDataset.open("C:/data/20100314_v_000000_l_0118800.nc"); GeoGrid grid = dataset.findGridByName("wind_speed"); assert null != grid; GridCoordSystem gcs = grid.getCoordinateSystem(); assert null != gcs; assert grid.getRank() == 3; CoordinateAxis axis = gcs.getXHorizAxis(); assert axis != null; assert axis.getShortName().equals("x") : axis.getShortName(); axis = gcs.getYHorizAxis(); assert axis != null; assert axis.getShortName().equals("y") : axis.getShortName(); dataset.close(); } }
private void testLatLonSubset(GeoGrid grid, LatLonRect bbox, int[] shape) throws Exception { logger.debug("grid bbox = {}", grid.getCoordinateSystem().getLatLonBoundingBox().toString2()); logger.debug("constrain bbox = {}", bbox.toString2()); GeoGrid grid_section = grid.subset(null, null, bbox, 1, 1, 1); GridCoordSystem gcs2 = grid_section.getCoordinateSystem(); assert null != gcs2; assert grid_section.getRank() == 2; logger.debug("resulting bbox = {}", gcs2.getLatLonBoundingBox().toString2()); Array data = grid_section.readDataSlice(0, 0, -1, -1); assert data != null; assert data.getRank() == 2; assert data.getShape()[0] == shape[0] : data.getShape()[0]; assert data.getShape()[1] == shape[1] : data.getShape()[1]; }
GridCoordSystem gcs = grid.getCoordinateSystem(); assert null != gcs; assert grid.getRank() == 4;
@Test @Category(NeedsCdmUnitTest.class) public void testLatLonSubset() throws Exception { try (GridDataset dataset = GridDataset.open(TestDir.cdmUnitTestDir + "conventions/cf/SUPER-NATIONAL_latlon_IR_20070222_1600.nc")) { GeoGrid grid = dataset.findGridByName("micron11"); assert null != grid; GridCoordSystem gcs = grid.getCoordinateSystem(); assert null != gcs; assert grid.getRank() == 2; logger.debug("original bbox = {}", gcs.getBoundingBox()); LatLonRect bbox = new LatLonRect(new LatLonPointImpl(40.0, -100.0), 10.0, 20.0); testLatLonSubset(grid, bbox, new int[]{141, 281}); bbox = new LatLonRect(new LatLonPointImpl(-40.0, -180.0), 120.0, 300.0); testLatLonSubset(grid, bbox, new int[]{800, 1300}); } }
@Test @Category(NeedsCdmUnitTest.class) public void testMSG() throws Exception { String filename = TestDir.cdmUnitTestDir + "transforms/Eumetsat.VerticalPerspective.grb"; try(GridDataset dataset = GridDataset.open(filename)) { logger.debug("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; assert grid.getRank() == 3; // bbox = ll: 16.79S 20.5W+ ur: 14.1N 20.09E LatLonRect bbox = new LatLonRect(new LatLonPointImpl(-16.79, -20.5), new LatLonPointImpl(14.1, 20.9)); ProjectionImpl p = gcs.getProjection(); ProjectionRect prect = p.latLonToProjBB(bbox); // must override default implementation logger.debug("{} -> {}", bbox, prect); ProjectionRect expected = new ProjectionRect( new ProjectionPointImpl(-2129.5688, -1793.0041), 4297.8453, 3308.3885); assert prect.nearlyEquals(expected); LatLonRect bb2 = p.projToLatLonBB(prect); logger.debug("{} -> {}", prect, bb2); GeoGrid grid_section = grid.subset(null, null, bbox, 1, 1, 1); Array data = grid_section.readDataSlice(-1, -1, -1, -1); assert data.getRank() == 3; int[] shape = data.getShape(); assert shape[0] == 1 : shape[0] + " should be 1"; assert shape[1] == 363 : shape[1] + " should be 363"; assert shape[2] == 479 : shape[2] + " should be 479"; } }
public void testSubset() throws Exception { ucar.nc2.dt.grid.GridDataset dataset = GridDataset.open(TestDir.cdmLocalTestDataDir+"rankTest.nc"); GeoGrid grid = dataset.findGridByName("full4"); assert null != grid; GridCoordSystem gcs = grid.getCoordinateSystem(); assert null != gcs; assert grid.getRank() == 4; doRead4(grid); GeoGrid grid_section = grid.subset(null, new Range(0,3,2), null, null); GridCoordSystem gcs_section = grid_section.getCoordinateSystem(); CoordinateAxis zaxis = gcs_section.getVerticalAxis(); assert zaxis.getSize() == 2; assert gcs_section.getXHorizAxis().equals( gcs.getXHorizAxis()); assert gcs_section.getYHorizAxis().equals( gcs.getYHorizAxis()); assert gcs_section.getTimeAxis().equals( gcs.getTimeAxis()); Array data = grid_section.readDataSlice(-1, -1, -1, -1); logger.debug(NCdumpW.toString( data, "grid_section", null)); dataset.close(); }
@Test @Category(NeedsCdmUnitTest.class) public void testGrib() throws Exception { try(GridDataset dataset = GridDataset.open(TestDir.cdmUnitTestDir + "formats/grib1/AVN.wmo")) { GeoGrid grid = dataset.findGridDatatypeByAttribute(Grib.VARIABLE_ID_ATTNAME, "VAR_7-0-2-11_L100"); // "Temperature_isobaric"); assert null != grid : dataset.getLocation(); GridCoordSystem gcs = grid.getCoordinateSystem(); assert null != gcs; assert grid.getRank() == 4; GeoGrid grid_section = grid.subset(null, null, null, 3, 3, 3); Array data = grid_section.readDataSlice(-1, -1, -1, -1); assert data.getShape()[0] == 3 : data.getShape()[0]; assert data.getShape()[1] == 3 : data.getShape()[1]; assert data.getShape()[2] == 13 : data.getShape()[2]; assert data.getShape()[3] == 15 : data.getShape()[3]; } }
@Test @Category(NeedsCdmUnitTest.class) public void testRegular() throws Exception { try(GridDataset dataset = GridDataset.open(TestDir.cdmUnitTestDir + "conventions/nuwg/03061219_ruc.nc")) { GeoGrid grid = dataset.findGridByName("T"); assert null != grid; GridCoordSystem gcs = grid.getCoordinateSystem(); assert null != gcs; assert grid.getRank() == 4; CoordinateAxis zaxis = gcs.getVerticalAxis(); assert zaxis.getUnitsString().equals("hectopascals"); GeoGrid grid_section = grid.subset(null, null, null, 3, 3, 3); GridCoordSystem gcs_section = grid_section.getCoordinateSystem(); CoordinateAxis zaxis2 = gcs_section.getVerticalAxis(); assert zaxis2.getSize() == 7; assert zaxis2.getUnitsString().equals("hectopascals"); assert gcs_section.getTimeAxis().equals(gcs.getTimeAxis()); Array data = grid_section.readDataSlice(-1, -1, -1, -1); assert data.getShape()[0] == 2 : data.getShape()[0]; assert data.getShape()[1] == 7 : data.getShape()[1]; assert data.getShape()[2] == 22 : data.getShape()[2]; assert data.getShape()[3] == 31 : data.getShape()[3]; // check axes for (CoordinateAxis axis : gcs_section.getCoordinateAxes()) { assert axis.getAxisType() != null; } } }
private void testGrid( GeoGrid grid) throws IOException, InvalidRangeException { assert null != grid; GridCoordSystem gcs = grid.getCoordinateSystem(); assert null != gcs; assert grid.getRank() == 4; Array data = grid.readDataSlice(0, -1, -1, -1); assert data.getRank() == 3; CoordinateAxis zaxis = gcs.getVerticalAxis(); assert data.getShape()[0] == zaxis.getSize() : zaxis.getSize(); CoordinateAxis yaxis = gcs.getYHorizAxis(); assert data.getShape()[1] == yaxis.getSize() : yaxis.getSize(); CoordinateAxis xaxis = gcs.getXHorizAxis(); assert data.getShape()[2] == xaxis.getSize() : xaxis.getSize(); VerticalTransform vt = gcs.getVerticalTransform(); assert vt != null; assert vt.getUnitString() != null; ucar.ma2.ArrayDouble.D3 vcoord = vt.getCoordinateArray(0); assert vcoord.getShape()[0] == zaxis.getSize() : vcoord.getShape()[0]; assert vcoord.getShape()[1] == yaxis.getSize() : vcoord.getShape()[1]; assert vcoord.getShape()[2] == xaxis.getSize() : vcoord.getShape()[2]; }